help-make
[Top][All Lists]
Advanced

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

RE: backslash does not simply continue line?


From: Paul Smith
Subject: RE: backslash does not simply continue line?
Date: Tue, 6 Mar 2012 15:44:54 -0500

On Tue, 2012-03-06 at 13:34 -0500, Brian R Cowan wrote:
> In many cases this construct is necessary to make a makefile readable.
> I've seen too many makefiles where there are 200+ files in a macro
> like that. Putting a macro liek that on a single line would break a
> number of editors. 

I don't think anyone is suggesting that backslash/newline is not an
important feature.

The question is how does it behave.  In most instances of
backslash/newline the backslash and newline are removed and the previous
and next line are concatenated directly.  So this:

foo = FOO\
BAR

assigns the value "FOOBAR" to the variable foo.

In make, though, as per POSIX, that's not how it works.  Instead, the
backslash/newline (plus all initial whitespace after the newline) is
replaced by a single space.  So, the above statement assigns "FOO BAR"
to the variable foo.

Similarly:

foo = FOO\
          BAR

also resolves to "FOO BAR".

The sucky thing about this behavior is that it's simple to add a space
when you want one, but it's very hard to REMOVE one that's added for you
automatically.  But, it is what it is and can't be changed now.  Another
example of how a decision made in haste during some late-night hacking
session 30 years ago which seemed like a good idea, has repercussions
far beyond what could be envisioned.


PS. GNU make actually does something even more than what POSIX requires:
it combines all whitespace PRECEDING the backslash, the
backslash/newline, and all whitespace after the newline, AND any
immediately subsequent sets of whitespace and backslash/newline pairs,
into a single space.

Starting in the next release of GNU make if you set the .POSIX special
target you'll get the POSIX behavior for whitespace.




reply via email to

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