help-make
[Top][All Lists]
Advanced

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

Re: the usage of strip


From: Peng Yu
Subject: Re: the usage of strip
Date: Thu, 8 Jul 2010 17:33:18 -0500

On Thu, Jul 8, 2010 at 5:10 PM, Paul Smith <address@hidden> wrote:
> 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.
>

OK. I get it. It is my fault to forget that the shell remove extra spaces.

However, I do think that the manual can be improved by removing stuff
that are not important for users to know and by only presenting users
things that they need to know. For example, the minimal test case for
the strip that I find is the following. This example is more
self-explanatory than the example in the manual, which uses
if-statement and an undefined variable $(needs_made).

As I mentioned previously, each part of the manual should be as much
as independent as it can be. I think that this is one improvement that
can be made on this aspect. If you do want to show the trick of the
current example, you can put it after my simpler example so that users
can first understand what 'strip' does before they learn the trick.

These are just my thoughts on how the manual can be improved.  Please
don't take it personally.


.PHONY: all

foo:=a b  c
bar:=$(strip $(foo))

all:
        echo "$(foo)"
        echo "$(bar)"

-- 
Regards,
Peng



reply via email to

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