SDL: Allow specifying APP_PLATFORM and APP_ABI on the command line

From 808d83dd67ca3cbedb76c846172f76735203db87 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 21 Jun 2023 13:49:09 -0700
Subject: [PATCH] Allow specifying APP_PLATFORM and APP_ABI on the command line

---
 build-scripts/androidbuildlibs.sh | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/build-scripts/androidbuildlibs.sh b/build-scripts/androidbuildlibs.sh
index cd916447b5ab..0aa4aeaa6687 100755
--- a/build-scripts/androidbuildlibs.sh
+++ b/build-scripts/androidbuildlibs.sh
@@ -25,30 +25,27 @@ cd $srcdir
 
 build=build
 buildandroid=$build/android
+platform=android-16
+abi="arm64-v8a" # "armeabi-v7a arm64-v8a x86 x86_64"
 obj=
 lib=
 ndk_args=
 
-# Allow overriding the ABI from the environment
-if [ "$APP_ABI" = "" ]; then
-    #APP_ABI="armeabi-v7a arm64-v8a x86 x86_64"
-    APP_ABI="arm64-v8a"
-fi
-
-# Allow overriding the platform from the environment
-if [ "$APP_PLATFORM" = "" ]; then
-    APP_PLATFORM=android-16
-fi
-
-# Allow an external caller to specify locations.
-for arg in $*; do
+# Allow an external caller to specify locations and platform.
+while [ $# -gt 0 ]; do
+    arg=$1
     if [ "${arg:0:8}" == "NDK_OUT=" ]; then
         obj=${arg#NDK_OUT=}
     elif [ "${arg:0:13}" == "NDK_LIBS_OUT=" ]; then
         lib=${arg#NDK_LIBS_OUT=}
+    elif [ "${arg:0:13}" == "APP_PLATFORM=" ]; then
+        platform=${arg#APP_PLATFORM=}
+    elif [ "${arg:0:8}" == "APP_ABI=" ]; then
+        abi=${arg#APP_ABI=}
     else
         ndk_args="$ndk_args $arg"
     fi
+    shift
 done
 
 if [ -z $obj ]; then
@@ -75,7 +72,7 @@ ndk-build \
     NDK_OUT=$obj \
     NDK_LIBS_OUT=$lib \
     APP_BUILD_SCRIPT=Android.mk \
-    APP_ABI="$APP_ABI" \
-    APP_PLATFORM="$APP_PLATFORM" \
+    APP_ABI="$abi" \
+    APP_PLATFORM="$platform" \
     APP_MODULES="SDL3" \
     $ndk_args