foreach function

hi,

I have 2 directories (../src/dir_a and ../src/dir_b) each with its own .cpp files.

I have written the following foreach function, but the problem is it is reading the .cpp files from both directories, dir_a and dir_b, to create libdir.a. Is there a way I can rewrite dirs (without hard-coding the directory names) so I can create 2 separate libraries for source files from each directory.

1
2
3
4
5
6
7
8
9
10
dirs := $(shell echo ../src/*)
find_files = $(wildcard $(dir)/*.cpp)
cppsources :=$(foreach dir, $(dirs),$(find_files)) 
cppobjects :=$(cppsources:.cpp=.o)
cppobjects:	$(cppsources)
	echo "this is the objects line"

libdir.a: cppobjects
	ar rcs $@ $(cppobjects)
	ranlib $@ */

thanks!
Last edited on
it sounds like you need to bifurcate your libdir.a target into libdir_a.a and libdir_b.a

and update your dependencies accordingly (including the source directory wildcards to put to dir_a and dir_b)
thx for your response kfmfe04.
so, basically, if I have 5 directories and want to create individual libraries, I'll have to hard code the libdir.a into 5 different libdir.a targets, right...
if you have that many, then maybe you'd want to change Line 1 to include all those directories - perhaps something like:

dirs := $(shell echo ../src/*/*)

if your code is in src/libdir_a/*, src/libdir_b/*, etc... and no other weird things live under src

if you do it this way, however, you will only have one target libdir.a
Last edited on
gotcha....thanks!
Topic archived. No new replies allowed.