help-make
[Top][All Lists]
Advanced

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

Re: Ignoring the whitespaces


From: Paul Smith
Subject: Re: Ignoring the whitespaces
Date: Wed, 07 Jun 2023 09:21:54 -0400
User-agent: Evolution 3.48.2 (by Flathub.org)

On Wed, 2023-06-07 at 12:23 +0200, Bartłomiej Wójcik wrote:
> The GNU make documentation states:
> 
> *define myrule
> target:
>         echo built
> endef
> 
> $(myrule)
> *

To be clear, the documentation says that the above will NOT work (as
you intend).

> *The above makefile results in the definition of a target ‘target’
> with prerequisites ‘echo’ and ‘built’, as if the makefile contained
> target: echo built, rather than a rule with a recipe. Newlines still
> present in a line after expansion is complete are ignored as normal
> whitespace.*
> 
> Why in that macro the whitespaces between *target:* and *echo built*
> are ignored?

They are not ignored in the macro.  The macro contains the text:

  target:
          echo built

including the newlines and TAB etc.

They are ignored when the macro is expanded, then parsed as a rule.

That's because make's parser is fundamentally line-oriented, and
breaking up of lines happens BEFORE expansion.  That means that AFTER
expansion, all whitespace including newlines is just treated like
normal whitespace: newlines no longer have their special significance
that they do during parsing and that entire output is considered just a
single logical line.

You can imagine it like make is adding backslashes to the end of every
line in the expanded output; that's not what actually happens but you
can think of it like that.  So after expansion of the above, make sees:

  target: \
          echo built

>  What is this property and what exactly does it refer to?
> Where is it stated in the documentation?

I mean, it's stated right there in the text you quoted so I'm not sure
what you  mean.



reply via email to

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