You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

292 rivejä
10 KiB

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