Can't figure out how to use SUBDIRS_TGTS for more than one level of subdirectories.
torpesco opened this issue · comments
Say I have:
- a/
- b1/
- some c files
- b2/
- some c files
- c1/
- some c files
- c2/
- some c files
- b3/
- some c files
- b1/
a/Rules.mk:
SUBDIRS = b1 b2 b3
LIB_A := $(OBJPATH)/liba.o
$(LIB_A)_DEPS = $(SUBDIRS_TGTS)
TARGETS := $(LIB_A)
a/b1/Rules.mk, a/b3/Rules.mk, a/b2/c1/Rules.mk, a/b2/c2/Rules.mk:
SRCS := *.c
a/b2/Rules.mk:
SUBDIRS = c1 c2
SRCS := *.c
TARGETS = b2.o
b2.o_DEPS = $(OBJS_$(d)) $(SUBDIRS_TGTS)
Is there some way to rewrite a/b2/Rules.mk to not need the intermediate target? Maybe something like:
SUBDIRS = c1 c2
SRCS := *.c
TARGETS = $(OBJS_$(d)) $(SUBDIRS_TGTS)
Could you take a look at Rules.mk of example 2 in repository?
I think this answers your problem - just take a look at directory structure of this example and what it's Rules.mk is trying to achieve.
Best regards
Andrzej
Hmm. Yes, using
Thanks,
James
I'm not sure I fully understand your need. My guess that in 'a' you want to have a library with all object files from 'a' and all its subdirectories (recursively) - then in a/Rules.mk I would simply put (I'm guessing that .o extension in your example is not intentional and you wanted to collect all objects into archive):
SUBDIRS = b1 b2 b3
# Just in case there are *.c in 'a'
SRCS := *.c
LIB_A := $(OBJPATH)/liba.a
$(LIB_A)_DEPS = $(call get_subtree,OBJS,$(d))
TARGETS := $(LIB_A)
Then all Rules.mk under 'a' could be simple SRCS = *.c
with additional SUBDIRS
in case of a/b2/Rules.mk. I would say that this is even more readable since you can nearly read _DEPS line in English but they say that "beauty is in the eye of beholder" so you may very well disagree :).
Finally catching up on this after a gap of a few months. :-\
Regarding the library vs. object thing... This is an old codebase, and I'm trying to drop in nonrec-make as transparently as possible. Yes, it actually is liba.o
. In this case, the files in each subdirectory were built into b1.o, b2.o (containing c1.o and c2.o) and b3.o, and the b*.o files were combined into liba.o. Out of those, my structure got rid of all but b2.o.
The $(LIB_A)_DEPS = $(call get_subtree,OBJS,$(d))
works nicely, and I think I've convinced myself the extra perceived complexity is fine (calling get_subtree once rather than the three times I thought I'd have to), so I've switched to that for now. I agree with you about it being more readable... I'm just trying to think about what problems I'll encounter when people without a good understanding of Make have to add or modify a Rules.mk file.
Thanks.