help-make
[Top][All Lists]
Advanced

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

Re: the usage of strip


From: Paul Smith
Subject: Re: the usage of strip
Date: Thu, 8 Jul 2010 18:10:49 -0400

On Thu, 2010-07-08 at 16:49 -0500, Peng Yu wrote:
> I don't get the what strip is for. In particular how "Replacing the
> variable reference `$(needs_made)'  with the function call `$(strip
> $(needs_made))'  in the ifneq directive would make it more robust"
> (from the manual). I tries to add two consecutive spaces in a
> variable. But I failed. Could somebody show me an example to
> demonstrate the effect of strip?
> 
> $ make
> a b c
> a b c
> $ cat Makefile
> .PHONY: all
> 
> empty:=
> space:=$(empty) $(empty)
> twospaces:=$(empty) $(empty) $(empty)
> foo:=a$(space)b$(twospaces)c
> bar:=$(strip a$(space)b$(space)$(space)c)
> 
> all:
>       @echo $(foo)
>       @echo $(bar)

The reason you're not seeing any difference is because you're passing
these values to the shell, and the shell is reducing the whitespace
before printing them.  Try running from the command line, rather than
make, and you'll see:

        $ echo a b  c
        a b c
        $ echo a b c
        a b c

You need to be viewing the command passed to the shell (remove the "@"
before the echo) or else quote the value so the shell doesn't mess with
it: @echo '$(foo)'

Or, you could test the point actually made in the manual by using ifneq
or similar, rather than an echo command, and prove to yourself that
these two strings are not identical when compared by make.

So, the problem is your test is invalid.

I believe I've mentioned before, you should AVOID using "@" when
creating and testing makefiles.  By looking at the output the shell
gives, rather than looking the commands that make passes to the shell,
you often are misled into thinking that something is a make problem when
it's really a behavior of the shell that you're not understanding.




reply via email to

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