[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question Regarding Emile van Bergen's Non-Recursive Make
From: |
Mike Shal |
Subject: |
Re: Question Regarding Emile van Bergen's Non-Recursive Make |
Date: |
Mon, 1 Dec 2008 17:09:11 -0500 |
On 12/1/08, Davidson, Josh <address@hidden> wrote:
> Ok, I'm close to getting this working. I'm trying to find an
> alternative to doing:
>
> dir := moduleA
> include $(dir)/Rules.mk
> dir := moduleB
> include $(dir)/Rules.mk
> dir := moduleC
> include $(dir)/Rules.mk
> #etc
>
> Normally, I would do something like
> MODULES = moduleA moduleB moduleC #etc
> include $(addsuffix /Rules.mk, $(MODULES))
>
> However, I need to set dir before adding the include. Is there a trick
> to doing that?
You can try to pull the directory name from the MAKEFILE_LIST
variable, which will have the Makefiles included up to that point (I
think that was added in make 3.80, though). For example (using % as
the prompt):
% cat Makefile
# macro to pull out the last entry in a list
last = $(if $1,$(word $(words $1),$1))
# macro to find the most recent Rules.mk file
makefile = $(call last,$(filter %/Rules.mk,$(MAKEFILE_LIST)))
dir = $(patsubst %/Rules.mk,%,$(makefile))
MODULES = ant bee
include $(MODULES:%=%/Rules.mk)
% cat ant/Rules.mk
$(warning in ant, dir=$(dir))
% cat bee/Rules.mk
$(warning in bee, dir=$(dir))
MODULES = test
include $(MODULES:%=$(dir)/%/Rules.mk)
% cat bee/test/Rules.mk
$(warning in bee/test, dir=$(dir))
% make
ant/Rules.mk:1: in ant, dir=ant
bee/Rules.mk:1: in bee, dir=bee
bee/test/Rules.mk:1: in bee/test, dir=bee/test
make: *** No targets. Stop.
You could also try to derive the MODULES from doing a $(wildcard
$(dir)/*/Rules.mk) or something instead of setting it in each Rules.mk
file. I use a similar setup for the Makefiles in marfitude, and it
seems to work reasonably well. Most of the per-directory Makefile
stubs end up fairly empty.
Hope that helps,
-Mike