[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Non-POSIX-ism in command script interpretation
From: |
Paul Smith |
Subject: |
Non-POSIX-ism in command script interpretation |
Date: |
Fri, 4 Oct 2002 16:05:34 -0400 |
The POSIX definition of make says this:
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>.
GNU make does not handle this correctly if it uses the "fast path" and
invokes fork/exec directly, unless you put the \<nl> inside single
quotes. It also doesn't handle the "slow path" properly, but I haven't
investigated that yet.
I believe that the above statement means that this makefile:
all: fast1 fast2
fast1: ; echo x\
x
fast2: ; echo x\
x
should produce this:
xx
xx
But in fact it produces this:
x x
x x
This is because of this area of the code in
job.c:construct_command_argv_internal():
case '\\':
/* Backslash-newline combinations are eaten. */
if (p[1] == '\n')
{
swallow_escaped_newline:
/* Eat the backslash, the newline, and following whitespace,
replacing it all with a single space. */
[...]
which then proceeds to do exactly as the comment says, except in the
case where we're inside a string--and the only time we find a \<nl>
inside a string in the fast path is inside single-quoted strings.
What do people think of modifying GNU make to confirm strictly to POSIX
here? It seems like the right thing to do, but there _could_ be
backward-compatibility concerns, especially in the case of the second
example (test2) where the <tab> is removed; that means that makefiles
that currently say:
foo: ; echo\
hi
will now fail with an "unknown command: echohi" error.
I'll investigate the slow path situation next.
Anyone else have any comments on this?
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> HASMAT: HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.
- Non-POSIX-ism in command script interpretation,
Paul Smith <=