help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question Regarding Emile van Bergen's Non-Recursive Make


From: Garrett Cooper
Subject: Re: Question Regarding Emile van Bergen's Non-Recursive Make
Date: Mon, 1 Dec 2008 18:43:37 -0800

On Mon, Dec 1, 2008 at 2:09 PM, Mike Shal <address@hidden> wrote:
> 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

You'll need to probably put the dereferencing items in define blocks
to avoid dereferencing variables too early.

Word to the wise -- don't use this methodology because it's confusing
as shit to follow once the make system gets sufficiently large. My
group at Cisco is currently trying to scrap this type of poorly
executed methodology we inherited from another group in favor of flat
makefiles, which is much easier to follow.

Then again the whole damn make system we got sucks.

-Garrett




reply via email to

[Prev in Thread] Current Thread [Next in Thread]