Android.mk, includes all cpp files

I am trying to create an Android project using ndk, but I ran into some problems.

Here is the Android.mk file that works:

LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := mylib LOCAL_CFLAGS := -Werror LOCAL_SRC_FILES := main.cpp, Screen.cpp, ScreenManager.cpp LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) 

Is there a way that allows me to list all * .cpp files in a directory without manually specifying them in LOCAL_SRC_FILES?

So far I tried to use LOCAL_SRC_FILES = $ (wildcard * .cpp), but now it worked, it seems that no files were selected.

+46
android android-ndk
Jan 23 '12 at 23:50
source share
3 answers

You can try something like this ...

 FILE_LIST := $(wildcard $(LOCAL_PATH)/[DIRECTORY]/*.cpp) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) 

... Change [DIRECTORY] to the actual file directory. If they are in the same directory as your .mk file, then delete this part. Create the FILE_LIST variable to find all .cpp files in the [DIRECTORY] directory. Then use it in the file list. After that, the line LOCAL_SRC_FILES will remove LOCAL_PATH from the list.

+71
Jan 24 '12 at 0:10
source share

I use this script for my Android.mk, it saved so much time!

 #traverse all the directory and subdirectory define walk $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e))) endef #find all the file recursively under jni/ ALLFILES = $(call walk, $(LOCAL_PATH)) FILE_LIST := $(filter %.cpp, $(ALLFILES)) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) 

Here is the gist

+20
Apr 30 '13 at 22:00
source share

How about this:

 LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/*.cpp)) 

If you are afraid that the * extension contains $ (LOCAL_PATH) /, this might be OK:

 LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/./,,$(wildcard $(LOCAL_PATH)/./*.cpp)) 
+2
May 7 '13 at 2:54
source share



All Articles