source: trunk/build/lol-build @ 2228

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

build: try to build neercs on Android; far from ready yet.

  • Property svn:executable set to *
File size: 10.5 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
89bootstrap()
90{
91    cd "$top_srcdir"
92    case "$platform" in
93        ios-arm)
94            # No bootstrapping needed
95            ;;
96        *)
97            PATH="$PATH" M4PATH="$M4PATH" ./bootstrap
98            ;;
99    esac
100}
101
102configure()
103{
104    cd "$top_srcdir"
105    case "$platform" in
106        android-arm)
107            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
108            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/arm-linux-androideabi -lz"
109            CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
110            ;;
111        win*-i386)
112            if test "x${MSYSTEM}" = xMINGW32; then
113                :
114            elif i586-mingw32msvc-g++ --version >/dev/null 2>&1; then
115                HOSTFLAGS=--host=i586-mingw32msvc
116                BUILDFLAGS=--build=none
117            elif i686-w64-mingw32-g++ --version >/dev/null 2>&1; then
118                HOSTFLAGS=--host=i686-w64-mingw32
119                BUILDFLAGS=--build=none
120            else
121                echo "Error: could not find win32 compiler" >&2
122                false
123            fi
124            if test "x${MSYSTEM}" = xMINGW64; then
125                # If using mingw64, we're not really cross-compiling
126                BUILDFLAGS=
127            fi
128            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
129            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
130            LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/i686-w64-mingw32"
131            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/i686-w64-mingw32"
132            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.10/lib/i686-w64-mingw32"
133            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.11/lib/i686-w64-mingw32"
134            LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/lib"
135            LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/bin"
136            LDFLAGS="$LDFLAGS -L$PWD/external/gtkglarea-2.0.1/lib"
137            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/i686-w64-mingw32"
138            ;;
139        win*-amd64)
140            if test "x${MSYSTEM}" = xMINGW64; then
141                :
142            elif x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then
143                HOSTFLAGS=--host=x86_64-w64-mingw32
144                BUILDFLAGS=--build=none
145            else
146                echo "Error: could not find win64 compiler" >&2
147                false
148            fi
149            if test "x${MSYSTEM}" = xMINGW32; then
150                # If using mingw32, we're not really cross-compiling
151                BUILDFLAGS=
152            fi
153            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
154            PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
155            LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/x86_64-w64-mingw32"
156            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/x86_64-w64-mingw32"
157            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.10/lib/x86_64-w64-mingw32"
158            LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.11/lib/x86_64-w64-mingw32"
159            LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/x86_64-w64-mingw32"
160            ;;
161        *-i386)
162            # Ensure we're _really_ on i386
163            CXXFLAGS="$CXXFLAGS -m32"
164            ;;
165        *-amd64)
166            # Ensure we're _really_ on amd64
167            CXXFLAGS="$CXXFLAGS -m64"
168            ;;
169    esac
170    case "$platform" in
171        ios-arm)
172            # No configuration needed
173            ;;
174        android-arm)
175            CPPFLAGS="$CPPFLAGS -Wno-psabi -I$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport -fpic -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64"
176            CFLAGS="$CFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb"
177            CXXFLAGS="$CXXFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb -fno-rtti -fno-exceptions"
178            LOL_LIBS="$LOL_LIBS -L$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared -lm -fpic -XCClinker -shared"
179            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"
180            # FIXME: is this needed?
181            # ant debug
182            # ant debug install
183            # ant clean
184            ;;
185        raspi-arm)
186            ./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"
187            ;;
188        nacl-i386)
189            ./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"
190            ;;
191        nacl-amd64)
192            ./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"
193            ;;
194        ps3-ppu)
195            PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=powerpc
196            ;;
197        win*-i386|win*-amd64)
198            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-1.2.15/include"
199            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-1.2.10/include"
200            CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-1.2.11/include"
201            CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-1.9.0/include/GL -DGLEW_STATIC"
202            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
203            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
204            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
205            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
206            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
207            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
208            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
209            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
210            CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
211            CPPFLAGS="$CPPFLAGS -mms-bitfields"
212            LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
213            GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
214            GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
215            GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
216
217            CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
218
219            PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
220            ;;
221        *)
222            PATH="$PATH" ./configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
223            ;;
224    esac
225}
226
227build()
228{
229    cd "$top_srcdir"
230    case "$platform" in
231        ios-arm)
232            cd monsterz/ios
233            xcodebuild -configuration Release -sdk iphonesimulator4.3
234            ;;
235        *)
236            make -j$LOL_PARALLEL
237            ;;
238    esac
239}
240
241check()
242{
243    cd "$top_srcdir"
244    case "$platform" in
245        ios-arm)
246            ;;
247        android-arm)
248            ;;
249        raspi-arm)
250            ;;
251        ps3-ppu)
252            ;;
253        nacl-*)
254            ;;
255        win*-i386)
256            # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run
257            # exists, use it to run the test suite.
258            if test "x${MSYSTEM}${DISPLAY}" = x \
259               && xvfb-run --help 2>&1 >/dev/null; then
260                xvfb-run make check
261            else
262                make check
263            fi
264            ;;
265        win*-amd64)
266            # No support for Wine64 yet
267            ;;
268        *)
269            make check
270            ;;
271    esac
272}
273
274clean()
275{
276    cd "$top_srcdir"
277    case "$platform" in
278        ios-arm)
279            cd monsterz/ios
280            xcodebuild -configuration Release -sdk iphonesimulator4.3 clean
281            ;;
282        *)
283            make distclean
284            ;;
285    esac
286}
287
288__init__
289echo "lol-build: executing action '$action' on platform '$platform'" >&2
290eval "$action"
291
Note: See TracBrowser for help on using the repository browser.