help-make
[Top][All Lists]
Advanced

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

Re: exporting functions?


From: Paul Smith
Subject: Re: exporting functions?
Date: Sun, 07 Nov 2010 11:43:47 -0500

On Thu, 2010-11-04 at 18:04 +0100, Erik Rull wrote:
> In the base file there is the following part:
> 
> assert_target_dir=$(assert_target_dir_cmd)
> define assert_target_dir_cmd
>       mkdir -p /home/user/target$(1)
> 
> endef
> export assert_target_dir assert_target_dir_cmd
> 
> install:
>       $(call assert_target_dir,/sbin)
>       + make -f Makefile.install

You should always use the variable $(MAKE), never the value 'make', when
invoking sub-makes.

> 
> in Makefile.install:
> 
> .PHONY: all
> all:
>       $(call assert_target_dir,/etc)
>       [...]
> 
> What happens when I call make install:
> 
> mkdir -p /home/user/target/sbin
> make -f Makefile.install
> mkdir -p /home/user/target
>                            ^^ here is /etc missing!
> 
> so basically the funtion gets "exported" but it seems to be not possible to 
> give a parameter with the $(call ...)

Variable values are expanded before being placed into the environment
due to "export".  That's why you see the behavior you do.

> What's wrong here? Am I doing something wrong? or is it not possible to 
> define and export functions in such way?

export is not a good way to communicate between parent and child makes,
except for simple settings of static strings.  What gets expanded when
it tricky to control.  The best way to do this is by having a standard
makefile that sets these values, then including it in all your other
makefiles.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "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]