From e1c7b8ad61a213014ae3bf87db197301ab2bac29 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 6 Feb 2023 22:26:45 +0800 Subject: [PATCH] Adjust ndk-build implementation for old NDK versions * configure.ac: Pass ANDROID_CFLAGS to ndk_INIT. * cross/ndk-build/Makefile.in (NDK_BUILD_CFLAGS): * cross/ndk-build/ndk-build-shared-library.mk ($(call objname,$(LOCAL_MODULE),$(basename $(1)))): ($$(error Unsupported suffix): * cross/ndk-build/ndk-build-static-library.mk ($(call objname,$(LOCAL_MODULE),$(basename $(1)))): ($$(error Unsupported suffix): Use NDK_BUILD_CFLAGS. * m4/ndk-build.m4 (ndk_INIT): Accept cflags. (ndk_CONFIG_FILES): Export NDK_BUILD_CFLAGS. --- configure.ac | 5 ++++- cross/ndk-build/Makefile.in | 1 + cross/ndk-build/ndk-build-shared-library.mk | 6 +++--- cross/ndk-build/ndk-build-static-library.mk | 6 +++--- m4/ndk-build.m4 | 8 ++++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index b8ce7840797..09ff1a845be 100644 --- a/configure.ac +++ b/configure.ac @@ -169,8 +169,11 @@ AC_CANONICAL_BUILD if test "$XCONFIGURE" = "android"; then # Initialize the Android NDK build system. Make sure to use the # passed through NDK path. + # Make sure to pass through the CFLAGS, as older versions of the + # NDK require them to be able to find system includes. with_ndk_path="$android_ndk_path" - ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build]) + ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build],\ + [$ANDROID_CFLAGS]) fi case $host in diff --git a/cross/ndk-build/Makefile.in b/cross/ndk-build/Makefile.in index 774858697b4..738a70a2f28 100644 --- a/cross/ndk-build/Makefile.in +++ b/cross/ndk-build/Makefile.in @@ -31,6 +31,7 @@ NDK_BUILD_ANDROID_MK = @NDK_BUILD_ANDROID_MK@ NDK_BUILD_CC = @NDK_BUILD_CC@ NDK_BUILD_AR = @NDK_BUILD_AR@ NDK_BUILD_NASM = @NDK_BUILD_NASM@ + NDK_BUILD_CFLAGS = @NDK_BUILD_CFLAGS@ # This is a list of targets to build. NDK_BUILD_MODULES = @NDK_BUILD_MODULES@ diff --git a/cross/ndk-build/ndk-build-shared-library.mk b/cross/ndk-build/ndk-build-shared-library.mk index be4d16cb4ed..44d5bbb1991 100644 --- a/cross/ndk-build/ndk-build-shared-library.mk +++ b/cross/ndk-build/ndk-build-shared-library.mk @@ -35,13 +35,13 @@ define single-object-target ifeq (x$(suffix $(1)),x.c) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(call LOCAL_C_ADDITIONAL_FLAGS,$(1)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(call LOCAL_C_ADDITIONAL_FLAGS,$(1)) else ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) @@ -54,7 +54,7 @@ ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else $$(error Unsupported suffix: $(suffix $(1))) diff --git a/cross/ndk-build/ndk-build-static-library.mk b/cross/ndk-build/ndk-build-static-library.mk index ebcc3cd531d..c1584e789a7 100644 --- a/cross/ndk-build/ndk-build-static-library.mk +++ b/cross/ndk-build/ndk-build-static-library.mk @@ -27,13 +27,13 @@ define single-object-target ifeq (x$(suffix $(1)),x.c) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(call LOCAL_C_ADDITIONAL_FLAGS,$(1)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(call LOCAL_C_ADDITIONAL_FLAGS,$(1)) else ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) @@ -46,7 +46,7 @@ ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(LOCAL_PATH)/$(1) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else $$(error Unsupported suffix: $(suffix $(1))) diff --git a/m4/ndk-build.m4 b/m4/ndk-build.m4 index 888b587af02..876c980ebb5 100644 --- a/m4/ndk-build.m4 +++ b/m4/ndk-build.m4 @@ -25,10 +25,11 @@ AC_ARG_WITH([ndk_cxx_shared], [AS_HELP_STRING([--with-ndk-cxx-shared], [name of the C++ standard library included with the NDK])]) -# ndk_INIT(ABI, API, DIR) -# -------- +# ndk_INIT(ABI, API, DIR, CFLAGS) +# ------------------------------- # Initialize the Android NDK. ABI is the ABI being built for. # API is the API version being built for. +# CFLAGS is a list of compiler flags. # As a side effect, set the variable ndk_INITIALIZED to true. # DIR should be a directory containing the Makefile.in actually # implementing the Android NDK build system. @@ -50,6 +51,7 @@ ndk_INITIALIZED=yes ndk_API=$2 ndk_DIR=$3 ndk_ANY_CXX= +ndk_BUILD_CFLAGS="$4" case "$ndk_ABI" in *arm64* ) @@ -370,6 +372,7 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES], NDK_BUILD_MODULES="$ndk_MODULES" NDK_BUILD_CXX_SHARED="$ndk_CXX_SHARED" NDK_BUILD_ANY_CXX_MODULE=$ndk_ANY_CXX + NDK_BUILD_CFLAGS="$ndk_BUILD_CFLAGS" AC_SUBST([NDK_BUILD_ANDROID_MK]) AC_SUBST([NDK_BUILD_ARCH]) @@ -381,6 +384,7 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES], AC_SUBST([NDK_BUILD_MODULES]) AC_SUBST([NDK_BUILD_CXX_SHARED]) AC_SUBST([NDK_BUILD_ANY_CXX_MODULE]) + AC_SUBST([NDK_BUILD_CFLAGS]) AC_CONFIG_FILES([$ndk_DIR/Makefile]) AC_CONFIG_FILES([$ndk_DIR/ndk-build.mk]) -- 2.39.5