<?xml version="1.0" encoding="utf-8"?>
<section version="5.0"
         xsi:schemaLocation="http://docbook.org/ns/docbook http://docbook.org/xml/5.0/xsd/docbook.xsd"
         xml:id="development.build_macosx" xmlns="http://docbook.org/ns/docbook"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:ns="http://docbook.org/ns/docbook">
  <title>Building OVITO on MacOS</title>

 <simplesect>
    <title>Installing dependencies</title>
    <para>
    See the <link linkend="development.requirements">list of requirements</link>
    and install the required build tools and third-party libraries. OVITO should be compiled with
    Apple's Clang compiler that is shipped with Xcode.
    It's easiest to use <link xlink:href="https://www.macports.org/">MacPorts</link> to install many of the required dependencies.
    After installing MacPorts, run 
<screen><command>sudo port install netcdf python35 py35-sphinx py35-numpy py35-sip zlib \
                  boost cmake docbook-xml doxygen libxslt yasm
</command></screen>
  </para>
  <para>
    Download and install <link xlink:href="http://www.qt.io/download/">Qt 5.x for Mac</link>.
  </para>
  <para>
    Download and install <link xlink:href="http://www.riverbankcomputing.com/software/pyqt/download5">PyQt5</link>. 
    Adjust the path to Qt's <command>qmake</command> below as needed:
<screen><command>/opt/local/bin/python3.5 configure.py \
	--qmake $HOME/Qt/5.7/clang_64/bin/qmake \
	--confirm-license \
	--no-designer-plugin \
	--no-qml-plugin \
	--assume-shared \
	--sip=/opt/local/bin/sip-3.5 \
	--concatenate \
	--enable QtCore \
	--enable QtGui \
	--enable QtWidgets \
	--enable QtMacExtras
make -j2
sudo make install
</command></screen>
  </para>
  <para>
    Download and install <link xlink:href="http://www.riverbankcomputing.com/software/qscintilla/download">QScintilla2</link>. Adjust the path to <command>qmake</command> below as needed:
<screen><command>
cd QScintilla_gpl-2.9.3/Qt4Qt5/
$HOME/Qt/5.7/clang_64/bin/qmake qscintilla.pro
make -j2
install_name_tool -id $PWD/libqscintilla2.dylib libqscintilla2.dylib
</command></screen>
  </para>
  <para>
Download and build a static version of the <emphasis>Libav</emphasis> video encoding library:
<screen><command>
wget https://libav.org/releases/libav-11.1.tar.gz
tar xzfv libav-11.1.tar.gz
cd libav-11.1
./configure \
	--disable-network \
	--disable-programs \
	--disable-debug \
	--disable-doc \
	--disable-filters \
	--enable-gpl \
	--prefix=$HOME/libavstatic
make install
</command></screen>
The compiled libraries will be installed under <filename>$HOME/libavstatic/</filename>.
  </para>
  </simplesect>

 <simplesect>
    <title>Downloading the source code</title>
    <para>
    To download OVITO's source code into a new subdirectory named <filename>ovito</filename>, run: 
<screen><command>git clone https://gitlab.com/stuko/ovito.git ovito</command></screen>
  </para>
  </simplesect>

  <simplesect>
    <title>Compiling OVITO</title>
    <para>
    Within that directory, create a build directory and let CMake generate the Makefile: 
<screen>
<command>cd ovito
mkdir build
cd build
cmake -DOVITO_BUILD_DOCUMENTATION=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=../install \
      -DCMAKE_PREFIX_PATH=$HOME/Qt/5.7/clang_64/ \
      -DPYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m \
      -DPYTHON_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib \
      -DLIBAV_INCLUDE_DIR=$HOME/libavstatic/include \
      -DLIBAV_LIBRARY_DIR=$HOME/libavstatic/lib \
      -DSPHINX_PROCESSOR=/opt/local/bin/sphinx-build-3.5 \
      -DQSCINTILLA_INCLUDE_DIR=$HOME/QScintilla_gpl-2.9.3/Qt4Qt5 \
      -DQSCINTILLA_LIBRARY=$HOME/QScintilla_gpl-2.9.3/Qt4Qt5/libqscintilla2.dylib \
      ..
</command></screen>
  </para>
  <para>
    Adjust the paths above as needed.
    If this step fails, or if you want to disable individual components of OVITO, you can now run "<command>ccmake .</command>" to open the CMake configuration program.    
    Finally build OVITO by running 
<screen>
<command>make -j4</command></screen>
  </para>
  <para>
    If this succeeds, you can run <command>make install</command> to create a distributable app bundle in <filename>ovito/install/</filename>, which contains all dependencies.
  </para>
  </simplesect>
  
</section>
