Android.mk - create the entire source file in the directory

I use the Android NDK to create my cocos2dx project, Android.mk has a definition for LOCAL_SRC_FILES, which lists each of the cpp files. Whenever I add a new source file, I also need to add it there ... it looks like this:

LOCAL_SRC_FILES := hellocpp/main.cpp \ hellocpp/myclass.cpp \ hellocpp/mynextclass.cpp \ ../../Classes/Screens/LaunchScreen.cpp \ 

the header file, however, can indicate the entire included directory, as follows:

 LOCAL_C_INCLUDES := $(LOCAL_PATH)/hellocpp LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/Screens 

I tried various ways to include the entire directory instead of a single file for LOCAL_SRC_FILES , so I do not need to change the version of the Android.mk script every time I add a new file, however, all my attempts failed.

I tried this:

 #SRC_PATH_HELLOCPP := $(wildcard hellocpp/*.cpp) #SRC_PATH_CLASSES += $(wildcard ../../Classes/*.cpp) #LOCAL_SRC_FILES := $(SRC_PATH_HELLOCPP:$(LOCAL_PATH/%=%) #LOCAL_SRC_FILES += $(SRC_PATH_CLASSES:$(LOCAL_PATH/%=%) 

and:

 #LOCAL_SRC_FILES += hellocpp/*.cpp #LOCAL_SRC_FILES += ../../Classes/*.cpp 

both do not work ...

I have another project that works well with the first option, although I really do not understand why it does not work in the cocos2dx project ... does anyone know why or know the solution? Or maybe I should just leave it as it is and take the trouble, as everyone does it, but it’s really troublesome, I hope someone can help, so that we can all be more productive.

Thanks!

+8
android android-ndk cocos2d-x cocos2d-iphone
source share
7 answers

The wildcard pattern also works for cocos2dx projects. I use it myself, just that your syntax is incorrect

Try:

 HELLOCPP_FILES := $(wildcard $(LOCAL_PATH)/hellocpp/*.cpp) HELLOCPP_FILES := $(HELLOCPP_FILES:$(LOCAL_PATH)/%=%) CLASSES_FILES := $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp) CLASSES_FILES := $(CLASSES_FILES:$(LOCAL_PATH)/%=%) LOCAL_SRC_FILES := $(HELLOCPP_FILES) LOCAL_SRC_FILES += $(CLASSES_FILES) 
+17
source share

Actually, the templates work, and you were on the right track ...

This is an example of what works great for me:

 UTILITIES := $(wildcard $(LOCAL_PATH)/Utility/*.cpp) ZIP := $(wildcard $(LOCAL_PATH)/Utility/zip/jni/*.c) 

Notice the inclusion of the variable $ (LOCAL_PATH), and then

 SOURCES := $(UTILITIES:$(LOCAL_PATH)/%=%) SOURCES += $(ZIP:$(LOCAL_PATH)/%=%) 

This should allow you to drop any source file and compile it without returning to the Android.mk file.

+6
source share

I think you do not need to add the whole header for the newly added .cpp files .. you should just add it this way

eg. if you want to add this LaunchScreen.cpp then you should enable it in such a simple way.

 LOCAL_SRC_FILES:=hellocpp/main.cpp \ ../../Classes/myclass.cpp\ ../../Classes/mynextclass.cpp\ ../../Classes/LaunchScreen.cpp\ 
+1
source share

This is a make file. Makefiles do not work like that. You cannot specify the entire directory for compiling files - it simply is not configured that way. So it was about 40 years. One of the many reasons people hate makefiles. The problem is that all the replacements were just as bad.

0
source share

To create all your .cpp files in the ../../Classes/ section, you can use the external find if you create a project on a UNIX-like OS:

 SRC_PATH_CLASSES := $(shell find ../../Classes/ -type f) SRC_PATH_CLASSES := $(filter %.cpp, $(SRC_PATH_CLASSES)) LOCAL_SRC_FILES += $(SRC_PATH_CLASSES:$(LOCAL_PATH)/%=%) 

As suggested in the link : Recursive wildcards in GNU make? , another method uses the following recursive pattern. It is written with clean Makefile rules, so it is portable and better.

 rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) SRC_PATH_CLASSES := $(call rwildcard, ../../Classes/, *.cpp) LOCAL_SRC_FILES += $(SRC_PATH_CLASSES:$(LOCAL_PATH)/%=%) 
0
source share

After hours of struggling with this, I found a solution that finally works with my cocos2dx installation (cocos2dx 3.10)

 LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../Classes FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp) LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) 

Answering questions in order to help someone with the same pain, as it works, this question still has to do with this day. It is noteworthy that this also works for Windows, which was the main problem I encountered with others decisions.

Source: http://qiita.com/YosukeMitsugi/items/137f1b57f03945ad2d50

0
source share

this is what worked for me in cocos2dx 3.10 under win 10:

 FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp) LOCAL_SRC_FILES := hellocpp/main.cpp \ LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%) 
0
source share

All Articles