Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

351 rader
13 KiB

  1. #!/bin/sh
  2. #
  3. # Lol Engine build script
  4. # Usage:
  5. # lol-build [<flags>...] <action> [<platform>]
  6. #
  7. # Supported flags:
  8. # --enable-debug
  9. # --enable-devel
  10. # --enable-release
  11. #
  12. # Where <action> is one of:
  13. # - bootstrap
  14. # - configure
  15. # - build
  16. # - check
  17. # - clean
  18. #
  19. # And <platform> is one of:
  20. # - linux-i386
  21. # - linux-amd64
  22. # - nacl-i386
  23. # - nacl-amd64
  24. # - ios-arm
  25. # - osx-amd64
  26. # - android-arm
  27. # - win*-i386
  28. # - win*-amd64
  29. # - raspi-arm
  30. # - web-html
  31. # - web-js
  32. #
  33. set -e
  34. ###############################################################################
  35. # Commandline parsing
  36. #
  37. action=""
  38. platform=""
  39. configure_flags=""
  40. while [ "$#" -gt 0 ]; do
  41. case "$1" in
  42. --enable-debug|--enable-devel|--enable-release)
  43. configure_flags="${configure_flags} $1"
  44. ;;
  45. --*)
  46. echo "E: invalid flag $1"
  47. exit 1
  48. ;;
  49. *)
  50. if [ -z "$action" ]; then
  51. action="$1"
  52. else
  53. platform="$1"
  54. fi
  55. ;;
  56. esac
  57. shift
  58. done
  59. ###############################################################################
  60. # Initialisation code
  61. #
  62. # - sets the top_srcdir variable
  63. # - sets the LOL_PARALLEL variable
  64. # - fix PATH and MKPATH if necessary
  65. #
  66. __init__()
  67. {
  68. top_srcdir="$(dirname "$0")/.."
  69. cd "$top_srcdir"
  70. top_srcdir="`pwd`"
  71. # Try to count CPU cores. First obvious try: /proc/cpuinfo on Linux
  72. case "$cpu_count" in
  73. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  74. *) if [ -r "/proc/cpuinfo" ]; then
  75. cpu_count="$(grep -c '^processor\>' /proc/cpuinfo 2>/dev/null || true)"
  76. fi ;;
  77. esac
  78. # If that didn't work, try sysctl (for OS X machines)
  79. case "$cpu_count" in
  80. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  81. *) cpu_count="$(sysctl -n hw.ncpu 2>/dev/null || true)" ;;
  82. esac
  83. # Otherwise, CPUInfo.exe (from Xoreax's XGE) may help on Windows
  84. case "$cpu_count" in
  85. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  86. *) cpu_count="$(CPUInfo.exe | sed -ne 's/CPU Cores.* \([0-9][0-9]*\)/\1/p')" ;;
  87. esac
  88. # Otherwise, Windows may define NUMBER_OF_PROCESSORS
  89. case "$cpu_count" in
  90. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  91. *) cpu_count="$NUMBER_OF_PROCESSORS" ;;
  92. esac
  93. # Otherwise, be conservative and assume 1 CPU core
  94. case "$cpu_count" in
  95. [1-9]|[1-9][0-9]|[1-9][0-9][0-9]) ;;
  96. *) cpu_count=1 ;;
  97. esac
  98. # Now decide how many parallel threads to launch
  99. case "$cpu_count" in
  100. 1) LOL_PARALLEL=1 ;;
  101. 2) LOL_PARALLEL=3 ;;
  102. *) LOL_PARALLEL="$(expr $cpu_count '*' 3 / 2)" ;;
  103. esac
  104. case "${MSYSTEM}" in
  105. MINGW32|MINGW64)
  106. PATH="$PATH:./external/gtk-2.22.1/bin"
  107. M4PATH="$M4PATH:./external/gtk-2.22.1/share/aclocal"
  108. ;;
  109. esac
  110. # Ensure we don’t launch weird Windows binaries when cross-compiling
  111. WINEDLLOVERRIDES="winemenubuilder.exe,wineboot.exe,explorer.exe,winedbg.exe=d"
  112. export WINEDLLOVERRIDES
  113. # Ensure SDL does not redirect stdout/stderr to local files
  114. SDL_STDIO_REDIRECT=0
  115. export SDL_STDIO_REDIRECT
  116. }
  117. bootstrap()
  118. {
  119. cd "$top_srcdir"
  120. case "$platform" in
  121. *)
  122. PATH="$PATH" M4PATH="$M4PATH" ./bootstrap
  123. ;;
  124. esac
  125. }
  126. do_configure()
  127. {
  128. ./configure ${configure_flags} "$@"
  129. }
  130. configure()
  131. {
  132. cd "$top_srcdir"
  133. case "$platform" in
  134. android-arm)
  135. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  136. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/arm-linux-androideabi -lz"
  137. CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
  138. ;;
  139. win*-i386)
  140. if test "x${MSYSTEM}" = xMINGW32; then
  141. :
  142. elif i586-mingw32msvc-g++ --version >/dev/null 2>&1; then
  143. HOSTFLAGS=--host=i586-mingw32msvc
  144. BUILDFLAGS=--build=none
  145. elif i686-w64-mingw32-g++ --version >/dev/null 2>&1; then
  146. HOSTFLAGS=--host=i686-w64-mingw32
  147. BUILDFLAGS=--build=none
  148. else
  149. echo "Error: could not find win32 compiler" >&2
  150. false
  151. fi
  152. if test "x${MSYSTEM}" = xMINGW64; then
  153. # If using mingw64, we're not really cross-compiling
  154. BUILDFLAGS=
  155. fi
  156. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
  157. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  158. LDFLAGS="$LDFLAGS -L$PWD/external/ffmpeg-20141018/lib/i686-w64-mingw32"
  159. LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/i686-w64-mingw32"
  160. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-2.0.3/lib/i686-w64-mingw32"
  161. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-2.0.0/lib/i686-w64-mingw32"
  162. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-2.0.0/lib/i686-w64-mingw32"
  163. LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/lib"
  164. LDFLAGS="$LDFLAGS -L$PWD/external/gtk-2.22.1/bin"
  165. LDFLAGS="$LDFLAGS -L$PWD/external/gtkglarea-2.0.1/lib"
  166. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/i686-w64-mingw32"
  167. ;;
  168. win*-amd64)
  169. if test "x${MSYSTEM}" = xMINGW64; then
  170. :
  171. elif x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then
  172. HOSTFLAGS=--host=x86_64-w64-mingw32
  173. BUILDFLAGS=--build=none
  174. else
  175. echo "Error: could not find win64 compiler" >&2
  176. false
  177. fi
  178. if test "x${MSYSTEM}" = xMINGW32; then
  179. # If using mingw32, we're not really cross-compiling
  180. BUILDFLAGS=
  181. fi
  182. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/gtkglarea-2.0.1/lib/pkgconfig"
  183. PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/external/libcaca-0.99.beta18/lib/pkgconfig"
  184. LDFLAGS="$LDFLAGS -L$PWD/external/ffmpeg-20141018/lib/x86_64-w64-mingw32"
  185. LDFLAGS="$LDFLAGS -L$PWD/external/glew-1.9.0/lib/x86_64-w64-mingw32"
  186. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-2.0.3/lib/x86_64-w64-mingw32"
  187. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-image-2.0.0/lib/x86_64-mingw32"
  188. LDFLAGS="$LDFLAGS -L$PWD/external/sdl-mixer-2.0.0/lib/x86_64-mingw32"
  189. LDFLAGS="$LDFLAGS -L$PWD/external/libcaca-0.99.beta18/lib/x86_64-w64-mingw32"
  190. ;;
  191. *-i386)
  192. # Ensure we're _really_ on i386
  193. CXXFLAGS="$CXXFLAGS -m32"
  194. ;;
  195. *-amd64)
  196. # Ensure we're _really_ on amd64
  197. CXXFLAGS="$CXXFLAGS -m64"
  198. ;;
  199. web-*)
  200. # Force cross-compilation because AC_TRY_LINK is going to check
  201. # whether our binaries have the executable bit set.
  202. HOSTFLAGS=--host=none
  203. BUILDFLAGS=--build=`$top_srcdir/.auto/config.guess`
  204. ;;
  205. esac
  206. case "$platform" in
  207. ios-arm)
  208. XCODE="/Applications/Xcode.app/Contents/Developer"
  209. SDKVER="6.1"
  210. DEVROOT="$XCODE/Platforms/iPhoneOS.platform/Developer"
  211. SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
  212. CC="$XCODE/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
  213. CXX="$XCODE/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
  214. do_configure --host=armv7-apple-darwin10 CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" CC="$CC" CXX="$CXX"
  215. ;;
  216. android-arm)
  217. 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"
  218. CFLAGS="$CFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb"
  219. CXXFLAGS="$CXXFLAGS -march=armv5te -mtune=xscale -msoft-float -mthumb -fno-rtti -fno-exceptions"
  220. LOL_LIBS="$LOL_LIBS -L$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi -lstlport_shared -lm -fpic -XCClinker -shared -u ANativeActivity_onCreate"
  221. PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure --host=arm-linux-androideabi ac_cv_exeext=.so CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" LOL_LIBS="$LOL_LIBS"
  222. # FIXME: is this needed?
  223. # ant debug
  224. # ant debug install
  225. # ant clean
  226. ;;
  227. raspi-arm)
  228. do_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/firmware/opt/vc/include/interface/vmcs_host/linux -I$RASPI_SDK_ROOT/chroot/usr/include -I$RASPI_SDK_ROOT/chroot/usr/include/arm-linux-gnueabihf" 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"
  229. ;;
  230. nacl-i386)
  231. do_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"
  232. ;;
  233. nacl-amd64)
  234. do_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"
  235. ;;
  236. osx-amd64)
  237. # HACK: use clang++ because of a memory leak in llvm-g++.
  238. do_configure CXX=clang++ CC=clang
  239. ;;
  240. win*-i386|win*-amd64)
  241. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-2.0.3/include"
  242. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-2.0.0/include"
  243. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-2.0.0/include"
  244. CPPFLAGS="$CPPFLAGS -I$PWD/external/ffmpeg-20141018/include"
  245. CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-1.9.0/include/GL -DGLEW_STATIC"
  246. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
  247. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
  248. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
  249. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
  250. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
  251. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
  252. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
  253. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
  254. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
  255. CPPFLAGS="$CPPFLAGS -mms-bitfields"
  256. LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
  257. GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
  258. GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
  259. GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
  260. CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
  261. PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
  262. ;;
  263. web-*)
  264. # We use --enable-release otherwise builds are really too slow
  265. do_configure --enable-release $HOSTFLAGS $BUILDFLAGS CC=emcc CXX=em++ AR=emar RANLIB=emranlib PKG_CONFIG=/bin/false SDL_CONFIG=/bin/false ac_cv_exeext=".${platform##web-}"
  266. ;;
  267. *)
  268. PATH="$PATH" do_configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
  269. ;;
  270. esac
  271. }
  272. build()
  273. {
  274. cd "$top_srcdir"
  275. case "$platform" in
  276. win*-i386)
  277. # Because of locking issues in Wine’s winepath.exe, we only
  278. # build the static libraries in parallel.
  279. make -j$LOL_PARALLEL -C src/bullet
  280. make -j$LOL_PARALLEL -C src/lua
  281. make -j$LOL_PARALLEL -C src/ liblolcore.a
  282. make
  283. ;;
  284. *)
  285. make -j$LOL_PARALLEL
  286. ;;
  287. esac
  288. }
  289. check()
  290. {
  291. cd "$top_srcdir"
  292. case "$platform" in
  293. ios-arm)
  294. ;;
  295. android-arm)
  296. ;;
  297. raspi-arm)
  298. ;;
  299. nacl-*)
  300. ;;
  301. web-*)
  302. ;;
  303. win*-i386)
  304. # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run
  305. # exists, use it to run the test suite.
  306. if test "x${MSYSTEM}${DISPLAY}" = x \
  307. && xvfb-run --help 2>&1 >/dev/null; then
  308. xvfb-run -a make check VERBOSE=1
  309. else
  310. make check VERBOSE=1
  311. fi
  312. ;;
  313. win*-amd64)
  314. # No support for Wine64 yet
  315. ;;
  316. *)
  317. make check VERBOSE=1
  318. ;;
  319. esac
  320. }
  321. clean()
  322. {
  323. cd "$top_srcdir"
  324. case "$platform" in
  325. *)
  326. make distclean
  327. ;;
  328. esac
  329. }
  330. __init__
  331. echo "lol-build: executing action '$action' on platform '$platform'" >&2
  332. eval "$action"