help-make
[Top][All Lists]
Advanced

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

Whitespace in variables


From: Leeuwesteijn,Joost
Subject: Whitespace in variables
Date: Wed, 3 May 2006 09:37:30 +0200

Hi *,

When I check my command/response files or print the make file variables when
debugging, I notice whitespace in places where I didn't expect it. See test
makefile below my sig.
The TEST2 variable also contains the whitespace up until the comment/#
character. Whitespace in front of the value does seem to be stripped, but
not the whitespace after the 
value. Being used to preprocessor like whitespace and comment handling this
was not what I expected. For example, I declare my cc/ld/asm flags like
this:

CCFLAGS += -foo           # enable file optimization operator

and this results in a final CCFLAGS value with a lot of whitespace when all
options are added. I could put the comment above each assignment but this is
more compact and easier to read.

Why does make (3.81) do this? I know I can use $(strip ) everywhere but that
unnecessarily clutters my makefiles. [RTFM+check list archive] I've just
checked the "Two flavors of variables" chapter :-) and it seems to be
intended behaviour but placing comment on the same line in general does not
seem to be a good idea. Is there a special reason to keep the whitespace
after a value? Stripping whitespace by default would make more sense to me
and then define variables like so, to intentionally keep whitespace.

FOO :=    BAR       $(eol)        # comment gone anyway
      ^^^^ stripped
             ^^^^^^^ kept
                          ^^^^^^^^ stripped

Regards,
Joost Leeuwesteijn

#############################################

# TEST1 -> space in front of value
# TEST2 -> spaces until comment
# TEST3 -> spaces in front of -and- after value

TEST1   := TEST1
TEST2   := TEST2                      # COMMENT
TEST3   :=     TEST3             
#                 ^^^^^^^^ spaces after TEST3 here

.PHONY : all
all:
        @echo TEST1='$(TEST1)'
        @echo TEST2='$(TEST2)'
        @echo TEST3='$(TEST3)'

-----

Output:
TEST1='TEST1'
TEST2='TEST2                      '
TEST3='TEST3             '




reply via email to

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