| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import platform | 
					
						
							| 
									
										
										
										
											2017-11-09 11:58:29 -04:00
										 |  |  | from distutils.version import LooseVersion | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 19:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def is_active(): | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     return True | 
					
						
							| 
									
										
										
										
											2016-04-02 20:26:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 19:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def get_name(): | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     return "Android" | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 19:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def can_build(): | 
					
						
							| 
									
										
										
										
											2021-02-17 19:11:05 -08:00
										 |  |  |     return ("ANDROID_SDK_ROOT" in os.environ) or ("ANDROID_HOME" in os.environ) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 19:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 15:39:09 +00:00
										 |  |  | def get_platform(platform): | 
					
						
							|  |  |  |     return int(platform.split("-")[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def get_opts(): | 
					
						
							| 
									
										
										
										
											2017-09-25 00:37:17 -04:00
										 |  |  |     from SCons.Variables import BoolVariable, EnumVariable | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     return [ | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  |         ("ANDROID_NDK_ROOT", "Path to the Android NDK", get_android_ndk_root()), | 
					
						
							|  |  |  |         ("ANDROID_SDK_ROOT", "Path to the Android SDK", get_android_sdk_root()), | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  |         ("ndk_platform", 'Target platform (android-<api>, e.g. "android-24")', "android-24"), | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         EnumVariable("android_arch", "Target architecture", "armv7", ("armv7", "arm64v8", "x86", "x86_64")), | 
					
						
							|  |  |  |         BoolVariable("android_neon", "Enable NEON support (armv7 only)", True), | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 17:22:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | # Return the ANDROID_SDK_ROOT environment variable. | 
					
						
							|  |  |  | # While ANDROID_HOME has been deprecated, it's used as a fallback for backward | 
					
						
							|  |  |  | # compatibility purposes. | 
					
						
							|  |  |  | def get_android_sdk_root(): | 
					
						
							|  |  |  |     if "ANDROID_SDK_ROOT" in os.environ: | 
					
						
							|  |  |  |         return os.environ.get("ANDROID_SDK_ROOT", 0) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         return os.environ.get("ANDROID_HOME", 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Return the ANDROID_NDK_ROOT environment variable. | 
					
						
							| 
									
										
										
										
											2021-02-17 19:11:05 -08:00
										 |  |  | # We generate one for this build using the ANDROID_SDK_ROOT env | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | # variable and the project ndk version. | 
					
						
							| 
									
										
										
										
											2021-02-17 19:11:05 -08:00
										 |  |  | # If the env variable is already defined, we override it with | 
					
						
							|  |  |  | # our own to match what the project expects. | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | def get_android_ndk_root(): | 
					
						
							| 
									
										
										
										
											2021-02-17 19:11:05 -08:00
										 |  |  |     return get_android_sdk_root() + "/ndk/" + get_project_ndk_version() | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def get_flags(): | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     return [ | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         ("tools", False), | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def create(env): | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     tools = env["TOOLS"] | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     if "mingw" in tools: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         tools.remove("mingw") | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     if "applelink" in tools: | 
					
						
							|  |  |  |         tools.remove("applelink") | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Tool("gcc") | 
					
						
							| 
									
										
										
										
											2016-11-01 00:24:30 +01:00
										 |  |  |     return env.Clone(tools=tools) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 19:05:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | # Check if ANDROID_NDK_ROOT is valid. | 
					
						
							|  |  |  | # If not, install the ndk using ANDROID_SDK_ROOT and sdkmanager. | 
					
						
							|  |  |  | def install_ndk_if_needed(env): | 
					
						
							|  |  |  |     print("Checking for Android NDK...") | 
					
						
							|  |  |  |     env_ndk_version = get_env_ndk_version(env["ANDROID_NDK_ROOT"]) | 
					
						
							|  |  |  |     if env_ndk_version is None: | 
					
						
							|  |  |  |         # Reinstall the ndk and update ANDROID_NDK_ROOT. | 
					
						
							|  |  |  |         print("Installing Android NDK...") | 
					
						
							|  |  |  |         if env["ANDROID_SDK_ROOT"] is None: | 
					
						
							|  |  |  |             raise Exception("Invalid ANDROID_SDK_ROOT environment variable.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         import subprocess | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         extension = ".bat" if os.name == "nt" else "" | 
					
						
							|  |  |  |         sdkmanager_path = env["ANDROID_SDK_ROOT"] + "/cmdline-tools/latest/bin/sdkmanager" + extension | 
					
						
							|  |  |  |         ndk_download_args = "ndk;" + get_project_ndk_version() | 
					
						
							|  |  |  |         subprocess.check_call([sdkmanager_path, ndk_download_args]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         env["ANDROID_NDK_ROOT"] = env["ANDROID_SDK_ROOT"] + "/ndk/" + get_project_ndk_version() | 
					
						
							|  |  |  |         print("ANDROID_NDK_ROOT: " + env["ANDROID_NDK_ROOT"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | def configure(env): | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  |     install_ndk_if_needed(env) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |     # Workaround for MinGW. See: | 
					
						
							|  |  |  |     # http://www.scons.org/wiki/LongCmdLinesOnWin32 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if os.name == "nt": | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         import subprocess | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |         def mySubProcess(cmdline, env): | 
					
						
							| 
									
										
										
										
											2017-08-26 18:53:49 +02:00
										 |  |  |             # print("SPAWNED : " + cmdline) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |             startupinfo = subprocess.STARTUPINFO() | 
					
						
							|  |  |  |             startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             proc = subprocess.Popen( | 
					
						
							|  |  |  |                 cmdline, | 
					
						
							|  |  |  |                 stdin=subprocess.PIPE, | 
					
						
							|  |  |  |                 stdout=subprocess.PIPE, | 
					
						
							|  |  |  |                 stderr=subprocess.PIPE, | 
					
						
							|  |  |  |                 startupinfo=startupinfo, | 
					
						
							|  |  |  |                 shell=False, | 
					
						
							|  |  |  |                 env=env, | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |             data, err = proc.communicate() | 
					
						
							|  |  |  |             rv = proc.wait() | 
					
						
							|  |  |  |             if rv: | 
					
						
							| 
									
										
										
										
											2017-08-26 18:53:49 +02:00
										 |  |  |                 print("=====") | 
					
						
							|  |  |  |                 print(err) | 
					
						
							|  |  |  |                 print("=====") | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |             return rv | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def mySpawn(sh, escape, cmd, args, env): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             newargs = " ".join(args[1:]) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |             cmdline = cmd + " " + newargs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |             rv = 0 | 
					
						
							|  |  |  |             if len(cmdline) > 32000 and cmd.endswith("ar"): | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |                 cmdline = cmd + " " + args[1] + " " + args[2] + " " | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |                 for i in range(3, len(args)): | 
					
						
							|  |  |  |                     rv = mySubProcess(cmdline + args[i], env) | 
					
						
							|  |  |  |                     if rv: | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |                         break | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |                 rv = mySubProcess(cmdline, env) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return rv | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["SPAWN"] = mySpawn | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  |     # Architecture | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["android_arch"] not in ["armv7", "arm64v8", "x86", "x86_64"]: | 
					
						
							|  |  |  |         env["android_arch"] = "armv7" | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |     neon_text = "" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["android_arch"] == "armv7" and env["android_neon"]: | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  |         neon_text = " (with NEON)" | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  |     print("Building for Android, platform " + env["ndk_platform"] + " (" + env["android_arch"] + ")" + neon_text) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  |     can_vectorize = True | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["android_arch"] == "x86": | 
					
						
							|  |  |  |         env["ARCH"] = "arch-x86" | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |         env.extra_suffix = ".x86" + env.extra_suffix | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |         target_subpath = "x86-4.9" | 
					
						
							|  |  |  |         abi_subpath = "i686-linux-android" | 
					
						
							|  |  |  |         arch_subpath = "x86" | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  |         env["x86_libtheora_opt_gcc"] = True | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["android_arch"] == "x86_64": | 
					
						
							| 
									
										
										
										
											2019-01-16 11:16:00 +01:00
										 |  |  |         if get_platform(env["ndk_platform"]) < 21: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             print( | 
					
						
							| 
									
										
										
										
											2020-07-26 19:38:10 +02:00
										 |  |  |                 "WARNING: android_arch=x86_64 is not supported by ndk_platform lower than android-21; setting" | 
					
						
							|  |  |  |                 " ndk_platform=android-21" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2019-01-16 11:16:00 +01:00
										 |  |  |             env["ndk_platform"] = "android-21" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["ARCH"] = "arch-x86_64" | 
					
						
							| 
									
										
										
										
											2019-01-16 11:16:00 +01:00
										 |  |  |         env.extra_suffix = ".x86_64" + env.extra_suffix | 
					
						
							|  |  |  |         target_subpath = "x86_64-4.9" | 
					
						
							|  |  |  |         abi_subpath = "x86_64-linux-android" | 
					
						
							|  |  |  |         arch_subpath = "x86_64" | 
					
						
							|  |  |  |         env["x86_libtheora_opt_gcc"] = True | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |     elif env["android_arch"] == "armv7": | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["ARCH"] = "arch-arm" | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |         target_subpath = "arm-linux-androideabi-4.9" | 
					
						
							|  |  |  |         abi_subpath = "arm-linux-androideabi" | 
					
						
							|  |  |  |         arch_subpath = "armeabi-v7a" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         if env["android_neon"]: | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |             env.extra_suffix = ".armv7.neon" + env.extra_suffix | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |             env.extra_suffix = ".armv7" + env.extra_suffix | 
					
						
							| 
									
										
										
										
											2017-07-25 12:28:31 +02:00
										 |  |  |     elif env["android_arch"] == "arm64v8": | 
					
						
							| 
									
										
										
										
											2017-12-18 15:39:09 +00:00
										 |  |  |         if get_platform(env["ndk_platform"]) < 21: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             print( | 
					
						
							| 
									
										
										
										
											2020-07-26 19:38:10 +02:00
										 |  |  |                 "WARNING: android_arch=arm64v8 is not supported by ndk_platform lower than android-21; setting" | 
					
						
							|  |  |  |                 " ndk_platform=android-21" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-12-18 15:39:09 +00:00
										 |  |  |             env["ndk_platform"] = "android-21" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["ARCH"] = "arch-arm64" | 
					
						
							| 
									
										
										
										
											2017-07-25 12:28:31 +02:00
										 |  |  |         target_subpath = "aarch64-linux-android-4.9" | 
					
						
							|  |  |  |         abi_subpath = "aarch64-linux-android" | 
					
						
							|  |  |  |         arch_subpath = "arm64-v8a" | 
					
						
							|  |  |  |         env.extra_suffix = ".armv8" + env.extra_suffix | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  |     # Build type | 
					
						
							| 
									
										
										
										
											2017-07-20 01:27:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["target"].startswith("release"): | 
					
						
							|  |  |  |         if env["optimize"] == "speed":  # optimize for speed (default) | 
					
						
							|  |  |  |             env.Append(LINKFLAGS=["-O2"]) | 
					
						
							|  |  |  |             env.Append(CCFLAGS=["-O2", "-fomit-frame-pointer"]) | 
					
						
							| 
									
										
										
										
											2021-03-13 15:29:55 +01:00
										 |  |  |         elif env["optimize"] == "size":  # optimize for size | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             env.Append(CCFLAGS=["-Os"]) | 
					
						
							|  |  |  |             env.Append(LINKFLAGS=["-Os"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-13 15:29:55 +01:00
										 |  |  |         env.Append(CPPDEFINES=["NDEBUG"]) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         if can_vectorize: | 
					
						
							|  |  |  |             env.Append(CCFLAGS=["-ftree-vectorize"]) | 
					
						
							|  |  |  |         if env["target"] == "release_debug": | 
					
						
							|  |  |  |             env.Append(CPPDEFINES=["DEBUG_ENABLED"]) | 
					
						
							|  |  |  |     elif env["target"] == "debug": | 
					
						
							|  |  |  |         env.Append(LINKFLAGS=["-O0"]) | 
					
						
							|  |  |  |         env.Append(CCFLAGS=["-O0", "-g", "-fno-limit-debug-info"]) | 
					
						
							| 
									
										
										
										
											2020-07-23 09:39:07 +02:00
										 |  |  |         env.Append(CPPDEFINES=["_DEBUG", "DEBUG_ENABLED"]) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(CPPFLAGS=["-UNDEBUG"]) | 
					
						
							| 
									
										
										
										
											2017-07-20 01:27:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  |     # Compiler configuration | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env["SHLIBSUFFIX"] = ".so" | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if env["PLATFORM"] == "win32": | 
					
						
							|  |  |  |         env.Tool("gcc") | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  |         env.use_windows_spawn_fix() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if sys.platform.startswith("linux"): | 
					
						
							| 
									
										
										
										
											2016-11-13 23:54:06 +01:00
										 |  |  |         host_subpath = "linux-x86_64" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     elif sys.platform.startswith("darwin"): | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |         host_subpath = "darwin-x86_64" | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     elif sys.platform.startswith("win"): | 
					
						
							|  |  |  |         if platform.machine().endswith("64"): | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |             host_subpath = "windows-x86_64" | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2016-11-13 23:54:06 +01:00
										 |  |  |             host_subpath = "windows" | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  |     compiler_path = env["ANDROID_NDK_ROOT"] + "/toolchains/llvm/prebuilt/" + host_subpath + "/bin" | 
					
						
							|  |  |  |     gcc_toolchain_path = env["ANDROID_NDK_ROOT"] + "/toolchains/" + target_subpath + "/prebuilt/" + host_subpath | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |     tools_path = gcc_toolchain_path + "/" + abi_subpath + "/bin" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # For Clang to find NDK tools in preference of those system-wide | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env.PrependENVPath("PATH", tools_path) | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-09 20:07:28 -04:00
										 |  |  |     ccache_path = os.environ.get("CCACHE") | 
					
						
							| 
									
										
										
										
											2018-10-27 01:18:15 +02:00
										 |  |  |     if ccache_path is None: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["CC"] = compiler_path + "/clang" | 
					
						
							|  |  |  |         env["CXX"] = compiler_path + "/clang++" | 
					
						
							| 
									
										
										
										
											2017-11-09 20:07:28 -04:00
										 |  |  |     else: | 
					
						
							|  |  |  |         # there aren't any ccache wrappers available for Android, | 
					
						
							|  |  |  |         # to enable caching we need to prepend the path to the ccache binary | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env["CC"] = ccache_path + " " + compiler_path + "/clang" | 
					
						
							|  |  |  |         env["CXX"] = ccache_path + " " + compiler_path + "/clang++" | 
					
						
							|  |  |  |     env["AR"] = tools_path + "/ar" | 
					
						
							|  |  |  |     env["RANLIB"] = tools_path + "/ranlib" | 
					
						
							|  |  |  |     env["AS"] = tools_path + "/as" | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     common_opts = ["-fno-integrated-as", "-gcc-toolchain", gcc_toolchain_path] | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  |     # Compile flags | 
					
						
							| 
									
										
										
										
											2019-07-30 15:49:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 15:33:24 +02:00
										 |  |  |     env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/include"]) | 
					
						
							|  |  |  |     env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++abi/include"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:47:32 +02:00
										 |  |  |     # Disable exceptions and rtti on non-tools (template) builds | 
					
						
							| 
									
										
										
										
											2021-04-20 21:50:48 +03:00
										 |  |  |     if env["tools"]: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(CXXFLAGS=["-frtti"]) | 
					
						
							| 
									
										
										
										
											2021-04-20 21:50:48 +03:00
										 |  |  |     elif env["builtin_icu"]: | 
					
						
							|  |  |  |         env.Append(CXXFLAGS=["-frtti", "-fno-exceptions"]) | 
					
						
							| 
									
										
										
										
											2018-08-23 05:02:47 +07:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(CXXFLAGS=["-fno-rtti", "-fno-exceptions"]) | 
					
						
							| 
									
										
										
										
											2019-05-20 16:47:32 +02:00
										 |  |  |         # Don't use dynamic_cast, necessary with no-rtti. | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(CPPDEFINES=["NO_SAFE_CAST"]) | 
					
						
							| 
									
										
										
										
											2018-08-23 05:02:47 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     lib_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env["ndk_platform"] + "/" + env["ARCH"] | 
					
						
							| 
									
										
										
										
											2019-07-30 15:49:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Using NDK unified headers (NDK r15+) | 
					
						
							|  |  |  |     sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot" | 
					
						
							|  |  |  |     env.Append(CPPFLAGS=["--sysroot=" + sysroot]) | 
					
						
							|  |  |  |     env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include/" + abi_subpath]) | 
					
						
							|  |  |  |     env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/android/support/include"]) | 
					
						
							|  |  |  |     # For unified headers this define has to be set manually | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env.Append(CPPDEFINES=[("__ANDROID_API__", str(get_platform(env["ndk_platform"])))]) | 
					
						
							| 
									
										
										
										
											2018-11-20 11:14:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env.Append( | 
					
						
							| 
									
										
										
										
											2020-07-26 19:38:10 +02:00
										 |  |  |         CCFLAGS=( | 
					
						
							|  |  |  |             "-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden" | 
					
						
							|  |  |  |             " -fno-strict-aliasing".split() | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     env.Append(CPPDEFINES=["NO_STATVFS", "GLES_ENABLED"]) | 
					
						
							| 
									
										
										
										
											2014-10-07 01:31:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env["neon_enabled"] = False | 
					
						
							|  |  |  |     if env["android_arch"] == "x86": | 
					
						
							|  |  |  |         target_opts = ["-target", "i686-none-linux-android"] | 
					
						
							| 
									
										
										
										
											2017-04-05 22:16:04 +02:00
										 |  |  |         # The NDK adds this if targeting API < 21, so we can drop it when Godot targets it at least | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(CCFLAGS=["-mstackrealign"]) | 
					
						
							| 
									
										
										
										
											2017-06-30 19:21:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     elif env["android_arch"] == "x86_64": | 
					
						
							|  |  |  |         target_opts = ["-target", "x86_64-none-linux-android"] | 
					
						
							| 
									
										
										
										
											2019-01-16 11:16:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 18:57:40 +01:00
										 |  |  |     elif env["android_arch"] == "armv7": | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         target_opts = ["-target", "armv7-none-linux-androideabi"] | 
					
						
							|  |  |  |         env.Append(CCFLAGS="-march=armv7-a -mfloat-abi=softfp".split()) | 
					
						
							|  |  |  |         env.Append(CPPDEFINES=["__ARM_ARCH_7__", "__ARM_ARCH_7A__"]) | 
					
						
							|  |  |  |         if env["android_neon"]: | 
					
						
							|  |  |  |             env["neon_enabled"] = True | 
					
						
							|  |  |  |             env.Append(CCFLAGS=["-mfpu=neon"]) | 
					
						
							|  |  |  |             env.Append(CPPDEFINES=["__ARM_NEON__"]) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             env.Append(CCFLAGS=["-mfpu=vfpv3-d16"]) | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 12:28:31 +02:00
										 |  |  |     elif env["android_arch"] == "arm64v8": | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         target_opts = ["-target", "aarch64-none-linux-android"] | 
					
						
							|  |  |  |         env.Append(CCFLAGS=["-mfix-cortex-a53-835769"]) | 
					
						
							|  |  |  |         env.Append(CPPDEFINES=["__ARM_ARCH_8A__"]) | 
					
						
							| 
									
										
										
										
											2017-07-25 12:28:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-24 16:49:12 +02:00
										 |  |  |     env.Append(CCFLAGS=target_opts) | 
					
						
							|  |  |  |     env.Append(CCFLAGS=common_opts) | 
					
						
							| 
									
										
										
										
											2016-10-30 18:44:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  |     # Link flags | 
					
						
							| 
									
										
										
										
											2019-07-30 15:49:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  |     ndk_version = get_env_ndk_version(env["ANDROID_NDK_ROOT"]) | 
					
						
							| 
									
										
										
										
											2019-07-30 15:49:31 +02:00
										 |  |  |     if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("17.1.4828580"): | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(LINKFLAGS=["-Wl,--exclude-libs,libgcc.a", "-Wl,--exclude-libs,libatomic.a", "-nostdlib++"]) | 
					
						
							| 
									
										
										
										
											2018-08-23 05:02:47 +07:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append( | 
					
						
							|  |  |  |             LINKFLAGS=[ | 
					
						
							|  |  |  |                 env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/" + arch_subpath + "/libandroid_support.a" | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     env.Append(LINKFLAGS=["-shared", "--sysroot=" + lib_sysroot, "-Wl,--warn-shared-textrel"]) | 
					
						
							| 
									
										
										
										
											2019-07-30 15:49:31 +02:00
										 |  |  |     env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/" + arch_subpath + "/"]) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env.Append( | 
					
						
							|  |  |  |         LINKFLAGS=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/" + arch_subpath + "/libc++_shared.so"] | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-11-20 11:14:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 12:28:31 +02:00
										 |  |  |     if env["android_arch"] == "armv7": | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         env.Append(LINKFLAGS="-Wl,--fix-cortex-a8".split()) | 
					
						
							|  |  |  |     env.Append(LINKFLAGS="-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now".split()) | 
					
						
							|  |  |  |     env.Append(LINKFLAGS="-Wl,-soname,libgodot_android.so -Wl,--gc-sections".split()) | 
					
						
							| 
									
										
										
										
											2018-11-20 11:14:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 10:54:51 +01:00
										 |  |  |     env.Append(LINKFLAGS=target_opts) | 
					
						
							|  |  |  |     env.Append(LINKFLAGS=common_opts) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     env.Append( | 
					
						
							|  |  |  |         LIBPATH=[ | 
					
						
							|  |  |  |             env["ANDROID_NDK_ROOT"] | 
					
						
							|  |  |  |             + "/toolchains/" | 
					
						
							|  |  |  |             + target_subpath | 
					
						
							|  |  |  |             + "/prebuilt/" | 
					
						
							|  |  |  |             + host_subpath | 
					
						
							|  |  |  |             + "/lib/gcc/" | 
					
						
							|  |  |  |             + abi_subpath | 
					
						
							|  |  |  |             + "/4.9.x" | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     env.Append( | 
					
						
							|  |  |  |         LIBPATH=[ | 
					
						
							|  |  |  |             env["ANDROID_NDK_ROOT"] | 
					
						
							|  |  |  |             + "/toolchains/" | 
					
						
							|  |  |  |             + target_subpath | 
					
						
							|  |  |  |             + "/prebuilt/" | 
					
						
							|  |  |  |             + host_subpath | 
					
						
							|  |  |  |             + "/" | 
					
						
							|  |  |  |             + abi_subpath | 
					
						
							|  |  |  |             + "/lib" | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     env.Prepend(CPPPATH=["#platform/android"]) | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  |     env.Append(CPPDEFINES=["ANDROID_ENABLED", "UNIX_ENABLED", "VULKAN_ENABLED", "NO_FCNTL"]) | 
					
						
							|  |  |  |     env.Append(LIBS=["OpenSLES", "EGL", "GLESv2", "vulkan", "android", "log", "z", "dl"]) | 
					
						
							| 
									
										
										
										
											2014-10-07 01:31:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 11:16:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | # Return the project NDK version. | 
					
						
							|  |  |  | # This is kept in sync with the value in 'platform/android/java/app/config.gradle'. | 
					
						
							|  |  |  | def get_project_ndk_version(): | 
					
						
							| 
									
										
										
										
											2021-02-18 00:28:27 +01:00
										 |  |  |     return "21.4.7075529" | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 09:26:43 -04:00
										 |  |  | # Return NDK version string in source.properties (adapted from the Chromium project). | 
					
						
							| 
									
										
										
										
											2021-01-05 13:40:42 -08:00
										 |  |  | def get_env_ndk_version(path): | 
					
						
							| 
									
										
										
										
											2018-10-27 01:18:15 +02:00
										 |  |  |     if path is None: | 
					
						
							| 
									
										
										
										
											2017-10-31 14:44:25 -04:00
										 |  |  |         return None | 
					
						
							|  |  |  |     prop_file_path = os.path.join(path, "source.properties") | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         with open(prop_file_path) as prop_file: | 
					
						
							|  |  |  |             for line in prop_file: | 
					
						
							| 
									
										
										
										
											2017-12-17 12:01:16 +00:00
										 |  |  |                 key_value = list(map(lambda x: x.strip(), line.split("="))) | 
					
						
							| 
									
										
										
										
											2017-10-31 14:44:25 -04:00
										 |  |  |                 if key_value[0] == "Pkg.Revision": | 
					
						
							| 
									
										
										
										
											2017-11-08 09:26:43 -04:00
										 |  |  |                     return key_value[1] | 
					
						
							| 
									
										
										
										
											2020-12-12 10:05:42 +00:00
										 |  |  |     except Exception: | 
					
						
							| 
									
										
										
										
											2017-10-31 14:44:25 -04:00
										 |  |  |         print("Could not read source prop file '%s'" % prop_file_path) | 
					
						
							|  |  |  |     return None |