Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Loop in GNU Makefile -- Gather all Object Files into one Variable Across Mutliple Directories

The general idea of what I am trying to be accomplished can hopefully be summed up by this small 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 accomplish this with a script within a Makefile?

like image 420
Matthew Hoggan Avatar asked Dec 21 '22 01:12

Matthew Hoggan


1 Answers

I'd do it this way:

DIRS = dir1 dir2 dir3 dir4 ...
OBJS = $(wildcard $(DIRS:=/*.o))

GENERATE_OBJECT_FILES:
    @echo $(OBJS);                                                          
like image 127
Beta Avatar answered Mar 05 '23 16:03

Beta