[Top][All Lists]

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

Re: Bug with comment parsing and variable expansion

From: Paul Smith
Subject: Re: Bug with comment parsing and variable expansion
Date: Tue, 09 Nov 2010 10:24:11 -0500

On Tue, 2010-11-09 at 15:47 +0100, Rafaël Carré wrote:
> Hello,
> I believe I've found a bug in make 3.81, or at least some confusing
> behaviour.
> Here is a comparison of GNU make and netbsd 'pmake'
> A-$(X) isn't expanded to "A-1" because of the comment on the line where
> X is set, although X is set to "1"

X is not set to "1".  It's set to "1 " (note trailing space).  This is
documented and required by the POSIX standard: trailing whitespace on a
variable assignment is preserved.

> % cat Makefile 
> X = 1 #comment
> Y = 1
> A-$(X) = a
> B-$(Y) = b
> all:
>       @echo $(X) $(A-1)
>       @echo $(Y) $(B-1)

It's a hugely bad idea to use simple "echo" when trying to see values,
because the shell will eat whitespace differences.  You should quote the
values and add characters before and after, like this:

        @echo '|$(X)|   |$(A-1)|'
        @echo '|$(Y)|   |$(B-1)|'

then you will immediately see the difference.

 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]