Home » Android » Android.mk file – including all source files in different folders and subfolders

Android.mk file – including all source files in different folders and subfolders

Posted by: admin May 14, 2020 Leave a comment

Questions:

In writing an android .mk file, is there a short way to include many source files which are in different folders and subfolders? Like a loop or a code for iterating the folders? For example:

folder1

|—subfolder1.1

      |---subfolder1.1.1

               |---some cpp files

      |--subfolder1.1.2

           |--some cpp files

folder2

|—subfolder2.1

      |--subfolder2.1.1

           |--some cpp files

|–(so on and so forth, another folders and subfolders and cpp
files)

I know I can use include $(call all-subdir-makefiles) for folders and subfolders but it will take too much time if I have so many folders, is there a better way? Like a loop for iterating through the folders? So I will have just one library for folder1 and another for folder2 and so on…

How to&Answers:
FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/**/*.cpp)
FILE_LIST += $(wildcard $(LOCAL_PATH)/**/**/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

Answer:

You can use ** wildcard to include files from all subdirectories:

LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard folder/**/*.cpp))