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.
 
 
 

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