linux_builder.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. #!/bin/sh
  2. #
  3. # (C) 2020 Dawid Gan, under the Holy Hedgehog License (do whatever you want)
  4. #
  5. # This is a build script that creates STK linux package.
  6. #
  7. # To run the script you need debootstrap and schroot packages, and working
  8. # chroot environment.
  9. #
  10. # The build environment can be created using debootstrap:
  11. #
  12. # debootstrap --arch i386 --components=main \
  13. # jessie ./chroot-jessie32 http://ftp.debian.org/debian
  14. #
  15. # debootstrap --arch amd64 --components=main \
  16. # jessie ./chroot-jessie64 http://ftp.debian.org/debian
  17. #
  18. #
  19. # Here is example configuration for schroot:
  20. # /etc/schroot/chroot.d/chroot-jessie32.conf
  21. #
  22. # [chroot-jessie32]
  23. # description=Debian Jessie
  24. # personality=linux32
  25. # directory=/path/to/chroot-jessie32
  26. # root-users=deve
  27. # type=directory
  28. # users=deve
  29. #
  30. #
  31. # /etc/schroot/chroot.d/chroot-jessie64.conf
  32. #
  33. # [chroot-jessie64]
  34. # description=Debian Jessie 64-bit
  35. # #personality=linux32
  36. # directory=/path/to/chroot-jessie64
  37. # root-users=deve
  38. # type=directory
  39. # users=deve
  40. #
  41. #
  42. # Packages that are needed to compile all STK dependencies have to be installed
  43. # manually inside both chroot directories.
  44. export DIRNAME="$(dirname "$(readlink -f "$0")")"
  45. ######################## CONFIG ########################
  46. export STK_VERSION="git`date +%Y%m%d`"
  47. export THREADS_NUMBER=`nproc`
  48. export SCHROOT_32BIT_NAME="chroot-stretch32"
  49. export SCHROOT_64BIT_NAME="chroot-stretch64"
  50. export SCHROOT_ARMV7_NAME="chroot-stretch-armhf"
  51. export SCHROOT_ARM64_NAME="chroot-stretch-arm64"
  52. export STKCODE_DIR="$DIRNAME/.."
  53. export STKASSETS_DIR="$STKCODE_DIR/../supertuxkart-assets"
  54. export OPENGLRECORDER_DIR="$STKCODE_DIR/../libopenglrecorder"
  55. export STKEDITOR_DIR="$STKCODE_DIR/../supertuxkart-editor"
  56. export BLACKLIST_LIBS="ld-linux libbsd.so libc.so libdl.so libdrm libexpat \
  57. libGL libgl libm.so libmvec.so libpthread libresolv \
  58. librt.so libX libxcb libxshm \
  59. libEGL libgbm libwayland libffi bcm_host libvc"
  60. export BUILD_DIR="build-linux"
  61. export DEPENDENCIES_DIR="$STKCODE_DIR/dependencies-linux"
  62. export STK_INSTALL_DIR="$STKCODE_DIR/build-linux-install"
  63. export STATIC_GCC=1
  64. # Use it if you build STK with Debian Jessie
  65. export ENABLE_JESSIE_HACKS=1
  66. ########################################################
  67. # A helper function that checks if error ocurred
  68. check_error()
  69. {
  70. if [ $? -gt 0 ]; then
  71. echo "Error ocurred."
  72. exit
  73. fi
  74. }
  75. write_run_game_sh()
  76. {
  77. if [ -z "$1" ]; then
  78. return
  79. fi
  80. export INSTALL_DIR=$1
  81. export FILE="$INSTALL_DIR/run_game.sh"
  82. echo '#!/bin/sh' > "$FILE"
  83. echo '' >> "$FILE"
  84. echo 'export DIRNAME="$(dirname "$(readlink -f "$0")")"' >> "$FILE"
  85. echo 'export SYSTEM_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"' >> "$FILE"
  86. echo '' >> "$FILE"
  87. echo 'export SUPERTUXKART_DATADIR="$DIRNAME"' >> "$FILE"
  88. echo 'export SUPERTUXKART_ASSETS_DIR="$DIRNAME/data/"' >> "$FILE"
  89. echo '' >> "$FILE"
  90. echo 'cd "$DIRNAME"' >> "$FILE"
  91. echo '' >> "$FILE"
  92. echo 'export LD_LIBRARY_PATH="$DIRNAME/lib:$LD_LIBRARY_PATH"' >> "$FILE"
  93. echo '"$DIRNAME/bin/supertuxkart" "$@"' >> "$FILE"
  94. echo '' >> "$FILE"
  95. }
  96. build_stk()
  97. {
  98. if [ -z "$1" ] || [ -z "$2" ]; then
  99. return
  100. fi
  101. export ARCH_OPTION="$1"
  102. export STK_CMAKE_FLAGS="$2"
  103. export DEPENDENCIES_DIR="$DEPENDENCIES_DIR-$ARCH_OPTION"
  104. export BUILD_DIR="$BUILD_DIR-$ARCH_OPTION"
  105. export INSTALL_DIR="$DEPENDENCIES_DIR/dependencies"
  106. export INSTALL_LIB_DIR="$INSTALL_DIR/lib"
  107. export INSTALL_INCLUDE_DIR="$INSTALL_DIR/include"
  108. export PKG_CONFIG_PATH="$INSTALL_LIB_DIR/pkgconfig"
  109. export CFLAGS="-I$INSTALL_INCLUDE_DIR"
  110. export CPPFLAGS="-I$INSTALL_INCLUDE_DIR"
  111. export LDFLAGS="-Wl,-rpath,$INSTALL_LIB_DIR -L$INSTALL_LIB_DIR"
  112. export PATH="$INSTALL_DIR/bin:$PATH"
  113. if [ "$STATIC_GCC" -gt 0 ]; then
  114. LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
  115. fi
  116. cd "$STKCODE_DIR"
  117. mkdir -p "$DEPENDENCIES_DIR"
  118. # CMake
  119. if [ ! -f "$DEPENDENCIES_DIR/cmake.stamp" ]; then
  120. echo "Compiling CMake"
  121. git clone --depth 1 -b v3.24.1 https://github.com/Kitware/CMake.git "$DEPENDENCIES_DIR/cmake"
  122. cd "$DEPENDENCIES_DIR/cmake"
  123. ./bootstrap --prefix="$INSTALL_DIR" \
  124. --parallel=$THREADS_NUMBER \
  125. -- -DCMAKE_USE_OPENSSL=0 &&
  126. make -j$THREADS_NUMBER &&
  127. make install
  128. check_error
  129. touch "$DEPENDENCIES_DIR/cmake.stamp"
  130. fi
  131. # ISPC
  132. if [ ! -f "$DEPENDENCIES_DIR/ispc.stamp" ]; then
  133. if [ "$ARCH_OPTION" = "x86_64" ]; then
  134. echo "Downloading ISPC"
  135. mkdir -p "$DEPENDENCIES_DIR/ispc"
  136. cd "$DEPENDENCIES_DIR/ispc"
  137. ISPC_VERSION="v1.18.0"
  138. wget https://github.com/ispc/ispc/releases/download/$ISPC_VERSION/ispc-$ISPC_VERSION-linux.tar.gz -O ispc.tar.gz
  139. check_error
  140. tar -xzf "ispc.tar.gz"
  141. check_error
  142. cp "$DEPENDENCIES_DIR/ispc/ispc-$ISPC_VERSION-linux/bin/ispc" "$INSTALL_DIR/bin/"
  143. fi
  144. touch "$DEPENDENCIES_DIR/ispc.stamp"
  145. fi
  146. # Zlib
  147. if [ ! -f "$DEPENDENCIES_DIR/zlib.stamp" ]; then
  148. echo "Compiling zlib"
  149. mkdir -p "$DEPENDENCIES_DIR/zlib"
  150. cp -a -f "$DEPENDENCIES_DIR/../lib/zlib/"* "$DEPENDENCIES_DIR/zlib"
  151. cd "$DEPENDENCIES_DIR/zlib"
  152. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  153. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  154. -DINSTALL_PKGCONFIG_DIR="$PKG_CONFIG_PATH" &&
  155. make -j$THREADS_NUMBER &&
  156. make install
  157. check_error
  158. touch "$DEPENDENCIES_DIR/zlib.stamp"
  159. fi
  160. # Libpng
  161. if [ ! -f "$DEPENDENCIES_DIR/libpng.stamp" ]; then
  162. echo "Compiling libpng"
  163. mkdir -p "$DEPENDENCIES_DIR/libpng"
  164. mkdir -p "$DEPENDENCIES_DIR/libpng/lib"
  165. cp -a -f "$DEPENDENCIES_DIR/../lib/libpng/"* "$DEPENDENCIES_DIR/libpng"
  166. cd "$DEPENDENCIES_DIR/libpng"
  167. ./configure --prefix="$INSTALL_DIR" &&
  168. make -j$THREADS_NUMBER &&
  169. make install
  170. check_error
  171. touch "$DEPENDENCIES_DIR/libpng.stamp"
  172. fi
  173. # Freetype bootstrap
  174. if [ ! -f "$DEPENDENCIES_DIR/freetype_bootstrap.stamp" ]; then
  175. echo "Compiling freetype bootstrap"
  176. mkdir -p "$DEPENDENCIES_DIR/freetype/build"
  177. cp -a -f "$DEPENDENCIES_DIR/../lib/freetype/"* "$DEPENDENCIES_DIR/freetype"
  178. cd "$DEPENDENCIES_DIR/freetype/build"
  179. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  180. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  181. -DBUILD_SHARED_LIBS=1 \
  182. -DFT_DISABLE_HARFBUZZ=1 \
  183. -DFT_DISABLE_BZIP2=1 \
  184. -DFT_DISABLE_BROTLI=1 \
  185. -DFT_REQUIRE_ZLIB=1 \
  186. -DFT_REQUIRE_PNG=1 &&
  187. make -j$THREADS_NUMBER &&
  188. make install
  189. check_error
  190. touch "$DEPENDENCIES_DIR/freetype_bootstrap.stamp"
  191. fi
  192. # Harfbuzz
  193. if [ ! -f "$DEPENDENCIES_DIR/harfbuzz.stamp" ]; then
  194. echo "Compiling harfbuzz"
  195. mkdir -p "$DEPENDENCIES_DIR/harfbuzz"
  196. cp -a -f "$DEPENDENCIES_DIR/../lib/harfbuzz/"* "$DEPENDENCIES_DIR/harfbuzz"
  197. cd "$DEPENDENCIES_DIR/harfbuzz"
  198. ./autogen.sh
  199. ./configure --prefix="$INSTALL_DIR" \
  200. --with-freetype=yes \
  201. --with-glib=no \
  202. --with-gobject=no \
  203. --with-cairo=no \
  204. --with-fontconfig=no \
  205. --with-icu=no \
  206. --with-graphite2=no &&
  207. make -j$THREADS_NUMBER &&
  208. make install
  209. check_error
  210. touch "$DEPENDENCIES_DIR/harfbuzz.stamp"
  211. fi
  212. # Freetype
  213. if [ ! -f "$DEPENDENCIES_DIR/freetype.stamp" ]; then
  214. echo "Compiling freetype"
  215. mkdir -p "$DEPENDENCIES_DIR/freetype/build"
  216. cp -a -f "$DEPENDENCIES_DIR/../lib/freetype/"* "$DEPENDENCIES_DIR/freetype"
  217. cd "$DEPENDENCIES_DIR/freetype/build"
  218. rm -rf ./*
  219. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  220. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  221. -DBUILD_SHARED_LIBS=1 \
  222. -DCMAKE_DISABLE_FIND_PACKAGE_BZip2=1 \
  223. -DCMAKE_DISABLE_FIND_PACKAGE_BrotliDec=1 \
  224. -DFT_REQUIRE_HARFBUZZ=1 \
  225. -DFT_DISABLE_BZIP2=1 \
  226. -DFT_DISABLE_BROTLI=1 \
  227. -DFT_REQUIRE_ZLIB=1 \
  228. -DFT_REQUIRE_PNG=1 &&
  229. make -j$THREADS_NUMBER &&
  230. make install
  231. check_error
  232. touch "$DEPENDENCIES_DIR/freetype.stamp"
  233. fi
  234. # Openal
  235. if [ ! -f "$DEPENDENCIES_DIR/openal.stamp" ]; then
  236. echo "Compiling openal"
  237. mkdir -p "$DEPENDENCIES_DIR/openal"
  238. cp -a -f "$DEPENDENCIES_DIR/../lib/openal/"* "$DEPENDENCIES_DIR/openal"
  239. if [ "$ENABLE_JESSIE_HACKS" -gt 0 ]; then
  240. JESSIE_HACK="-DHAVE_LIBATOMIC=0"
  241. fi
  242. cd "$DEPENDENCIES_DIR/openal"
  243. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  244. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  245. -DALSOFT_UTILS=0 \
  246. -DALSOFT_EXAMPLES=0 \
  247. -DALSOFT_TESTS=0 \
  248. -DALSOFT_BACKEND_SNDIO=0 \
  249. $JESSIE_HACK &&
  250. make -j$THREADS_NUMBER &&
  251. make install
  252. check_error
  253. touch "$DEPENDENCIES_DIR/openal.stamp"
  254. fi
  255. # MbedTLS
  256. if [ ! -f "$DEPENDENCIES_DIR/mbedtls.stamp" ]; then
  257. echo "Compiling mbedtls"
  258. mkdir -p "$DEPENDENCIES_DIR/mbedtls"
  259. cp -a -f "$DEPENDENCIES_DIR/../lib/mbedtls/"* "$DEPENDENCIES_DIR/mbedtls"
  260. cd "$DEPENDENCIES_DIR/mbedtls"
  261. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  262. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  263. -DUSE_SHARED_MBEDTLS_LIBRARY=1 \
  264. -DENABLE_TESTING=0 \
  265. -DENABLE_PROGRAMS=0 &&
  266. make -j$THREADS_NUMBER &&
  267. make install
  268. check_error
  269. touch "$DEPENDENCIES_DIR/mbedtls.stamp"
  270. fi
  271. # Curl
  272. if [ ! -f "$DEPENDENCIES_DIR/curl.stamp" ]; then
  273. echo "Compiling curl"
  274. mkdir -p "$DEPENDENCIES_DIR/curl"
  275. cp -a -f "$DEPENDENCIES_DIR/../lib/curl/"* "$DEPENDENCIES_DIR/curl"
  276. cd "$DEPENDENCIES_DIR/curl"
  277. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  278. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  279. -DBUILD_TESTING=0 \
  280. -DBUILD_CURL_EXE=0 \
  281. -DCURL_USE_MBEDTLS=1 \
  282. -DUSE_ZLIB=1 \
  283. -DCURL_USE_OPENSSL=0 \
  284. -DCURL_USE_LIBSSH=0 \
  285. -DCURL_USE_LIBSSH2=0 \
  286. -DCURL_USE_GSSAPI=0 \
  287. -DUSE_NGHTTP2=0 \
  288. -DUSE_QUICHE=0 \
  289. -DHTTP_ONLY=1 \
  290. -DCURL_CA_BUNDLE=none \
  291. -DCURL_CA_PATH=none \
  292. -DENABLE_THREADED_RESOLVER=1 &&
  293. make -j$THREADS_NUMBER &&
  294. make install
  295. check_error
  296. rm -rf "$INSTALL_DIR/lib/cmake/CURL"
  297. touch "$DEPENDENCIES_DIR/curl.stamp"
  298. fi
  299. # Libjpeg
  300. if [ ! -f "$DEPENDENCIES_DIR/libjpeg.stamp" ]; then
  301. echo "Compiling libjpeg"
  302. mkdir -p "$DEPENDENCIES_DIR/libjpeg"
  303. cp -a -f "$DEPENDENCIES_DIR/../lib/libjpeg/"* "$DEPENDENCIES_DIR/libjpeg"
  304. cd "$DEPENDENCIES_DIR/libjpeg"
  305. chmod a+x ./configure
  306. ASM_NASM=yasm \
  307. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  308. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" &&
  309. make -j$THREADS_NUMBER &&
  310. make install
  311. check_error
  312. touch "$DEPENDENCIES_DIR/libjpeg.stamp"
  313. fi
  314. # Libogg
  315. if [ ! -f "$DEPENDENCIES_DIR/libogg.stamp" ]; then
  316. echo "Compiling libogg"
  317. mkdir -p "$DEPENDENCIES_DIR/libogg"
  318. cp -a -f "$DEPENDENCIES_DIR/../lib/libogg/"* "$DEPENDENCIES_DIR/libogg"
  319. cd "$DEPENDENCIES_DIR/libogg"
  320. ./autogen.sh
  321. ./configure --prefix="$INSTALL_DIR" &&
  322. make -j$THREADS_NUMBER &&
  323. make install
  324. check_error
  325. touch "$DEPENDENCIES_DIR/libogg.stamp"
  326. fi
  327. # Libvorbis
  328. if [ ! -f "$DEPENDENCIES_DIR/libvorbis.stamp" ]; then
  329. echo "Compiling libvorbis"
  330. mkdir -p "$DEPENDENCIES_DIR/libvorbis"
  331. cp -a -f "$DEPENDENCIES_DIR/../lib/libvorbis/"* "$DEPENDENCIES_DIR/libvorbis"
  332. cd "$DEPENDENCIES_DIR/libvorbis"
  333. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  334. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  335. -DBUILD_SHARED_LIBS=1 &&
  336. make -j$THREADS_NUMBER &&
  337. make install
  338. check_error
  339. touch "$DEPENDENCIES_DIR/libvorbis.stamp"
  340. fi
  341. # Shaderc
  342. if [ ! -f "$DEPENDENCIES_DIR/shaderc.stamp" ]; then
  343. echo "Compiling shaderc"
  344. "$DEPENDENCIES_DIR/../lib/shaderc/utils/git-sync-deps"
  345. mkdir -p "$DEPENDENCIES_DIR/shaderc"
  346. cp -a -f "$DEPENDENCIES_DIR/../lib/shaderc/"* "$DEPENDENCIES_DIR/shaderc"
  347. cd "$DEPENDENCIES_DIR/shaderc"
  348. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  349. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  350. -DCMAKE_C_FLAGS="-fpic -O3" \
  351. -DCMAKE_CXX_FLAGS="-fpic -O3" \
  352. -DSHADERC_SKIP_INSTALL=1 \
  353. -DCMAKE_BUILD_TYPE=Release \
  354. -DSHADERC_SKIP_TESTS=1 \
  355. -DSHADERC_SKIP_EXAMPLES=1 \
  356. -DSPIRV_HEADERS_SKIP_INSTALL=1 \
  357. -DSPIRV_HEADERS_SKIP_EXAMPLES=1 \
  358. -DSKIP_SPIRV_TOOLS_INSTALL=1 \
  359. -DSPIRV_SKIP_TESTS=1 \
  360. -DSPIRV_SKIP_EXECUTABLES=1 \
  361. -DENABLE_GLSLANG_BINARIES=0 \
  362. -DENABLE_CTEST=0 &&
  363. make -j$THREADS_NUMBER &&
  364. cp "$DEPENDENCIES_DIR/shaderc/libshaderc/libshaderc"* "$INSTALL_DIR/lib/" &&
  365. cp -a -f "$DEPENDENCIES_DIR/shaderc/libshaderc/include/"* "$INSTALL_DIR/include/"
  366. check_error
  367. touch "$DEPENDENCIES_DIR/shaderc.stamp"
  368. fi
  369. # ASTC-encoder
  370. if [ ! -f "$DEPENDENCIES_DIR/astc-encoder.stamp" ]; then
  371. echo "Compiling astc-encoder"
  372. mkdir -p "$DEPENDENCIES_DIR/astc-encoder"
  373. cp -a -f "$DEPENDENCIES_DIR/../lib/astc-encoder/"* "$DEPENDENCIES_DIR/astc-encoder"
  374. cd "$DEPENDENCIES_DIR/astc-encoder"
  375. sed -i '/-Werror/d' Source/cmake_core.cmake
  376. sed -i 's|${ASTC_TARGET}-static|astcenc|g' Source/cmake_core.cmake
  377. if [ "$ARCH_OPTION" = "armv7" ]; then
  378. ASTC_CMAKE_FLAGS=""
  379. ASTC_CFLAGS="-mfpu=neon"
  380. elif [ "$ARCH_OPTION" = "arm64" ]; then
  381. ASTC_CMAKE_FLAGS="-DISA_NEON=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang"
  382. elif [ "$ARCH_OPTION" = "x86" ]; then
  383. #ASTC_CMAKE_FLAGS="-DISA_SSE2=ON"
  384. ASTC_CMAKE_FLAGS=""
  385. elif [ "$ARCH_OPTION" = "x86_64" ]; then
  386. ASTC_CMAKE_FLAGS="-DISA_SSE41=ON"
  387. fi
  388. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  389. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  390. $ASTC_CMAKE_FLAGS \
  391. -DCMAKE_C_FLAGS="-fpic -O3 -g $ASTC_CFLAGS" \
  392. -DCMAKE_CXX_FLAGS="-fpic -O3 -g $ASTC_CFLAGS" \
  393. -DNO_INVARIANCE=ON -DCLI=OFF &&
  394. make -j$THREADS_NUMBER &&
  395. cp "$DEPENDENCIES_DIR/astc-encoder/Source/libastcenc.a" "$INSTALL_DIR/lib/" &&
  396. cp "$DEPENDENCIES_DIR/astc-encoder/Source/astcenc.h" "$INSTALL_DIR/include/"
  397. check_error
  398. touch "$DEPENDENCIES_DIR/astc-encoder.stamp"
  399. fi
  400. # Wayland
  401. if [ ! -f "$DEPENDENCIES_DIR/wayland.stamp" ]; then
  402. echo "Compiling wayland"
  403. mkdir -p "$DEPENDENCIES_DIR/wayland"
  404. cp -a -f "$DEPENDENCIES_DIR/../lib/wayland/"* "$DEPENDENCIES_DIR/wayland"
  405. cd "$DEPENDENCIES_DIR/wayland"
  406. ./autogen.sh
  407. ./configure --prefix="$INSTALL_DIR" --disable-documentation &&
  408. make -j$THREADS_NUMBER &&
  409. make install
  410. check_error
  411. touch "$DEPENDENCIES_DIR/wayland.stamp"
  412. fi
  413. # SDL2
  414. if [ ! -f "$DEPENDENCIES_DIR/sdl2.stamp" ]; then
  415. echo "Compiling SDL2"
  416. mkdir -p "$DEPENDENCIES_DIR/sdl2"
  417. cp -a -f "$DEPENDENCIES_DIR/../lib/sdl2/"* "$DEPENDENCIES_DIR/sdl2"
  418. cd "$DEPENDENCIES_DIR/sdl2"
  419. ./configure --prefix="$INSTALL_DIR" &&
  420. make -j$THREADS_NUMBER &&
  421. make install
  422. check_error
  423. touch "$DEPENDENCIES_DIR/sdl2.stamp"
  424. fi
  425. # Libvpx
  426. if [ ! -f "$DEPENDENCIES_DIR/libvpx.stamp" ]; then
  427. echo "Compiling libvpx"
  428. mkdir -p "$DEPENDENCIES_DIR/libvpx"
  429. cp -a -f "$DEPENDENCIES_DIR/../lib/libvpx/"* "$DEPENDENCIES_DIR/libvpx"
  430. cd "$DEPENDENCIES_DIR/libvpx"
  431. ./configure --prefix="$INSTALL_DIR" \
  432. --enable-shared &&
  433. make -j$THREADS_NUMBER &&
  434. make install
  435. check_error
  436. touch "$DEPENDENCIES_DIR/libvpx.stamp"
  437. fi
  438. # Libbluetooth
  439. if [ ! -f "$DEPENDENCIES_DIR/bluez.stamp" ]; then
  440. echo "Compiling libbluetooth"
  441. mkdir -p "$DEPENDENCIES_DIR/bluez"
  442. cp -a -f "$DEPENDENCIES_DIR/../lib/bluez/"* "$DEPENDENCIES_DIR/bluez"
  443. cd "$DEPENDENCIES_DIR/bluez"
  444. ./bootstrap
  445. ./configure --prefix="$INSTALL_DIR" \
  446. --enable-library \
  447. --disable-debug \
  448. --disable-systemd \
  449. --disable-tools \
  450. --disable-obex \
  451. --disable-cups \
  452. --disable-client \
  453. --disable-datafiles \
  454. --disable-monitor \
  455. --disable-udev &&
  456. make -j$THREADS_NUMBER &&
  457. make install
  458. check_error
  459. touch "$DEPENDENCIES_DIR/bluez.stamp"
  460. fi
  461. # Sqlite
  462. if [ ! -f "$DEPENDENCIES_DIR/sqlite.stamp" ]; then
  463. echo "Compiling sqlite"
  464. mkdir -p "$DEPENDENCIES_DIR/sqlite"
  465. cp -a -f "$DEPENDENCIES_DIR/../lib/sqlite/"* "$DEPENDENCIES_DIR/sqlite"
  466. sed -i s/' STATIC '/' SHARED '/g "$DEPENDENCIES_DIR/sqlite/CMakeLists.txt"
  467. cd "$DEPENDENCIES_DIR/sqlite"
  468. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  469. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  470. -DINSTALL_PKGCONFIG_DIR="$PKG_CONFIG_PATH" &&
  471. make -j$THREADS_NUMBER &&
  472. make install
  473. check_error
  474. touch "$DEPENDENCIES_DIR/sqlite.stamp"
  475. fi
  476. # Openglrecorder
  477. if [ ! -f "$DEPENDENCIES_DIR/openglrecorder.stamp" ]; then
  478. echo "Compiling openglrecorder"
  479. mkdir -p "$DEPENDENCIES_DIR/openglrecorder"
  480. cp -a -f "$OPENGLRECORDER_DIR/"* "$DEPENDENCIES_DIR/openglrecorder"
  481. cd "$DEPENDENCIES_DIR/openglrecorder"
  482. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  483. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  484. -DBUILD_PULSE_WO_DL=0 &&
  485. make -j$THREADS_NUMBER &&
  486. make install
  487. check_error
  488. touch "$DEPENDENCIES_DIR/openglrecorder.stamp"
  489. fi
  490. # Supertuxkart
  491. mkdir -p "$STKCODE_DIR/$BUILD_DIR"
  492. cd "$STKCODE_DIR/$BUILD_DIR"
  493. if [ -f "$INSTALL_DIR/bin/ispc" ]; then
  494. HAS_ISPC=1
  495. else
  496. HAS_ISPC=0
  497. fi
  498. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  499. -DUSE_SYSTEM_ANGELSCRIPT=0 \
  500. -DUSE_SYSTEM_ENET=0 \
  501. -DUSE_SYSTEM_WIIUSE=0 \
  502. -DUSE_CRYPTO_OPENSSL=0 \
  503. -DENABLE_WAYLAND_DEVICE=0 \
  504. -DBC7_ISPC=$HAS_ISPC \
  505. -DCMAKE_DISABLE_FIND_PACKAGE_Fontconfig=1 \
  506. $STK_CMAKE_FLAGS &&
  507. make -j$THREADS_NUMBER
  508. check_error
  509. # Stk editor
  510. mkdir -p "$STKEDITOR_DIR/$BUILD_DIR"
  511. cd "$STKEDITOR_DIR/$BUILD_DIR"
  512. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  513. -DSTATIC_ZLIB=1 \
  514. -DSTATIC_PHYSFS=1 \
  515. -DCMAKE_DISABLE_FIND_PACKAGE_Fontconfig=1 \
  516. $STK_CMAKE_FLAGS &&
  517. make -j$THREADS_NUMBER
  518. check_error
  519. }
  520. copy_libraries()
  521. {
  522. if [ -z "$1" ] || [ -z "$2" ]; then
  523. return
  524. fi
  525. export ARCH_OPTION="$1"
  526. export LIB_INSTALL_DIR="$2"
  527. export DEPENDENCIES_DIR="$DEPENDENCIES_DIR-$ARCH_OPTION"
  528. export BUILD_DIR="$BUILD_DIR-$ARCH_OPTION"
  529. if [ -z "$DEPENDENCIES_DIR" ] || [ -z "$BUILD_DIR" ] || [ -z "$LIB_INSTALL_DIR" ]; then
  530. return
  531. fi
  532. LIBRARIES_LIST=`LD_LIBRARY_PATH="$DEPENDENCIES_DIR/dependencies/lib" \
  533. ldd "$STKCODE_DIR/$BUILD_DIR/bin/supertuxkart" | \
  534. cut -d">" -f2 | cut -d"(" -f1 | grep "\.so"`
  535. for FILE in $LIBRARIES_LIST; do
  536. BLACKLISTED=0
  537. for BLACKLIST_LIB in $BLACKLIST_LIBS; do
  538. if [ `echo "$FILE" | grep -c "$BLACKLIST_LIB"` -gt 0 ]; then
  539. BLACKLISTED=1
  540. break
  541. fi
  542. done
  543. if [ $BLACKLISTED -eq 1 ]; then
  544. continue
  545. fi
  546. if [ -f "$FILE" ]; then
  547. echo " Copying $FILE"
  548. cp -L "$FILE" "$LIB_INSTALL_DIR"
  549. fi
  550. done
  551. }
  552. test_package()
  553. {
  554. if [ -z "$1" ]; then
  555. return
  556. fi
  557. PACKAGE_DIR="$1"
  558. BINARY_ARCH="$2"
  559. if [ `objdump -a "$PACKAGE_DIR/bin/supertuxkart" | grep -c "$BINARY_ARCH"` -eq 0 ]; then
  560. echo "Error: bin/supertuxkart is not $BINARY_ARCH"
  561. exit 1
  562. fi
  563. if [ `objdump -a "$PACKAGE_DIR/bin/supertuxkart-editor" | grep -c "$BINARY_ARCH"` -eq 0 ]; then
  564. echo "Error: bin/supertuxkart-editor is not $BINARY_ARCH"
  565. exit 1
  566. fi
  567. if [ `LD_LIBRARY_PATH="$PACKAGE_DIR/lib" ldd "$PACKAGE_DIR/bin/supertuxkart" | grep -c "not found"` -gt 0 ]; then
  568. echo "Error: bin/supertuxkart has some missing libraries"
  569. exit 1
  570. fi
  571. if [ `ldd "$PACKAGE_DIR/bin/supertuxkart-editor" | grep -c "not found"` -gt 0 ]; then
  572. echo "Error: bin/supertuxkart-editor has some missing libraries"
  573. exit 1
  574. fi
  575. LD_LIBRARY_PATH="$PACKAGE_DIR/lib" "$PACKAGE_DIR/bin/supertuxkart" --version
  576. if [ $? -ne 0 ]; then
  577. echo "Error: Couldn't start bin/supertuxkart"
  578. exit 1
  579. fi
  580. }
  581. create_package()
  582. {
  583. SCHROOT_NAME="$1"
  584. ARCH="$2"
  585. BINARY_ARCH="$3"
  586. echo "Building $ARCH version..."
  587. schroot -c $SCHROOT_NAME -- "$0" build_stk "$ARCH" "-DDEBUG_SYMBOLS=1"
  588. if [ ! -f "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" ]; then
  589. echo "Couldn't build $ARCH version."
  590. exit 1
  591. fi
  592. echo "Prepare package..."
  593. STK_PACKAGE_DIR="$STK_INSTALL_DIR/SuperTuxKart-$STK_VERSION-linux-$ARCH"
  594. if [ -f "$STK_PACKAGE_DIR" ]; then
  595. rm -rf "$STK_PACKAGE_DIR"
  596. fi
  597. mkdir -p "$STK_PACKAGE_DIR"
  598. mkdir -p "$STK_PACKAGE_DIR/bin"
  599. mkdir -p "$STK_PACKAGE_DIR/lib"
  600. schroot -c $SCHROOT_NAME -- "$0" copy_libraries "$ARCH" "$STK_PACKAGE_DIR/lib"
  601. find "$STK_PACKAGE_DIR/lib" -type f -exec strip -s {} \;
  602. if [ "$STATIC_GCC" -eq 0 ]; then
  603. mv "$STK_PACKAGE_DIR/lib/libgcc_s.so.1" "$STK_PACKAGE_DIR/lib/libgcc_s.so.1-orig"
  604. mv "$STK_PACKAGE_DIR/lib/libstdc++.so.6" "$STK_PACKAGE_DIR/lib/libstdc++.so.6-orig"
  605. fi
  606. write_run_game_sh "$STK_PACKAGE_DIR"
  607. cp "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" "$STK_INSTALL_DIR/supertuxkart-$STK_VERSION-linux-$ARCH-symbols"
  608. cp "$STKEDITOR_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart-editor" "$STK_INSTALL_DIR/supertuxkart-editor-$STK_VERSION-linux-$ARCH-symbols"
  609. cp -a "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" "$STK_PACKAGE_DIR/bin/"
  610. cp -a "$STKEDITOR_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart-editor" "$STK_PACKAGE_DIR/bin/"
  611. cp -a "$STKCODE_DIR/data/." "$STK_PACKAGE_DIR/data"
  612. cp -a "$STKASSETS_DIR/editor" "$STK_PACKAGE_DIR/data/"
  613. cp -a "$STKASSETS_DIR/karts" "$STK_PACKAGE_DIR/data/"
  614. cp -a "$STKASSETS_DIR/library" "$STK_PACKAGE_DIR/data/"
  615. cp -a "$STKASSETS_DIR/models" "$STK_PACKAGE_DIR/data/"
  616. cp -a "$STKASSETS_DIR/music" "$STK_PACKAGE_DIR/data/"
  617. cp -a "$STKASSETS_DIR/sfx" "$STK_PACKAGE_DIR/data/"
  618. cp -a "$STKASSETS_DIR/textures" "$STK_PACKAGE_DIR/data/"
  619. cp -a "$STKASSETS_DIR/tracks" "$STK_PACKAGE_DIR/data/"
  620. cp -a "$STKASSETS_DIR/licenses.txt" "$STK_PACKAGE_DIR/data/"
  621. strip --strip-debug "$STK_PACKAGE_DIR/bin/supertuxkart"
  622. strip --strip-debug "$STK_PACKAGE_DIR/bin/supertuxkart-editor"
  623. find "$STK_PACKAGE_DIR/bin" -type f -exec chrpath -d {} \;
  624. find "$STK_PACKAGE_DIR/lib" -type f -exec chrpath -d {} \;
  625. chmod a+rwx "$STK_PACKAGE_DIR" -R
  626. find "$STK_PACKAGE_DIR" -type f -exec chmod a-x {} \;
  627. find "$STK_PACKAGE_DIR/bin" -type f -exec chmod a+x {} \;
  628. chmod a+x "$STK_PACKAGE_DIR/run_game.sh"
  629. schroot -c $SCHROOT_NAME -- "$0" test_package "$STK_PACKAGE_DIR" "$BINARY_ARCH"
  630. # Compress package
  631. echo "Compress package..."
  632. cd "$STK_INSTALL_DIR"
  633. tar cf - "SuperTuxKart-$STK_VERSION-linux-$ARCH" | xz -T$THREADS_NUMBER -z -e -f - > "SuperTuxKart-$STK_VERSION-linux-$ARCH.tar.xz"
  634. cd -
  635. }
  636. # Handle clean command
  637. if [ ! -z "$1" ] && [ "$1" = "clean" ]; then
  638. rm -rf "$DEPENDENCIES_DIR-"*
  639. rm -rf "$STKCODE_DIR/$BUILD_DIR-"*
  640. rm -rf "$STKEDITOR_DIR/$BUILD_DIR-"*
  641. rm -rf "$STK_INSTALL_DIR"
  642. exit 0
  643. fi
  644. # Handle build_stk command (internal only)
  645. if [ ! -z "$1 " ] && [ "$1" = "build_stk" ]; then
  646. build_stk "$2" "$3"
  647. exit 0
  648. fi
  649. # Handle copy_libraries command (internal only)
  650. if [ ! -z "$1 " ] && [ "$1" = "copy_libraries" ]; then
  651. copy_libraries "$2" "$3"
  652. exit 0
  653. fi
  654. # Handle test_package command (internal only)
  655. if [ ! -z "$1 " ] && [ "$1" = "test_package" ]; then
  656. test_package "$2" "$3"
  657. exit 0
  658. fi
  659. # Building STK
  660. create_package "$SCHROOT_32BIT_NAME" "x86" "elf32-i386"
  661. create_package "$SCHROOT_64BIT_NAME" "x86_64" "elf64-x86-64"
  662. create_package "$SCHROOT_ARMV7_NAME" "armv7" "elf32-littlearm"
  663. create_package "$SCHROOT_ARM64_NAME" "arm64" "elf64-littleaarch64"
  664. echo "Success."