From 351813556da2dc04ae5cc639d5ddebdf8edf4f5e Mon Sep 17 00:00:00 2001 From: Po Lu Date: Thu, 23 Feb 2023 21:31:42 +0800 Subject: [PATCH] Fix ImageMagick build on Android * INSTALL.android (-linux_arm_sources): * build-aux/ndk-build-helper-1.mk: (NDK_$(LOCAL_MODULE)_STATIC_LIBRARIES)::(NDK_CXX_FLAG_$(LOCAL_MODULE)): * build-aux/ndk-build-helper-2.mk: (NDK_$(LOCAL_MODULE)_STATIC_LIBRARIES)::(NDK_CXX_FLAG_$(LOCAL_MODULE)): * cross/ndk-build/ndk-build-shared-library.mk (objname)::($(call objname,$(LOCAL_MODULE),$(basename $(1))))::(ALL_OBJECT_FILES$(LOCAL_MODULE)): * cross/ndk-build/ndk-build-static-library.mk (objname)::($(call objname,$(LOCAL_MODULE),$(basename $(1))))::(ALL_OBJECT_FILES$(LOCAL_MODULE)): (ALL_SOURCE_FILES): Update ImageMagick build instructions and C++ module detection. --- INSTALL.android | 347 +++++++++++++++++++- build-aux/ndk-build-helper-1.mk | 11 +- build-aux/ndk-build-helper-2.mk | 11 +- cross/ndk-build/ndk-build-shared-library.mk | 27 +- cross/ndk-build/ndk-build-static-library.mk | 31 +- 5 files changed, 403 insertions(+), 24 deletions(-) diff --git a/INSTALL.android b/INSTALL.android index b3a29d511db..ea1b07c0b7b 100644 --- a/INSTALL.android +++ b/INSTALL.android @@ -852,8 +852,310 @@ index e82f3d5..be3a3c4 100644 PATCH FOR IMAGEMAGICK +diff --git a/Android.mk b/Android.mk +index 5ab6699..4441417 100644 +--- a/Android.mk ++++ b/Android.mk +@@ -52,6 +52,20 @@ LZMA_LIB_PATH := $(LOCAL_PATH)/xz-5.2.4 + BZLIB_LIB_PATH := $(LOCAL_PATH)/bzip-1.0.8 + LCMS_LIB_PATH := $(LOCAL_PATH)/liblcms2-2.9 + ++LIBBZ2_ENABLED := true ++LIBFFTW_ENABLED := true ++LIBFREETYPE2_ENABLED := true ++LIBJPEG_TURBO_ENABLED := true ++LIBLZMA_ENABLED := true ++LIBOPENJPEG_ENABLED := true ++LIBPNG_ENABLED := true ++LIBTIFF_ENABLED := true ++LIBWEBP_ENABLED := true ++LIBXML2_ENABLED := true ++LIBZLIB_ENABLED := true ++LIBLCMS2_ENABLED := true ++BUILD_MAGICKWAND := true ++ + #------------------------------------------------------------- + # Include all modules + #------------------------------------------------------------- +@@ -68,6 +82,9 @@ include $(MAKE_PATH)/libjpeg-turbo.mk + # libopenjpeg + include $(MAKE_PATH)/libopenjpeg.mk + ++# libwebp ++include $(MAKE_PATH)/libwebp.mk ++ + # libtiff + include $(MAKE_PATH)/libtiff.mk + +@@ -77,9 +94,6 @@ include $(MAKE_PATH)/libpng.mk + # libfreetype2 + include $(MAKE_PATH)/libfreetype2.mk + +-# libwebp +-include $(MAKE_PATH)/libwebp.mk +- + # libfftw + include $(MAKE_PATH)/libfftw.mk + +diff --git a/libjpeg-turbo-2.0.2/jconfig.h b/libjpeg-turbo-2.0.2/jconfig.h +index 47d14c9..5c6f8ee 100644 +--- a/libjpeg-turbo-2.0.2/jconfig.h ++++ b/libjpeg-turbo-2.0.2/jconfig.h +@@ -1,57 +1,43 @@ +-/* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */ ++/* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */ + #ifndef JPEG_LIB_VERSION + #define JPEG_LIB_VERSION 62 + #endif +- + #ifndef LIBJPEG_TURBO_VERSION + #define LIBJPEG_TURBO_VERSION 2.0.2 + #endif +- + #ifndef LIBJPEG_TURBO_VERSION_NUMBER + #define LIBJPEG_TURBO_VERSION_NUMBER 202 + #endif +- + #ifndef C_ARITH_CODING_SUPPORTED + #define C_ARITH_CODING_SUPPORTED + #endif +- + #ifndef D_ARITH_CODING_SUPPORTED + #define D_ARITH_CODING_SUPPORTED + #endif +- + #ifndef MEM_SRCDST_SUPPORTED + #define MEM_SRCDST_SUPPORTED + #endif +- + #ifndef WITH_SIMD + #define WITH_SIMD + #endif +- + #ifndef BITS_IN_JSAMPLE + #define BITS_IN_JSAMPLE 8 + #endif +- + #ifndef HAVE_LOCALE_H + #define HAVE_LOCALE_H + #endif +- + #ifndef HAVE_STDDEF_H + #define HAVE_STDDEF_H + #endif +- + #ifndef HAVE_STDLIB_H + #define HAVE_STDLIB_H + #endif +- + #ifndef NEED_SYS_TYPES_H + #define NEED_SYS_TYPES_H + #endif +- + #ifndef HAVE_UNSIGNED_CHAR + #define HAVE_UNSIGNED_CHAR + #endif +- + #ifndef HAVE_UNSIGNED_SHORT + #define HAVE_UNSIGNED_SHORT + #endif +- +diff --git a/libxml2-2.9.9/encoding.c b/libxml2-2.9.9/encoding.c +index a3aaf10..60f165b 100644 +--- a/libxml2-2.9.9/encoding.c ++++ b/libxml2-2.9.9/encoding.c +@@ -2394,7 +2394,6 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init) + { + int ret; + size_t written; +- size_t writtentot = 0; + size_t toconv; + int c_in; + int c_out; +@@ -2451,7 +2450,6 @@ retry: + xmlBufContent(in), &c_in); + xmlBufShrink(in, c_in); + xmlBufAddLen(out, c_out); +- writtentot += c_out; + if (ret == -1) { + if (c_out > 0) { + /* Can be a limitation of iconv or uconv */ +@@ -2536,7 +2534,6 @@ retry: + } + + xmlBufAddLen(out, c_out); +- writtentot += c_out; + goto retry; + } + } +@@ -2567,9 +2564,7 @@ xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out, + xmlBufferPtr in) { + int ret; + int written; +- int writtentot = 0; + int toconv; +- int output = 0; + + if (handler == NULL) return(-1); + if (out == NULL) return(-1); +@@ -2612,7 +2607,6 @@ retry: + in->content, &toconv); + xmlBufferShrink(in, toconv); + out->use += written; +- writtentot += written; + out->content[out->use] = 0; + if (ret == -1) { + if (written > 0) { +@@ -2622,8 +2616,6 @@ retry: + ret = -3; + } + +- if (ret >= 0) output += ret; +- + /* + * Attempt to handle error cases + */ +@@ -2700,7 +2692,6 @@ retry: + } + + out->use += written; +- writtentot += written; + out->content[out->use] = 0; + goto retry; + } +diff --git a/libxml2-2.9.9/xpath.c b/libxml2-2.9.9/xpath.c +index 5e3bb9f..505ec82 100644 +--- a/libxml2-2.9.9/xpath.c ++++ b/libxml2-2.9.9/xpath.c +@@ -10547,7 +10547,7 @@ xmlXPathCompFilterExpr(xmlXPathParserContextPtr ctxt) { + + static xmlChar * + xmlXPathScanName(xmlXPathParserContextPtr ctxt) { +- int len = 0, l; ++ int l; + int c; + const xmlChar *cur; + xmlChar *ret; +@@ -10567,7 +10567,6 @@ xmlXPathScanName(xmlXPathParserContextPtr ctxt) { + (c == '_') || (c == ':') || + (IS_COMBINING(c)) || + (IS_EXTENDER(c)))) { +- len += l; + NEXTL(l); + c = CUR_CHAR(l); + } +diff --git a/make/libicu4c.mk b/make/libicu4c.mk +index 21ec121..8b77865 100644 +--- a/make/libicu4c.mk ++++ b/make/libicu4c.mk +@@ -250,7 +250,7 @@ LOCAL_MODULE := libicuuc + LOCAL_SRC_FILES := $(src_files) + + # when built in android, they require uconfig_local (because of android project), but we don't need this +-$(shell > $(ICU_COMMON_PATH)/unicode/uconfig_local.h echo /* Autogenerated stub file to make libicuuc build happy */) \ ++$(shell > $(ICU_COMMON_PATH)/unicode/uconfig_local.h echo /\* Autogenerated stub file to make libicuuc build happy \*/) \ + + ifeq ($(LIBXML2_ENABLED),true) + include $(BUILD_STATIC_LIBRARY) +diff --git a/make/libjpeg-turbo.mk b/make/libjpeg-turbo.mk +index d39dd41..fdebcf3 100644 +--- a/make/libjpeg-turbo.mk ++++ b/make/libjpeg-turbo.mk +@@ -230,30 +230,30 @@ JCONFIG_FLAGS += \ + HAVE_UNSIGNED_SHORT + + JCONFIGINT_FLAGS += \ +- BUILD="20190814" \ +- PACKAGE_NAME="libjpeg-turbo" \ +- VERSION="2.0.2" ++ BUILD=\"20190814\" \ ++ PACKAGE_NAME=\"libjpeg-turbo\" \ ++ VERSION=\"2.0.2\" + + # originally defined in jconfigint.h, but the substitution has problems with spaces + LOCAL_CFLAGS := \ + -DINLINE="inline __attribute__((always_inline))" + + # create definition file jconfig.h, needed in order to build +-$(shell echo /* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */ > $(JPEG_LIB_PATH)/jconfig.h) ++$(shell echo \/\* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS \*\/ > $(JPEG_LIB_PATH)/jconfig.h) + $(foreach name,$(JCONFIG_FLAGS), \ + $(if $(findstring =,$(name)), \ +- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #ifndef $(firstword $(subst =, ,$(name)))) \ ++ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#ifndef $(firstword $(subst =, ,$(name)))) \ + , \ +- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #ifndef $(name)) \ ++ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#ifndef $(name)) \ + ) \ +- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #define $(subst =, ,$(name))) \ +- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #endif) \ ++ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#define $(subst =, ,$(name))) \ ++ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#endif) \ + $(shell >> $(JPEG_LIB_PATH)/jconfig.h echo.) \ + ) + + # create definition file jconfigint.h, needed in order to build +-$(shell >$(JPEG_LIB_PATH)/jconfigint.h echo /* autogenerated jconfigint.h based on Android.mk vars JCONFIGINT_FLAGS */) +-$(foreach name,$(JCONFIGINT_FLAGS),$(shell >>$(JPEG_LIB_PATH)/jconfigint.h echo #define $(subst =, ,$(name)))) ++$(shell >$(JPEG_LIB_PATH)/jconfigint.h echo /\* autogenerated jconfigint.h based on Android.mk vars JCONFIGINT_FLAGS \*/) ++$(foreach name,$(JCONFIGINT_FLAGS),$(shell >>$(JPEG_LIB_PATH)/jconfigint.h echo \#define $(subst =, ,$(name)))) + + ifeq ($(LIBJPEG_TURBO_ENABLED),true) + include $(BUILD_STATIC_LIBRARY) +diff --git a/make/liblcms2.mk b/make/liblcms2.mk +index e1fd3b9..29ca791 100644 +--- a/make/liblcms2.mk ++++ b/make/liblcms2.mk +@@ -10,6 +10,10 @@ LOCAL_C_INCLUDES := \ + $(LCMS_LIB_PATH)/include \ + $(LCMS_LIB_PATH)/src + ++LOCAL_EXPORT_C_INCLUDES := \ ++ $(LCMS_LIB_PATH) \ ++ $(LCMS_LIB_PATH)/include \ ++ $(LCMS_LIB_PATH)/src + + LOCAL_CFLAGS := \ + -DHAVE_FUNC_ATTRIBUTE_VISIBILITY=1 \ +diff --git a/make/libmagick++-7.mk b/make/libmagick++-7.mk +index 5352ccb..929396d 100644 +--- a/make/libmagick++-7.mk ++++ b/make/libmagick++-7.mk +@@ -12,7 +12,7 @@ LOCAL_C_INCLUDES := \ + + ifneq ($(STATIC_BUILD),true) + LOCAL_LDFLAGS += -fexceptions +- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz ++ LOCAL_LDLIBS := -llog -lz + endif + + LOCAL_SRC_FILES := \ +diff --git a/make/libmagickcore-7.mk b/make/libmagickcore-7.mk +index 81293b2..d51fced 100644 +--- a/make/libmagickcore-7.mk ++++ b/make/libmagickcore-7.mk +@@ -25,6 +25,7 @@ else ifeq ($(TARGET_ARCH_ABI),x86_64) + + endif + ++LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK) + + LOCAL_C_INCLUDES += \ + $(IMAGE_MAGICK) \ +@@ -45,10 +46,9 @@ LOCAL_C_INCLUDES += \ + $(BZLIB_LIB_PATH) \ + $(LCMS_LIB_PATH)/include + +- + ifneq ($(STATIC_BUILD),true) + # ignored in static library builds +- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz ++ LOCAL_LDLIBS := -llog -lz + endif + + diff --git a/make/libmagickwand-7.mk b/make/libmagickwand-7.mk -index 7be2fb6..70a2cee 100644 +index 7be2fb6..0bbcca5 100644 --- a/make/libmagickwand-7.mk +++ b/make/libmagickwand-7.mk @@ -14,7 +14,7 @@ LOCAL_C_INCLUDES := \ @@ -865,10 +1167,12 @@ index 7be2fb6..70a2cee 100644 endif LOCAL_SRC_FILES := \ -@@ -54,6 +54,27 @@ ifeq ($(OPENCL_BUILD),true) +@@ -54,6 +54,29 @@ ifeq ($(OPENCL_BUILD),true) LOCAL_SHARED_LIBRARIES += libopencl endif ++LOCAL_SHARED_LIBRARIES += libstdc++ ++ +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm64 + LOCAL_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm64 @@ -893,3 +1197,42 @@ index 7be2fb6..70a2cee 100644 ifeq ($(BUILD_MAGICKWAND),true) ifeq ($(STATIC_BUILD),true) LOCAL_STATIC_LIBRARIES := \ +diff --git a/make/libpng.mk b/make/libpng.mk +index 24fb8ac..dda05fd 100644 +--- a/make/libpng.mk ++++ b/make/libpng.mk +@@ -30,6 +30,7 @@ ifeq ($(TARGET_ARCH_ABI), arm64-v8a) + endif # TARGET_ARCH_ABI == arm64-v8a + + ++LOCAL_EXPORT_C_INCLUDES := $(PNG_LIB_PATH) + LOCAL_C_INCLUDES := $(PNG_LIB_PATH) + + LOCAL_SRC_FILES += \ +diff --git a/make/libtiff.mk b/make/libtiff.mk +index ca43f25..2b17508 100644 +--- a/make/libtiff.mk ++++ b/make/libtiff.mk +@@ -12,6 +12,9 @@ LOCAL_C_INCLUDES := \ + $(LZMA_LIB_PATH)/liblzma/api \ + $(WEBP_LIB_PATH)/src + ++LOCAL_EXPORT_C_INCLUDES := \ ++ $(TIFF_LIB_PATH) ++ + ifeq ($(LIBLZMA_ENABLED),true) + LOCAL_CFLAGS += -DLZMA_SUPPORT=1 + endif +diff --git a/make/magick.mk b/make/magick.mk +index 3ba4b1d..5471608 100644 +--- a/make/magick.mk ++++ b/make/magick.mk +@@ -18,7 +18,7 @@ LOCAL_C_INCLUDES := \ + $(FREETYPE_LIB_PATH)/include + + +-LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz ++LOCAL_LDLIBS := -llog -lz + LOCAL_SRC_FILES := \ + $(IMAGE_MAGICK)/utilities/magick.c \ + diff --git a/build-aux/ndk-build-helper-1.mk b/build-aux/ndk-build-helper-1.mk index 04acecb5b29..2cde5146301 100644 --- a/build-aux/ndk-build-helper-1.mk +++ b/build-aux/ndk-build-helper-1.mk @@ -31,6 +31,7 @@ NDK_A_NAMES = NDK_$(LOCAL_MODULE)_STATIC_LIBRARIES := $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES) NDK_$(LOCAL_MODULE)_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES) NDK_$(LOCAL_MODULE)_EXPORT_INCLUDES := $(LOCAL_EXPORT_C_INCLUDE_DIRS) $(LOCAL_EXPORT_C_INCLUDES) +NDK_CXX_FLAG_$(LOCAL_MODULE) := $(info Building $(build_kind)) $(info $(LOCAL_MODULE)) @@ -64,6 +65,10 @@ $$(foreach module,$$(filter-out $$(SYSTEM_LIBRARIES), $$(NDK_$(1)_SHARED_LIBRARI # Recurse over static library dependencies of this shared library. $$(foreach module,$$(filter-out $$(SYSTEM_LIBRARIES), $$(NDK_$(1)_STATIC_LIBRARIES) $$(NDK_$(1)_WHOLE_LIBRARIES)),$$(eval $$(call add-so-name-1,$$(module)))) endif + +ifneq ($$(findstring stdc++,$$(NDK_$(1)_SHARED_LIBRARIES)),) +NDK_CXX_FLAG_$(LOCAL_MODULE) := yes +endif endef # Figure out includes from dependencies as well. @@ -94,10 +99,14 @@ SYSTEM_LIBRARIES = z libz libc c libdl dl stdc++ libstdc++ log liblog android li $(foreach module,$(filter-out $(SYSTEM_LIBRARIES), $(LOCAL_SHARED_LIBRARIES)),$(eval $(call add-so-name,$(module)))) $(foreach module,$(filter-out $(SYSTEM_LIBRARIES), $(LOCAL_SHARED_LIBRARIES) $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES)),$(eval $(call add-includes,$(module)))) +ifneq ($(findstring stdc++,$(LOCAL_SHARED_LIBRARIES)),) +NDK_CXX_FLAG_$(LOCAL_MODULE) := yes +endif + $(info $(foreach dir,$(NDK_INCLUDES),-I$(dir))) $(info $(LOCAL_EXPORT_CFLAGS)) $(info $(LOCAL_EXPORT_LDFLAGS) $(abspath $(addprefix $(NDK_BUILD_DIR)/,$(NDK_A_NAMES))) -L$(abspath $(NDK_BUILD_DIR)) $(foreach soname,$(NDK_SO_NAMES),-l:$(soname))) $(info $(NDK_SO_NAMES)) -$(info $(filter %stdc++,$(LOCAL_SHARED_LIBRARIES))) +$(info $(NDK_CXX_FLAG_$(LOCAL_MODULE))) $(info End) diff --git a/build-aux/ndk-build-helper-2.mk b/build-aux/ndk-build-helper-2.mk index 59f77106784..186f3aec333 100644 --- a/build-aux/ndk-build-helper-2.mk +++ b/build-aux/ndk-build-helper-2.mk @@ -25,6 +25,7 @@ NDK_A_NAMES = NDK_$(LOCAL_MODULE)_STATIC_LIBRARIES := $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_STATIC_LIBRARIES) NDK_$(LOCAL_MODULE)_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES) NDK_$(LOCAL_MODULE)_EXPORT_INCLUDES := $(LOCAL_EXPORT_C_INCLUDE_DIRS) $(LOCAL_EXPORT_C_INCLUDES) +NDK_CXX_FLAG_$(LOCAL_MODULE) := $(info Building $(build_kind)) $(info $(LOCAL_MODULE)) @@ -50,6 +51,10 @@ NDK_A_NAMES := $$(NDK_A_NAMES) $$(NDK_A_NAME) $$(foreach module,$$(filter-out $$(SYSTEM_LIBRARIES), $$(NDK_$(1)_STATIC_LIBRARIES)),$$(eval $$(call add-a-name,$$(module)))) $$(foreach module,$$(filter-out $$(SYSTEM_LIBRARIES), $$(NDK_$(1)_SHARED_LIBRARIES)),$$(eval $$(call add-so-name,$$(module)))) endif + +ifneq ($$(findstring stdc++,$$(NDK_$(1)_SHARED_LIBRARIES)),) +NDK_CXX_FLAG_$(LOCAL_MODULE) := yes +endif endef define add-so-name @@ -88,9 +93,13 @@ $(foreach module,$(filter-out $(SYSTEM_LIBRARIES), $(LOCAL_STATIC_LIBRARIES) $(L $(foreach module,$(filter-out $(SYSTEM_LIBRARIES), $(LOCAL_SHARED_LIBRARIES)),$(eval $(call add-so-name,$(module)))) $(foreach module,$(filter-out $(SYSTEM_LIBRARIES), $(LOCAL_SHARED_LIBRARIES) $(LOCAL_STATIC_LIBRARIES) $(LOCAL_WHOLE_LIBRARIES)),$(eval $(call add-includes,$(module)))) +ifneq ($(findstring stdc++,$(LOCAL_SHARED_LIBRARIES)),) +NDK_CXX_FLAG_$(LOCAL_MODULE) := yes +endif + $(info $(foreach dir,$(NDK_INCLUDES),-I$(dir))) $(info $(LOCAL_EXPORT_CFLAGS)) $(info $(LOCAL_EXPORT_LDFLAGS) $(abspath $(addprefix $(NDK_BUILD_DIR)/,$(NDK_A_NAMES))) $(and $(NDK_SO_NAMES), -L$(abspath $(NDK_BUILD_DIR)) $(foreach soname,$(NDK_SO_NAMES),-l:$(soname)))) $(info $(NDK_A_NAMES) $(NDK_SO_NAMES)) -$(info $(filter %stdc++,$(LOCAL_SHARED_LIBRARIES))) +$(info $(NDK_CXX_FLAG_$(LOCAL_MODULE))) $(info End) diff --git a/cross/ndk-build/ndk-build-shared-library.mk b/cross/ndk-build/ndk-build-shared-library.mk index 3f1cec9c2dc..2209e94d359 100644 --- a/cross/ndk-build/ndk-build-shared-library.mk +++ b/cross/ndk-build/ndk-build-shared-library.mk @@ -28,8 +28,9 @@ eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) objname = $(1)-shared-$(subst /,_,$(2).o) # LOCAL_SRC_FILES sometimes contains absolute file names. Filter them -# out with this function. -maybe-absolute = $(or $(and $(wildcard $(1)),$(1)),$(LOCAL_PATH)/$(1)) +# out with this function. If $(2), this is a file relative to the +# build directory. +maybe-absolute = $(or $(and $(2),$(1)),$(and $(wildcard $(1)),$(1)),$(LOCAL_PATH)/$(1)) # Here are the default flags to link shared libraries with. NDK_SO_DEFAULT_LDFLAGS := -lc -lm @@ -38,7 +39,7 @@ define single-object-target ifeq (x$(suffix $(1)),x.c) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS) $(call LOCAL_C_ADDITIONAL_FLAGS,$(1)) else @@ -50,14 +51,14 @@ $(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) else ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_ASFLAGS_$(LOCAL_MODULE)) else ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(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)) else @@ -89,6 +90,13 @@ ALL_OBJECT_FILES$(LOCAL_MODULE) += $(call objname,$(LOCAL_MODULE),$(basename $(1 endef +define single-neon-target + +# Define rules for the target. +$$(eval $$(call single-object-target,$(patsubst %.neon,%,$(1)),)) + +endef + # Make sure to not add a prefix to local includes that already specify # $(LOCAL_PATH). NDK_CFLAGS_$(LOCAL_MODULE) := $(addprefix -I,$(LOCAL_C_INCLUDES)) @@ -140,10 +148,13 @@ ALL_SOURCE_FILES := $(LOCAL_SRC_FILES) $(LOCAL_SRC_FILES_$(NDK_BUILD_ARCH)) # This defines all dependencies. ALL_OBJECT_FILES$(LOCAL_MODULE) := -# Now filter out code that is only built on systems with neon. -ALL_SOURCE_FILES := $(filter-out %.neon,$(ALL_SOURCE_FILES)) +# Now filter out code that is built with neon. Define rules to build +# those separately. +NEON_SOURCE_FILES := $(filter %.neon,$(ALL_SOURCE_FILES)) +ALL_SOURCE_FILES := $(filter-out %.neon,$(ALL_SOURCE_FILES)) -$(foreach source,$(ALL_SOURCE_FILES),$(eval $(call single-object-target,$(source)))) +$(foreach source,$(ALL_SOURCE_FILES),$(eval $(call single-object-target,$(source),))) +$(foreach source,$(NEON_SOURCE_FILES),$(eval $(call single-neon-target,$(source)))) # Now define the rule to build the shared library. Shared libraries # link with all of the archive files from the static libraries on diff --git a/cross/ndk-build/ndk-build-static-library.mk b/cross/ndk-build/ndk-build-static-library.mk index 3c68b902e6a..04aea49bffe 100644 --- a/cross/ndk-build/ndk-build-static-library.mk +++ b/cross/ndk-build/ndk-build-static-library.mk @@ -21,35 +21,32 @@ eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) objname = $(1)-static-$(subst /,_,$(2).o) - -# LOCAL_SRC_FILES sometimes contains absolute file names. Filter them -# out with this function. -maybe-absolute = $(or $(and $(wildcard $(1)),$(1)),$(LOCAL_PATH)/$(1)) +maybe-absolute = $(or $(and $(2),$(1)),$(and $(wildcard $(1)),$(1)),$(LOCAL_PATH)/$(1)) define single-object-target ifeq (x$(suffix $(1)),x.c) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) $(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))): $(call maybe-absolute,$(1)) +$(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)) else ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_ASFLAGS_$(LOCAL_MODULE)) else ifneq (x$(suffix $(1)),x.asm) ifeq (x$(suffix $(1)),x.cc) -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(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)) else @@ -67,7 +64,7 @@ ifeq ($(findstring x86,$(NDK_BUILD_ARCH)),) $$(error Trying to build nasm file on non-Intel platform!) else -$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) +$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) $(NDK_BUILD_NASM) -o $$@ -i $(LOCAL_PATH) -i $$(dir $$<) $(NDK_ASFLAGS_$(LOCAL_MODULE)) $$< endif @@ -80,6 +77,13 @@ endif ALL_OBJECT_FILES$(LOCAL_MODULE) += $(call objname,$(LOCAL_MODULE),$(basename $(1))) endef +define single-neon-target + +# Define rules for the target. +$$(eval $$(call single-object-target,$(patsubst %.neon,%,$(1)),)) + +endef + NDK_CFLAGS_$(LOCAL_MODULE) := $(addprefix -I,$(LOCAL_C_INCLUDES)) NDK_CFLAGS_$(LOCAL_MODULE) += -fPIC -iquote $(LOCAL_PATH) $(LOCAL_EXPORT_CFLAGS) $(LOCAL_CFLAGS) $(LOCAL_CFLAGS_$(NDK_BUILD_ARCH)) NDK_ASFLAGS_$(LOCAL_MODULE) := $(LOCAL_ASFLAGS) $(LOCAL_ASFLAGS_$(NDK_BUILD_ARCH)) $(and $(findstring clang,$(NDK_BUILD_CC)),$(LOCAL_CLANG_ASFLAGS_$(NDK_BUILD_ARCH))) @@ -122,13 +126,16 @@ include ndk-resolve.mk # Then define rules to build all objects. ALL_SOURCE_FILES := $(LOCAL_SRC_FILES) $(LOCAL_SRC_FILES_$(NDK_BUILD_ARCH)) -# Now filter out code that is only built on systems with neon. -ALL_SOURCE_FILES := $(filter-out %.neon,$(ALL_SOURCE_FILES)) +# Now filter out code that is built with neon. Define rules to build +# those separately. +NEON_SOURCE_FILES := $(filter %.neon,$(ALL_SOURCE_FILES)) +ALL_SOURCE_FILES := $(filter-out %.neon,$(ALL_SOURCE_FILES)) # This defines all dependencies. ALL_OBJECT_FILES$(LOCAL_MODULE) = -$(foreach source,$(ALL_SOURCE_FILES),$(eval $(call single-object-target,$(source)))) +$(foreach source,$(ALL_SOURCE_FILES),$(eval $(call single-object-target,$(source),))) +$(foreach source,$(NEON_SOURCE_FILES),$(eval $(call single-neon-target,$(source),))) # Now define the rule to build the library. $(LOCAL_MODULE_FILENAME): $(ALL_OBJECT_FILES$(LOCAL_MODULE)) -- 2.39.5