Workaround to enable cross-compiling from macOS® to Android™

Change-Id: I2e64b714b0da39cd39d6d498c69e81ffaa008b1e
Signed-off-by: Jakub Sujak <jakub.sujak@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/11329
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Suhail M <MohammedSuhail.Munshi@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
diff --git a/SConscript b/SConscript
index 4c4bcc7..f1b81ec 100644
--- a/SConscript
+++ b/SConscript
@@ -30,6 +30,7 @@
 import zlib
 import json
 import codecs
+import platform
 
 VERSION = "v0.0-unreleased"
 LIBRARY_VERSION_MAJOR = 35
@@ -41,6 +42,13 @@
 Import('vars')
 Import('install_lib')
 
+# Workaround to enable cross-compiling from macOS® to Android™ using the Android NDK.
+if platform.system() == 'Darwin' and env['os'] == 'android':
+    # SCons incorrectly assumes that we always want to build a dynamic library on a macOS host.
+    # When targeting Android, we overwrite the following construction variables to build a shared library instead.
+    env.Replace(SHLIBSUFFIX = '.so')                      # overwrites .dylib
+    env.Replace(SHLINKFLAGS = ['$LINKFLAGS', '-shared'])  # overwrites -dynamiclib
+
 def build_bootcode_objs(sources):
     arm_compute_env.Append(ASFLAGS = "-I bootcode/")
     obj = arm_compute_env.Object(sources)