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.
 
 
 

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