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.
 
 
 

345 lines
12 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 -I$ANDROID_NDK_ROOT/sources/android/native_app_glue -fpic -fomit-frame-pointer -fno-strict-aliasing"
  216. CFLAGS="$CFLAGS"
  217. CXXFLAGS="$CXXFLAGS"
  218. LOL_LIBS="$LOL_LIBS -lm -fpic -XCClinker -shared -u ANativeActivity_onCreate"
  219. HOST=armv7a-linux-androideabi27
  220. PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure --host="$HOST" CC="$HOST-clang" CXX="$HOST-clang++" ac_cv_exeext=.so CPPFLAGS="$CPPFLAGS" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" LOL_LIBS="$LOL_LIBS"
  221. # FIXME: is this needed?
  222. # ant debug
  223. # ant debug install
  224. # ant clean
  225. ;;
  226. raspi-arm)
  227. 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"
  228. ;;
  229. osx-amd64)
  230. # HACK: use clang++ because of a memory leak in llvm-g++.
  231. do_configure CXX=clang++ CC=clang
  232. ;;
  233. win*-i386|win*-amd64)
  234. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-2.0.9/include"
  235. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-image-2.0.4/include"
  236. CPPFLAGS="$CPPFLAGS -I$PWD/external/sdl-mixer-2.0.4/include"
  237. CPPFLAGS="$CPPFLAGS -I$PWD/external/ffmpeg-20190130/include"
  238. CPPFLAGS="$CPPFLAGS -I$PWD/external/glew-2.1.0/include -DGLEW_STATIC"
  239. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/glib-2.0/include"
  240. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/lib/gtk-2.0/include"
  241. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/glib-2.0"
  242. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gtk-2.0"
  243. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/cairo"
  244. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/pango-1.0"
  245. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/gdk-pixbuf-2.0"
  246. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtk-2.22.1/include/atk-1.0"
  247. CPPFLAGS="$CPPFLAGS -I$PWD/external/gtkglarea-2.0.1/include"
  248. CPPFLAGS="$CPPFLAGS -I$PWD/src/3rdparty/imgui/include"
  249. CPPFLAGS="$CPPFLAGS -mms-bitfields"
  250. LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
  251. GTK_LIBS="$GTK_LIBS -lgtkgl-2.0 -lopengl32 -lglew32 -lgdi32"
  252. GTK_LIBS="$GTK_LIBS -lgtk-win32-2.0 -lgdk-win32-2.0"
  253. GTK_LIBS="$GTK_LIBS -lglib-2.0 -lgthread-2.0 -lgobject-2.0"
  254. CPPFLAGS="$CPPFLAGS -I$PWD/external/libcaca-0.99.beta18/include -DCACA_STATIC"
  255. PATH="$PATH" PKG_CONFIG_PATH="$PKG_CONFIG_PATH" do_configure $HOSTFLAGS $BUILDFLAGS CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" GTK_LIBS="$GTK_LIBS"
  256. ;;
  257. web-*)
  258. # First do an emcc run so that dependent libraries are generated
  259. emflags="-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s USE_SDL_MIXER=2"
  260. touch conftest.c ; emcc $(echo $emflags) conftest.c -c -o conftest.o ; rm -f conftest.c conftest.o
  261. # We use --enable-release otherwise builds are really too slow
  262. 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="$emflags" CXXFLAGS="$emflags" CFLAGS="$emflags"
  263. ;;
  264. *)
  265. PATH="$PATH" do_configure CFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS"
  266. ;;
  267. esac
  268. }
  269. build()
  270. {
  271. cd "$top_srcdir"
  272. case "$platform" in
  273. win*-i386)
  274. # Because of locking issues in Wine’s winepath.exe, we only
  275. # build the static libraries in parallel.
  276. make -j$LOL_PARALLEL -C src/3rdparty liblol-lua.a
  277. make -j$LOL_PARALLEL -C src/ liblol-core.a
  278. make
  279. ;;
  280. *)
  281. make -j$LOL_PARALLEL
  282. ;;
  283. esac
  284. }
  285. check()
  286. {
  287. cd "$top_srcdir"
  288. case "$platform" in
  289. ios-arm)
  290. ;;
  291. android-arm)
  292. ;;
  293. raspi-arm)
  294. ;;
  295. web-*)
  296. ;;
  297. win*-i386)
  298. # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run
  299. # exists, use it to run the test suite.
  300. if test "x${MSYSTEM}${DISPLAY}" = x \
  301. && xvfb-run --help 2>&1 >/dev/null; then
  302. xvfb-run -a make check VERBOSE=1
  303. else
  304. make check VERBOSE=1
  305. fi
  306. ;;
  307. win*-amd64)
  308. # No support for Wine64 yet
  309. ;;
  310. *)
  311. make check VERBOSE=1
  312. ;;
  313. esac
  314. }
  315. clean()
  316. {
  317. cd "$top_srcdir"
  318. case "$platform" in
  319. *)
  320. make distclean
  321. ;;
  322. esac
  323. }
  324. __init__
  325. echo "lol-build: executing action '$action' on platform '$platform'" >&2
  326. eval "$action"