Search code examples
cmakefileposix

Are escaped newlines part of POSIX make?


The POSIX make standard page has this to say about escaped newlines (emphasis mine):

The treatment of escaped s throughout the makefile is historical practice. For example, the inference rule:

.c.o\
:

works, and the macro:

f=  bar baz\
   biz
a:
   echo ==$f==

echoes "==bar baz biz==".

What does "historical practice" mean?

Can I use escaped newlines in a strictly conforming POSIX makefile or not?


Solution

  • The POSIX standard says this about escaped newlines (this is in the actual standard text not in the informative sections or rational):

    When an escaped <newline> (one preceded by a <backslash>) is found anywhere in the makefile except in a command line, an include line, or a line immediately preceding an include line, it shall be replaced, along with any leading white space on the following line, with a single <space>. When an escaped <newline> is found in a command line in a makefile, the command line shall contain the <backslash>, the <newline>, and the next line, except that the first character of the next line shall not be included if it is a <tab>. When an escaped <newline> is found in an include line or in a line immediately preceding an include line, the behavior is unspecified.

    That is the POSIX mandated behavior you an rely on with respect to escaped newlines.