source: trunk/build/lol-build @ 2533

Last change on this file since 2533 was 2533, checked in by sam, 10 years ago

build: make sure the builds _and_ the autobuilds work around the
memory leak in OS X llvm-g++.

  • Property svn:executable set to *
File size: 11.0 KB
Line 
1#!/bin/sh
2
3#
4# Lol Engine build script
5# Usage:
6#   lol-build <action> [<platform>]
7#
8# Where <action> is one of:
9#  - bootstrap
10#  - configure
11#  - build
12#  - check
13#  - clean
14#
15# And <platform> is one of:
16#  - linux-i386
17#  - linux-amd64
18#  - nacl-i386
19#  - nacl-amd64
20#  - ios-arm
21#  - osx-amd64
22#  - android-arm
23#  - ps3-ppu
24#  - win*-i386
25#  - win*-amd64
26#  - raspi-arm
27#
28
29set -e
30
31action="$1"
32platform="$2"
33
34###############################################################################
35# Initialisation code
36#
37#  - sets the top_srcdir variable
38#  - sets the LOL_PARALLEL variable
39#  - fix PATH and MKPATH if necessary
40#
41__init__()
42{
43    top_srcdir="$(dirname "$0")/.."
44    cd "$top_srcdir"
45    top_srcdir="`pwd`"
46
47    # Try to count CPU cores. First obvious try: /proc/cpuinfo on Linux
48    case "$cpu_count" in
49      [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
50      *) if [ -r "/proc/cpuinfo" ]; then
51           cpu_count="$(grep -c '^processor\>' /proc/cpuinfo 2>/dev/null || true)"
52         fi ;;
53    esac
54    # If that didn't work, try sysctl (for OS X machines)
55    case "$cpu_count" in
56      [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
57      *) cpu_count="$(sysctl -n hw.ncpu 2>/dev/null || true)" ;;
58    esac
59    # Otherwise, CPUInfo.exe (from Xoreax's XGE) may help on Windows
60    case "$cpu_count" in
61      [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
62      *) cpu_count="$(CPUInfo.exe | sed -ne 's/CPU Cores.* \([0-9][0-9]*\)/\1/p')" ;;
63    esac
64    # Otherwise, Windows may define NUMBER_OF_PROCESSORS
65    case "$cpu_count" in
66      [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
67      *) cpu_count="$NUMBER_OF_PROCESSORS" ;;
68    esac
69    # Otherwise, be conservative and assume 1 CPU core
70    case "$cpu_count" in
71      [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
72      *) cpu_count=1 ;;
73    esac
74    # Now decide how many parallel threads to launch
75    case "$cpu_count" in
76      1) LOL_PARALLEL=1 ;;
77      2) LOL_PARALLEL=3 ;;
78      *) LOL_PARALLEL="$(expr $cpu_count '*' 3 / 2)" ;;
79    esac
80
81    case "${MSYSTEM}" in
82        MINGW32|MINGW64)
83            PATH="$PATH:./external/gtk-2.22.1/bin"
84            M4PATH="$M4PATH:./external/gtk-2.22.1/share/aclocal"
85            ;;
86    esac
87
88    # Ensure we don’t launch weird Windows binaries when cross-compiling
89    WINEDLLOVERRIDES="winemenubuilder.exe,wineboot.exe,explorer.exe,winedbg.exe=d"
90    export WINEDLLOVERRIDES
91
92    # Ensure SDL does not redirect stdout/stderr to local files
93    SDL_STDIO_REDIRECT=0
94    export SDL_STDIO_REDIRECT
95}
96
97bootstrap()
98{
99    cd "$top_srcdir"
100    case "$platform" in
101        ios-arm)
102            # No bootstrapping needed
103            ;;
104        *)
105            PATH="$PATH" M4PATH="$M4PATH" ./bootstrap
106            ;;
107    esac
108}
109
110configure()
111{
112    cd "$top_srcdir"
113    case "$platform" in
114        android-arm)
115            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
116            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/arm-linux-androideabi -lz"
117            CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
118            ;;
119        win*-i386)
120            if test "x${MSYSTEM}" = xMINGW32; then
121                :
122            elif i586-mingw32msvc-g++ --version >/dev/null 2>&1; then
123                HOSTFLAGS=--host=i586-mingw32msvc
124                BUILDFLAGS=--build=none
125            elif i686-w64-mingw32-g++ --version >/dev/null 2>&1; then
126                HOSTFLAGS=--host=i686-w64-mingw32
127                BUILDFLAGS=--build=none
128            else
129                echo "Error: could not find win32 compiler" >&2
130                false
131            fi
132            if test "x${MSYSTEM}" = xMINGW64; then
133                # If using mingw64, we're not really cross-compiling
134                BUILDFLAGS=
135            fi
136            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
137            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
138            LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/i686-w64-mingw32"
139            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/i686-w64-mingw32"
140            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.12/lib/i686-w64-mingw32"
141            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.12/lib/i686-w64-mingw32"
142            LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/lib"
143            LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/bin"
144            LDFLAGS="$LDFLAGS -L$PWD/external/gtkglarea-2.0.1/lib"
145            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/i686-w64-mingw32"
146            ;;
147        win*-amd64)
148            if test "x${MSYSTEM}" = xMINGW64; then
149                :
150            elif x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then
151                HOSTFLAGS=--host=x86_64-w64-mingw32
152                BUILDFLAGS=--build=none
153            else
154                echo "Error: could not find win64 compiler" >&2
155                false
156            fi
157            if test "x${MSYSTEM}" = xMINGW32; then
158                # If using mingw32, we're not really cross-compiling
159                BUILDFLAGS=
160            fi
161            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
162            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
163            LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/x86_64-w64-mingw32"
164            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/x86_64-w64-mingw32"
165            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.12/lib/x86_64-msvc"
166            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.12/lib/x86_64-msvc"
167            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/x86_64-w64-mingw32"
168            ;;
169        *-i386)
170            # Ensure we're _really_ on i386
171            CXXFLAGS="$CXXFLAGS -m32"
172            ;;
173        *-amd64)
174            # Ensure we're _really_ on amd64
175            CXXFLAGS="$CXXFLAGS -m64"
176            ;;
177    esac
178    case "$platform" in
179        ios-arm)
180            # No configuration needed
181            ;;
182        android-arm)
183            CPPFLAGS="$CPPFLAGS -Wno-psabi -I$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport -fpic -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64"
184            CFLAGS="$CFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb"
185            CXXFLAGS="$CXXFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb -fno-rtti -fno-exceptions"
186            LOL_LIBS="$LOL_LIBS -L$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared -lm -fpic -XCClinker -shared"
187            PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure --host=arm-linux-androideabi ac_cv_exeext=.so CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" LOL_LIBS="$LOL_LIBS"
188            # FIXME: is this needed?
189            # ant debug
190            # ant debug install
191            # ant clean
192            ;;
193        raspi-arm)
194            ./configure --host=arm-bcm2708hardfp-linux-gnueabi CPPFLAGS="-I$RASPI_SDK_ROOT/firmware/opt/vc/include -I$RASPI_SDK_ROOT/firmware/opt/vc/include/interface/vcos/pthreads -I$RASPI_SDK_ROOT/chroot/usr/include" LDFLAGS="-L$RASPI_SDK_ROOT/firmware/opt/vc/lib -L$RASPI_SDK_ROOT/chroot/lib/arm-linux-gnueabihf -Wl,-rpath-link -Wl,$RASPI_SDK_ROOT/chroot/lib/arm-linux-gnueabihf -L$RASPI_SDK_ROOT/chroot/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link -Wl,$RASPI_SDK_ROOT/chroot/usr/lib/arm-linux-gnueabihf -Wl,--unresolved-symbols=ignore-in-shared-libs"
195            ;;
196        nacl-i386)
197            ./configure CXX=i686-nacl-g++ CC=i686-nacl-gcc ac_cv_exeext=.32.nexe --host=i386 LOL_LIBS="-lppapi -lppapi_gles2 -lppapi_cpp -u _ZN2pp12CreateModuleEv"
198            ;;
199        nacl-amd64)
200            ./configure CXX=x86_64-nacl-g++ CC=x86_64-nacl-gcc ac_cv_exeext=.64.nexe --host=x86_64 LOL_LIBS="-lppapi -lppapi_gles2 -lppapi_cpp -u _ZN2pp12CreateModuleEv"
201            ;;
202        osx-amd64)
203            # HACK: use clang++ because of a memory leak in llvm-g++.
204            ./configure CXX=clang++ CC=clang
205            ;;
206        ps3-ppu)
207            PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=powerpc
208            ;;
209        win*-i386|win*-amd64)
210            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-1.2.15/include"
211            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-1.2.12/include"
212            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-1.2.12/include"
213            CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-1.9.0/include/GL -DGLEW_STATIC"
214            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
215            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
216            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
217            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
218            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
219            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
220            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
221            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
222            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
223            CPPFLAGS="$CPPFLAGS -mms-bitfields"
224            LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
225            GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
226            GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
227            GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
228
229            CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
230
231            PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
232            ;;
233        *)
234            PATH="$PATH" ./configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
235            ;;
236    esac
237}
238
239build()
240{
241    cd "$top_srcdir"
242    case "$platform" in
243        ios-arm)
244            cd monsterz/ios
245            xcodebuild -configuration Release -sdk iphonesimulator4.3
246            ;;
247        *)
248            make -j$LOL_PARALLEL
249            ;;
250    esac
251}
252
253check()
254{
255    cd "$top_srcdir"
256    case "$platform" in
257        ios-arm)
258            ;;
259        android-arm)
260            ;;
261        raspi-arm)
262            ;;
263        ps3-ppu)
264            ;;
265        nacl-*)
266            ;;
267        win*-i386)
268            # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run
269            # exists, use it to run the test suite.
270            if test "x${MSYSTEM}${DISPLAY}" = x \
271               && xvfb-run --help 2>&1 >/dev/null; then
272                xvfb-run -a make check
273            else
274                make check
275            fi
276            ;;
277        win*-amd64)
278            # No support for Wine64 yet
279            ;;
280        *)
281            make check
282            ;;
283    esac
284}
285
286clean()
287{
288    cd "$top_srcdir"
289    case "$platform" in
290        ios-arm)
291            cd monsterz/ios
292            xcodebuild -configuration Release -sdk iphonesimulator4.3 clean
293            ;;
294        *)
295            make distclean
296            ;;
297    esac
298}
299
300__init__
301echo "lol-build: executing action '$action' on platform '$platform'" >&2
302eval "$action"
303
Note: See TracBrowser for help on using the repository browser.