%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2003-2018 by The University of Queensland
% http://www.uq.edu.au
%
% Primary Business: Queensland, Australia
% Licensed under the Apache License, version 2.0
% http://www.apache.org/licenses/LICENSE-2.0
%
% Development until 2012 by Earth Systems Science Computational Center (ESSCC)
% Development 2012-2013 by School of Earth Sciences
% Development from 2014 by Centre for Geoscience Computing (GeoComp)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Installing from source for \macosx}
\label{sec:srcmac}

Before you start installing from source you will need \macosx development tools installed on your Mac.
This will ensure that you have the following available:
\begin{itemize}
\item \file{g++} and associated tools.
\item \file{make}
\end{itemize}

Here are the instructions on how to install these.
\begin{enumerate}
\item Insert the \macosx 10.5 (Leopard) DVD
\item Double-click on XcodeTools.mpkg, located inside Optional Installs/Xcode Tools
\item Follow the instructions in the Installer
\item Authenticate as the administrative user (the first user you create when setting up \macosx has administrator privileges by default)
\end{enumerate}


Once these tools have been installed, follow the linux instructions in Section~\ref{sec:prelim}.
If you do not know how to open a terminal on Mac, then just type terminal in the spotlight (search tool on the top of the right corner) and once found just click on it.

% You will also need a copy of the \esfinley source code.
% If you retrieved the source using subversion, don't forget that one can use the export command instead of checkout to get a smaller copy.
% For additional visualization functionality see Section~\ref{sec:addfunc}.
% 
% These instructions will produce the following directory structure:
% \begin{itemize}
%  \item[] \file{stand}: \begin{itemize}
%   \item[] \file{escript.d}
%   \item[] \file{pkg}
%   \item[] \file{pkg_src}
%   \item[] \file{build}
%   \item[] \file{doc}
%  \end{itemize}
% \end{itemize}
% 
% The following instructions assume you are running the \file{bash} shell.
% Comments are indicated with \# characters. 
% 
% Open a terminal~\footnote{If you do not know how to open a terminal on Mac, then just type terminal in the spotlight (search tool on the top of the right corner) and once found just click on it.} and type
% 
% \begin{shellCode}
% mkdir stand
% cd stand
% export PKG_ROOT=`pwd`/pkg
% \end{shellCode}
% 
% Copy compressed source bundles into \file{stand/package_src}.
% Copy documentation files into \file{doc}.
% 
% \begin{shellCode}
% mkdir packages
% mkdir build
% cd build
% tar -jxf ../pkg_src/Python-2.6.2.tar.bz2
% tar -jxf ../pkg_src/boost_1_39_0.tar.bz2
% tar -zxf ../pkg_src/scons-1.2.0.tar.gz
% tar -zxf ../pkg_src/numpy-1.3.0.tar.gz
% tar -zxf ../pkg_src/netcdf-4.0.tar.gz
% tar -zxf ../pkg_src/matplotlib-0.98.5.3.tar.gz
% \end{shellCode}
% 
% \begin{itemize}
% 
% \item Build python:
% \begin{shellCode}
% cd Python*
% ./configure --prefix=$PKG_ROOT/python-2.6.2 --enable-shared 2>&1 \
%   | tee tt.configure.out
% make 
% make install 2>&1 | tee tt.make.out
% 
% cd ..
% 
% export PATH=$PKG_ROOT/python/bin:$PATH
% export PYTHONHOME=$PKG_ROOT/python
% export LD_LIBRARY_PATH=$PKG_ROOT/python/lib:$LD_LIBRARY_PATH
% 
% pushd ../pkg
% ln -s python-2.6.2/ python
% popd
% \end{shellCode}
% 
% Run the new python executable to make sure it works.
% 
% \item Now build NumPy:
% \begin{shellCode}
% cd numpy-1.3.0
% python setup.py build
% python setup.py install --prefix $PKG_ROOT/numpy-1.3.0
% cd ..
% pushd ../pkg
% ln -s numpy-1.3.0 numpy
% popd
% export PYTHONPATH=$PKG_ROOT/numpy/lib/python2.6/site-packages:$PYTHONPATH
% \end{shellCode}
% 
% \item Next build scons:
% \begin{shellCode}
% cd scons-1.2.0
% python setup.py install --prefix=$PKG_ROOT/scons-1.2.0
% 
% export PATH=$PKG_ROOT/scons/bin:$PATH
% cd ..
% pushd ../pkg
% ln -s scons-1.2.0 scons
% popd
% \end{shellCode}
% 
% \item The Boost libraries...:
% \begin{shellCode}
% pushd ../pkg
% mkdir boost_1_39_0
% ln -s boost_1_39_0 boost
% popd
% cd boost_1_39_0
% ./bootstrap.sh --with-libraries=python --prefix=$PKG_ROOT/boost
% ./bjam
% ./bjam install --prefix=$PKG_ROOT/boost --libdir=$PKG_ROOT/boost/lib
% export LD_LIBRARY_PATH=$PKG_ROOT/boost/lib:$LD_LIBRARY_PATH
% cd ..
% pushd ../pkg/boost/lib/
% ln -s libboost_python*-1_39.dylib libboost_python.dylib
% popd
% \end{shellCode}
% 
% \item ...and NetCDF:
% \begin{shellCode}
% cd netcdf-4.0
% CFLAGS="-O2 -fPIC -Df2cFortran" CXXFLAGS="-O2 -fPIC -Df2cFortran" \
% FFLAGS="-O2 -fPIC -Df2cFortran" FCFLAGS="-O2 -fPIC -Df2cFortran" \
% ./configure --prefix=$PKG_ROOT/netcdf-4.0
% 
% make 
% make install
% 
% export LD_LIBRARY_PATH=$PKG_ROOT/netcdf/lib:$LD_LIBRARY_PATH
% cd ..
% pushd ../pkg
% ln -s netcdf-4.0 netcdf
% popd
% \end{shellCode}
% 
% \item Finally matplotlib:
% \begin{shellCode}
% cd matplotlib-0.98.5.3
% python setup.py build
% python setup.py install --prefix=$PKG_ROOT/matplotlib-0.98.5.3
% cd ..
% pushd ../pkg
% ln -s matplotlib-0.98.5.3 matplotlib
% popd
% cd ..
% \end{shellCode}
% \end{itemize}
% 
% \subsection{Compiling escript}\label{sec:compileescriptmac}
% 
% Change to the directory containing your escript source (\file{stand/escript.d}), then:
% 
% \begin{shellCode}
% cd escript.d/scons
% cp TEMPLATE_linux.py YourMachineName_options.py
% 
% echo $PKG_ROOT
% \end{shellCode}
% 
% Edit the options file and put the value of PKG_ROOT between the quotes in the PKG_ROOT= line.
% For example:
% \begin{shellCode}
% PKG_ROOT="/Users/bob/stand/pkg"
% \end{shellCode}
% 
% \begin{shellCode}
% cd ../bin
% \end{shellCode}
% 
% Modify the STANDALONE line of \file{escript} to read:
%  
% STANDALONE=1
% 
% Start a new terminal and go to the \file{stand} directory.
% 
% \begin{shellCode}
% export PATH=$(pwd)/pkg/scons/bin:$PATH
% cd escript.d
% eval $(bin/run-escript -e)
% scons
% \end{shellCode}
% 
% If you wish to test your build, then you can do the following. 
% Note this may take a while if you have a slow processor and/or less than 1GB of RAM.
% \begin{shellCode}
% scons all_tests
% \end{shellCode}
% 
% Once you are satisfied, the \file{build} and \file{\$PKG_ROOT/build} directories can be removed.
% Within the \file{packages} directory, the \file{scons}, \file{scons-1.2.0} entries can also be removed.
% If you are not redistributing this bundle you can remove \file{\$PKG_ROOT/package_src}.
% 
% If you do not plan to edit or recompile the source you can remove it.
% The only entries which are required in \file{escript.d} are:
% \begin{itemize}
%  \item \file{bin}
%  \item \file{esys}
%  \item \file{include}
%  \item \file{lib}
%  \item \file{README_LICENSE}
% \end{itemize}
% 
% Hidden files can be removed with
% \begin{shellCode}
% find . -name '.?*' | xargs rm -rf
% \end{shellCode}


