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.
 
 
 

310 line
12 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. # - emscripten-html
  27. # - emscripten-js
  28. #
  29. set -e
  30. action="$1"
  31. platform="$2"
  32. ###############################################################################
  33. # Initialisation code
  34. #
  35. # - sets the top_srcdir variable
  36. # - sets the LOL_PARALLEL variable
  37. # - fix PATH and MKPATH if necessary
  38. #
  39. __init__()
  40. {
  41. top_srcdir="$(dirname "$0")/.."
  42. cd "$top_srcdir"
  43. top_srcdir="`pwd`"
  44. # Try to count CPU cores. First obvious try: /proc/cpuinfo on Linux
  45. case "$cpu_count" in
  46. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  47. *) if [ -r "/proc/cpuinfo" ]; then
  48. cpu_count="$(grep -c '^processor\>' /proc/cpuinfo 2>/dev/null || true)"
  49. fi ;;
  50. esac
  51. # If that didn't work, try sysctl (for OS X machines)
  52. case "$cpu_count" in
  53. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  54. *) cpu_count="$(sysctl -n hw.ncpu 2>/dev/null || true)" ;;
  55. esac
  56. # Otherwise, CPUInfo.exe (from Xoreax's XGE) may help on Windows
  57. case "$cpu_count" in
  58. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  59. *) cpu_count="$(CPUInfo.exe | sed -ne 's/CPU Cores.* \([0-9][0-9]*\)/\1/p')" ;;
  60. esac
  61. # Otherwise, Windows may define NUMBER_OF_PROCESSORS
  62. case "$cpu_count" in
  63. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  64. *) cpu_count="$NUMBER_OF_PROCESSORS" ;;
  65. esac
  66. # Otherwise, be conservative and assume 1 CPU core
  67. case "$cpu_count" in
  68. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  69. *) cpu_count=1 ;;
  70. esac
  71. # Now decide how many parallel threads to launch
  72. case "$cpu_count" in
  73. 1) LOL_PARALLEL=1 ;;
  74. 2) LOL_PARALLEL=3 ;;
  75. *) LOL_PARALLEL="$(expr $cpu_count '*' 3 / 2)" ;;
  76. esac
  77. case "${MSYSTEM}" in
  78. MINGW32|MINGW64)
  79. PATH="$PATH:./external/gtk-2.22.1/bin"
  80. M4PATH="$M4PATH:./external/gtk-2.22.1/share/aclocal"
  81. ;;
  82. esac
  83. # Ensure we don’t launch weird Windows binaries when cross-compiling
  84. WINEDLLOVERRIDES="winemenubuilder.exe,wineboot.exe,explorer.exe,winedbg.exe=d"
  85. export WINEDLLOVERRIDES
  86. # Ensure SDL does not redirect stdout/stderr to local files
  87. SDL_STDIO_REDIRECT=0
  88. export SDL_STDIO_REDIRECT
  89. }
  90. bootstrap()
  91. {
  92. cd "$top_srcdir"
  93. case "$platform" in
  94. *)
  95. PATH="$PATH" M4PATH="$M4PATH" ./bootstrap
  96. ;;
  97. esac
  98. }
  99. configure()
  100. {
  101. cd "$top_srcdir"
  102. case "$platform" in
  103. android-arm)
  104. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  105. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/arm-linux-androideabi -lz"
  106. CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
  107. ;;
  108. win*-i386)
  109. if test "x${MSYSTEM}" = xMINGW32; then
  110. :
  111. elif i586-mingw32msvc-g++ --version >/dev/null 2>&1; then
  112. HOSTFLAGS=--host=i586-mingw32msvc
  113. BUILDFLAGS=--build=none
  114. elif i686-w64-mingw32-g++ --version >/dev/null 2>&1; then
  115. HOSTFLAGS=--host=i686-w64-mingw32
  116. BUILDFLAGS=--build=none
  117. else
  118. echo "Error: could not find win32 compiler" >&2
  119. false
  120. fi
  121. if test "x${MSYSTEM}" = xMINGW64; then
  122. # If using mingw64, we're not really cross-compiling
  123. BUILDFLAGS=
  124. fi
  125. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
  126. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  127. LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/i686-w64-mingw32"
  128. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/i686-w64-mingw32"
  129. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.12/lib/i686-w64-mingw32"
  130. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.12/lib/i686-w64-mingw32"
  131. LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/lib"
  132. LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/bin"
  133. LDFLAGS="$LDFLAGS -L$PWD/external/gtkglarea-2.0.1/lib"
  134. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/i686-w64-mingw32"
  135. ;;
  136. win*-amd64)
  137. if test "x${MSYSTEM}" = xMINGW64; then
  138. :
  139. elif x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then
  140. HOSTFLAGS=--host=x86_64-w64-mingw32
  141. BUILDFLAGS=--build=none
  142. else
  143. echo "Error: could not find win64 compiler" >&2
  144. false
  145. fi
  146. if test "x${MSYSTEM}" = xMINGW32; then
  147. # If using mingw32, we're not really cross-compiling
  148. BUILDFLAGS=
  149. fi
  150. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
  151. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  152. LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/x86_64-w64-mingw32"
  153. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-1.2.15/lib/x86_64-w64-mingw32"
  154. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-1.2.12/lib/x86_64-msvc"
  155. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-1.2.12/lib/x86_64-msvc"
  156. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/x86_64-w64-mingw32"
  157. ;;
  158. *-i386)
  159. # Ensure we're _really_ on i386
  160. CXXFLAGS="$CXXFLAGS -m32"
  161. ;;
  162. *-amd64)
  163. # Ensure we're _really_ on amd64
  164. CXXFLAGS="$CXXFLAGS -m64"
  165. ;;
  166. emscripten-*)
  167. # Force cross-compilation because AC_TRY_LINK is going to check
  168. # whether our binaries have the executable bit set.
  169. HOSTFLAGS=--host=none
  170. BUILDFLAGS=--build=`$top_srcdir/.auto/config.guess`
  171. ;;
  172. esac
  173. case "$platform" in
  174. ios-arm)
  175. XCODE="/Applications/Xcode.app/Contents/Developer"
  176. SDKVER="6.1"
  177. DEVROOT="$XCODE/Platforms/iPhoneOS.platform/Developer"
  178. SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
  179. CC="$XCODE/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
  180. CXX="$XCODE/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
  181. ./configure --host=armv7-apple-darwin10 CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" CC="$CC" CXX="$CXX"
  182. ;;
  183. android-arm)
  184. 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"
  185. CFLAGS="$CFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb"
  186. CXXFLAGS="$CXXFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb -fno-rtti -fno-exceptions"
  187. LOL_LIBS="$LOL_LIBS -L$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared -lm -fpic -XCClinker -shared -u ANativeActivity_onCreate"
  188. 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"
  189. # FIXME: is this needed?
  190. # ant debug
  191. # ant debug install
  192. # ant clean
  193. ;;
  194. raspi-arm)
  195. ./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"
  196. ;;
  197. nacl-i386)
  198. ./configure CXX=i686-nacl-g++ CC=i686-nacl-gcc ac_cv_exeext=.32.nexe --host=i386 CPPFLAGS="-I$NACL_SDK_ROOT/include" LOL_LIBS="-lppapi -lppapi_gles2 -lppapi_cpp -u _ZN2pp12CreateModuleEv"
  199. ;;
  200. nacl-amd64)
  201. ./configure CXX=x86_64-nacl-g++ CC=x86_64-nacl-gcc ac_cv_exeext=.64.nexe --host=x86_64 CPPFLAGS="-I$NACL_SDK_ROOT/include" LOL_LIBS="-lppapi -lppapi_gles2 -lppapi_cpp -u _ZN2pp12CreateModuleEv"
  202. ;;
  203. osx-amd64)
  204. # HACK: use clang++ because of a memory leak in llvm-g++.
  205. ./configure CXX=clang++ CC=clang
  206. ;;
  207. ps3-ppu)
  208. PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=powerpc
  209. ;;
  210. win*-i386|win*-amd64)
  211. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-1.2.15/include"
  212. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-1.2.12/include"
  213. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-1.2.12/include"
  214. CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-1.9.0/include/GL -DGLEW_STATIC"
  215. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
  216. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
  217. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
  218. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
  219. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
  220. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
  221. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
  222. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
  223. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
  224. CPPFLAGS="$CPPFLAGS -mms-bitfields"
  225. LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
  226. GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
  227. GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
  228. GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
  229. CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
  230. PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" ./configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
  231. ;;
  232. emscripten-*)
  233. ./configure $HOSTFLAGS $BUILDFLAGS CC=emcc CXX=em++ AR=emar RANLIB=emranlib PKG_CONFIG=/bin/false SDL_CONFIG=/bin/false ac_cv_exeext=".${platform##emscripten-}"
  234. ;;
  235. *)
  236. PATH="$PATH" ./configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
  237. ;;
  238. esac
  239. }
  240. build()
  241. {
  242. cd "$top_srcdir"
  243. case "$platform" in
  244. *)
  245. make -j$LOL_PARALLEL
  246. ;;
  247. esac
  248. }
  249. check()
  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 -a 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. clean()
  282. {
  283. cd "$top_srcdir"
  284. case "$platform" in
  285. *)
  286. make distclean
  287. ;;
  288. esac
  289. }
  290. __init__
  291. echo "lol-build: executing action '$action' on platform '$platform'" >&2
  292. eval "$action"