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.
 
 
 

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