🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

351 lines
11 KiB

  1. #!/bin/bash
  2. set -e
  3. if ! [ "x$ANDROID_NDK_HOME" != "x" -a -d "$ANDROID_NDK_HOME" ]; then
  4. echo "ANDROID_NDK_HOME environment variable is not set"
  5. exit 1
  6. fi
  7. if ! [ "x$ANDROID_HOME" != "x" -a -d "$ANDROID_HOME" ]; then
  8. echo "ANDROID_HOME environment variable is not set"
  9. exit 1
  10. fi
  11. if [ "x$ANDROID_API" = "x" ]; then
  12. ANDROID_API="$(ls "$ANDROID_HOME/platforms" | grep -E "^android-[0-9]+$" | sed 's/android-//' | sort -n -r | head -1)"
  13. if [ "x$ANDROID_API" = "x" ]; then
  14. echo "No Android platform found in $ANDROID_HOME/platforms"
  15. exit 1
  16. fi
  17. else
  18. if ! [ -d "$ANDROID_HOME/platforms/android-$ANDROID_API" ]; then
  19. echo "Android api version $ANDROID_API is not available ($ANDROID_HOME/platforms/android-$ANDROID_API does not exist)" >2
  20. exit 1
  21. fi
  22. fi
  23. android_platformdir="$ANDROID_HOME/platforms/android-$ANDROID_API"
  24. echo "Building for android api version $ANDROID_API"
  25. echo "android_platformdir=$android_platformdir"
  26. scriptdir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
  27. sdl_root=$(cd -P -- "$(dirname -- "$0")/.." && printf '%s\n' "$(pwd -P)")
  28. build_root="${sdl_root}/build-android-prefab"
  29. android_abis="armeabi-v7a arm64-v8a x86 x86_64"
  30. android_api=19
  31. android_ndk=21
  32. android_stl="c++_shared"
  33. sdl_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION *//p' "${sdl_root}/include/SDL_version.h")
  34. sdl_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION *//p' "${sdl_root}/include/SDL_version.h")
  35. sdl_patch=$(sed -ne 's/^#define SDL_PATCHLEVEL *//p' "${sdl_root}/include/SDL_version.h")
  36. sdl_version="${sdl_major}.${sdl_minor}.${sdl_patch}"
  37. echo "Building Android prefab package for SDL version $sdl_version"
  38. prefabhome="${build_root}/prefab-${sdl_version}"
  39. rm -rf "$prefabhome"
  40. mkdir -p "${prefabhome}"
  41. build_cmake_projects() {
  42. for android_abi in $android_abis; do
  43. echo "Configuring CMake project for $android_abi"
  44. cmake -S "$sdl_root" -B "${build_root}/build_${android_abi}" \
  45. -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
  46. -DANDROID_PLATFORM=${android_platform} \
  47. -DANDROID_ABI=${android_abi} \
  48. -DSDL_SHARED=ON \
  49. -DSDL_STATIC=ON \
  50. -DSDL_STATIC_PIC=ON \
  51. -DSDL_TEST=ON \
  52. -DSDL2_DISABLE_SDL2MAIN=OFF \
  53. -DSDL2_DISABLE_INSTALL=OFF \
  54. -DCMAKE_INSTALL_PREFIX="${build_root}/build_${android_abi}/prefix" \
  55. -DCMAKE_INSTALL_INCLUDEDIR=include \
  56. -DCMAKE_INSTALL_LIBDIR=lib \
  57. -DCMAKE_BUILD_TYPE=Release \
  58. -GNinja
  59. rm -rf "${build_root}/build_${android_abi}/prefix"
  60. echo "Building CMake project for $android_abi"
  61. cmake --build "${build_root}/build_${android_abi}"
  62. echo "Installing CMake project for $android_abi"
  63. cmake --install "${build_root}/build_${android_abi}"
  64. done
  65. }
  66. classes_sources_jar_path="${prefabhome}/classes-sources.jar"
  67. classes_jar_path="${prefabhome}/classes.jar"
  68. compile_java() {
  69. classes_sources_root="${prefabhome}/classes-sources"
  70. rm -rf "${classes_sources_root}"
  71. mkdir -p "${classes_sources_root}/META-INF"
  72. echo "Copying LICENSE.txt to java build folder"
  73. cp "$sdl_root/LICENSE.txt" "${classes_sources_root}/META-INF"
  74. echo "Copy JAVA sources to java build folder"
  75. cp -r "$sdl_root/android-project/app/src/main/java/org" "${classes_sources_root}"
  76. java_sourceslist_path="${prefabhome}/java_sources.txt"
  77. pushd "${classes_sources_root}"
  78. echo "Collecting sources for classes-sources.jar"
  79. find "." -name "*.java" >"${java_sourceslist_path}"
  80. find "META-INF" -name "*" >>"${java_sourceslist_path}"
  81. echo "Creating classes-sources.jar"
  82. jar -cf "${classes_sources_jar_path}" "@${java_sourceslist_path}"
  83. popd
  84. classes_root="${prefabhome}/classes"
  85. mkdir -p "${classes_root}/META-INF"
  86. cp "$sdl_root/LICENSE.txt" "${classes_root}/META-INF"
  87. java_sourceslist_path="${prefabhome}/java_sources.txt"
  88. echo "Collecting sources for classes.jar"
  89. find "$sdl_root/android-project/app/src/main/java" -name "*.java" >"${java_sourceslist_path}"
  90. echo "Compiling classes"
  91. javac -encoding utf-8 -classpath "$android_platformdir/android.jar" -d "${classes_root}" "@${java_sourceslist_path}"
  92. java_classeslist_path="${prefabhome}/java_classes.txt"
  93. pushd "${classes_root}"
  94. find "." -name "*.class" >"${java_classeslist_path}"
  95. find "META-INF" -name "*" >>"${java_classeslist_path}"
  96. echo "Creating classes.jar"
  97. jar -cf "${classes_jar_path}" "@${java_classeslist_path}"
  98. popd
  99. }
  100. pom_filename="SDL${sdl_major}-${sdl_version}.pom"
  101. pom_filepath="${prefabhome}/${pom_filename}"
  102. create_pom_xml() {
  103. echo "Creating ${pom_filename}"
  104. cat >"${pom_filepath}" <<EOF
  105. <project>
  106. <modelVersion>4.0.0</modelVersion>
  107. <groupId>org.libsdl.android</groupId>
  108. <artifactId>SDL${sdl_major}</artifactId>
  109. <version>${sdl_version}</version>
  110. <packaging>aar</packaging>
  111. <name>SDL${sdl_major}</name>
  112. <description>The AAR for SDL${sdl_major}</description>
  113. <url>https://libsdl.org/</url>
  114. <licenses>
  115. <license>
  116. <name>zlib License</name>
  117. <url>https://github.com/libsdl-org/SDL/blob/main/LICENSE.txt</url>
  118. <distribution>repo</distribution>
  119. </license>
  120. </licenses>
  121. <scm>
  122. <connection>scm:git:https://github.com/libsdl-org/SDL</connection>
  123. <url>https://github.com/libsdl-org/SDL</url>
  124. </scm>
  125. </project>
  126. EOF
  127. }
  128. create_aar_androidmanifest() {
  129. echo "Creating AndroidManifest.xml"
  130. cat >"${aar_root}/AndroidManifest.xml" <<EOF
  131. <manifest
  132. xmlns:android="http://schemas.android.com/apk/res/android"
  133. package="org.libsdl.android" android:versionCode="1"
  134. android:versionName="1.0">
  135. <uses-sdk android:minSdkVersion="16"
  136. android:targetSdkVersion="29"/>
  137. </manifest>
  138. EOF
  139. }
  140. echo "Creating AAR root directory"
  141. aar_root="${prefabhome}/SDL${sdl_major}-${sdl_version}"
  142. mkdir -p "${aar_root}"
  143. aar_metainfdir_path=${aar_root}/META-INF
  144. mkdir -p "${aar_metainfdir_path}"
  145. cp "${sdl_root}/LICENSE.txt" "${aar_metainfdir_path}"
  146. prefabworkdir="${aar_root}/prefab"
  147. mkdir -p "${prefabworkdir}"
  148. cat >"${prefabworkdir}/prefab.json" <<EOF
  149. {
  150. "schema_version": 2,
  151. "name": "SDL$sdl_major",
  152. "version": "$sdl_version",
  153. "dependencies": []
  154. }
  155. EOF
  156. modulesworkdir="${prefabworkdir}/modules"
  157. mkdir -p "${modulesworkdir}"
  158. create_shared_sdl_module() {
  159. echo "Creating SDL${sdl_major} prefab module"
  160. for android_abi in $android_abis; do
  161. sdl_moduleworkdir="${modulesworkdir}/SDL${sdl_major}"
  162. mkdir -p "${sdl_moduleworkdir}"
  163. abi_build_prefix="${build_root}/build_${android_abi}/prefix"
  164. cat >"${sdl_moduleworkdir}/module.json" <<EOF
  165. {
  166. "export_libraries": [],
  167. "library_name": "libSDL${sdl_major}"
  168. }
  169. EOF
  170. mkdir -p "${sdl_moduleworkdir}/include"
  171. cp -r "${abi_build_prefix}/include/SDL${sdl_major}/"* "${sdl_moduleworkdir}/include/"
  172. rm "${sdl_moduleworkdir}/include/SDL_config.h"
  173. cp "$sdl_root/include/SDL_config.h" "$sdl_root/include/SDL_config_android.h" "${sdl_moduleworkdir}/include/"
  174. abi_sdllibdir="${sdl_moduleworkdir}/libs/android.${android_abi}"
  175. mkdir -p "${abi_sdllibdir}"
  176. cat >"${abi_sdllibdir}/abi.json" <<EOF
  177. {
  178. "abi": "${android_abi}",
  179. "api": ${android_api},
  180. "ndk": ${android_ndk},
  181. "stl": "${android_stl}",
  182. "static": false
  183. }
  184. EOF
  185. cp "${abi_build_prefix}/lib/libSDL${sdl_major}.so" "${abi_sdllibdir}"
  186. done
  187. }
  188. create_static_sdl_module() {
  189. echo "Creating SDL${sdl_major}-static prefab module"
  190. for android_abi in $android_abis; do
  191. sdl_moduleworkdir="${modulesworkdir}/SDL${sdl_major}-static"
  192. mkdir -p "${sdl_moduleworkdir}"
  193. abi_build_prefix="${build_root}/build_${android_abi}/prefix"
  194. cat >"${sdl_moduleworkdir}/module.json" <<EOF
  195. {
  196. "export_libraries": ["-ldl", "-lGLESv1_CM", "-lGLESv2", "-llog", "-landroid", "-lOpenSLES"]
  197. "library_name": "libSDL${sdl_major}"
  198. }
  199. EOF
  200. mkdir -p "${sdl_moduleworkdir}/include"
  201. cp -r "${abi_build_prefix}/include/SDL${sdl_major}/"* "${sdl_moduleworkdir}/include"
  202. rm "${sdl_moduleworkdir}/include/SDL_config.h"
  203. cp "$sdl_root/include/SDL_config.h" "$sdl_root/include/SDL_config_android.h" "${sdl_moduleworkdir}/include/"
  204. abi_sdllibdir="${sdl_moduleworkdir}/libs/android.${android_abi}"
  205. mkdir -p "${abi_sdllibdir}"
  206. cat >"${abi_sdllibdir}/abi.json" <<EOF
  207. {
  208. "abi": "${android_abi}",
  209. "api": ${android_api},
  210. "ndk": ${android_ndk},
  211. "stl": "${android_stl}",
  212. "static": true
  213. }
  214. EOF
  215. cp "${abi_build_prefix}/lib/libSDL${sdl_major}.a" "${abi_sdllibdir}"
  216. done
  217. }
  218. create_sdlmain_module() {
  219. echo "Creating SDL${sdl_major}main prefab module"
  220. for android_abi in $android_abis; do
  221. sdl_moduleworkdir="${modulesworkdir}/SDL${sdl_major}main"
  222. mkdir -p "${sdl_moduleworkdir}"
  223. abi_build_prefix="${build_root}/build_${android_abi}/prefix"
  224. cat >"${sdl_moduleworkdir}/module.json" <<EOF
  225. {
  226. "export_libraries": [],
  227. "library_name": "libSDL${sdl_major}main"
  228. }
  229. EOF
  230. abi_sdllibdir="${sdl_moduleworkdir}/libs/android.${android_abi}"
  231. mkdir -p "${abi_sdllibdir}"
  232. cat >"${abi_sdllibdir}/abi.json" <<EOF
  233. {
  234. "abi": "${android_abi}",
  235. "api": ${android_api},
  236. "ndk": ${android_ndk},
  237. "stl": "${android_stl}",
  238. "static": true
  239. }
  240. EOF
  241. cp "${abi_build_prefix}/lib/libSDL${sdl_major}main.a" "${abi_sdllibdir}"
  242. done
  243. }
  244. create_sdltest_module() {
  245. echo "Creating SDL${sdl_major}test prefab module"
  246. for android_abi in $android_abis; do
  247. sdl_moduleworkdir="${modulesworkdir}/SDL${sdl_major}test"
  248. mkdir -p "${sdl_moduleworkdir}"
  249. abi_build_prefix="${build_root}/build_${android_abi}/prefix"
  250. cat >"${sdl_moduleworkdir}/module.json" <<EOF
  251. {
  252. "export_libraries": [],
  253. "library_name": "libSDL${sdl_major}_test"
  254. }
  255. EOF
  256. abi_sdllibdir="${sdl_moduleworkdir}/libs/android.${android_abi}"
  257. mkdir -p "${abi_sdllibdir}"
  258. cat >"${abi_sdllibdir}/abi.json" <<EOF
  259. {
  260. "abi": "${android_abi}",
  261. "api": ${android_api},
  262. "ndk": ${android_ndk},
  263. "stl": "${android_stl}",
  264. "static": true
  265. }
  266. EOF
  267. cp "${abi_build_prefix}/lib/libSDL${sdl_major}_test.a" "${abi_sdllibdir}"
  268. done
  269. }
  270. build_cmake_projects
  271. compile_java
  272. create_pom_xml
  273. create_aar_androidmanifest
  274. create_shared_sdl_module
  275. create_static_sdl_module
  276. create_sdlmain_module
  277. create_sdltest_module
  278. pushd "${aar_root}"
  279. aar_filename="SDL${sdl_major}-${sdl_version}.aar"
  280. cp "${classes_jar_path}" ./classes.jar
  281. cp "${classes_sources_jar_path}" ./classes-sources.jar
  282. zip -r "${aar_filename}" AndroidManifest.xml classes.jar classes-sources.jar prefab META-INF
  283. zip -Tv "${aar_filename}" 2>/dev/null ;
  284. mv "${aar_filename}" "${prefabhome}"
  285. popd
  286. maven_filename="SDL${sdl_major}-${sdl_version}.zip"
  287. pushd "${prefabhome}"
  288. zip_filename="SDL${sdl_major}-${sdl_version}.zip"
  289. zip "${maven_filename}" "${aar_filename}" "${pom_filename}" 2>/dev/null;
  290. zip -Tv "${zip_filename}" 2>/dev/null;
  291. popd
  292. echo "Prefab zip is ready at ${prefabhome}/${aar_filename}"
  293. echo "Maven archive is ready at ${prefabhome}/${zip_filename}"