I'm trying to build an Android project using the ndk, but I have run into some troubles.
我正在尝试使用ndk构建一个Android项目,但是遇到了一些麻烦。
Here's the Android.mk file that works:
这是Android。可工作的文件:
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 specify all the *.cpp files in the directory, without listing them manually under LOCAL_SRC_FILES?
有没有一种方法可以让我指定所有的*。目录中的cpp文件,没有在LOCAL_SRC_FILES下手动列出它们吗?
So far I tried using LOCAL_SRC_FILES = $(wildcard *.cpp), but it did now work, it seems that no files get selected.
到目前为止,我尝试使用LOCAL_SRC_FILES = $(通配符*.cpp),但它现在确实有效,似乎没有文件被选中。
3 个解决方案
#1
70
You could try something like this...
你可以试试这个……
FILE_LIST := $(wildcard $(LOCAL_PATH)/[DIRECTORY]/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
... Change [DIRECTORY]
to the actual directory of the files. If they are in the same directory as your .mk
file then remove that part. Create the FILE_LIST
variable to find all of the .cpp
files under the [DIRECTORY]
directory. Then use it in the file listing. The LOCAL_SRC_FILES
line will then remove the LOCAL_PATH
from the listing.
…将[目录]更改为文件的实际目录。如果它们位于与.mk文件相同的目录中,则删除该部分。创建FILE_LIST变量来查找[目录]目录下的所有.cpp文件。然后在文件列表中使用它。然后,LOCAL_SRC_FILES行将从清单中删除LOCAL_PATH。
#2
20
I've been using this script for my Android.mk saved me so much time!
我一直在为我的Android使用这个脚本。mk帮了我很多时间!
#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
这是要点
#3
2
How about like this:
如何是这样的:
LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/*.cpp))
If you'd be afraid that expansion of * contains $(LOCAL_PATH)/, it might be OK:
如果您担心*的扩展包含$(LOCAL_PATH)/,那么可以:
LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/./,,$(wildcard $(LOCAL_PATH)/./*.cpp))
#1
70
You could try something like this...
你可以试试这个……
FILE_LIST := $(wildcard $(LOCAL_PATH)/[DIRECTORY]/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
... Change [DIRECTORY]
to the actual directory of the files. If they are in the same directory as your .mk
file then remove that part. Create the FILE_LIST
variable to find all of the .cpp
files under the [DIRECTORY]
directory. Then use it in the file listing. The LOCAL_SRC_FILES
line will then remove the LOCAL_PATH
from the listing.
…将[目录]更改为文件的实际目录。如果它们位于与.mk文件相同的目录中,则删除该部分。创建FILE_LIST变量来查找[目录]目录下的所有.cpp文件。然后在文件列表中使用它。然后,LOCAL_SRC_FILES行将从清单中删除LOCAL_PATH。
#2
20
I've been using this script for my Android.mk saved me so much time!
我一直在为我的Android使用这个脚本。mk帮了我很多时间!
#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
这是要点
#3
2
How about like this:
如何是这样的:
LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/*.cpp))
If you'd be afraid that expansion of * contains $(LOCAL_PATH)/, it might be OK:
如果您担心*的扩展包含$(LOCAL_PATH)/,那么可以:
LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/./,,$(wildcard $(LOCAL_PATH)/./*.cpp))