Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't figure out how to use SUBDIRS_TGTS for more than one level of subdirectories. #22

Closed
torpesco opened this issue Dec 10, 2014 · 4 comments

Comments

@torpesco
Copy link

Say I have:

  • a/
    • b1/
      • some c files
    • b2/
      • some c files
      • c1/
        • some c files
      • c2/
        • some c files
    • b3/
      • some c files

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)
@aostruszka
Copy link
Owner

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

@torpesco
Copy link
Author

Hmm. Yes, using $(call subtree_tgts,$(d)/b2) from a/Rules.mk seems to work. However, that seems even less intuitive to me, so I think I'll stick with what I got. My goal is to keep the Rules.mk files as clean-looking and hopefully as easy to understand as possible.

Thanks,
James

@aostruszka
Copy link
Owner

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 :).

@torpesco
Copy link
Author

torpesco commented Apr 7, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants