On Tue, 2008-12-09 at 13:20 +0100, Sam Ravnborg wrote:
> Why not just use:
> 
> include $(call magic,someutil.mak)
> 
> Where magic is a macro that based on a variabes passed
> or something decide on the directory to try.
> 
> Something like this mockup for example:
> magic = $(if $(wildcard $(mydir)/$1),$(mydir)/$1, \
>             $(if $(wildcard $(anotherdir)/$1),$(anotherdir)/$1,NOTFOUND))

If you don't mind doing a few extra stat() calls you can make this much
cleaner and more generic.  For example, given a variable containing a
whitespace-separated list of directories to search:

        MKINCLUDES := /foo /bar /baz

You can use:

        include $(firstword $(wildcard $(addsuffix /someutil.mk,$(MKINCLUDES))))

Obviously you can hide this behind a call macro too if you prefer.


> p.s.  as a top-level solution, i can set up the alias
> 
>   alias mymake="make -I..."
> 
> and tell everyone to use "mymake" from now on, so that's how i could
> get my includes into that top-level makefile.  but it's the subsequent
> propagation through all submakes that is still an issue.

??? Why is this an issue?  Make always propagates all options like this
to sub-makes automatically.  This will work fine as long as you invoke
your sub-makes with the variable $(MAKE) rather than hardcoded "make".
Have you actually tried this?


> If you can change the top-level make, why not set a variable to the
> directory (absolute path) from which the makefiles shall be included:
> 
>   export MAKE_INCLUDE_DIR ?= /var/make/includes
> 
> and then use 
> 
>   vpath %.mak $(MAKE_INCLUDE_DIR)
> 
> in every sub-make (or in a generally used include-make)?
> 
> Or is this too simple?

It's too simple... because it doesn't work.  Make doesn't search for
included files using VPATH or vpath.  It never has, and nowhere is it
documented that it does.

However, there is an enhancement request that it should do so in the
Savannah project bug list.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[EMAIL PROTECTED]>          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


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to