Ticket #1112: build-osx-libs.3.sh

File build-osx-libs.3.sh, 10.6 KB (added by historic_bruno, 12 years ago)
Line 
1#!/bin/bash
2#
3# Script for acquiring and building OSX dependencies for 0 A.D.
4#
5# The script checks whether a source tarball exists for each
6# dependency, if not it will download the correct version from
7# the project's website, then it removes previous temp files,
8# extracts the tarball, configures and builds the lib. The script
9# should die on any errors to ease troubleshooting.
10#
11# make install is used to copy the compiled libs to each specific
12# directory and also the config tools (e.g. sdl-config). Because
13# of this, every developer must run this script at least once,
14# to configure the correct lib directories. It must be run again
15# if the libraries are moved.
16#
17# Building against an SDK is an option, though not required,
18# as not all build environments contain the Developer SDKs.
19# (Xcode does, but the Command Line Tools package does not)
20#
21
22set -e
23
24die()
25{
26 echo ERROR: $*
27 exit 1
28}
29
30download_lib()
31{
32 local url=$1
33 local filename=$2
34
35 if [ ! -e $filename ]; then
36 echo "Downloading $filename"
37 curl -L -O ${url}${filename} || die "Download of $url$filename failed"
38 fi
39}
40
41JOBS=${JOBS:="-j5"}
42
43# Force build architecture, as sometimes configure is broken.
44# Using multiple values would in theory produce a "universal"
45# or fat binary, but this is untested.
46# Choices are: x86_64 i386 (ppc and ppc64 not supported)
47ARCH="x86_64"
48
49# Define compiler as GCC (in case anything expects e.g. gcc-4.2)
50export CC=${CC:="gcc"} CXX=${CXX:="g++"}
51
52# The various libs offer inconsistent configure options, some allow
53# setting sysroot and OSX-specific options, others don't. Adding to
54# the confusion, Apple moved /Developer/SDKs into the Xcode app bundle
55# so the path can't be guessed by clever build tools (like Boost.Build).
56# Sometimes configure gets it wrong anyway, especially on cross compiles.
57# This is why we prefer using CFLAGS, CPPFLAGS, and LDFLAGS.
58
59# Check if SYSROOT is set and not empty
60if [[ $SYSROOT && ${SYSROOT-_} ]]; then
61 CFLAGS="$CFLAGS -isysroot $SYSROOT"
62 LDFLAGS="$LDFLAGS -Wl,-syslibroot,$SYSROOT"
63fi
64# Check if MIN_OSX_VERSION is set and not empty
65if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
66 CFLAGS="$CFLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
67 LDFLAGS="$LDFLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
68fi
69CFLAGS="$CFLAGS -arch $ARCH"
70CPPFLAGS="$CPPFLAGS $CFLAGS"
71LDFLAGS="$LDFLAGS -arch $ARCH"
72
73cd "$(dirname $0)"
74# Now in libraries/osx/ (where we assume this script resides)
75
76# TODO: Do we really want to rebuild these every time?
77
78# ---------------------------------------------------
79echo -e "\nBuilding SDL...\n"
80
81# SDL 1.2.15 required for Lion support
82LIB_VERSION="SDL-1.2.15"
83LIB_ARCHIVE="$LIB_VERSION.tar.gz"
84LIB_DIRECTORY=$LIB_VERSION
85LIB_URL="http://www.libsdl.org/release/"
86
87mkdir -p sdl
88cd sdl
89
90INSTALL_DIR="$(pwd)"
91
92download_lib $LIB_URL $LIB_ARCHIVE
93
94rm -rf $LIB_DIRECTORY
95tar -xf $LIB_ARCHIVE
96cd $LIB_DIRECTORY
97
98(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no && make $JOBS && make install) || die "SDL build failed"
99
100cd ../../
101
102# ---------------------------------------------------
103echo -e "\nBuilding Boost...\n"
104
105LIB_VERSION="boost_1_49_0"
106LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
107LIB_DIRECTORY="$LIB_VERSION"
108LIB_URL="http://download.sourceforge.net/boost/"
109
110mkdir -p boost
111cd boost
112
113INSTALL_DIR="$(pwd)"
114
115download_lib $LIB_URL $LIB_ARCHIVE
116
117rm -rf $LIB_DIRECTORY
118tar -xf $LIB_ARCHIVE
119cd $LIB_DIRECTORY
120
121# Can't use macosx-version, see above comment.
122(./bootstrap.sh --with-libraries=filesystem,system,signals --prefix=$INSTALL_DIR && ./b2 cflags="$CFLAGS" cxxflags="$CPPFLAGS" linkflags="$LDFLAGS" -d2 --layout=tagged --debug-configuration link=static threading=multi variant=release,debug install) || die "Boost build failed"
123
124# Copy files
125cd ../../
126
127# ---------------------------------------------------
128echo -e "\nBuilding wxWidgets...\n"
129
130# wxWidgets is required for Atlas
131# version 2.9+ is necessary for 64-bit OSX build
132# with OpenGL support
133# TODO: This build takes ages, anything we can exlude?
134
135LIB_VERSION="wxWidgets-2.9.3"
136LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
137LIB_DIRECTORY="$LIB_VERSION"
138LIB_URL="http://download.sourceforge.net/wxwindows/"
139
140mkdir -p wxwidgets
141cd wxwidgets
142
143INSTALL_DIR="$(pwd)"
144
145download_lib $LIB_URL $LIB_ARCHIVE
146
147rm -rf $LIB_DIRECTORY
148tar -xf $LIB_ARCHIVE
149cd $LIB_DIRECTORY
150
151mkdir -p build-release
152cd build-release
153
154(../configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix=$INSTALL_DIR --disable-shared --enable-unicode --with-cocoa --with-opengl && make $JOBS && make install) || die "wxWidgets build failed"
155
156cd ../../../
157
158# ---------------------------------------------------
159echo -e "\nBuilding libjpg...\n"
160
161LIB_VERSION="jpegsrc.v8c"
162LIB_ARCHIVE="$LIB_VERSION.tar.gz"
163LIB_DIRECTORY="jpeg-8c"
164LIB_URL="http://www.ijg.org/files/"
165
166mkdir -p libjpg
167cd libjpg
168
169INSTALL_DIR="$(pwd)"
170
171download_lib $LIB_URL $LIB_ARCHIVE
172
173rm -rf $LIB_DIRECTORY
174tar -xf $LIB_ARCHIVE
175cd $LIB_DIRECTORY
176
177(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix=$INSTALL_DIR --enable-shared=no && make $JOBS && make install) || die "libjpg build failed"
178
179cd ../../
180
181# ---------------------------------------------------
182echo -e "\nBuilding libpng...\n"
183
184# Even though libpng is provided in the SDK, the 10.6 bundled version
185# is the ancient 1.2 which lacks functions we use like
186# png_set_longjmp_fn, so it seems better to provide it ourselves
187
188LIB_VERSION="libpng-1.5.8"
189LIB_ARCHIVE="$LIB_VERSION.tar.gz"
190LIB_DIRECTORY="$LIB_VERSION"
191LIB_URL="http://download.sourceforge.net/libpng/"
192
193mkdir -p libpng
194cd libpng
195
196INSTALL_DIR="$(pwd)"
197
198download_lib $LIB_URL $LIB_ARCHIVE
199
200rm -rf $LIB_DIRECTORY
201tar -xf $LIB_ARCHIVE
202cd $LIB_DIRECTORY
203
204(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix=$INSTALL_DIR --enable-shared=no && make $JOBS && make install) || die "libpng build failed"
205
206cd ../../
207
208# ---------------------------------------------------
209echo -e "\nBuilding libogg...\n"
210
211LIB_VERSION="libogg-1.3.0"
212LIB_ARCHIVE="$LIB_VERSION.tar.gz"
213LIB_DIRECTORY="$LIB_VERSION"
214LIB_URL="http://downloads.xiph.org/releases/ogg/"
215
216# Dependency of vorbis
217# we can install them in the same directory for convenience
218mkdir -p libogg
219mkdir -p vorbis
220
221INSTALL_DIR="$(pwd)/vorbis"
222
223cd libogg
224
225download_lib $LIB_URL $LIB_ARCHIVE
226
227rm -rf $LIB_DIRECTORY
228tar -xf $LIB_ARCHIVE
229cd $LIB_DIRECTORY
230
231(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix=$INSTALL_DIR --enable-shared=no && make $JOBS && make install) || die "libogg build failed"
232
233cd ../../
234
235# ---------------------------------------------------
236echo -e "\nBuilding libvorbis...\n"
237
238LIB_VERSION="libvorbis-1.3.2"
239LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
240LIB_DIRECTORY="$LIB_VERSION"
241LIB_URL="http://downloads.xiph.org/releases/vorbis/"
242
243cd vorbis
244
245INSTALL_DIR="$(pwd)"
246
247download_lib $LIB_URL $LIB_ARCHIVE
248
249rm -rf $LIB_DIRECTORY
250tar -xf $LIB_ARCHIVE
251cd $LIB_DIRECTORY
252
253(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no --with-ogg="$INSTALL_DIR" && make $JOBS && make install) || die "libvorbis build failed"
254
255cd ../../
256
257# ---------------------------------------------------
258echo -e "\nBuilding libxml2...\n"
259
260LIB_VERSION="libxml2-2.7.8"
261LIB_ARCHIVE="$LIB_VERSION.tar.gz"
262LIB_DIRECTORY="$LIB_VERSION"
263LIB_URL="ftp://xmlsoft.org/libxml2/"
264
265mkdir -p libxml2
266cd libxml2
267
268INSTALL_DIR="$(pwd)"
269
270download_lib $LIB_URL $LIB_ARCHIVE
271
272rm -rf $LIB_DIRECTORY
273tar -xf $LIB_ARCHIVE
274cd $LIB_DIRECTORY
275
276(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no && make $JOBS && make install) || die "libxml2 build failed"
277
278cd ../../
279
280# ---------------------------------------------------
281# The following libraries are shared on different
282# OSes and may be modified, so we build and install
283# them from bundled sources
284# ---------------------------------------------------
285echo -e "\nBuilding Spidermonkey...\n"
286pushd ../source/spidermonkey/
287
288INSTALL_DIR="$(pwd)"
289
290rm -rf lib/
291rm -rf js-1.8.5
292tar -xf js185-1.0.0.tar.gz
293cd js-1.8.5/js/src
294
295# We want separate debug/release versions of the library, so change their install name in the Makefile
296sed -i.bak -e 's/\(STATIC_LIBRARY_NAME),mozjs185-\)\(\$(SRCREL_ABI_VERSION)\)\{0,1\}/\1ps-debug/' Makefile.in
297
298CONF_OPTS="--prefix=${INSTALL_DIR} --disable-tests --disable-shared-js"
299# Uncomment this line for 32-bit 10.5 cross compile:
300#CONF_OPTS="$CONF_OPTS --target=i386-apple-darwin9.0.0"
301if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
302 CONF_OPTS="$CONF_OPTS --enable-macos-target=$MIN_OSX_VERSION"
303fi
304if [[ $SYSROOT && ${SYSROOT-_} ]]; then
305 CONF_OPTS="$CONF_OPTS --with-macosx-sdk=$SYSROOT"
306fi
307
308mkdir -p build-debug
309cd build-debug
310(CC="$CC -arch $ARCH" CXX="$CXX -arch $ARCH" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS --enable-debug --disable-optimize && make ${JOBS} && make install) || die "Spidermonkey build failed"
311cd ..
312
313mv Makefile.in.bak Makefile.in
314sed -i.bak -e 's/\(STATIC_LIBRARY_NAME),mozjs185-\)\(\$(SRCREL_ABI_VERSION)\)\{0,1\}/\1ps-release/' Makefile.in
315
316mkdir -p build-release
317cd build-release
318(CC="$CC -arch $ARCH" CXX="$CXX -arch $ARCH" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS && make ${JOBS} && make install) || die "Spidermonkey build failed"
319cd ..
320
321mv Makefile.in.bak Makefile.in
322
323popd
324
325# ---------------------------------------------------
326echo -e "\nBuilding ENet...\n"
327pushd ../source/enet/
328
329INSTALL_DIR="$(pwd)"
330
331pushd src
332(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix=${INSTALL_DIR} --enable-shared=no && make clean && make ${JOBS} && make install) || die "ENet build failed"
333popd
334
335popd
336
337# ---------------------------------------------------
338# NVTT - no install
339echo -e "\nBuilding NVTT...\n"
340pushd ../source/nvtt/src
341
342rm -rf build
343mkdir -p build
344
345pushd build
346
347# Could use CMAKE_OSX_DEPLOYMENT_TARGET and CMAKE_OSX_SYSROOT
348# but they're not as flexible for cross-compiling
349(cmake .. -DCMAKE_LINK_FLAGS="$LDFLAGS" -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CPPFLAGS" -DCMAKE_BUILD_TYPE=Release -DBINDIR=bin -DLIBDIR=lib -DGLUT=0 -DGLEW=0 -DCG=0 -DCUDA=0 -DOPENEXR=0 -G "Unix Makefiles" && make clean && make nvtt ${JOBS}) || die "NVTT build failed"
350popd
351
352mkdir -p ../lib
353cp build/src/nv*/libnv*.a ../lib/
354cp build/src/nvtt/squish/libsquish.a ../lib/
355
356popd
357
358# ---------------------------------------------------
359# FCollada - no install
360echo -e "\nBuilding FCollada...\n"
361pushd ../source/fcollada/src
362
363rm -rf output
364# The Makefile refers to pkg-config for libxml2, but we
365# don't have that (replace with xml2-config instead)
366sed -i.bak -e 's/pkg-config libxml-2.0/xml2-config/' Makefile
367(make clean && CXXFLAGS=$CPPFLAGS make $JOBS) || die "FCollada build failed"
368# Undo Makefile change
369mv Makefile.bak Makefile
370
371popd