[Top][All Lists]

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

Re: Suggestion/Offer: new rinclude directive

From: Kamil Mierzejewski
Subject: Re: Suggestion/Offer: new rinclude directive
Date: Fri, 11 Feb 2011 09:42:39 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv: Gecko/20110207 Lightning/1.0b2 Thunderbird/3.1.8


Some time ago I came up with the same idea.
I have already implemented this functionality in GNU make, but then my involvement in the build team had to be stopped, so I couldn't find more time to test the implementation carefully nor to create a good quality patch.

I called it "import", but it works like your "rinclude". I have not implemented passing variable definitions back to the main file, but it shouldn't be difficult to add.

I can provide you with my modified GNU make sources if you'd like to take a 


W dniu 2011-02-09 19:11, Luke Shumaker pisze:
I had an idea for a feature that I believe will allow more elegant
multi-directory Makefiles to be written.

An alternate include directive, rinclude' (for relative include) that
treats all targets described in the included makefile as relative to the
included path.

[ Note: in this email, code samples are bracketed in<<<...>>>  ]

So in my main Makefile, I can have
foo.out: foo/bar

Where bar foo/bar does not exist, and is not described in the Makefile.
However, I
rinclude foo/Makefile

which does describe bar, but without the `foo/'.  However, since I used
rinclude, all the targets (and dependencies) have `foo/' prefixed to

Of course, there are other considerations, such as if the
target/dependency is an absolute filename.

Currently, this can be emulated two ways, by using recursive make:
rinclude = $1/%:$1/Makefile; $(MAKE) -C '$1' '$*'

and is used:
$(call rinclude,mysubdir)

Using this method, issues can arise with parallelization.  The
alternative is by using include, and prefixing all targets/dependencies
with a variable that stores the current directory:

THISDIR=$(patsubst %/,%,$(dir $(THISFILE)))
rinclude=$(foreach THISFILE,$(abspath $1),\
$(eval include $(THISFILE)))

and is used:
$(call rinclude,mysubdir)

Which creates precisely the desired behavior, but requires you to muck
up your Makefiles by prefixing everything with `$(THISDIR)/'.

Further, it might be desirable to have to two implementations, one where
variables in the included file get passed back to the main file,
following normal include behavior; and one where they are ignored, as
the recursive option above does.  The benefit of separating them is that
it would allow a component that was not designed with this feature in
mind to be incorporated into a larger system without modification.

If you think this feature would be a good addition to GNU Make, I would
be willing to implement it.

reply via email to

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