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

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