Merge 'remotes/trunk'
[0ad.git] / build / workspaces / update-workspaces.sh
blob25130099c1bf9216e68ab981508dc5627805cac3
1 #!/bin/sh
3 if [ "$(id -u)" = "0" ]; then
4 echo "Running as root will mess up file permissions. Aborting ..." 1>&2
5 exit 1
6 fi
8 die()
10 echo ERROR: $*
11 exit 1
14 # Check for whitespace in absolute path; this will cause problems in the
15 # SpiderMonkey build (https://bugzilla.mozilla.org/show_bug.cgi?id=459089)
16 # and maybe elsewhere, so we just forbid it
17 # Use perl as an alternative to readlink -f, which isn't available on BSD or OS X
18 SCRIPTPATH=`perl -MCwd -e 'print Cwd::abs_path shift' "$0"`
19 case "$SCRIPTPATH" in
20 *\ * )
21 die "Absolute path contains whitespace, which will break the build - move the game to a path without spaces" ;;
22 esac
24 JOBS=${JOBS:="-j2"}
26 # Some of our makefiles depend on GNU make, so we set some sane defaults if MAKE
27 # is not set.
28 case "`uname -s`" in
29 "FreeBSD" | "OpenBSD" )
30 MAKE=${MAKE:="gmake"}
32 * )
33 MAKE=${MAKE:="make"}
35 esac
37 # Parse command-line options:
39 premake_args=""
41 with_system_premake5=false
42 without_nvtt=false
43 with_system_nvtt=false
44 with_system_mozjs=false
45 enable_atlas=true
47 for i in "$@"
49 case $i in
50 --with-system-premake5 ) with_system_premake5=true ;;
51 --without-nvtt ) without_nvtt=true; premake_args="${premake_args} --without-nvtt" ;;
52 --with-system-nvtt ) with_system_nvtt=true; premake_args="${premake_args} --with-system-nvtt" ;;
53 --with-system-mozjs ) with_system_mozjs=true; premake_args="${premake_args} --with-system-mozjs" ;;
54 --enable-atlas ) enable_atlas=true ;;
55 --disable-atlas ) enable_atlas=false ;;
56 -j* ) JOBS=$i ;;
57 # Assume any other --options are for Premake
58 --* ) premake_args="${premake_args} $i" ;;
59 esac
60 done
62 if [ "$enable_atlas" = "true" ]; then
63 premake_args="${premake_args} --atlas"
64 if [ "$(uname -s)" = "Darwin" ]; then
65 # Provide path to wx-config on OS X (as wxwidgets doesn't support pkgconfig)
66 export WX_CONFIG="${WX_CONFIG:="$(pwd)/../../libraries/osx/wxwidgets/bin/wx-config"}"
67 else
68 export WX_CONFIG="${WX_CONFIG:="wx-config"}"
71 if [ ! -x "$(command -v $WX_CONFIG)" ]
72 then
73 echo 'WX_CONFIG must be set and valid or wx-config must be present when --atlas is passed as argument.'
74 exit 1
78 cd "$(dirname $0)"
79 # Now in build/workspaces/ (where we assume this script resides)
81 if [ "`uname -s`" = "Darwin" ]; then
82 # Set minimal SDK version
83 export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.12"}
86 # Don't want to build bundled libs on OS X
87 # (build-osx-libs.sh is used instead)
88 if [ "`uname -s`" != "Darwin" ]; then
89 echo "Updating bundled third-party dependencies..."
90 echo
92 # Build/update bundled external libraries
93 (cd ../../libraries/source/fcollada && MAKE=${MAKE} JOBS=${JOBS} ./build.sh) || die "FCollada build failed"
94 echo
95 if [ "$with_system_mozjs" = "false" ]; then
96 (cd ../../libraries/source/spidermonkey && MAKE=${MAKE} JOBS=${JOBS} ./build.sh) || die "SpiderMonkey build failed"
98 echo
99 if [ "$with_system_nvtt" = "false" ] && [ "$without_nvtt" = "false" ]; then
100 (cd ../../libraries/source/nvtt && MAKE=${MAKE} JOBS=${JOBS} ./build.sh) || die "NVTT build failed"
102 echo
105 # Now run premake to create the makefiles
107 cd ../premake
108 premake_command="premake5"
110 if [ "$with_system_premake5" = "false" ]; then
111 # Build bundled premake
112 cd premake5
113 PREMAKE_BUILD_DIR=build/gmake2.unix
114 # BSD and OS X need different Makefiles
115 case "`uname -s`" in
116 "GNU/kFreeBSD" )
117 # use default gmake2.unix (needs -ldl as we have a GNU userland and libc)
119 *"BSD" )
120 PREMAKE_BUILD_DIR=build/gmake2.bsd
122 "Darwin" )
123 PREMAKE_BUILD_DIR=build/gmake2.macosx
125 esac
126 ${MAKE} -C $PREMAKE_BUILD_DIR ${JOBS} || die "Premake build failed"
128 cd ..
129 premake_command="premake5/bin/release/premake5"
132 echo
134 # If we're in bash then make HOSTTYPE available to Premake, for primitive arch-detection
135 export HOSTTYPE="$HOSTTYPE"
137 echo "Premake args: ${premake_args}"
138 if [ "`uname -s`" != "Darwin" ]; then
139 ${premake_command} --file="premake5.lua" --outpath="../workspaces/gcc/" ${premake_args} gmake || die "Premake failed"
140 else
141 ${premake_command} --file="premake5.lua" --outpath="../workspaces/gcc/" --macosx-version-min="${MIN_OSX_VERSION}" ${premake_args} gmake || die "Premake failed"
142 # Also generate xcode workspaces if on OS X
143 ${premake_command} --file="premake5.lua" --outpath="../workspaces/xcode4" --macosx-version-min="${MIN_OSX_VERSION}" ${premake_args} xcode4 || die "Premake failed"
146 # test_root.cpp gets generated by cxxtestgen and passing different arguments to premake could require a regeneration of this file.
147 # It doesn't depend on anything in the makefiles, so make won't notice that the prebuild command for creating test_root.cpp needs to be triggered.
148 # We force this by deleting the file.
149 rm -f ../../source/test_root.cpp