Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001549 [1003.1(2016/18)/Issue7+TC2] Shell and Utilities Editorial Clarification Requested 2022-01-13 16:18 2022-01-14 20:31
Reporter dmitry_goncharov View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Dmitry Goncharov
Organization
User Reference
Section Makefile Syntax
Page Number 2973
Line Number 98627
Interp Status ---
Final Accepted Text
Summary 0001549: Escaped newline in macro expansion in command line.
Description Section "Makefile Syntax" says

"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..."

Consider the following example

.POSIX:
M=word
N=${M:word=a\
b}
all:; echo ${N} ${M:word=a\
b}

Does posix require that in this example N and M expand to different values?

i tested gmake, bmake, sun make and aix make.
gmake and bmake both replace the newline with a space and pass 'a b a
b' to the shell.
sun make fails to find the closing brace and exits with an error message.
aix make removes the newline and passes 'a b ab' to the shell.

in the following example
all:; echo 'a\
b'
gmake and sun make both pass 'a\
b' to the shell.
bmake passes 'a b' to the shell.
aix make passes 'ab' to the shell.

i think gnu make's behavior is correct. Otherwise, variable expansion
becomes context dependent and who needs that complication?
Gnu make manual is quite explicit
5.1.2 says
"Variable and function references in recipes have identical syntax and
semantics to references elsewhere in the makefile."
Desired Action Modify the text quoted above like this

"After all macro expansion is complete, 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>".
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0005604)
geoffclare (manager)
2022-01-14 09:47

This is not a problem with the HTML translation, so I have moved it to the Issue7+TC2 project.
(0005605)
geoffclare (manager)
2022-01-14 09:53

The proposed change would leave it implicitly unspecified what happens to <backslash><newline> in a macro expansion in a command line, such as for the second expansion in the example command line given:

all:; echo ${N} ${M:word=a\
b}

Not sure if that's intentional. If it is (which would allow the Solaris behaviour), it would be better to make it explicit.
(0005606)
psmith (developer)
2022-01-14 14:14

I don't think it's intended to be left unspecified. I think the intent is that all macros are expanded using macro expansion rules (which do define how a backslash-newline pair should be handled), then any remaining backslash-newlines are handled as described for command lines (which, unfortunately, is different).
(0005609)
dmitry_goncharov (reporter)
2022-01-14 20:31

i believe everybody benefits if posix specifies explicitly that the required processing of an escaped newline in a recipe takes place after macro expansion. i'd like to stress again that the main benefit is that, this allows context independ macro expansion.

i thought the proposed change was explicit enough. But apparently it is not. If you can propose a better wording, that will be good.

i suspect, that sun make's behavior is not intentional, but rather a bug. Sun make handles various other cases like the following as required by posix.

.POSIX:
M=word
N=${M:word=a\
b}
K=a\
b

all: ; echo ${N} ${K}

all: ; echo 'a\
b'

all: ; echo 'a\
        b'

all: ; echo 'a\
 b'

- Issue History
Date Modified Username Field Change
2022-01-13 16:18 dmitry_goncharov New Issue
2022-01-13 16:18 dmitry_goncharov Name => Dmitry Goncharov
2022-01-13 16:18 dmitry_goncharov URL => https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html [^]
2022-01-13 16:18 dmitry_goncharov Section => Makefile Syntax
2022-01-14 09:46 geoffclare Project Online Pubs => 1003.1(2016/18)/Issue7+TC2
2022-01-14 09:47 geoffclare Page Number => 2973
2022-01-14 09:47 geoffclare Line Number => 98627
2022-01-14 09:47 geoffclare Interp Status => ---
2022-01-14 09:47 geoffclare Note Added: 0005604
2022-01-14 09:53 geoffclare Note Added: 0005605
2022-01-14 14:14 psmith Note Added: 0005606
2022-01-14 20:31 dmitry_goncharov Note Added: 0005609


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker