Compiling the viewer libraries (Mac OS X)

This page supplements Compiling the viewer (Mac OS X).
You can download, build, and install third party libraries with the following steps. It is assumed that you are on MacOS X 10.4 and using XCode 2.4.1.
= Preparation =
We recommend creating a separate third party library directory named 'lindenlib' on the same level as the 'linden' tree in your directory structure. Download, unpack, and build from there and copy the files specified to their final location.
 $ cd to linden libraries location
 $ mkdir lindenlib
A sample directory structure:
 Second_Life_Viewer
 linden
 LICENSE-libraries-mac.txt
 etc.
 lindenlib
 boost_1_33_0
 etc.
Most of the libs built here are architecture specific, so these instructions will refer to $PLATFORM to denote that. You can set an environment variable to make it so copy & paste from these instructions will work:
 $ export PLATFORM=`uname -p`-darwin
Building the Universal target requires that you have built both the i386 and ppc libraries. (Please see for more background information.)
Using gcc 4.0 on a ppc box when building many of these libraries will insert an undefined reference to _fprintf$LBDLStub which then fails to link later. Until we have a better solution to this issue, you will need to use an earlier version of gcc. Some of the instructions below will include a call to gcc_select which is only necessary if you are building on a ppc box.
= Boost =
Download & extract Boost source.
The viewer does not link to the boost libraries, so much of this is not necessary. You can simply copy the header files if you have problems getting the boost package to build.
== Copy the Headers ==
 $ cp -r lindenlib/boost_1_33_0/boost linden/libraries/include/boost
== Build Boost.Jam ==
 $ sudo gcc_select 4.0
 $ cd boost_1_33_0/tools/build/jam_src
 $ ./build.sh
 $ if [ $PLATFORM = "i386-darwin" ]; then PLATDIR=bin.macosxx86; else PLATDIR=bin.macosxppc; fi
 $ printenv PLATFORM (displays platform name)
 $ cp $PLATDIR/bjam ../../..
 $ unset PLATDIR
== Build Boost ==
 $ cd ../../../ (puts you into boost_1_33_0 directory)
 $ export PYTHON_ROOT=/System/Library/Frameworks/Python.framework/Versions/2.3/
 $ export PYTHON_VERSION=2.3
 $ ./bjam stage
== Copy the Libraries ==
 $ cd boost_1_33_0
 $ cp src/stage/lib/libboost_python-gcc.a libraries/$PLATFORM/lib_release
 $ cp src/stage/lib/libboost_python-gcc-d.a libraries/$PLATFORM/lib_debug/libboost_python-gcc.a
 $ cp src/stage/lib/libboost_python-gcc-mt.a libraries/$PLATFORM/lib_release
 $ cp src/stage/lib/libboost_python-gcc-mt-d.a libraries/$PLATFORM/lib_debug/libboost_python-gcc-mt.a
 $ cp src/stage/lib/libboost_regex-gcc.a libraries/$PLATFORM/lib_release
 $ cp src/stage/lib/libboost_regex-gcc-d.a libraries/$PLATFORM/lib_debug/libboost_regex-gcc.a
 $ cp src/stage/lib/libboost_regex-gcc-mt.a libraries/$PLATFORM/lib_release
 $ cp src/stage/lib/libboost_regex-gcc-mt-d.a libraries/$PLATFORM/lib_debug/libboost_regex-gcc-mt.a
= Apache Portable Runtime =
* Download & extract apr and apr-util.
* Build and install the headers and lib files using a terminal.
1.x viewers:
 $ sudo gcc_select 3.3
 (Note: sudo gcc_select 3.3 is used until your run XCode, so you don't have to keep selecting it in each section)
 $ cd lindenlib/apr-1.2.8
 $ ./configure --disable-shared --disable-lfs --prefix=/tmp/apr
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/apr/include/apr-1 linden/libraries/$PLATFORM/include
 $ cp /tmp/apr/lib/libapr-1.a linden/libraries/$PLATFORM/lib_release
 $ cp /tmp/apr/lib/libapr-1.a linden/libraries/$PLATFORM/lib_debug
 
 $ cd lindenlib/apr-util-1.2.8
 $ ./configure --disable-shared --disable-lfs --with-apr=/tmp/apr --prefix=/tmp/apr-util
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/apr-util/include/apr-1 linden/libraries/$PLATFORM/include
 $ cp /tmp/apr-util/lib/*.a linden/libraries/$PLATFORM/lib_release
 $ cp /tmp/apr-util/lib/*.a linden/libraries/$PLATFORM/lib_debug
2.x viewers:
 $ alias libtool='libtool -dynamic'
 $ cd lindenlib/apr-1.3.9
 $ ./configure --enable-shared --disable-lfs --prefix=/tmp/apr
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/apr/include/apr-1 linden/libraries/$PLATFORM/include
 $ cp /tmp/apr/lib/libapr-1.dylib linden/libraries/$PLATFORM/lib_release
 $ cp /tmp/apr/lib/libapr-1.dylib linden/libraries/$PLATFORM/lib_debug
 
 $ cd lindenlib/apr-util-1.3.9
 $ ./configure --with-apr=/tmp/apr --prefix=/tmp/apr-util
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/apr-util/include/apr-1 linden/libraries/$PLATFORM/include
 $ cp /tmp/apr-util/lib/*.dylib linden/libraries/$PLATFORM/lib_release
 $ cp /tmp/apr-util/lib/*.dylib linden/libraries/$PLATFORM/lib_debug
 $ unalias libtool
= zlib =
* Download and extract zlib.
* Build and install it.
 $ sudo gcc_select 3.3
 $ cd lindenlib/zlib-1.2.3
 $ ./configure --prefix=/tmp/zlib
 $ make
 $ make install
 $ cd ../..
 $ cp -Rp /tmp/zlib/include linden/libraries/include/zlib
 $ cp -p /tmp/zlib/lib/libz.a linden/libraries/$PLATFORM/lib_debug/libllz.a
 $ cp -p /tmp/zlib/lib/libz.a linden/libraries/$PLATFORM/lib_release/libllz.a
 
* Note that the library has a different name in the libraries directory.
= Expat =
* Download an extract the 1.95.8 version of expat.
* Build and install the library
 $ sudo gcc_select 3.3
 $ cd lindenlib/expat-1.95.8
 $ ./configure --prefix=/tmp/expat
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/expat/include linden/libraries/include/expat
1.x viewers:
 $ cp -p /tmp/expat/lib/libexpat.a linden/libraries/$PLATFORM/lib_release
 $ cp -p /tmp/expat/lib/libexpat.a linden/libraries/$PLATFORM/lib_debug
2.0 viewers:
 $ cp -p /tmp/expat/lib/libexpat.dylib linden/libraries/$PLATFORM/lib_debug
 $ cp -p /tmp/expat/lib/libexpat.dylib linden/libraries/$PLATFORM/lib_release
= pth =
* Download and extract GNU Portable Threads.
* Build and install the library
 $ cd lindenlib/pth-2.0.7
 $ ./configure -prefix=/tmp/pth
 $ make
 $ make install
 $ cd ../..
 $ mkdir linden/libraries/include/pth
 $ cp -p /tmp/pth/include/* linden/libraries/include/pth/
 $ cp -p /tmp/pth/lib/libpth.a linden/libraries/$PLATFORM/lib_release
 $ cp -p /tmp/pth/lib/libpth.a linden/libraries/$PLATFORM/lib_debug
= XMLRPC-epi =
* Download a source package for xmlrpc-epi.
* $ cd lindenlib/xmlrpc-epi-0.51 (save patches here and run here)
* Apply patch 1 and 2 from the instructions in patch xmlrpc-epi.
* Configure the project:
 $ sudo gcc_select 3.3
 $ ./configure --disable-shared --prefix=/tmp/xmlrpc-epi
* Apply patch 3 from the instructions in patch xmlrpc-epi.
* Finish the removal of expat, build, and install
 $ rm -rf expat
 $ mkdir expat
 $ cp /tmp/expat/include/* expat
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/xmlrpc-epi/include linden/libraries/include/xmlrpc-epi
 $ cp -p /tmp/xmlrpc-epi/lib/libxmlrpc.a linden/libraries/$PLATFORM/lib_release
 $ cp -p /tmp/xmlrpc-epi/lib/libxmlrpc.a linden/libraries/$PLATFORM/lib_debug
= JPEGlib =
* Download & extract jpeglib. You will minimally need jpegsrc.v6b.tar.gz.
* Build and install the library:
 $ sudo gcc_select 3.3
 $ cd jpeg-6b
 $ ./configure
 $ make
 $ cd ../..
 (if directory doesn't exist do: $ mkdir linden/libraries/include/jpeglib)
 $ cp lindenlib/jpeg-6b/jconfig.h linden/libraries/include/jpeglib
 $ cp lindenlib/jpeg-6b/jerror.h linden/libraries/include/jpeglib
 $ cp lindenlib/jpeg-6b/jinclude.h linden/libraries/include/jpeglib
 $ cp lindenlib/jpeg-6b/jmorecfg.h linden/libraries/include/jpeglib
 $ cp lindenlib/jpeg-6b/jpeglib.h linden/libraries/include/jpeglib
 $ cp lindenlib/jpeg-6b/libjpeg.a linden/libraries/$PLATFORM/lib_debug/liblljpeg.a
 $ cp lindenlib/jpeg-6b/libjpeg.a linden/libraries/$PLATFORM/lib_release/liblljpeg.a
* Note that the library has a different name in the libraries directory.
* If you plan to use the header file from windows, you will need to patch jpeglib using any terminal.
= OpenJPEG =
* Download and extract version 1.1.1 openjpeg source.
* Copy the linden openjpeg makefiles into the openjpeg source top level directory. We do this to maintain 10.3.9 compatibility.
* Build and install the library
 $ sudo gcc_select 3.3
 $ cd lindenlib/openjpeg
 (if directory does not exist do $ mkdir ../../linden/libraries/include/openjpeg)
 $ cp -p libopenjpeg/openjpeg.h ../../linden/libraries/include/openjpeg
 $ make -f Makefile-i386.ppc libopenjpeg.a
 $ cp libopenjpeg.a ../../linden/libraries/ppc-darwin/lib_debug
 $ cp libopenjpeg.a ../../linden/libraries/ppc-darwin/lib_release
 $ make -f Makefile-i386.ppc clean
 $ make -f Makefile-i386.osx libopenjpeg.a
 $ cp libopenjpeg.a ../../linden/libraries/i386-darwin/lib_debug
 $ cp libopenjpeg.a ../../linden/libraries/i386-darwin/lib_release
* 02-26-2007, another set of patches is required to Second Life to make it usable, that is fix a crash, make it look good, and speed it up. See https://jira.secondlife.com:443/browse/VWR-123
= Freetype =
* Download and extract FreeType.
* Build and install the FreeType library:
 $ sudo gcc_select 3.3
 $ cd lindenlib/freetype-2.2.1
 $ ./configure --prefix=/tmp/freetype
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/freetype/include/freetype2/freetype linden/libraries/include
 $ cp -p /tmp/freetype/include/ft2build.h linden/libraries/include
 $ cp -p /tmp/freetype/lib/libfreetype.a linden/libraries/$PLATFORM/lib_release
 $ cp -p /tmp/freetype/lib/libfreetype.a linden/libraries/$PLATFORM/lib_debug
= Vorbis & Ogg =
== Download files ==
* Download & extract libvorbis.
* Download & extract libogg.
== Build and copy ogg ==
* Build libogg first.
 $ sudo gcc_select 3.3
 $ cd lindenlib/libogg-1.1.3
 $ ./configure --prefix=/tmp/ogg
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/ogg/include/ogg linden/libraries/include
 $ cp -p /tmp/ogg/lib/libogg.a linden/libraries/$PLATFORM/lib_debug
 $ cp -p /tmp/ogg/lib/libogg.a linden/libraries/$PLATFORM/lib_release
== Build and copy vorbis ==
 $ sudo gcc_select 3.3
 $ cd lindenlib/libvorbis-1.1.2
 $ ./configure --prefix=/tmp/vorbis --with-ogg=/tmp/ogg
 $ make
 $ make install
 $ cd ../..
 $ cp -pR /tmp/vorbis/include/vorbis linden/libraries/include
 $ cp -p /tmp/vorbis/lib/libvorbis*.a linden/libraries/$PLATFORM/lib_debug
 $ cp -p /tmp/vorbis/lib/libvorbis*.a linden/libraries/$PLATFORM/lib_release
= CURL =
* Make a sub-directory in lindenlib called curl; cd into it
* Download libcurl; untar; rename the expanded tree src-curl
* Download c-ares; untar; rename the expanded tree src-c-ares
* Run the following commands (you may find it convenient to put this in a shell script file):
 #!/bin/sh
 
 BUILD_C_ARES=$PWD/build-c-ares
 BUILD_CURL=$PWD/build-curl
 
 mkdir build-c-ares || true
 mkdir build-curl || true
 
 case `arch` in
 (i386) export CFLAGS="-O2 -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk";;
 (ppc) export CFLAGS="-O2 -g -isysroot /Developer/SDKs/MacOSX10.3.9.sdk";;
 (*) echo "unknown architecture"; exit 1;;
 esac
 
 #export CFLAGS="$CFLAGS -arch i386 -arch ppc"
 #export LDFLAGS="-arch i386 -arch ppc"
 	# this won't work until we abandon 10.3.9
 
 cd src-c-ares
 ./configure --prefix=$BUILD_C_ARES --disable-dependency-tracking
 make clean
 make
 make install
 cd ..
 
 cd src-curl
 ./configure --prefix=$BUILD_CURL \
 --disable-dependency-tracking \
 	--disable-shared \
 	--enable-http \
 	--disable-ftp \
 	--disable-file \
 	--disable-ldap \
 	--disable-dict \
 	--disable-telnet \
 	--disable-tftp \
 	--disable-manual \
 	--disable-ipv6 \
 	--enable-nonblocking \
 	--enable-ares=$BUILD_C_ARES \
 	--enable-verbose \
 	--disable-cookies \
 	--without-libidn \
 	--with-ca-bundle=`curl-config --ca`
 make clean
 make
 make install -k
 	# because you won't be able to overwrite the ca-bundle in your system
 
 cd ..
 
 cp $BUILD_C_ARES/lib/libcares.a .
 cp $BUILD_CURL/lib/libcurl.a libllcurl.a
 # note the name change
 
 tar cvzf libs-curl-`arch`.tgz libcares.a libllcurl.a
* This builds a tar file called libs-curl-$PLATFORM.tgz
* Expand this tar file into linden/libraries/$PLATFORM-darwin/lib_release and linden/libraries/$PLATFORM-darwin/lib_debug
= TUT =
* Download tut into lindenlib
* Move it into a sub-directory, extract, and copy the headers
 $ cd lindenlab
 $ mkdir tut
 $ mv TUT-2006-11-04.tar.gz tut
 $ cd tut
 $ tar xvzf TUT-2006-11-04.tar.gz
* Patch TUT to add test skipping.
 $ cd ../..
 $ mkdir linden/libraries/include/tut
 $ cp -p lindenlib/tut/tut.h lindenlib/tut/tut_reporter.h lindenlib/tut/tut_restartable.h linden/libraries/include/tut
= Mozilla =
Download the llmozlib source tarball and extract it (it doesn't need to be in any particular place relative to the linden tree)
; Note : The llmozlib tarball is not currently linked from the main source download page. There's a link to it on the Source archive page.
== Build libxul from the mozilla source ==
If you have a multiprocessor machine, you may wish to enable parallel make for the mozilla build by adding the following line to llmozlib/build_mozilla/mac-universal-libxul-bits/mozconfig:
 mk_add_options MOZ_MAKE_FLAGS=-j4
I use -j4 on a 4-core machine. Adjust to taste.
Run the shell script that checks out the mozilla source, applies a few patches, configures and builds:
 $ cd llmozlib/build_mozilla
 $ ./mac-checkout_patch_build.sh
You'll have to answer a CVS password prompt immediately after starting the script (use password "anonymous"), but the rest should complete without any intevention.
This will take some time. I usually go for a cup of coffee or a nice dinner.
If the build completes without errors, you've got the hard part done.
== Copy headers and libraries needed to build llmozlib ==
 $ cd llmozlib
 $ ./copy_products_mac.sh
This copies certain of the headers and libraries created by the mozilla build into llmozlib/libraries. It also pulls the files needed by libxul at runtime into a .tgz file in the llmozlib directory.
After you've done this, you can safely delete the intermediate results created by step 1. These are:
 llmozlib/build_mozilla/mozilla/
 llmozlib/build_mozilla/objdir-mozilla-universal/
 llmozlib/build_mozilla/cvsco.log
== Build llmozlib ==
Open llmozlib/llmozlib.xcodeproj and build the "Release" configuration of the "llmozlib" target. 
There's a problem which sometimes causes XCode to not be able to find some of the mozilla headers the first time you build after a clean checkout or download of llmozlib. Close the project, re-open it, and build again and it should work.
Alternately, if you'd rather stay on the command line, you can do:
 $ cd llmozlib
 $ xcodebuild -project llmozlib.xcodeproj -target llmozlib -configuration Release build
== Copy build results into the linden tree ==
 $ cd llmozlib
 $ ./repackage_runtime_mac.sh ../path/to/linden/
This will copy the necessary libraries and runtime files to the linden source tree.
The argument to the script should be either a relative or absolute path to the root of the tree (i.e. the directory that contains 'indra').
Category:Compiling viewer