From 0d363aded1e33762f9ed91aef2497a162de956b2 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 4 Mar 2023 08:45:11 +0800 Subject: [PATCH] Fix cross-compilation of C++ code with old NDK versions * cross/ndk-build/Makefile.in (NDK_BUILD_CFLAGS_CXX): New variable. * cross/ndk-build/ndk-build-shared-library.mk ($(call objname,$(LOCAL_MODULE),$(basename $(1)))): * cross/ndk-build/ndk-build-static-library.mk ($(call objname,$(LOCAL_MODULE),$(basename $(1)))): Use it to build C++ code. --- cross/ndk-build/Makefile.in | 4 ++++ cross/ndk-build/ndk-build-shared-library.mk | 4 ++-- cross/ndk-build/ndk-build-static-library.mk | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cross/ndk-build/Makefile.in b/cross/ndk-build/Makefile.in index 738a70a2f28..b546c5b6231 100644 --- a/cross/ndk-build/Makefile.in +++ b/cross/ndk-build/Makefile.in @@ -56,6 +56,10 @@ NDK_BUILD_ANDROID_MK := $(call uniqify,$(NDK_BUILD_ANDROID_MK)) # LOCAL_SHARED_LIBRARIES. NDK_BUILD_MODULES := $(call uniqify,$(NDK_BUILD_MODULES)) +# Define CFLAGS for compiling C++ code; this involves removing all +# -std=NNN options. +NDK_BUILD_CFLAGS_CXX := $(filter-out -std=%,$(NDK_BUILD_CFLAGS)) + define subr-1 # Define ndk-build functions. Many of these are identical to those in diff --git a/cross/ndk-build/ndk-build-shared-library.mk b/cross/ndk-build/ndk-build-shared-library.mk index b7a64865e38..12712265de2 100644 --- a/cross/ndk-build/ndk-build-shared-library.mk +++ b/cross/ndk-build/ndk-build-shared-library.mk @@ -46,7 +46,7 @@ else ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) @@ -59,7 +59,7 @@ ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(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 a597bc0d691..163a4487e5f 100644 --- a/cross/ndk-build/ndk-build-static-library.mk +++ b/cross/ndk-build/ndk-build-static-library.mk @@ -34,7 +34,7 @@ else ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(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)),) @@ -47,7 +47,7 @@ ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) - $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) + $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) else $$(error Unsupported suffix: $(suffix $(1)))