From 739241bb7b46ecb3ca7aeb11bbd47594bd4a5cd6 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Wed, 20 Mar 2024 23:27:19 +0800 Subject: [PATCH] Remove 'register' keyword. Tweak logic for finding android NDK. --- src/hx/AndroidCompat.cpp | 4 +-- tools/hxcpp/Setup.hx | 65 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/hx/AndroidCompat.cpp b/src/hx/AndroidCompat.cpp index 4974e2c31..c9f99201e 100644 --- a/src/hx/AndroidCompat.cpp +++ b/src/hx/AndroidCompat.cpp @@ -15,8 +15,8 @@ extern "C" { char * stpcpy(char *dest, const char *src) { - register char *d = dest; - register const char *s = src; + char *d = dest; + const char *s = src; do *d++ = *s; while (*s++ != '\0'); diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index d1a0c92b1..546fc7efa 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -64,11 +64,26 @@ class Setup { Log.v("checks default ndk-bundle in android sdk"); var ndkBundle = defines.get("ANDROID_SDK")+"/ndk-bundle"; + var newStyle = false; + if (!FileSystem.exists(ndkBundle) ) + { + Log.v("ndk-bundle directory not found in sdk,try ndk"); + var altDir = defines.get("ANDROID_SDK")+"/ndk/"; + if (FileSystem.exists(altDir) ) + { + var alt = findBestNdk(altDir); + if (alt!=null) + { + Log.v('using $alt ndk dir'); + ndkBundle = alt; + } + } + } ndkBundle = ndkBundle.split("\\").join("/"); - var version = getNdkVersion(ndkBundle); + var version = getNdkVersion(ndkBundle, newStyle); if (version>bestVersion && (inBaseVersion==0 || inBaseVersion==Std.int(version)) ) { - Log.v("Using default ndk-bundle in android sdk"); + Log.v("Using default ndk-bundle in android sdk:" + ndkBundle); result = ndkBundle; } } @@ -76,8 +91,45 @@ class Setup return result; } - static public function getNdkVersion(inDirName:String):Float + static function findBestNdk(root:String) : String { + var versionMatch = ~/(\d+)\.(\d+\.\d+)/; + var version:String = null; + var best = 0.0; + try + { + for (file in FileSystem.readDirectory(root)) + { + if (versionMatch.match(file)) + { + var maj = Std.parseInt(versionMatch.matched(1)); + var minor = Std.parseFloat(versionMatch.matched(2)); + var combined = maj*1000 + minor; + Log.v(" found ndk:" + file); + if (combined>best) + { + best = combined; + version = file; + } + } + } + } + catch(e:Dynamic) + { + } + + if (version!=null) + return root + "/" + version; + + return null; + } + + static var gotNdkVersion = 0.0; + static public function getNdkVersion(inDirName:String, newStyle=false):Float + { + if (gotNdkVersion!=0) + return gotNdkVersion; + Log.v("Try to get version from source.properties"); var src = toPath(inDirName+"/source.properties"); if (sys.FileSystem.exists(src)) @@ -97,8 +149,9 @@ class Setup var result:Float = 1.0 * Std.parseInt(split2[0]) + 0.001 * Std.parseInt(split2[1]); if (result>=8) { - Log.v('Deduced NDK version '+result+' from "$inDirName"/source.properties'); + Log.v('Deduced NDK version '+result+' from "$inDirName/source.properties"'); fin.close(); + gotNdkVersion = result; return result; } } @@ -121,11 +174,13 @@ class Setup var minor = extract_version.matched(3); if (minor!=null && minor.length>0) result += 0.001 * (minor.toLowerCase().charCodeAt(0)-'a'.code); + gotNdkVersion = result; return result; } Log.v('Could not deduce NDK version from "$inDirName" - assuming 8'); - return 8; + gotNdkVersion = 8; + return gotNdkVersion; } public static function initHXCPPConfig(ioDefines:Hash)