diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar')
3 files changed, 147 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in new file mode 100755 index 0000000..344cf71 --- /dev/null +++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in | |||
@@ -0,0 +1,104 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | """ | ||
4 | Create a @<@PROJECT_NAME@>@ SDK prefix from an Android archive | ||
5 | This file is meant to be placed in a the root of an android .aar archive | ||
6 | |||
7 | Example usage: | ||
8 | ```sh | ||
9 | python @<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar -o /usr/opt/android-sdks | ||
10 | cmake -S my-project \ | ||
11 | -DCMAKE_PREFIX_PATH=/usr/opt/android-sdks \ | ||
12 | -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \ | ||
13 | -B build-arm64 -DANDROID_ABI=arm64-v8a \ | ||
14 | -DCMAKE_BUILD_TYPE=Releaase | ||
15 | cmake --build build-arm64 | ||
16 | ``` | ||
17 | """ | ||
18 | import argparse | ||
19 | import io | ||
20 | import json | ||
21 | import os | ||
22 | import pathlib | ||
23 | import re | ||
24 | import stat | ||
25 | import zipfile | ||
26 | |||
27 | |||
28 | AAR_PATH = pathlib.Path(__file__).resolve().parent | ||
29 | ANDROID_ARCHS = { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" } | ||
30 | |||
31 | |||
32 | def main(): | ||
33 | parser = argparse.ArgumentParser( | ||
34 | description="Convert a @<@PROJECT_NAME@>@ Android .aar archive into a SDK", | ||
35 | allow_abbrev=False, | ||
36 | ) | ||
37 | parser.add_argument("--version", action="version", version="@<@PROJECT_NAME@>@ @<@PROJECT_VERSION@>@") | ||
38 | parser.add_argument("-o", dest="output", type=pathlib.Path, required=True, help="Folder where to store the SDK") | ||
39 | args = parser.parse_args() | ||
40 | |||
41 | print(f"Creating a @<@PROJECT_NAME@>@ SDK at {args.output}...") | ||
42 | |||
43 | prefix = args.output | ||
44 | incdir = prefix / "include" | ||
45 | libdir = prefix / "lib" | ||
46 | |||
47 | RE_LIB_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/libs/android\.(?P<arch>[a-zA-Z0-9_-]+)/(?P<filename>lib[A-Za-z0-9_]+\.(?:so|a))") | ||
48 | RE_INC_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/include/(?P<header>[a-zA-Z0-9_./-]+)") | ||
49 | RE_LICENSE = re.compile(r"(?:.*/)?(?P<filename>(?:license|copying)(?:\.md|\.txt)?)", flags=re.I) | ||
50 | RE_PROGUARD = re.compile(r"(?:.*/)?(?P<filename>proguard.*\.(?:pro|txt))", flags=re.I) | ||
51 | RE_CMAKE = re.compile(r"(?:.*/)?(?P<filename>.*\.cmake)", flags=re.I) | ||
52 | |||
53 | with zipfile.ZipFile(AAR_PATH) as zf: | ||
54 | project_description = json.loads(zf.read("description.json")) | ||
55 | project_name = project_description["name"] | ||
56 | project_version = project_description["version"] | ||
57 | licensedir = prefix / "share/licenses" / project_name | ||
58 | cmakedir = libdir / "cmake" / project_name | ||
59 | javadir = prefix / "share/java" / project_name | ||
60 | javadocdir = prefix / "share/javadoc" / project_name | ||
61 | |||
62 | def read_zipfile_and_write(path: pathlib.Path, zippath: str): | ||
63 | data = zf.read(zippath) | ||
64 | path.parent.mkdir(parents=True, exist_ok=True) | ||
65 | path.write_bytes(data) | ||
66 | |||
67 | for zip_info in zf.infolist(): | ||
68 | zippath = zip_info.filename | ||
69 | if m := RE_LIB_MODULE_ARCH.match(zippath): | ||
70 | lib_path = libdir / m["arch"] / m["filename"] | ||
71 | read_zipfile_and_write(lib_path, zippath) | ||
72 | if m["filename"].endswith(".so"): | ||
73 | os.chmod(lib_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) | ||
74 | |||
75 | elif m := RE_INC_MODULE_ARCH.match(zippath): | ||
76 | header_path = incdir / m["header"] | ||
77 | read_zipfile_and_write(header_path, zippath) | ||
78 | elif m:= RE_LICENSE.match(zippath): | ||
79 | license_path = licensedir / m["filename"] | ||
80 | read_zipfile_and_write(license_path, zippath) | ||
81 | elif m:= RE_PROGUARD.match(zippath): | ||
82 | proguard_path = javadir / m["filename"] | ||
83 | read_zipfile_and_write(proguard_path, zippath) | ||
84 | elif m:= RE_CMAKE.match(zippath): | ||
85 | cmake_path = cmakedir / m["filename"] | ||
86 | read_zipfile_and_write(cmake_path, zippath) | ||
87 | elif zippath == "classes.jar": | ||
88 | versioned_jar_path = javadir / f"{project_name}-{project_version}.jar" | ||
89 | unversioned_jar_path = javadir / f"{project_name}.jar" | ||
90 | read_zipfile_and_write(versioned_jar_path, zippath) | ||
91 | os.symlink(src=versioned_jar_path.name, dst=unversioned_jar_path) | ||
92 | elif zippath == "classes-sources.jar": | ||
93 | jarpath = javadir / f"{project_name}-{project_version}-sources.jar" | ||
94 | read_zipfile_and_write(jarpath, zippath) | ||
95 | elif zippath == "classes-doc.jar": | ||
96 | jarpath = javadocdir / f"{project_name}-{project_version}-javadoc.jar" | ||
97 | read_zipfile_and_write(jarpath, zippath) | ||
98 | |||
99 | print("... done") | ||
100 | return 0 | ||
101 | |||
102 | |||
103 | if __name__ == "__main__": | ||
104 | raise SystemExit(main()) | ||
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in new file mode 100644 index 0000000..3268da7 --- /dev/null +++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in | |||
@@ -0,0 +1,38 @@ | |||
1 | # @<@PROJECT_NAME@>@ CMake version configuration file: | ||
2 | # This file is meant to be placed in a lib/cmake/@<@PROJECT_NAME@>@ subfolder of a reconstructed Android SDL3 SDK | ||
3 | |||
4 | set(PACKAGE_VERSION "@<@PROJECT_VERSION@>@") | ||
5 | |||
6 | if(PACKAGE_FIND_VERSION_RANGE) | ||
7 | # Package version must be in the requested version range | ||
8 | if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN) | ||
9 | OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX) | ||
10 | OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX))) | ||
11 | set(PACKAGE_VERSION_COMPATIBLE FALSE) | ||
12 | else() | ||
13 | set(PACKAGE_VERSION_COMPATIBLE TRUE) | ||
14 | endif() | ||
15 | else() | ||
16 | if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) | ||
17 | set(PACKAGE_VERSION_COMPATIBLE FALSE) | ||
18 | else() | ||
19 | set(PACKAGE_VERSION_COMPATIBLE TRUE) | ||
20 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) | ||
21 | set(PACKAGE_VERSION_EXACT TRUE) | ||
22 | endif() | ||
23 | endif() | ||
24 | endif() | ||
25 | |||
26 | # if the using project doesn't have CMAKE_SIZEOF_VOID_P set, fail. | ||
27 | if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "") | ||
28 | set(PACKAGE_VERSION_UNSUITABLE TRUE) | ||
29 | endif() | ||
30 | |||
31 | include("${CMAKE_CURRENT_LIST_DIR}/sdlcpu.cmake") | ||
32 | SDL_DetectTargetCPUArchitectures(_detected_archs) | ||
33 | |||
34 | # check that the installed version has a compatible architecture as the one which is currently searching: | ||
35 | if(NOT(SDL_CPU_X86 OR SDL_CPU_X64 OR SDL_CPU_ARM32 OR SDL_CPU_ARM64)) | ||
36 | set(PACKAGE_VERSION "${PACKAGE_VERSION} (X86,X64,ARM32,ARM64)") | ||
37 | set(PACKAGE_VERSION_UNSUITABLE TRUE) | ||
38 | endif() | ||
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in new file mode 100644 index 0000000..e75ef38 --- /dev/null +++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in | |||
@@ -0,0 +1,5 @@ | |||
1 | { | ||
2 | "name": "@<@PROJECT_NAME@>@", | ||
3 | "version": "@<@PROJECT_VERSION@>@", | ||
4 | "git-hash": "@<@PROJECT_COMMIT@>@" | ||
5 | } | ||