Ticket #1112: build-osx-libs.sh

File build-osx-libs.sh, 10.3 KB (added by historic_bruno, 12 years ago)
Line 
1#!/bin/sh
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
30JOBS=${JOBS:="-j5"}
31
32# Define compiler as GCC (in case anything expects e.g. gcc-4.2)
33export CC=${CC:="gcc"} CXX=${CXX:="g++"}
34
35# The various libs offer inconsistent configure options, some allow
36# setting sysroot and OSX-specific options, others don't. Adding to
37# the confusion, Apple moved /Developer/SDKs into the Xcode app bundle
38# so the path can't be guessed by clever build tools (like Boost.Build)
39# This is why we set CFLAGS, CPPFLAGS, and LDFLAGS.
40
41# Check if SYSROOT is set and not empty
42if [[ $SYSROOT && ${SYSROOT-_} ]]; then
43 CFLAGS="$CFLAGS -isysroot $SYSROOT"
44 CPPFLAGS="$CPPFLAGS -isysroot $SYSROOT"
45 LDFLAGS="$LDFLAGS -Wl,-syslibroot,$SYSROOT"
46fi
47# Check if MIN_OSX_VERSION is set and not empty
48if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
49 CFLAGS="$CFLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
50 CPPFLAGS="$CPPFLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
51fi
52# Force 64-bit build (we could also add 32-bit if we want universal)
53CFLAGS="$CFLAGS -arch x86_64"
54CPPFLAGS="$CPPFLAGS -arch x86_64"
55LDFLAGS="$LDFLAGS -arch x86_64"
56
57cd "$(dirname $0)"
58# Now in libraries/osx/ (where we assume this script resides)
59
60# TODO: Do we really want to rebuild these every time?
61# TODO: Debug builds of any of these libs?
62
63# ---------------------------------------------------
64echo "\nBuilding SDL...\n"
65
66# SDL 1.2.15 required for Lion support
67mkdir -p sdl
68cd sdl
69
70INSTALL_DIR="$(pwd)"
71
72if [ ! -e SDL-1.2.15.tar.gz ]; then
73 echo "Downloading source tarball"
74 curl -O http://www.libsdl.org/release/SDL-1.2.15.tar.gz
75fi
76
77rm -rf SDL-1.2.15/
78tar xzf SDL-1.2.15.tar.gz
79cd SDL-1.2.15
80
81(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no && make $JOBS && make install) || die "SDL build failed"
82
83cd ../../
84
85# ---------------------------------------------------
86echo "\nBuilding Boost...\n"
87
88mkdir -p boost
89cd boost
90
91INSTALL_DIR="$(pwd)"
92
93if [ ! -e boost_1_49_0.tar.bz2 ]; then
94 echo "Downloading source tarball"
95 curl -L -O http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.bz2
96fi
97
98rm -rf boost_1_49_0/
99tar --bzip2 -xf boost_1_49_0.tar.bz2
100cd boost_1_49_0
101
102# Can't use macosx-version because Boost only searches /Developer for SDKs
103(./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"
104
105# Copy files
106cd ../../
107
108# ---------------------------------------------------
109echo "\nBuilding wxWidgets...\n"
110
111# wxWidgets is required for Atlas
112# version 2.9+ is necessary for 64-bit OSX build
113# with OpenGL support
114
115# TODO: This build takes ages, anything we can exlude?
116mkdir -p wxwidgets
117cd wxwidgets
118
119INSTALL_DIR="$(pwd)"
120
121if [ ! -e wxWidgets-2.9.3.tar.bz2 ]; then
122 echo "Downloading source tarball"
123 curl -L -O http://download.sourceforge.net/wxwindows/wxWidgets-2.9.3.tar.bz2
124fi
125
126rm -rf wxWidgets-2.9.3
127tar --bzip2 -xf wxWidgets-2.9.3.tar.bz2
128cd wxWidgets-2.9.3
129
130mkdir -p build-release
131cd build-release
132
133CONF_OPTS="--prefix=$INSTALL_DIR --disable-shared --enable-unicode --with-cocoa --with-opengl"
134if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
135 CONF_OPTS="$CONF_OPTS --with-macosx-version-min=$MIN_OSX_VERSION"
136fi
137if [[ $SYSROOT && ${SYSROOT-_} ]]; then
138 CONF_OPTS="$CONF_OPTS --with-macosx-sdk=$SYSROOT"
139fi
140
141(../configure $CONF_OPTS && make $JOBS && make install) || die "wxWidgets build failed"
142
143cd ../../../
144
145# ---------------------------------------------------
146echo "\nBuilding libjpg...\n"
147
148mkdir -p libjpg
149cd libjpg
150
151INSTALL_DIR="$(pwd)"
152
153if [ ! -e jpegsrc.v8c.tar.gz ]; then
154 echo "Downloading source tarball"
155 curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
156fi
157
158rm -rf jpeg-8c
159tar xzf jpegsrc.v8c.tar.gz
160cd jpeg-8c
161
162CONF_OPTS="--prefix=$INSTALL_DIR --enable-shared=no"
163if [[ $SYSROOT && ${SYSROOT-_} ]]; then
164 CONF_OPTS="$CONF_OPTS --with-sysroot=$SYSROOT"
165fi
166(./configure $CONF_OPTS && make $JOBS && make install) || die "libjpg build failed"
167
168cd ../../
169
170# ---------------------------------------------------
171echo "\nBuilding libpng...\n"
172
173# Even though libpng is provided in the SDK, the 10.6 bundled version
174# is the ancient 1.2 which lacks functions we use like
175# png_set_longjmp_fn, so it seems easier to provide it ourselves
176mkdir -p libpng
177cd libpng
178
179INSTALL_DIR="$(pwd)"
180
181if [ ! -e libpng-1.5.8.tar.gz ]; then
182 echo "Downloading source tarball"
183 curl -L -O http://download.sourceforge.net/libpng/libpng-1.5.8.tar.gz
184fi
185
186rm -rf libpng-1.5.8
187tar xzf libpng-1.5.8.tar.gz
188cd libpng-1.5.8
189
190CONF_OPTS="--prefix=$INSTALL_DIR --enable-shared=no"
191if [[ $SYSROOT && ${SYSROOT-_} ]]; then
192 CONF_OPTS="$CONF_OPTS --with-sysroot=$SYSROOT"
193fi
194(./configure $CONF_OPTS && make $JOBS && make install) || die "libpng build failed"
195
196cd ../../
197
198# ---------------------------------------------------
199echo "\nBuilding libogg...\n"
200
201# Dependency of vorbis
202# we can install them in the same directory for convenience
203mkdir -p libogg
204mkdir -p vorbis
205
206INSTALL_DIR="$(pwd)/vorbis"
207
208cd libogg
209
210if [ ! -e libogg-1.3.0.tar.gz ]
211then
212 echo "Downloading source tarball"
213 curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
214fi
215
216rm -rf libogg-1.3.0
217tar xzf libogg-1.3.0.tar.gz
218cd libogg-1.3.0
219
220CONF_OPTS="--prefix=$INSTALL_DIR --enable-shared=no"
221if [[ $SYSROOT && ${SYSROOT-_} ]]; then
222 CONF_OPTS="$CONF_OPTS --with-sysroot=$SYSROOT"
223fi
224(./configure $CONF_OPTS && make $JOBS && make install) || die "libogg build failed"
225
226cd ../../
227
228# ---------------------------------------------------
229echo "\nBuilding libvorbis...\n"
230
231cd vorbis
232
233INSTALL_DIR="$(pwd)"
234
235if [ ! -e libvorbis-1.3.2.tar.bz2 ]; then
236 echo "Downloading source tarball"
237 curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.bz2
238fi
239
240rm -rf libvorbis-1.3.2
241tar --bzip2 -xf libvorbis-1.3.2.tar.bz2
242cd libvorbis-1.3.2
243
244(./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"
245
246cd ../../
247
248# ---------------------------------------------------
249echo "\nBuilding libxml2...\n"
250
251mkdir -p libxml2
252cd libxml2
253
254INSTALL_DIR="$(pwd)"
255
256if [ ! -e libxml2-2.7.8.tar.gz ]; then
257 echo "Downloading source tarball"
258 curl -O ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
259fi
260
261rm -rf libmxl2-2.7.8
262tar xzf libxml2-2.7.8.tar.gz
263cd libxml2-2.7.8
264
265(./configure CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no && make $JOBS && make install) || die "libxml2 build failed"
266
267cd ../../
268
269
270# ---------------------------------------------------
271# The following libraries are shared on different
272# OSes and may be modified, so we build and install
273# them from bundled sources
274# ---------------------------------------------------
275echo "\nBuilding Spidermonkey...\n"
276pushd ../source/spidermonkey/
277
278INSTALL_DIR="$(pwd)"
279
280rm -f lib/*.a
281rm -rf js-1.8.5
282tar xzf js185-1.0.0.tar.gz
283cd js-1.8.5/js/src
284
285# We want separate debug/release versions of the library, so change their install name in the Makefile
286sed -i.bak -e 's/\(STATIC_LIBRARY_NAME),mozjs185-\)\(\$(SRCREL_ABI_VERSION)\)\{0,1\}/\1ps-debug/' Makefile.in
287
288CONF_OPTS="--prefix=${INSTALL_DIR} --disable-tests --disable-shared-js"
289if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
290 CONF_OPTS="$CONF_OPTS --enable-macos-target=$MIN_OSX_VERSION"
291fi
292if [[ $SYSROOT && ${SYSROOT-_} ]]; then
293 CONF_OPTS="$CONF_OPTS --with-macosx-sdk=$SYSROOT"
294fi
295
296mkdir -p build-debug
297cd build-debug
298(../configure $CONF_OPTS --enable-debug --disable-optimize && make ${JOBS} && make install) || die "Spidermonkey build failed"
299cd ..
300
301sed -i.bak -e 's/\(STATIC_LIBRARY_NAME),mozjs185-\)\(ps-debug\)\{0,1\}/\1ps-release/' Makefile.in
302
303mkdir -p build-release
304cd build-release
305(../configure $CONF_OPTS && make ${JOBS} && make install) || die "Spidermonkey build failed"
306cd ..
307
308# Remove the install name changes to avoid spurious SVN diffs
309sed -i.bak -e 's/\(STATIC_LIBRARY_NAME),mozjs185-\)\(ps-release\)\{0,1\}/\1$(SRCREL_ABI_VERSION)/' Makefile.in
310
311popd
312
313# ---------------------------------------------------
314echo "\nBuilding ENet...\n"
315pushd ../source/enet/
316
317INSTALL_DIR="$(pwd)"
318
319pushd src
320(./configure CFLAGS="${CFLAGS}" CPPFLAGS="${CPPFLAGS}" LDFLAGS="${LDFLAGS}" --prefix=${INSTALL_DIR} --enable-shared=no && make ${JOBS} && make install) || die "ENet build failed"
321popd
322
323popd
324
325# ---------------------------------------------------
326# NVTT - no install
327echo "\nBuilding NVTT...\n"
328pushd ../source/nvtt/src
329
330rm -rf build
331mkdir -p build
332
333pushd build
334
335CMAKE_OPTS=""
336if [[ $SYSROOT && ${SYSROOT-_} ]]; then
337 CMAKE_OPTS="-DCMAKE_OSX_SYSROOT=$SYSROOT"
338fi
339(cmake .. $CMAKE_OPTS -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"
340popd
341
342mkdir -p ../lib
343cp build/src/nv*/libnv*.a ../lib/
344cp build/src/nvtt/squish/libsquish.a ../lib/
345
346popd
347
348# ---------------------------------------------------
349# FCollada - no install
350echo "\nBuilding FCollada...\n"
351pushd ../source/fcollada/src
352
353rm -rf output
354# The Makefile refers to pkg-config for libxml2, but we
355# don't have that (replace with xml2-config instead)
356sed -i.bak -e 's/pkg-config libxml-2.0/xml2-config/' Makefile
357make $JOBS || die "FCollada build failed"
358# Undo Makefile change
359sed -i.bak -e 's/xml2-config/pkg-config libxml-2.0/' Makefile
360
361popd
362