TOC
1. Introduction
2. Getting the source code
3. Install required libs
  3.1. Install Xcode
  3.2. Install MacPorts 1.7
4. How to compile and run
	4.1 Using XCode
	4.2 Using Command line
5. Packaging

-----------------------------------------------------------------------------
1. Introduction
-----------------------------------------------------------------------------

This is a platform port of XBMC for the Apple OSX operating system. Both 10.5
and 10.4 Intel development platforms are supported. The current build system
is Xcode 2.5 or Xcode 3.1.2 There are two ways to build XBMC for Mac.
1) command-line or
2) Xcode.

Generally, Xcode is the easiest as it presents the build system in a GUI environment.
The command-line build is still under development.

XBMC for Mac is composed of a main binary with numerous dynamic libraries and
codecs that support a multitude of music and video formats.

NOTE TO NEW OS X USERS: All lines that are prefixed with the '$' character are
commands that need to be typed into a Terminal window. Note that the '$'
character itself should NOT be typed as part of the command.


-----------------------------------------------------------------------------
2. Getting the source code
-----------------------------------------------------------------------------

 $ cd $HOME
 $ git clone git://github.com/xbmc/xbmc.git xbmc

-----------------------------------------------------------------------------
3.0 Install XCODE
-----------------------------------------------------------------------------
Install latest Xcode. You can download it from Apple's site after registration at
(http://developer.apple.com/tools/download). You also need to install the 10.4
sdk. If using Xcode 3.x, you MUST use Xcode 3.1.2 so update your existing version
if you are running a previous Xcode 3.x version. Xcode 3.x only runs on 10.5.


-----------------------------------------------------------------------------
3.1 Install MacPorts 1.7
-----------------------------------------------------------------------------

These build instructions depend on MacPorts 1.7.1 from xbmc-port-depends at 
http://code.google.com/p/xbmc-port-depends/ .
If you have another version of MacPorts installed, it's best to remove it and
install this 1.7.1 version. To remove a previous install of MacPorts, enter the
following from a terminal windows:

 $ sudo rm -rf \
    /opt/local \
    /etc/manpaths.d/macports \
    /etc/paths.d/macports \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0

Install MacPorts 1.7.1 (see http://code.google.com/p/xbmc-port-depends/). No NOT
install the versions from http://www.macports.org, they were hopelessly broke
for XBMC usage when their devs released MacPorts 1.8. Change MacPorts's behavior
to always build universal against 10.4sdk using the following instructions.

 1)
   $ sudo nano /opt/local/etc/macports/macports.conf
   a) change "universal_target	10.5" to "universal_target	10.4"

   b) change "universal_sysroot	/Developer/SDKs/MacOSX10.5.sdk" to
     "universal_sysroot	/Developer/SDKs/MacOSX10.4u.sdk"

   c) change "universal_archs         ppc i386"
     to reflect the arch you are building by removing the unused arch.

 2) These are needed to build openssl (used by samba3 and mysql5) against 10.4sdk
   $ sudo ln -s /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/dylib1.o /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/dylib1.10.5.o
   $ sudo ln -s /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/crt1.o /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/crt1.10.5.o


Then install the following port packages (order is very important):

 $ sudo port install pcre +universal
 $ sudo port install expat +universal
 $ sudo port install libiconv +universal
 $ sudo port install gettext +universal
 $ sudo port install libtool yasm cmake gmake pkgconfig

 $ sudo port install lzo +universal
 $ sudo port install lzo2 +universal
 $ sudo port install bzip2 +universal
 $ sudo port install fontconfig +universal
 $ sudo port install boost +universal

 $ sudo port install jpeg +universal
 $ sudo port install tiff +universal
 $ sudo port install libpng +universal
 $ sudo port install libogg +universal
 $ sudo port install libvorbis +universal
 $ sudo port install libmad macosx_deployment_target=10.4
 $ sudo port install fribidi +universal
 $ sudo port install wavpack +universal
 $ sudo port install libmpeg2 +no_sdl +no_x11 +universal

 $ sudo port install glew +universal
 $ sudo port install libcdio +universal
 $ sudo port install openssl +universal
 $ sudo port install libssh2 +universal
 $ sudo port install samba3 macosx_deployment_target=10.4
 $ sudo port install mysql5 +universal
 $ sudo port install sqlite3 +universal
 $ sudo port install libsamplerate +universal

 $ sudo port install libsdl +no_x11 +universal
 $ sudo port install smpeg +universal
 $ sudo port install libsdl_mixer +universal
 $ sudo port install libsdl_image +universal

If you understand the following two lines, you can run it to automate
the installation of the ports in the above order:

  sudo bash
  perl -ne 'print `port install $1` if /^ \$ sudo port install (.*)$/;' README.osx

Finally, fix the mysql package default install location with this symlink:

 $ sudo ln -s /opt/local/include/mysql5/mysql/ /opt/local/include/mysql

-----------------------------------------------------------------------------
4. How to compile
-----------------------------------------------------------------------------
Both Xcode and Terminal compilation require that build environment be setup
first. This is a simple step and involves the following:

 $ cd $HOME/XBMC
 $ ./bootstrap
 $ make -C lib/librtmp
 $ sudo make -C lib/librtmp install
 $ ./configure
 $ make clean
 $ make xcode_depends
 $ make -C lib/addons/script.module.pil
 $ make -C lib/addons/script.module.pysqlite
 $ sh lib/librtmp/darwin_package_librtmp.sh

The configure operation will setup the build environment for codecs and
internal libraries that are used by XBMC. This step is required for both Xcode
and command-line building. The "make clean" ensures that there are no stale
binaries from git that might cause problems. The last step will pre-build
the majority of the codecs and libs:


The configure operation will default to building "debug". To build "release"
codecs and libraries for Xcode, do the configure step with "--disable-debug"
but remember that Xcode will need to be also built "Release":

 $ ./configure --disable-debug

-----------------------------------------------------------------------------
4.1 Using Xcode
-----------------------------------------------------------------------------
Start XCode and open the XBMC project (XBMC.xcodeproj) located in $HOME/XBMC.
For development, XBMC is run from the $HOME/XBMC directory and needs to have
the XBMC_HOME environment variable set to know where that directory is located.
To set XBMC_HOME environment variable:

Menu -> Project -> Edit Active Executable "XBMC", click "Arguments" tab and
add "XBMC_HOME" as an enviroment variable. Set the value to the path to the
XBMC root folder. For example, "/Users/bigdog/Documents/XBMC"

There are two build targets "XBMC" and "XBMC.app" with debug and release
settings. The "XBMC" target is used for rapid build and debug cycles while
the "XBMC.app" target is used to build a self contained OSX application.

Set the build target to "XBMC" or "XBMC.app", then build. The build process
will take a long time when builting the first time. You can see the progress
in "Build Results". There are a large number of static and dynamic libaries
that will need to be built. Once these are built, subsequent builds will be
faster.

After the build, you can ether run XBMC for Mac from Xcode or run it from
the command-line. If you run it from the command-line, make sure your set
the XBMC_HOME environment variable (export XBMC_HOME=$HOME/XBMC). Then, to
run the debug version:

$ ./build/Debug/XBMC

Or the release version:

$ ./build/Release/XBMC

You can also build via Xcode from the command-line using the following:

$ xcodebuild -configuration Release -target "XBMC.app" -project XBMC.xcodeproj

You can specify "Release" instead of "Debug" as a configuration.

-----------------------------------------------------------------------------
4.2 Using Terminal (command-line) (this is a work in progress and might fail)
-----------------------------------------------------------------------------
There are two methods, a) make/Xcode and b) make (which might fail as it's under
construction).

If you want to build a cross-compiled version that can run under 10.5/10.4/AppleTV, 
then you'll need to follow the additional steps listed in $HOME/XBMC/tools/XBMCTex/README.osx
before running xcodebuild from the command-line.

 a)
 $ cd $HOME/XBMC
 $ export XBMC_HOME=`pwd`
 $ make xcode_depends
 $ make -C lib/addons/script.module.pil
 $ make -C lib/addons/script.module.pysqlite
 $ sh lib/librtmp/darwin_package_librtmp.sh
 $ xcodebuild -sdk macosx10.4 -project XBMC.xcodeproj -target XBMC.app -configuration Release build

 b)
 $ cd $HOME/XBMC
 $ export XBMC_HOME=`pwd`
 $ make xbmc
 $ ./xbmc.bin

-----------------------------------------------------------------------------
5. Packaging
-----------------------------------------------------------------------------
This section describes how to package XBMC in a disk image for
distribution.

  1. build XBMC.app from XCode so that the application bundle is correctly updated.

  2. make -C tools/PackageMaker/

  3. If completed successfully, a disk image named XBMC_for_Mac.dmg will be
  present in the users XBMC build directory:

Remember to unmount/eject XBMC.dmg before attempting to recreate it,
otherwise dmgmaker.pl will fail.
