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