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 | case "$cpu_count" in |
---|
48 | [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;; |
---|
49 | *) if [ -r "/proc/cpuinfo" ]; then |
---|
50 | cpu_count="$(grep -c '^processor\>' /proc/cpuinfo)" |
---|
51 | fi ;; |
---|
52 | esac |
---|
53 | case "$cpu_count" in |
---|
54 | [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;; |
---|
55 | *) cpu_count="$(sysctl -n hw.ncpu 2>/dev/null)" ;; |
---|
56 | esac |
---|
57 | case "$cpu_count" in |
---|
58 | [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;; |
---|
59 | *) cpu_count=1 ;; |
---|
60 | esac |
---|
61 | case "$cpu_count" in |
---|
62 | 1) LOL_PARALLEL=1 ;; |
---|
63 | 2) LOL_PARALLEL=3 ;; |
---|
64 | *) LOL_PARALLEL="$(expr $cpu_count '*' 3 / 2)" ;; |
---|
65 | esac |
---|
66 | |
---|
67 | case "${MSYSTEM}" in |
---|
68 | MINGW32|MINGW64) |
---|
69 | PATH="$PATH:./contrib/gtk-2.22.1/bin" |
---|
70 | M4PATH="$M4PATH:./contrib/gtk-2.22.1/share/aclocal" |
---|
71 | ;; |
---|
72 | esac |
---|
73 | } |
---|
74 | |
---|
75 | bootstrap() |
---|
76 | { |
---|
77 | cd "$top_srcdir" |
---|
78 | case "$platform" in |
---|
79 | ios-arm) |
---|
80 | # No bootstrapping needed |
---|
81 | ;; |
---|
82 | android-arm) |
---|
83 | # No bootstrapping needed |
---|
84 | ;; |
---|
85 | *) |
---|
86 | PATH="$PATH" M4PATH="$M4PATH" ./bootstrap |
---|
87 | ;; |
---|
88 | esac |
---|
89 | } |
---|
90 | |
---|
91 | configure() |
---|
92 | { |
---|
93 | cd "$top_srcdir" |
---|
94 | case "$platform" in |
---|
95 | win*-i386) |
---|
96 | if test "x${MSYSTEM}" = xMINGW32; then |
---|
97 | : |
---|
98 | elif i586-mingw32msvc-g++ --version >/dev/null 2>&1; then |
---|
99 | HOSTFLAGS=--host=i586-mingw32msvc |
---|
100 | BUILDFLAGS=--build=none |
---|
101 | elif i686-w64-mingw32-g++ --version >/dev/null 2>&1; then |
---|
102 | HOSTFLAGS=--host=i686-w64-mingw32 |
---|
103 | BUILDFLAGS=--build=none |
---|
104 | else |
---|
105 | echo "Error: could not find win32 compiler" >&2 |
---|
106 | false |
---|
107 | fi |
---|
108 | if test "x${MSYSTEM}" = xMINGW64; then |
---|
109 | # If using mingw64, we're not really cross-compiling |
---|
110 | BUILDFLAGS= |
---|
111 | fi |
---|
112 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/contrib/gtkglarea-2.0.1/lib/pkgconfig" |
---|
113 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/contrib/libcaca-0.99.beta18/lib/pkgconfig" |
---|
114 | LDFLAGS="$LDFLAGS -L$PWD/contrib/glew-1.7.0/lib/i686-w64-mingw32" |
---|
115 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-1.2.15/lib/i686-w64-mingw32" |
---|
116 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-image-1.2.10/lib/i686-w64-mingw32" |
---|
117 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-mixer-1.2.11/lib/i686-w64-mingw32" |
---|
118 | LDFLAGS="$LDFLAGS -L$PWD/contrib/gtk-2.22.1/lib" |
---|
119 | LDFLAGS="$LDFLAGS -L$PWD/contrib/gtk-2.22.1/bin" |
---|
120 | LDFLAGS="$LDFLAGS -L$PWD/contrib/gtkglarea-2.0.1/lib" |
---|
121 | LDFLAGS="$LDFLAGS -L$PWD/contrib/libcaca-0.99.beta18/lib/i686-w64-mingw32" |
---|
122 | ;; |
---|
123 | win*-amd64) |
---|
124 | if test "x${MSYSTEM}" = xMINGW64; then |
---|
125 | : |
---|
126 | elif x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then |
---|
127 | HOSTFLAGS=--host=x86_64-w64-mingw32 |
---|
128 | BUILDFLAGS=--build=none |
---|
129 | else |
---|
130 | echo "Error: could not find win64 compiler" >&2 |
---|
131 | false |
---|
132 | fi |
---|
133 | if test "x${MSYSTEM}" = xMINGW32; then |
---|
134 | # If using mingw32, we're not really cross-compiling |
---|
135 | BUILDFLAGS= |
---|
136 | fi |
---|
137 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/contrib/gtkglarea-2.0.1/lib/pkgconfig" |
---|
138 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/contrib/libcaca-0.99.beta18/lib/pkgconfig" |
---|
139 | LDFLAGS="$LDFLAGS -L$PWD/contrib/glew-1.7.0/lib/x86_64-w64-mingw32" |
---|
140 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-1.2.15/lib/x86_64-w64-mingw32" |
---|
141 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-image-1.2.10/lib/x86_64-w64-mingw32" |
---|
142 | LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-mixer-1.2.11/lib/x86_64-w64-mingw32" |
---|
143 | LDFLAGS="$LDFLAGS -L$PWD/contrib/libcaca-0.99.beta18/lib/x86_64-w64-mingw32" |
---|
144 | ;; |
---|
145 | *-i386) |
---|
146 | # Ensure we're _really_ on i386 |
---|
147 | CXXFLAGS="$CXXFLAGS -m32" |
---|
148 | ;; |
---|
149 | *-amd64) |
---|
150 | # Ensure we're _really_ on amd64 |
---|
151 | CXXFLAGS="$CXXFLAGS -m64" |
---|
152 | ;; |
---|
153 | esac |
---|
154 | case "$platform" in |
---|
155 | ios-arm) |
---|
156 | # No configuration needed |
---|
157 | ;; |
---|
158 | android-arm) |
---|
159 | cd monsterz/android |
---|
160 | android update project --path . |
---|
161 | ;; |
---|
162 | raspi-arm) |
---|
163 | ./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" LDFLAGS="-L$RASPI_SDK_ROOT/firmware/opt/vc/lib" |
---|
164 | ;; |
---|
165 | nacl-i386) |
---|
166 | ./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" |
---|
167 | ;; |
---|
168 | nacl-amd64) |
---|
169 | ./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" |
---|
170 | ;; |
---|
171 | ps3-ppu) |
---|
172 | PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=powerpc |
---|
173 | ;; |
---|
174 | win*-i386|win*-amd64) |
---|
175 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-1.2.15/include" |
---|
176 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-image-1.2.10/include" |
---|
177 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-mixer-1.2.11/include" |
---|
178 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/glew-1.7.0/include/GL -DGLEW_STATIC" |
---|
179 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/lib/glib-2.0/include" |
---|
180 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/lib/gtk-2.0/include" |
---|
181 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/glib-2.0" |
---|
182 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/gtk-2.0" |
---|
183 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/cairo" |
---|
184 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/pango-1.0" |
---|
185 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/gdk-pixbuf-2.0" |
---|
186 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtk-2.22.1/include/atk-1.0" |
---|
187 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gtkglarea-2.0.1/include" |
---|
188 | CPPFLAGS="$CPPFLAGS -mms-bitfields" |
---|
189 | LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++" |
---|
190 | GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32" |
---|
191 | GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0" |
---|
192 | GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0" |
---|
193 | |
---|
194 | CPPFLAGS="$CPPFLAGS -I$PWD/contrib/libcaca-0.99.beta18/include -DCACA_STATIC" |
---|
195 | |
---|
196 | PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS" |
---|
197 | ;; |
---|
198 | *) |
---|
199 | PATH="$PATH" ./configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS" |
---|
200 | ;; |
---|
201 | esac |
---|
202 | } |
---|
203 | |
---|
204 | build() |
---|
205 | { |
---|
206 | cd "$top_srcdir" |
---|
207 | case "$platform" in |
---|
208 | ios-arm) |
---|
209 | cd monsterz/ios |
---|
210 | xcodebuild -configuration Release -sdk iphonesimulator4.3 |
---|
211 | ;; |
---|
212 | android-arm) |
---|
213 | cd monsterz/android |
---|
214 | ndk-build |
---|
215 | ant compile |
---|
216 | ;; |
---|
217 | *) |
---|
218 | make -j$LOL_PARALLEL |
---|
219 | ;; |
---|
220 | esac |
---|
221 | } |
---|
222 | |
---|
223 | check() |
---|
224 | { |
---|
225 | cd "$top_srcdir" |
---|
226 | case "$platform" in |
---|
227 | ios-arm) |
---|
228 | ;; |
---|
229 | android-arm) |
---|
230 | ;; |
---|
231 | raspi-arm) |
---|
232 | ;; |
---|
233 | ps3-ppu) |
---|
234 | ;; |
---|
235 | nacl-*) |
---|
236 | ;; |
---|
237 | win*-i386) |
---|
238 | # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run |
---|
239 | # exists, use it to run the test suite. |
---|
240 | if test "x${MSYSTEM}${DISPLAY}" = x \ |
---|
241 | && xvfb-run --help 2>&1 >/dev/null; then |
---|
242 | xvfb-run make check |
---|
243 | else |
---|
244 | make check |
---|
245 | fi |
---|
246 | ;; |
---|
247 | win*-amd64) |
---|
248 | # No support for Wine64 yet |
---|
249 | ;; |
---|
250 | *) |
---|
251 | make check |
---|
252 | ;; |
---|
253 | esac |
---|
254 | } |
---|
255 | |
---|
256 | clean() |
---|
257 | { |
---|
258 | cd "$top_srcdir" |
---|
259 | case "$platform" in |
---|
260 | ios-arm) |
---|
261 | cd monsterz/ios |
---|
262 | xcodebuild -configuration Release -sdk iphonesimulator4.3 clean |
---|
263 | ;; |
---|
264 | android-arm) |
---|
265 | cd monsterz/android |
---|
266 | ndk-build distclean |
---|
267 | ant clean |
---|
268 | ;; |
---|
269 | *) |
---|
270 | make distclean |
---|
271 | ;; |
---|
272 | esac |
---|
273 | } |
---|
274 | |
---|
275 | __init__ |
---|
276 | echo "lol-build: executing action '$action' on platform '$platform'" >&2 |
---|
277 | eval "$action" |
---|
278 | |
---|