Merge 'remotes/trunk'
[0ad.git] / libraries / osx / build-osx-libs.sh
blobdd98ad5b94b388256541dad69aeee9c0c63586d3
1 #!/bin/bash
3 # Script for acquiring and building OS X dependencies for 0 A.D.
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 build files,
8 # extracts the tarball, configures and builds the lib. The script
9 # should die on any errors to ease troubleshooting.
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, OS X developers 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.
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)
21 # --------------------------------------------------------------
22 # Library versions for ease of updating:
23 ZLIB_VERSION="zlib-1.2.11"
24 CURL_VERSION="curl-7.59.0"
25 ICONV_VERSION="libiconv-1.15"
26 XML2_VERSION="libxml2-2.9.8"
27 SDL2_VERSION="SDL2-2.0.5"
28 BOOST_VERSION="boost_1_64_0"
29 # NOTE: remember to also update LIB_URL below when changing version
30 WXWIDGETS_VERSION="wxWidgets-3.0.3.1"
31 # libpng was included as part of X11 but that's removed from Mountain Lion
32 # (also the Snow Leopard version was ancient 1.2)
33 PNG_VERSION="libpng-1.6.34"
34 OGG_VERSION="libogg-1.3.3"
35 VORBIS_VERSION="libvorbis-1.3.6"
36 # gloox is necessary for multiplayer lobby
37 GLOOX_VERSION="gloox-1.0.20"
38 # NSPR is necessary for threadsafe Spidermonkey
39 NSPR_VERSION="4.15"
40 # OS X only includes part of ICU, and only the dylib
41 # NOTE: remember to also update LIB_URL below when changing version
42 ICU_VERSION="icu4c-59_1"
43 ENET_VERSION="enet-1.3.13"
44 MINIUPNPC_VERSION="miniupnpc-2.0.20180222"
45 SODIUM_VERSION="libsodium-1.0.16"
46 # --------------------------------------------------------------
47 # Bundled with the game:
48 # * SpiderMonkey 38
49 # * NVTT
50 # * FCollada
51 # --------------------------------------------------------------
52 # Provided by OS X:
53 # * OpenAL
54 # * OpenGL
55 # --------------------------------------------------------------
57 # Force build architecture, as sometimes environment is broken.
58 # For a universal fat binary, the approach would be to build every
59 # dependency with both archs and combine them with lipo, then do the
60 # same thing with the game itself.
61 # Choices are "x86_64" or "i386" (ppc and ppc64 not supported)
62 ARCH=${ARCH:="x86_64"}
64 # Define compiler as "clang", this is all Mavericks supports.
65 # gcc symlinks may still exist, but they are simply clang with
66 # slightly different config, which confuses build scripts.
67 # llvm-gcc and gcc 4.2 are no longer supported by SpiderMonkey.
68 export CC=${CC:="clang"} CXX=${CXX:="clang++"}
69 export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.9"}
71 # The various libs offer inconsistent configure options, some allow
72 # setting sysroot and OS X-specific options, others don't. Adding to
73 # the confusion, Apple moved /Developer/SDKs into the Xcode app bundle
74 # so the path can't be guessed by clever build tools (like Boost.Build).
75 # Sometimes configure gets it wrong anyway, especially on cross compiles.
76 # This is why we prefer using (OBJ)CFLAGS, (OBJ)CXXFLAGS, and LDFLAGS.
78 # Check if SYSROOT is set and not empty
79 if [[ $SYSROOT && ${SYSROOT-_} ]]; then
80 C_FLAGS="-isysroot $SYSROOT"
81 LDFLAGS="$LDFLAGS -Wl,-syslibroot,$SYSROOT"
83 # Check if MIN_OSX_VERSION is set and not empty
84 if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
85 C_FLAGS="$C_FLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
86 # clang and llvm-gcc look at mmacosx-version-min to determine link target
87 # and CRT version, and use it to set the macosx_version_min linker flag
88 LDFLAGS="$LDFLAGS -mmacosx-version-min=$MIN_OSX_VERSION"
90 # Force using libc++ since it has better C++11 support required by the game
91 # but pre-Mavericks still use libstdc++ by default
92 # Also enable c++0x for consistency with the game build
93 C_FLAGS="$C_FLAGS -arch $ARCH -fvisibility=hidden"
94 LDFLAGS="$LDFLAGS -arch $ARCH -stdlib=libc++"
96 CFLAGS="$CFLAGS $C_FLAGS"
97 CXXFLAGS="$CXXFLAGS $C_FLAGS -stdlib=libc++ -std=c++0x"
98 OBJCFLAGS="$OBJCFLAGS $C_FLAGS"
99 OBJCXXFLAGS="$OBJCXXFLAGS $C_FLAGS"
101 JOBS=${JOBS:="-j2"}
103 set -e
105 die()
107 echo ERROR: $*
108 exit 1
111 download_lib()
113 local url=$1
114 local filename=$2
116 if [ ! -e $filename ]; then
117 echo "Downloading $filename"
118 curl -L -o ${filename} ${url}${filename} || die "Download of $url$filename failed"
122 already_built()
124 echo -e "Skipping - already built (use --force-rebuild to override)"
127 # Check that we're actually on OS X
128 if [ "`uname -s`" != "Darwin" ]; then
129 die "This script is intended for OS X only"
132 # Parse command-line options:
133 force_rebuild=false
135 for i in "$@"
137 case $i in
138 --force-rebuild ) force_rebuild=true;;
139 -j* ) JOBS=$i ;;
140 esac
141 done
143 cd "$(dirname $0)"
144 # Now in libraries/osx/ (where we assume this script resides)
146 # --------------------------------------------------------------
147 echo -e "Building zlib..."
149 LIB_VERSION="${ZLIB_VERSION}"
150 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
151 LIB_DIRECTORY=$LIB_VERSION
152 LIB_URL="http://zlib.net/"
154 mkdir -p zlib
155 pushd zlib > /dev/null
157 ZLIB_DIR="$(pwd)"
159 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
160 then
161 rm -f .already-built
162 download_lib $LIB_URL $LIB_ARCHIVE
164 rm -rf $LIB_DIRECTORY include lib share
165 tar -xf $LIB_ARCHIVE
166 pushd $LIB_DIRECTORY
168 # patch zlib's configure script to use our CFLAGS and LDFLAGS
169 (patch -p0 -i ../../patches/zlib_flags.diff && CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" ./configure --prefix="$ZLIB_DIR" --static && make ${JOBS} && make install) || die "zlib build failed"
170 popd
171 touch .already-built
172 else
173 already_built
175 popd > /dev/null
177 # --------------------------------------------------------------
178 echo -e "Building libcurl..."
180 LIB_VERSION="${CURL_VERSION}"
181 LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
182 LIB_DIRECTORY="$LIB_VERSION"
183 LIB_URL="http://curl.haxx.se/download/"
185 mkdir -p libcurl
186 pushd libcurl > /dev/null
188 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
189 then
190 INSTALL_DIR="$(pwd)"
192 rm -f .already-built
193 download_lib $LIB_URL $LIB_ARCHIVE
195 rm -rf $LIB_DIRECTORY bin include lib share
196 tar -xf $LIB_ARCHIVE
197 pushd $LIB_DIRECTORY
199 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-ipv6 --with-darwinssl --without-gssapi --without-libmetalink --without-librtmp --without-libssh2 --without-nss --without-polarssl --without-spnego --disable-ares --disable-ldap --disable-ldaps --without-libidn --with-zlib="${ZLIB_DIR}" --enable-shared=no && make ${JOBS} && make install) || die "libcurl build failed"
200 popd
201 touch .already-built
202 else
203 already_built
205 popd > /dev/null
207 # --------------------------------------------------------------
208 echo -e "Building libiconv..."
210 LIB_VERSION="${ICONV_VERSION}"
211 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
212 LIB_DIRECTORY="$LIB_VERSION"
213 LIB_URL="http://ftp.gnu.org/pub/gnu/libiconv/"
215 mkdir -p iconv
216 pushd iconv > /dev/null
218 ICONV_DIR="$(pwd)"
220 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
221 then
222 rm -f .already-built
223 download_lib $LIB_URL $LIB_ARCHIVE
225 rm -rf $LIB_DIRECTORY bin include lib share
226 tar -xf $LIB_ARCHIVE
227 pushd $LIB_DIRECTORY
229 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix="$ICONV_DIR" --without-libiconv-prefix --without-libintl-prefix --disable-nls --enable-shared=no && make ${JOBS} && make install) || die "libiconv build failed"
230 popd
231 touch .already-built
232 else
233 already_built
235 popd > /dev/null
237 # --------------------------------------------------------------
238 echo -e "Building libxml2..."
240 LIB_VERSION="${XML2_VERSION}"
241 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
242 LIB_DIRECTORY="$LIB_VERSION"
243 LIB_URL="ftp://xmlsoft.org/libxml2/"
245 mkdir -p libxml2
246 pushd libxml2 > /dev/null
248 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
249 then
250 INSTALL_DIR="$(pwd)"
252 rm -f .already-built
253 download_lib $LIB_URL $LIB_ARCHIVE
255 rm -rf $LIB_DIRECTORY bin include lib share
256 tar -xf $LIB_ARCHIVE
257 pushd $LIB_DIRECTORY
259 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --without-lzma --without-python --with-iconv="${ICONV_DIR}" --with-zlib="${ZLIB_DIR}" --enable-shared=no && make ${JOBS} && make install) || die "libxml2 build failed"
260 popd
261 touch .already-built
262 else
263 already_built
265 popd > /dev/null
267 # --------------------------------------------------------------
269 echo -e "Building SDL2..."
271 LIB_VERSION="${SDL2_VERSION}"
272 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
273 LIB_DIRECTORY=$LIB_VERSION
274 LIB_URL="https://libsdl.org/release/"
276 mkdir -p sdl2
277 pushd sdl2 > /dev/null
279 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
280 then
281 INSTALL_DIR="$(pwd)"
283 rm -f .already-built
284 download_lib $LIB_URL $LIB_ARCHIVE
286 rm -rf $LIB_DIRECTORY bin include lib share
287 tar -xf $LIB_ARCHIVE
288 pushd $LIB_DIRECTORY
290 # We don't want SDL2 to pull in system iconv, force it to detect ours with flags.
291 # Don't use X11 - we don't need it and Mountain Lion removed it
292 (./configure CPPFLAGS="-I${ICONV_DIR}/include" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS -L${ICONV_DIR}/lib" --prefix="$INSTALL_DIR" --disable-video-x11 --without-x --enable-shared=no && make $JOBS && make install) || die "SDL2 build failed"
293 popd
294 touch .already-built
295 else
296 already_built
298 popd > /dev/null
300 # --------------------------------------------------------------
301 echo -e "Building Boost..."
303 LIB_VERSION="${BOOST_VERSION}"
304 LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
305 LIB_DIRECTORY="$LIB_VERSION"
306 LIB_URL="http://download.sourceforge.net/boost/"
308 mkdir -p boost
309 pushd boost > /dev/null
311 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
312 then
313 INSTALL_DIR="$(pwd)"
315 rm -f .already-built
316 download_lib $LIB_URL $LIB_ARCHIVE
318 rm -rf $LIB_DIRECTORY include lib
319 tar -xf $LIB_ARCHIVE
320 pushd $LIB_DIRECTORY
322 # Can't use macosx-version, see above comment.
323 (./bootstrap.sh --with-libraries=filesystem,system --prefix=$INSTALL_DIR && ./b2 cflags="$CFLAGS" toolset=clang cxxflags="$CXXFLAGS" linkflags="$LDFLAGS" ${JOBS} -d2 --layout=tagged --debug-configuration link=static threading=multi variant=release,debug install) || die "Boost build failed"
325 popd
326 touch .already-built
327 else
328 already_built
330 popd > /dev/null
332 # --------------------------------------------------------------
333 # TODO: This build takes ages, anything we can exclude?
334 echo -e "Building wxWidgets..."
336 LIB_VERSION="${WXWIDGETS_VERSION}"
337 LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
338 LIB_DIRECTORY="$LIB_VERSION"
339 LIB_URL="http://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3.1/"
341 mkdir -p wxwidgets
342 pushd wxwidgets > /dev/null
344 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
345 then
346 INSTALL_DIR="$(pwd)"
348 rm -f .already-built
349 download_lib $LIB_URL $LIB_ARCHIVE
351 rm -rf $LIB_DIRECTORY bin include lib share
352 tar -xf $LIB_ARCHIVE
353 pushd $LIB_DIRECTORY
355 mkdir -p build-release
356 pushd build-release
358 CONF_OPTS="--prefix=$INSTALL_DIR --disable-shared --enable-macosx_arch=$ARCH --enable-unicode --with-cocoa --with-opengl --with-libiconv-prefix=${ICONV_DIR} --with-expat=builtin --with-png=builtin --without-libtiff --without-sdl --without-x --disable-webview --disable-webkit --disable-webviewwebkit --disable-webviewie"
359 # wxWidgets configure now defaults to targeting 10.5, if not specified,
360 # but that conflicts with our flags
361 if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
362 CONF_OPTS="$CONF_OPTS --with-macosx-version-min=$MIN_OSX_VERSION"
364 (../configure CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" CPPFLAGS="-stdlib=libc++ -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1" LDFLAGS="$LDFLAGS" $CONF_OPTS && make ${JOBS} && make install) || die "wxWidgets build failed"
365 popd
366 popd
367 touch .already-built
368 else
369 already_built
371 popd > /dev/null
373 # --------------------------------------------------------------
374 echo -e "Building libpng..."
376 LIB_VERSION="${PNG_VERSION}"
377 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
378 LIB_DIRECTORY="$LIB_VERSION"
379 LIB_URL="http://download.sourceforge.net/libpng/"
381 mkdir -p libpng
382 pushd libpng > /dev/null
384 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
385 then
386 INSTALL_DIR="$(pwd)"
388 rm -f .already-built
389 download_lib $LIB_URL $LIB_ARCHIVE
391 rm -rf $LIB_DIRECTORY bin include lib share
392 tar -xf $LIB_ARCHIVE
393 pushd $LIB_DIRECTORY
395 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix=$INSTALL_DIR --enable-shared=no && make ${JOBS} && make install) || die "libpng build failed"
396 popd
397 touch .already-built
398 else
399 already_built
401 popd > /dev/null
403 # --------------------------------------------------------------
404 echo -e "Building libogg..."
406 LIB_VERSION="${OGG_VERSION}"
407 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
408 LIB_DIRECTORY="$LIB_VERSION"
409 LIB_URL="http://downloads.xiph.org/releases/ogg/"
411 # Dependency of vorbis
412 # we can install them in the same directory for convenience
413 mkdir -p libogg
414 mkdir -p vorbis
416 pushd libogg > /dev/null
417 OGG_DIR="$(pwd)"
419 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
420 then
421 rm -f .already-built
422 download_lib $LIB_URL $LIB_ARCHIVE
424 rm -rf $LIB_DIRECTORY include lib share
425 tar -xf $LIB_ARCHIVE
426 pushd $LIB_DIRECTORY
428 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix=$OGG_DIR --enable-shared=no && make ${JOBS} && make install) || die "libogg build failed"
429 popd
430 touch .already-built
431 else
432 already_built
434 popd > /dev/null
436 # --------------------------------------------------------------
437 echo -e "Building libvorbis..."
439 LIB_VERSION="${VORBIS_VERSION}"
440 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
441 LIB_DIRECTORY="$LIB_VERSION"
442 LIB_URL="http://downloads.xiph.org/releases/vorbis/"
444 pushd vorbis > /dev/null
446 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
447 then
448 INSTALL_DIR="$(pwd)"
450 rm -f .already-built
451 download_lib $LIB_URL $LIB_ARCHIVE
453 rm -rf $LIB_DIRECTORY include lib share
454 tar -xf $LIB_ARCHIVE
455 pushd $LIB_DIRECTORY
457 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no --with-ogg="$OGG_DIR" && make ${JOBS} && make install) || die "libvorbis build failed"
458 popd
459 touch .already-built
460 else
461 already_built
463 popd > /dev/null
465 # --------------------------------------------------------------
466 echo -e "Building gloox..."
468 LIB_VERSION="${GLOOX_VERSION}"
469 LIB_ARCHIVE="$LIB_VERSION.tar.bz2"
470 LIB_DIRECTORY="$LIB_VERSION"
471 LIB_URL="http://camaya.net/download/"
473 mkdir -p gloox
474 pushd gloox > /dev/null
476 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
477 then
478 INSTALL_DIR="$(pwd)"
480 rm -f .already-built
481 download_lib $LIB_URL $LIB_ARCHIVE
483 rm -rf $LIB_DIRECTORY bin include lib
484 tar -xf $LIB_ARCHIVE
485 pushd $LIB_DIRECTORY
487 # TODO: pulls in libresolv dependency from /usr/lib
488 # TODO: if we ever use SSL/TLS, that will add yet another dependency...
489 (./configure CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" --prefix="$INSTALL_DIR" --enable-shared=no --with-zlib="${ZLIB_DIR}" --without-libidn --without-gnutls --without-openssl --without-tests --without-examples && make ${JOBS} && make install) || die "gloox build failed"
490 popd
491 touch .already-built
492 else
493 already_built
495 popd > /dev/null
497 # --------------------------------------------------------------
498 echo -e "Building NSPR..."
500 LIB_VERSION="${NSPR_VERSION}"
501 LIB_ARCHIVE="nspr-$LIB_VERSION.tar.gz"
502 LIB_DIRECTORY="nspr-$LIB_VERSION"
503 LIB_URL="https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v$LIB_VERSION/src/"
505 mkdir -p nspr
506 pushd nspr > /dev/null
508 NSPR_DIR="$(pwd)"
510 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
511 then
512 rm -f .already-built
513 download_lib $LIB_URL $LIB_ARCHIVE
515 rm -rf $LIB_DIRECTORY bin include lib share
516 tar -xf $LIB_ARCHIVE
517 pushd $LIB_DIRECTORY/nspr
519 (CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" ./configure --prefix="$NSPR_DIR" && make ${JOBS} && make install) || die "NSPR build failed"
520 popd
521 # TODO: how can we not build the dylibs?
522 rm -f lib/*.dylib
523 touch .already-built
524 else
525 already_built
527 popd > /dev/null
529 # --------------------------------------------------------------
530 echo -e "Building ICU..."
532 LIB_VERSION="${ICU_VERSION}"
533 LIB_ARCHIVE="$LIB_VERSION-src.tgz"
534 LIB_DIRECTORY="icu"
535 LIB_URL="http://download.icu-project.org/files/icu4c/59.1/"
537 mkdir -p icu
538 pushd icu > /dev/null
540 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
541 then
542 INSTALL_DIR="$(pwd)"
544 rm -f .already-built
545 download_lib $LIB_URL $LIB_ARCHIVE
547 rm -rf $LIB_DIRECTORY bin include lib sbin share
548 tar -xf $LIB_ARCHIVE
549 pushd $LIB_DIRECTORY
551 mkdir -p source/build
552 pushd source/build
554 (CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" ../runConfigureICU MacOSX --prefix=$INSTALL_DIR --disable-shared --enable-static --disable-samples --enable-extras --enable-icuio --enable-tools && make ${JOBS} && make install) || die "ICU build failed"
555 popd
556 popd
557 touch .already-built
558 else
559 already_built
561 popd > /dev/null
563 # --------------------------------------------------------------
564 echo -e "Building ENet..."
566 LIB_VERSION="${ENET_VERSION}"
567 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
568 LIB_DIRECTORY="$LIB_VERSION"
569 LIB_URL="http://enet.bespin.org/download/"
571 mkdir -p enet
572 pushd enet > /dev/null
574 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
575 then
576 INSTALL_DIR="$(pwd)"
578 rm -f .already-built
579 download_lib $LIB_URL $LIB_ARCHIVE
581 rm -rf $LIB_DIRECTORY bin include lib sbin share
582 tar -xf $LIB_ARCHIVE
583 pushd $LIB_DIRECTORY
585 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix=${INSTALL_DIR} --enable-shared=no && make clean && make ${JOBS} && make install) || die "ENet build failed"
586 popd
587 touch .already-built
588 else
589 already_built
591 popd > /dev/null
593 # --------------------------------------------------------------
594 echo -e "Building MiniUPnPc..."
596 LIB_VERSION="${MINIUPNPC_VERSION}"
597 LIB_ARCHIVE="$LIB_VERSION.tar.gz"
598 LIB_DIRECTORY="$LIB_VERSION"
599 LIB_URL="http://miniupnp.tuxfamily.org/files/download.php?file="
601 mkdir -p miniupnpc
602 pushd miniupnpc > /dev/null
604 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
605 then
606 INSTALL_DIR="$(pwd)"
608 rm -f .already-built
609 download_lib $LIB_URL $LIB_ARCHIVE
611 rm -rf $LIB_DIRECTORY bin include lib share
612 tar -xf $LIB_ARCHIVE
613 pushd $LIB_DIRECTORY
615 (make clean && CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS make ${JOBS} && INSTALLPREFIX="$INSTALL_DIR" make install) || die "MiniUPnPc build failed"
616 popd
617 # TODO: how can we not build the dylibs?
618 rm -f lib/*.dylib
619 touch .already-built
620 else
621 already_built
623 popd > /dev/null
625 # --------------------------------------------------------------
626 echo -e "Building libsodium..."
628 LIB_VERSION="${SODIUM_VERSION}"
629 LIB_ARCHIVE="$SODIUM_VERSION.tar.gz"
630 LIB_DIRECTORY="$LIB_VERSION"
631 LIB_URL="https://download.libsodium.org/libsodium/releases/"
633 mkdir -p libsodium
634 pushd libsodium > /dev/null
636 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]]
637 then
638 INSTALL_DIR="$(pwd)"
640 rm -f .already-built
641 download_lib $LIB_URL $LIB_ARCHIVE
643 rm -rf $LIB_DIRECTORY include lib
644 tar -xf $LIB_ARCHIVE
645 pushd $LIB_DIRECTORY
647 (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" --prefix=${INSTALL_DIR} && make clean && CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS make ${JOBS} && make check && INSTALLPREFIX="$INSTALL_DIR" make install) || die "libsodium build failed"
648 popd
649 touch .already-built
650 else
651 already_built
653 popd > /dev/null
655 # --------------------------------------------------------------------
656 # The following libraries are shared on different OSes and may
657 # be customized, so we build and install them from bundled sources
658 # --------------------------------------------------------------------
659 echo -e "Building Spidermonkey..."
660 LIB_VERSION="mozjs-38.2.1"
661 LIB_ARCHIVE="$LIB_VERSION.rc0.tar.bz2"
662 LIB_DIRECTORY="mozjs-38.0.0"
664 pushd ../source/spidermonkey/ > /dev/null
666 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]] || [[ .already-built -ot README.txt ]]
667 then
668 INSTALL_DIR="$(pwd)"
669 INCLUDE_DIR_DEBUG=$INSTALL_DIR/include-unix-debug
670 INCLUDE_DIR_RELEASE=$INSTALL_DIR/include-unix-release
672 rm -f .already-built
673 rm -f lib/*.a
674 rm -rf $LIB_DIRECTORY $INCLUDE_DIR_DEBUG $INCLUDE_DIR_RELEASE
675 tar -xf $LIB_ARCHIVE
677 # Apply patches
678 pushd $LIB_DIRECTORY
679 . ../patch.sh
680 popd
682 pushd $LIB_DIRECTORY/js/src
683 # We want separate debug/release versions of the library, so change their install name in the Makefile
684 perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs38-ps-debug'\''/' moz.build
686 CONF_OPTS="--target=$ARCH-apple-darwin --prefix=${INSTALL_DIR} --with-system-nspr --with-nspr-prefix=${NSPR_DIR} --with-system-zlib=${ZLIB_DIR} --disable-tests --disable-shared-js"
687 # Change the default location where the tracelogger should store its output, which is /tmp/ on OSX.
688 TLCXXFLAGS='-DTRACE_LOG_DIR="\"../../source/tools/tracelogger/\""'
689 # Uncomment this line for 32-bit 10.5 cross compile:
690 #CONF_OPTS="$CONF_OPTS --target=i386-apple-darwin9.0.0"
691 if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
692 CONF_OPTS="$CONF_OPTS --enable-macos-target=$MIN_OSX_VERSION"
694 if [[ $SYSROOT && ${SYSROOT-_} ]]; then
695 CONF_OPTS="$CONF_OPTS --with-macosx-sdk=$SYSROOT"
698 mkdir -p build-debug
699 pushd build-debug
700 (CC="clang" CXX="clang++" CXXFLAGS="${TLCXXFLAGS}" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal && make ${JOBS}) || die "Spidermonkey build failed"
701 # js-config.h is different for debug and release builds, so we need different include directories for both
702 mkdir -p $INCLUDE_DIR_DEBUG
703 cp -R -L dist/include/* $INCLUDE_DIR_DEBUG/
704 cp dist/lib/*.a $INSTALL_DIR/lib
705 popd
706 mv moz.build.bak moz.build
708 perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs38-ps-release'\''/' moz.build
709 mkdir -p build-release
710 pushd build-release
711 (CC="clang" CXX="clang++" CXXFLAGS="${TLCXXFLAGS}" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS --enable-optimize && make ${JOBS}) || die "Spidermonkey build failed"
712 # js-config.h is different for debug and release builds, so we need different include directories for both
713 mkdir -p $INCLUDE_DIR_RELEASE
714 cp -R -L dist/include/* $INCLUDE_DIR_RELEASE/
715 cp dist/lib/*.a $INSTALL_DIR/lib
716 popd
717 mv moz.build.bak moz.build
719 popd
720 touch .already-built
721 else
722 already_built
724 popd > /dev/null
726 # --------------------------------------------------------------
727 # NVTT - no install
728 echo -e "Building NVTT..."
730 pushd ../source/nvtt > /dev/null
732 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]]
733 then
734 rm -f .already-built
735 rm -f lib/*.a
736 pushd src
737 rm -rf build
738 mkdir -p build
740 pushd build
742 # Could use CMAKE_OSX_DEPLOYMENT_TARGET and CMAKE_OSX_SYSROOT
743 # but they're not as flexible for cross-compiling
744 # Disable optional libs that we don't need (avoids some conflicts with MacPorts)
745 (cmake .. -DCMAKE_LINK_FLAGS="$LDFLAGS" -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" -DCMAKE_BUILD_TYPE=Release -DBINDIR=bin -DLIBDIR=lib -DGLUT=0 -DGLEW=0 -DCG=0 -DCUDA=0 -DOPENEXR=0 -DJPEG=0 -DPNG=0 -DTIFF=0 -G "Unix Makefiles" && make clean && make nvtt ${JOBS}) || die "NVTT build failed"
746 popd
748 mkdir -p ../lib
749 cp build/src/nv*/libnv*.a ../lib/
750 cp build/src/nvtt/squish/libsquish.a ../lib/
751 popd
752 touch .already-built
753 else
754 already_built
756 popd > /dev/null
758 # --------------------------------------------------------------
759 # FCollada - no install
760 echo -e "Building FCollada..."
762 pushd ../source/fcollada > /dev/null
764 if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]]
765 then
766 rm -f .already-built
767 rm -f lib/*.a
768 pushd src
769 rm -rf output
770 mkdir -p ../lib
772 # The Makefile refers to pkg-config for libxml2, but we
773 # don't have that (replace with xml2-config instead)
774 sed -i.bak -e 's/pkg-config libxml-2.0/xml2-config/' Makefile
775 (make clean && CXXFLAGS=$CXXFLAGS make ${JOBS}) || die "FCollada build failed"
776 # Undo Makefile change
777 mv Makefile.bak Makefile
778 popd
779 touch .already-built
780 else
781 already_built
783 popd > /dev/null