For Loop in the GNU Makefile - Collect all object files into a single variable through Mutliple directories

The general idea of โ€‹โ€‹what I'm trying to do can hopefully be summarized with this little script.

DIRS = dir1 dir2 dir3 dir4 ... OBJS = all: GENERATE_OBJECT_FILES GENERATE_OBJECT_FILES: for curr_dir in $(DIRS); \ do \ $(join $(OBJS), `ls $${curr_dir}/*.o`); \ done echo $(OBJS); 

How could I execute this with a script in a Makefile?

+4
source share
2 answers

I would use the wildcard function outside the recipe, for example:

 DIRS := dir1 dir2 dir3 dir4 ... OBJS := $(foreach dir,$(DIRS),$(wildcard $(dir)/*.o)) all : $(OBJS) @echo $^ 
+4
source

I would do it like this:

 DIRS = dir1 dir2 dir3 dir4 ... OBJS = $(wildcard $(DIRS:=/*.o)) GENERATE_OBJECT_FILES: @echo $(OBJS); 
+6
source

Source: https://habr.com/ru/post/1399875/


All Articles