                                 +++++++++++++++++++++++
                                MAC OSX BUILD WALKTHROUGH
                                 +++++++++++++++++++++++

                                     Mark Liversedge

                                        Nov 2011
                                      Version 1.1

A walkthrough of building GoldenCheetah from scratch on Mac OSX. This was performed
on Mac OSX Lion (10.7) but the instructions are largely the same for all versions of
Mac OS X.

CONTENTS

1. BASIC INSTALLATION WITH MANDATORY DEPENDENCIES
   - Xcode
   - Qt

2. ADDING OPTIONAL DEPENDENCIES
   - FTDI D2XX
   - SRMIO
   - liboauth
   - QwtPlot3d
   - libkml
   - libusb
   - libical
   - libclucene


1. BASIC INSTALLATION WITH MANDATORY DEPENDENCIES
=================================================

Depending upon the speed of your internet connection and availability of the
required software the steps in section 1 will take approximately 1 hour.

1.1 Ensure OS X is up-to-date
-----------------------------

Make sure you have applied all the latest updates to Mac OS X. This can be
found from the system menu, apple, about this mac, software update.

This walkthrough was performed on an iMac running 10.7.2 (Lion)

1.2 Install XCode from App Store
--------------------------------

If you are building on 10.6 or higher you should install Xcode4, for earlier
releases you will need Xcode 3.1.4. If you have capable hardware you should
consider upgrading to Lion to get the latest bug fixes and capabilities.

To install Xcode on Lion you need to download it via the App Store. You can
launch the App Store from launchpad, or it may be already in your dock.

Under the search box type in Xcode and it will return a few optios, generally
Xcode is the first item and shows a blueprint with a hammer icon. Click on
this to install it. It should be free. The usual app store process will apply
as the application is downloaded and installed. The download is about 2GB
so do bear this in mind if you have limits on your internet bandwidth or cap.

1.3 Run the Xcode installer
---------------------------

The app store download will have added an Install Xcode icon in the launchpad.
Go ahead and run it.

Xcode includes all the development tools such as a compiler, debugger and
SDKs. It also installs the 'git' tool for working with Git repositories.

It will run through a wizard to install, just read and then accept the license
agreement and let it get on with it. If you don't like the license then quit
and use the development builds from goldencheetah.stand2surtf.net.

You may find it borks at iTunes helper running, you will
need to force quit the iTunes helper via Finder, Applications, Utilities,
Activity Monitor if this happens.

1.4 Get the source code
-----------------------

We store all the Golden Cheetah source code on github.com, it is a great
site holding repositories for many open source projects. 

First open up a terminal session, then;

$ cd
$ mkdir Projects
$ cd Projects
$ git clone git://github.com/GoldenCheetah/GoldenCheetah.git

You will now have the GoldenCheetah sources downloaded into a 'GoldenCheetah'
directory in your home directory, under another folder called 'Projects'.

$ cd GoldenCheetah
$ ls

You should see a number of directories such as doc, qwt, src etc. If you are
building the latest development release you may need to check it out. At the
time of writing the latest development release is release_3.0.0dev, if you
want to build version 3 then you should perform the next command, otherwise 
skip to 1.5.

$ checkout release_3.0.0dev
$ ls

You will now see an updated version of this walkthrough, please jump to using
that since it may be more up-to-date than this walkthrough (depending upon
where you got it from of course!).

1.5 Install the QT SDK
----------------------

GoldenCheetah is developed using the Nokia QT toolkit, it is large and will
need to be downloaded and installed from their website. Alternatively, you 
can intall qt via macports (http://www.macports.org) as described in section 
1.5.1. 

As of today, the latest stable release is 4.7.4, we need 4.7 or higher so
go ahead and download the offline installer - it has everything you need
but is about 1.3GB. Please make sure you download the installer for Mac
OS X 10.6 or later, 64-bit.

The url for QT downloads is: http://qt.nokia.com/downloads and whilst the
offline installer is only 12mb it will still call back and download the
required objects as you install, I think it is better to get it all in
one hit (and you can save it to reinstall on another computer or if you
want to rebuild/reinstall for any other reason).

Once the QT SDK is downloaded you will have a .dmg (disk image) that you
need to mount by double clicking on it. You will then get a volume mounted
and shown on your desktop. Go ahead and double click that to start the install
process. It is probably called something like 'Qt SDK Installer'.

It will popup with a dialog warning that this is downloaded from the internet
and are you sure you want to open it? Go ahead and click Open.

A wizard will now guide you through the QT install process. Go ahead and accept
all the defaults, it will install in your home directory and avoid updating the
system directories, this means you are less likely to bork your Mac OSX installation.

Read and accept the license agreement and then continue and install.

We need to make sure that a program called qmake is installed in a directory where
it can be found. So, we need to create a link from what we just installed in the
user programs folder. For QT SDK1.1 (4.7.4) we need to:

$ sudo ln -s ~/QtSDK/Desktop/Qt/474/gcc/bin/qmake /usr/bin/qmake

1.5.1 Install via Mac Ports
---------------------------

If you have macports installed, you can install the qt dependices 
with the following commands: 

$ sudo port install qt4-mac
$ sudo port install qt4-mac-sqlite3-plugin

1.6 DEPRECATED
--------------

No longer need this step (install boost)

1.7 Configure and Build GoldenCheetah (with no optional dependencies)
---------------------------------------------------------------------

First thing we need to do is set the build configuration, this means editing the
private build profile settings. There is one for qwt (a charting library) and
there is another for GoldenCheetah itself.

$ cd ~/Projects/GoldenCheetah/qwt
$ cp qwtconfig.pri.in qwtconfig.pri
$ cd ../src
$ cp gcconfig.pri.in gcconfig.pri
$ vi gcconfig.pri 

In that last step you can use whatever editor you feel most comfortable with.

For now we will comment out some of the dependencies we have not installed
support for yet:

#SRMIO_INSTALL = /usr/local/srmio
#D2XX_INCLUDE = /usr/local/include/D2XX

we may need to additionally configure to use the local compression
libraries (at least I did), by adding the following line:

LIBS += -lz

Lastly, since we are on Lion, we can also uncomment and change the following line:

DEFINES += GC_HAVE_LION

Once the changes have been made we are now ready to build for the first time. You
may notice a lot of warning messages about the version of O/S not being supported.
This is because QT does not officially support Lion at this point in time (but it
does work). You can either ignore the warning messages or (like me) go and edit out
the warning (once you have seen the message once you don't need reminding every
time you compile).

To do this, edit the file in question as an administrator:

$ sudo vi ~/QtSDK/Desktop/Qt/474/gcc/include/QtCore/qglobal.h

And comment out line 320 (or thereabouts):

//#    warning "This version of Mac OS X is unsupported"

Once this is done you can kick off the build:

$ cd .. #this should put you in the top level dir containing this file
$ qmake -recursive
$ make

If make fails to find a Makefile then qmake is configured, by default, to create
an xcode project file. You will need to change the qmake command above to tell it
to create a makefile with the following:
$ qmake -spec macx-g++ -recursive
$ make

Once this completes you will have a GoldenCheetah.app in the src directory which
can be launched:

$ open src/GoldenCheetah.app

And you're up and running.

2. ADDING OPTIONAL DEPENDENCIES
===============================

   - SRMIO
   - liboauth
   - QwtPlot3d
   - libkml
   - libusb
   - libical

Since these optional dependencies are more complex and require more advanced
technical skills we do not provide a walkthrough for building them all but
instead provide the configure settings and any special considerations that
should be taken into account.

2.1 SRMIO - For working with PC 5/6/7
-------------------------------------

SRMIO (git)
./configure CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64" CPPFLAGS=-I/usr/local/D2XX/ --disable-dependency-tracking

2.2 Liboauth - For Twitter support
----------------------------------

oauth (0.8.8)

./configure CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64 CURL_CFLAGS="-I/Developer/SDKs/MacOSX10.7.sdk/usr/include/curl"  CURL_LIBS="-lcurl" --disable-dependency-tracking

2.3 QwtPlot3d - For 3d plot support
-----------------------------------

qwtplot3d (maintain_0_2_x)

Add the following to qwtplot3d.pro:
CONFIG += x86_64 static
QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.7.sdk

2.4 libkml - For export to Google Earth
---------------------------------------

expat (2.0.1)
./configure CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64" --disable-dependency-tracking 

libkml (pulled down from the svn repo)

./configure CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64" --disable-dependency-tracking --with-expat-include-dir=/usr/local/include --with-expat-lib-dir=/usr/local/lib --disable-swig CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64"

note: the added CXXFLAGS helped clear the -Werror flag that stopped compilation.

2.5 libusb - For Garmin USB2 stick support
------------------------------------------

libusb (0.1.12)

To compile on OSX you need to apply the patch here:
https://trac.macports.org/browser/trunk/dports/devel/libusb-legacy/files?rev=97840

Then:
./configure --prefix=/opt/libusb/ CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" --disable-dependency-tracking
then 
sed -i 'bak' 's|CC -dynamiclib|CC -dynamiclib -arch x86_64|g' libtool
make
make install

note: that the sed line updates some commands in libtool.  not sure why the arch clags are not getting passed.  

2.6 libical
-----------

libical (0.46)
first run autogen.sh
then
./configure CFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -arch x86_64" --disable-dependency-tracking

2.7 clucene
-----------

DO NOT USE THE MACPORTS VERSION (0.9.23) IT DOES NOT WORK.

git clone git://clucene.git.sourceforge.net/gitroot/clucene/clucene 
cmake -G "Unix Makefiles"
make
sudo make install

will install clucene into /usr/local/include/clucene and /usr/local/lib
