linux_builder.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. # ASTC-encoder
  342. if [ ! -f "$DEPENDENCIES_DIR/astc-encoder.stamp" ]; then
  343. echo "Compiling astc-encoder"
  344. mkdir -p "$DEPENDENCIES_DIR/astc-encoder"
  345. cp -a -f "$DEPENDENCIES_DIR/../lib/astc-encoder/"* "$DEPENDENCIES_DIR/astc-encoder"
  346. cd "$DEPENDENCIES_DIR/astc-encoder"
  347. sed -i '/-Werror/d' Source/cmake_core.cmake
  348. sed -i 's|${ASTC_TARGET}-static|astcenc|g' Source/cmake_core.cmake
  349. if [ "$ARCH_OPTION" = "armv7" ]; then
  350. ASTC_CMAKE_FLAGS=""
  351. ASTC_CFLAGS="-mfpu=neon"
  352. elif [ "$ARCH_OPTION" = "arm64" ]; then
  353. ASTC_CMAKE_FLAGS="-DISA_NEON=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang"
  354. elif [ "$ARCH_OPTION" = "x86" ]; then
  355. #ASTC_CMAKE_FLAGS="-DISA_SSE2=ON"
  356. ASTC_CMAKE_FLAGS=""
  357. elif [ "$ARCH_OPTION" = "x86_64" ]; then
  358. ASTC_CMAKE_FLAGS="-DISA_SSE41=ON"
  359. fi
  360. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  361. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  362. $ASTC_CMAKE_FLAGS \
  363. -DCMAKE_C_FLAGS="-fpic -O3 -g $ASTC_CFLAGS" \
  364. -DCMAKE_CXX_FLAGS="-fpic -O3 -g $ASTC_CFLAGS" \
  365. -DNO_INVARIANCE=ON -DCLI=OFF &&
  366. make -j$THREADS_NUMBER &&
  367. cp "$DEPENDENCIES_DIR/astc-encoder/Source/libastcenc.a" "$INSTALL_DIR/lib/" &&
  368. cp "$DEPENDENCIES_DIR/astc-encoder/Source/astcenc.h" "$INSTALL_DIR/include/"
  369. check_error
  370. touch "$DEPENDENCIES_DIR/astc-encoder.stamp"
  371. fi
  372. # Wayland
  373. if [ ! -f "$DEPENDENCIES_DIR/wayland.stamp" ]; then
  374. echo "Compiling wayland"
  375. mkdir -p "$DEPENDENCIES_DIR/wayland"
  376. cp -a -f "$DEPENDENCIES_DIR/../lib/wayland/"* "$DEPENDENCIES_DIR/wayland"
  377. cd "$DEPENDENCIES_DIR/wayland"
  378. ./autogen.sh
  379. ./configure --prefix="$INSTALL_DIR" --disable-documentation &&
  380. make -j$THREADS_NUMBER &&
  381. make install
  382. check_error
  383. touch "$DEPENDENCIES_DIR/wayland.stamp"
  384. fi
  385. # SDL2
  386. if [ ! -f "$DEPENDENCIES_DIR/sdl2.stamp" ]; then
  387. echo "Compiling SDL2"
  388. mkdir -p "$DEPENDENCIES_DIR/sdl2"
  389. cp -a -f "$DEPENDENCIES_DIR/../lib/sdl2/"* "$DEPENDENCIES_DIR/sdl2"
  390. cd "$DEPENDENCIES_DIR/sdl2"
  391. ./configure --prefix="$INSTALL_DIR" &&
  392. make -j$THREADS_NUMBER &&
  393. make install
  394. check_error
  395. touch "$DEPENDENCIES_DIR/sdl2.stamp"
  396. fi
  397. # Libvpx
  398. if [ ! -f "$DEPENDENCIES_DIR/libvpx.stamp" ]; then
  399. echo "Compiling libvpx"
  400. mkdir -p "$DEPENDENCIES_DIR/libvpx"
  401. cp -a -f "$DEPENDENCIES_DIR/../lib/libvpx/"* "$DEPENDENCIES_DIR/libvpx"
  402. cd "$DEPENDENCIES_DIR/libvpx"
  403. ./configure --prefix="$INSTALL_DIR" \
  404. --enable-shared &&
  405. make -j$THREADS_NUMBER &&
  406. make install
  407. check_error
  408. touch "$DEPENDENCIES_DIR/libvpx.stamp"
  409. fi
  410. # Libbluetooth
  411. if [ ! -f "$DEPENDENCIES_DIR/bluez.stamp" ]; then
  412. echo "Compiling libbluetooth"
  413. mkdir -p "$DEPENDENCIES_DIR/bluez"
  414. cp -a -f "$DEPENDENCIES_DIR/../lib/bluez/"* "$DEPENDENCIES_DIR/bluez"
  415. cd "$DEPENDENCIES_DIR/bluez"
  416. ./bootstrap
  417. ./configure --prefix="$INSTALL_DIR" \
  418. --enable-library \
  419. --disable-debug \
  420. --disable-systemd \
  421. --disable-tools \
  422. --disable-obex \
  423. --disable-cups \
  424. --disable-client \
  425. --disable-datafiles \
  426. --disable-monitor \
  427. --disable-udev &&
  428. make -j$THREADS_NUMBER &&
  429. make install
  430. check_error
  431. touch "$DEPENDENCIES_DIR/bluez.stamp"
  432. fi
  433. # Sqlite
  434. if [ ! -f "$DEPENDENCIES_DIR/sqlite.stamp" ]; then
  435. echo "Compiling sqlite"
  436. mkdir -p "$DEPENDENCIES_DIR/sqlite"
  437. cp -a -f "$DEPENDENCIES_DIR/../lib/sqlite/"* "$DEPENDENCIES_DIR/sqlite"
  438. sed -i s/' STATIC '/' SHARED '/g "$DEPENDENCIES_DIR/sqlite/CMakeLists.txt"
  439. cd "$DEPENDENCIES_DIR/sqlite"
  440. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  441. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  442. -DINSTALL_PKGCONFIG_DIR="$PKG_CONFIG_PATH" &&
  443. make -j$THREADS_NUMBER &&
  444. make install
  445. check_error
  446. touch "$DEPENDENCIES_DIR/sqlite.stamp"
  447. fi
  448. # Openglrecorder
  449. if [ ! -f "$DEPENDENCIES_DIR/openglrecorder.stamp" ]; then
  450. echo "Compiling openglrecorder"
  451. mkdir -p "$DEPENDENCIES_DIR/openglrecorder"
  452. cp -a -f "$OPENGLRECORDER_DIR/"* "$DEPENDENCIES_DIR/openglrecorder"
  453. cd "$DEPENDENCIES_DIR/openglrecorder"
  454. cmake . -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  455. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
  456. -DBUILD_PULSE_WO_DL=0 &&
  457. make -j$THREADS_NUMBER &&
  458. make install
  459. check_error
  460. touch "$DEPENDENCIES_DIR/openglrecorder.stamp"
  461. fi
  462. # Supertuxkart
  463. mkdir -p "$STKCODE_DIR/$BUILD_DIR"
  464. cd "$STKCODE_DIR/$BUILD_DIR"
  465. if [ -f "$INSTALL_DIR/bin/ispc" ]; then
  466. HAS_ISPC=1
  467. else
  468. HAS_ISPC=0
  469. fi
  470. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  471. -DUSE_SYSTEM_ANGELSCRIPT=0 \
  472. -DUSE_SYSTEM_ENET=0 \
  473. -DUSE_SYSTEM_WIIUSE=0 \
  474. -DUSE_CRYPTO_OPENSSL=0 \
  475. -DENABLE_WAYLAND_DEVICE=0 \
  476. -DBC7_ISPC=$HAS_ISPC \
  477. -DCMAKE_DISABLE_FIND_PACKAGE_Fontconfig=1 \
  478. $STK_CMAKE_FLAGS &&
  479. make -j$THREADS_NUMBER
  480. check_error
  481. # Stk editor
  482. mkdir -p "$STKEDITOR_DIR/$BUILD_DIR"
  483. cd "$STKEDITOR_DIR/$BUILD_DIR"
  484. cmake .. -DCMAKE_FIND_ROOT_PATH="$INSTALL_DIR" \
  485. -DSTATIC_ZLIB=1 \
  486. -DSTATIC_PHYSFS=1 \
  487. -DCMAKE_DISABLE_FIND_PACKAGE_Fontconfig=1 \
  488. $STK_CMAKE_FLAGS &&
  489. make -j$THREADS_NUMBER
  490. check_error
  491. }
  492. copy_libraries()
  493. {
  494. if [ -z "$1" ] || [ -z "$2" ]; then
  495. return
  496. fi
  497. export ARCH_OPTION="$1"
  498. export LIB_INSTALL_DIR="$2"
  499. export DEPENDENCIES_DIR="$DEPENDENCIES_DIR-$ARCH_OPTION"
  500. export BUILD_DIR="$BUILD_DIR-$ARCH_OPTION"
  501. if [ -z "$DEPENDENCIES_DIR" ] || [ -z "$BUILD_DIR" ] || [ -z "$LIB_INSTALL_DIR" ]; then
  502. return
  503. fi
  504. LIBRARIES_LIST=`LD_LIBRARY_PATH="$DEPENDENCIES_DIR/dependencies/lib" \
  505. ldd "$STKCODE_DIR/$BUILD_DIR/bin/supertuxkart" | \
  506. cut -d">" -f2 | cut -d"(" -f1 | grep "\.so"`
  507. for FILE in $LIBRARIES_LIST; do
  508. BLACKLISTED=0
  509. for BLACKLIST_LIB in $BLACKLIST_LIBS; do
  510. if [ `echo "$FILE" | grep -c "$BLACKLIST_LIB"` -gt 0 ]; then
  511. BLACKLISTED=1
  512. break
  513. fi
  514. done
  515. if [ $BLACKLISTED -eq 1 ]; then
  516. continue
  517. fi
  518. if [ -f "$FILE" ]; then
  519. echo " Copying $FILE"
  520. cp -L "$FILE" "$LIB_INSTALL_DIR"
  521. fi
  522. done
  523. }
  524. test_package()
  525. {
  526. if [ -z "$1" ]; then
  527. return
  528. fi
  529. PACKAGE_DIR="$1"
  530. BINARY_ARCH="$2"
  531. if [ `objdump -a "$PACKAGE_DIR/bin/supertuxkart" | grep -c "$BINARY_ARCH"` -eq 0 ]; then
  532. echo "Error: bin/supertuxkart is not $BINARY_ARCH"
  533. exit 1
  534. fi
  535. if [ `objdump -a "$PACKAGE_DIR/bin/supertuxkart-editor" | grep -c "$BINARY_ARCH"` -eq 0 ]; then
  536. echo "Error: bin/supertuxkart-editor is not $BINARY_ARCH"
  537. exit 1
  538. fi
  539. if [ `LD_LIBRARY_PATH="$PACKAGE_DIR/lib" ldd "$PACKAGE_DIR/bin/supertuxkart" | grep -c "not found"` -gt 0 ]; then
  540. echo "Error: bin/supertuxkart has some missing libraries"
  541. exit 1
  542. fi
  543. if [ `ldd "$PACKAGE_DIR/bin/supertuxkart-editor" | grep -c "not found"` -gt 0 ]; then
  544. echo "Error: bin/supertuxkart-editor has some missing libraries"
  545. exit 1
  546. fi
  547. LD_LIBRARY_PATH="$PACKAGE_DIR/lib" "$PACKAGE_DIR/bin/supertuxkart" --version
  548. if [ $? -ne 0 ]; then
  549. echo "Error: Couldn't start bin/supertuxkart"
  550. exit 1
  551. fi
  552. }
  553. create_package()
  554. {
  555. SCHROOT_NAME="$1"
  556. ARCH="$2"
  557. BINARY_ARCH="$3"
  558. echo "Building $ARCH version..."
  559. schroot -c $SCHROOT_NAME -- "$0" build_stk "$ARCH" "-DDEBUG_SYMBOLS=1"
  560. if [ ! -f "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" ]; then
  561. echo "Couldn't build $ARCH version."
  562. exit 1
  563. fi
  564. echo "Prepare package..."
  565. STK_PACKAGE_DIR="$STK_INSTALL_DIR/SuperTuxKart-$STK_VERSION-linux-$ARCH"
  566. if [ -f "$STK_PACKAGE_DIR" ]; then
  567. rm -rf "$STK_PACKAGE_DIR"
  568. fi
  569. mkdir -p "$STK_PACKAGE_DIR"
  570. mkdir -p "$STK_PACKAGE_DIR/bin"
  571. mkdir -p "$STK_PACKAGE_DIR/lib"
  572. schroot -c $SCHROOT_NAME -- "$0" copy_libraries "$ARCH" "$STK_PACKAGE_DIR/lib"
  573. find "$STK_PACKAGE_DIR/lib" -type f -exec strip -s {} \;
  574. if [ "$STATIC_GCC" -eq 0 ]; then
  575. mv "$STK_PACKAGE_DIR/lib/libgcc_s.so.1" "$STK_PACKAGE_DIR/lib/libgcc_s.so.1-orig"
  576. mv "$STK_PACKAGE_DIR/lib/libstdc++.so.6" "$STK_PACKAGE_DIR/lib/libstdc++.so.6-orig"
  577. fi
  578. write_run_game_sh "$STK_PACKAGE_DIR"
  579. cp "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" "$STK_INSTALL_DIR/supertuxkart-$STK_VERSION-linux-$ARCH-symbols"
  580. cp "$STKEDITOR_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart-editor" "$STK_INSTALL_DIR/supertuxkart-editor-$STK_VERSION-linux-$ARCH-symbols"
  581. cp -a "$STKCODE_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart" "$STK_PACKAGE_DIR/bin/"
  582. cp -a "$STKEDITOR_DIR/$BUILD_DIR-$ARCH/bin/supertuxkart-editor" "$STK_PACKAGE_DIR/bin/"
  583. cp -a "$STKCODE_DIR/data/." "$STK_PACKAGE_DIR/data"
  584. cp -a "$STKASSETS_DIR/editor" "$STK_PACKAGE_DIR/data/"
  585. cp -a "$STKASSETS_DIR/karts" "$STK_PACKAGE_DIR/data/"
  586. cp -a "$STKASSETS_DIR/library" "$STK_PACKAGE_DIR/data/"
  587. cp -a "$STKASSETS_DIR/models" "$STK_PACKAGE_DIR/data/"
  588. cp -a "$STKASSETS_DIR/music" "$STK_PACKAGE_DIR/data/"
  589. cp -a "$STKASSETS_DIR/sfx" "$STK_PACKAGE_DIR/data/"
  590. cp -a "$STKASSETS_DIR/textures" "$STK_PACKAGE_DIR/data/"
  591. cp -a "$STKASSETS_DIR/tracks" "$STK_PACKAGE_DIR/data/"
  592. cp -a "$STKASSETS_DIR/licenses.txt" "$STK_PACKAGE_DIR/data/"
  593. strip --strip-debug "$STK_PACKAGE_DIR/bin/supertuxkart"
  594. strip --strip-debug "$STK_PACKAGE_DIR/bin/supertuxkart-editor"
  595. find "$STK_PACKAGE_DIR/bin" -type f -exec chrpath -d {} \;
  596. find "$STK_PACKAGE_DIR/lib" -type f -exec chrpath -d {} \;
  597. chmod a+rwx "$STK_PACKAGE_DIR" -R
  598. find "$STK_PACKAGE_DIR" -type f -exec chmod a-x {} \;
  599. find "$STK_PACKAGE_DIR/bin" -type f -exec chmod a+x {} \;
  600. chmod a+x "$STK_PACKAGE_DIR/run_game.sh"
  601. schroot -c $SCHROOT_NAME -- "$0" test_package "$STK_PACKAGE_DIR" "$BINARY_ARCH"
  602. # Compress package
  603. echo "Compress package..."
  604. cd "$STK_INSTALL_DIR"
  605. tar cf - "SuperTuxKart-$STK_VERSION-linux-$ARCH" | xz -T$THREADS_NUMBER -z -e -f - > "SuperTuxKart-$STK_VERSION-linux-$ARCH.tar.xz"
  606. cd -
  607. }
  608. # Handle clean command
  609. if [ ! -z "$1" ] && [ "$1" = "clean" ]; then
  610. rm -rf "$DEPENDENCIES_DIR-"*
  611. rm -rf "$STKCODE_DIR/$BUILD_DIR-"*
  612. rm -rf "$STKEDITOR_DIR/$BUILD_DIR-"*
  613. rm -rf "$STK_INSTALL_DIR"
  614. exit 0
  615. fi
  616. # Handle build_stk command (internal only)
  617. if [ ! -z "$1 " ] && [ "$1" = "build_stk" ]; then
  618. build_stk "$2" "$3"
  619. exit 0
  620. fi
  621. # Handle copy_libraries command (internal only)
  622. if [ ! -z "$1 " ] && [ "$1" = "copy_libraries" ]; then
  623. copy_libraries "$2" "$3"
  624. exit 0
  625. fi
  626. # Handle test_package command (internal only)
  627. if [ ! -z "$1 " ] && [ "$1" = "test_package" ]; then
  628. test_package "$2" "$3"
  629. exit 0
  630. fi
  631. # Building STK
  632. create_package "$SCHROOT_32BIT_NAME" "x86" "elf32-i386"
  633. create_package "$SCHROOT_64BIT_NAME" "x86_64" "elf64-x86-64"
  634. create_package "$SCHROOT_ARMV7_NAME" "armv7" "elf32-littlearm"
  635. create_package "$SCHROOT_ARM64_NAME" "arm64" "elf64-littleaarch64"
  636. echo "Success."