4

I have an Android.mk file that has a number of files for which LOCAL_CFLAGS get applied to them. I would like to apply a different flag to only one of the files out of the many. How can this be accomplished?

I searched the internet from the Android perspective, but didn't find a whole lot. Considering the following example I would like to apply flag TEST3 to file test3.c only. I looked at Per-file CPPFLAGS in Android.mk, but I couldn't find anything as far as how to use PRIVATE_CPPFLAGS to one file. Any ideas?

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3

include $(BUILD_SHARED_LIBRARY)
4

1 回答 1

2

实现目标的受支持方法是为需要不同参数的 C/CPP 文件使用单独的静态库。在这种特殊情况下,修复将像

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)  

LOCAL_MODULE := test3
LOCAL_SRC_FILES := test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3 -DTEST3
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)  

LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c
LOCAL_CFLAGS := -DTEST1_2_AND_3
LOCAL_WHOLE_STATIC_LIBRARIES := test3

include $(BUILD_SHARED_LIBRARY)

还有另一种方法,类似于我前段时间伪造的方法

LOCAL_PATH := $(call my-dir)

TARGET-process-src-files-tags += $(call add-src-files-target-cflags, $(LOCAL_TEST3_SRC_FILES), $(LOCAL_TEST3_CFLAGS))

include $(CLEAR_VARS)  

LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3

LOCAL_TEST3_SRC_FILES := test3.c
LOCAL_TEST3_CFLAGS := -DTEST3

include $(BUILD_SHARED_LIBRARY)

如果-Dtest3可以,您可以使用另一个技巧:

LOCAL_PATH := $(call my-dir)

get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) -D$(basename $1)_DEFINE

include $(CLEAR_VARS)  

LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3

include $(BUILD_SHARED_LIBRARY)

请参阅如何在 Android.mk 的 LOCAL_CFLAGS 中动态获取当前编译器目标文件名中的更多内容?.

于 2018-08-26T09:06:38.803 回答