source: trunk/build/lol-build @ 2272

Last change on this file since 2272 was 2272, checked in by sam, 7 years ago

build: do not launch weird Windows binaries when cross-compiling.

  • Property svn:executable set to *
File size: 10.8 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    case "${platform}" in
90        win*)
91            WINEDLLOVERRIDES="winemenubuilder.exe=d;wineboot.exe=d"
92            export WINEDLLOVERRIDES
93            ;;
94    esac
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.10/lib/i686-w64-mingw32"
141            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.11/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.10/lib/x86_64-w64-mingw32"
166            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.11/lib/x86_64-w64-mingw32"
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        ps3-ppu)
203            PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=powerpc
204            ;;
205        win*-i386|win*-amd64)
206            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-1.2.15/include"
207            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-1.2.10/include"
208            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-1.2.11/include"
209            CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-1.9.0/include/GL -DGLEW_STATIC"
210            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
211            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
212            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
213            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
214            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
215            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
216            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
217            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
218            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
219            CPPFLAGS="$CPPFLAGS -mms-bitfields"
220            LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
221            GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
222            GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
223            GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
224
225            CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
226
227            PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
228            ;;
229        *)
230            PATH="$PATH" ./configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
231            ;;
232    esac
233}
234
235build()
236{
237    cd "$top_srcdir"
238    case "$platform" in
239        ios-arm)
240            cd monsterz/ios
241            xcodebuild -configuration Release -sdk iphonesimulator4.3
242            ;;
243        *)
244            make -j$LOL_PARALLEL
245            ;;
246    esac
247}
248
249check()
250{
251    cd "$top_srcdir"
252    case "$platform" in
253        ios-arm)
254            ;;
255        android-arm)
256            ;;
257        raspi-arm)
258            ;;
259        ps3-ppu)
260            ;;
261        nacl-*)
262            ;;
263        win*-i386)
264            # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run
265            # exists, use it to run the test suite.
266            if test "x${MSYSTEM}${DISPLAY}" = x \
267               && xvfb-run --help 2>&1 >/dev/null; then
268                xvfb-run make check
269            else
270                make check
271            fi
272            ;;
273        win*-amd64)
274            # No support for Wine64 yet
275            ;;
276        *)
277            make check
278            ;;
279    esac
280}
281
282clean()
283{
284    cd "$top_srcdir"
285    case "$platform" in
286        ios-arm)
287            cd monsterz/ios
288            xcodebuild -configuration Release -sdk iphonesimulator4.3 clean
289            ;;
290        *)
291            make distclean
292            ;;
293    esac
294}
295
296__init__
297echo "lol-build: executing action '$action' on platform '$platform'" >&2
298eval "$action"
299
Note: See TracBrowser for help on using the repository browser.