bug-make
[Top][All Lists]
Advanced

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

Re: make's apparent weird behaviour


From: Paul Smith
Subject: Re: make's apparent weird behaviour
Date: Thu, 16 Dec 2010 10:56:55 -0500

Hi Sergio; it would help us greatly if you'd choose an email client that
would preserve whitespace in your mail when you send it; stripping
leading whitespace from your messages makes it very difficult to
correctly parse your examples.  Thanks!

On Wed, 2010-12-15 at 10:22 +0100, Sergio Villone wrote:
> as requested,I report the offending maketile,
> the result and my comment directly here in
> the mail body:
> ------------makefile-------------
> .SILENT :;
> SHELL:="/bin/tcsh"

First, you should not use any csh derivative with make.  csh is a badly
broken (by design) shell and should be relegated to the dustbin of
history.  In particular, for the purposes of GNU make, csh/tcsh do
bizarre and inappropriate things with open file descriptors which means
that you cannot use GNU make's jobserver feature for parallel build
support if you use csh/tcsh as your SHELL.

> define heastuff
> echo "------heastuff----$(1)--------"
> #aa create necessary vars
> endef

> doheastuff:;
> echo "••••doheastuff_heanm:>$(heanm)<"
> $(foreach nm,$(heanm),$(call heastuff,$(nm)))

Second, this foreach loop will not do what you want in the case where
there is more than one value in the "heanm" variable, since the second
expansion of the $(call ...) will simply be added to the first after a
space.  Basically if your value of "heanm" was "foo bar" then this
foreach loop would be the same as writing:

        $(call heastuff,foo) $(call heastuff,bar)

which is obviously not going to work.  And, if you only ever expect
$(heanm) to have a single word as its value, then the foreach is
unnecessary in the first place.

> #aa: Command not found.

This is expected because the expansion of the define appears inside a
recipe context.  The GNU make manual discussion of the define/endef
feature says:

           When used in a recipe, the previous example is functionally
        equivalent to this:
        
             two-lines = echo foo; echo $(bar)
        
        since two commands separated by semicolon behave much like two
        separate shell commands.  However, note that using two separate
        lines means `make' will invoke the shell twice, running an
        independent subshell for each line.

In other words, if a variable created with define/endef appears in a
recipe, the entire expansion is part of the recipe.  That means that the
comment line will be passed to your shell, and if your shell treats it
like a comment then it will be a comment; if your shell does not, then
it won't be.

You're right that this means you cannot put make comments into
define/endef variable values.

-- 
-------------------------------------------------------------------------------
 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]