[Top][All Lists]

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

Re: wishlist item: namespaces for include

From: Paul Smith
Subject: Re: wishlist item: namespaces for include
Date: Thu, 13 Dec 2007 14:33:25 -0500

On Wed, 2007-12-12 at 17:19 -0900, Britton Kerin wrote:
> I would like to be able to tell make to automatically prefix all rules
> and variables that come from an include'ed makefile with a namespace
> prefix.  So maybe this syntax:
> namespace foo_ include module_foo/Makefile
> The Makefile in foo might have targets build, test, and install, and a
> variable INSTALL_PREFIX.  In the include'ing makefile, these would be
> available as foo_build, foo_test, foo_install, and foo_INSTALL_PREFIX,
> respectively.

I don't see how this can work.  I suspect you haven't really thought
this through completely--or else I'm really not understanding the
proposal :-).

Sure, some of the targets that a makefile includes are pseudo targets
like "build", etc., but MOST of them are actual files to be created:
main.o, run.o etc.  Make has absolutely no way to know which is which,
so any "namespace" feature that automatically modified all the targets
in the makefile would be magically renaming your targets to
"foo_main.o", "foo_run.o", etc.  That's odd enough, but even worse is
how would you have other makefiles refer to those targets in any
portable way?  They would need references to link in "main.o" for
example, but they would have to use "foo_main.o".

Variables have problems at least as bad: sure you can change the name of
the variable but then later you have to REFERENCE the variable... is
make supposed to modify all variables referenced to also contain the
prefix?  How can make know which variables are local to this scope and
which are supposed to refer to variables in some other scope?

I really don't see any way around actually declaring the scope that you
want.  Makefile syntax is far too free-form: make is basically a text
matching and manipulation engine.

There are ways you can do some kinds of scoping today with a simplified
syntax, using constructed variable names: something like:

   N = foo_
   include module_foo/Makefile

then in module_foo/Makefile wherever you wanted a "locally scoped"
variable or target you'd prefix it with $N.  Or something like that.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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