Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 May 2004 09:55:57 -0700
From:      "Mark D. Baushke" <mdb@juniper.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        "Simon J. Gerraty" <sjg@crufty.net>
Subject:   standards/66357: make POSIX conformance problem ('sh -e' & '+' command-line flag)
Message-ID:  <11525.1083948957@juniper.net>
Resent-Message-ID: <200405071700.i47H0diV029426@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         66357
>Category:       standards
>Synopsis:       make POSIX conformance problem ('sh -e' & '+' command-line)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 07 10:00:38 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Mark Baushke
>Release:        FreeBSD 5.2-RELEASE i386
>Organization:
Juniper Networks, Inc.
>Environment:
System: FreeBSD rat52.juniper.net 5.2-RELEASE FreeBSD 5.2-RELEASE #0: Sun Jan 11 04:21:45 GMT 2004 root@wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC i386

>Description:
Background:

POSIX 1003.2-1997 states that each makefile command line is processed
as if given to system(3) (see URL
http://www.opengroup.org/onlinepubs/009695399/utilities/make.html)

POSIX 1003.1-2004 (as well as older versions of the standard) states
that system() does not use the "sh -e" command to exit immediately if
any untested command fails in non-interactive mode. (see URL
http://www.opengroup.org/onlinepubs/009695399/functions/system.html)

The FreeBSD /usr/bin/make program generates an error and does not
support the '+' command line flag properly.
(tested on FreeBSD 2.2.8-RELEASE, 3.3-RELEASE, 4.2-RELEASE,
4.10-PRERELEASE and 5.2-RELEASE versions)

My guess is that the .POSIX: directive in the test case would not have
much impact as the sys.mk file seems to be read before the first
Makefile is opened, but I have added that rule to underline that this
change is really only required in order to be POSIX compliant.

Should you wish to retain your existing behavior, that would be fine as
long as the behavior is modified as expected when the .POSIX: directive
is given.

I have consulted with Simon J. Gerraty who commits changes to the NetBSD
version of make as well as providing portable versions of bmake for
other platforms (see URL http://www.crufty.net/help/sjg/bmake.html). He
says he has committed a patch to the NetBSD -current version of the make
program.

Part of the e-mail exchange focused on this problem is found here:

http://mail-index.netbsd.org/tech-toolchain/2004/05/05/0008.html

After my .signature are the log message and URLs for the changes made to
the NetBSD.

>How-To-Repeat:
How to reproduce the problem:

The following Makefile

 --------------- start Makefile ---------------
.POSIX:
all: x plus sub err
x:
	@echo "Hello,"; false; echo "World"
plus:
	@echo a command
	+@echo "a command prefixed by '+' executes even with -n"
	@echo another command
subs:
	@echo make -n
	@${.MAKE} -f ${MAKEFILE} -n plus
	@echo make -n -j1
	@${.MAKE} -f ${MAKEFILE} -n -j1 plus

err:
	@(echo Now we expect an error...; exit 1)
	@echo "Oops! you shouldn't see this!"
	
 --------------- end Makefile ---------------

The
	make x

command should therefore generate two lines:

	Hello,
	World

with no error on a 'make' command that is POSIX-compliant. 

The
	make -n plus

command should print

	echo a command
	echo "a command prefixed by '+' executes even with -n"
	a command prefixed by '+' executes even with -n
	echo another command

to show that it is not executing the first and last echo command, but
is executing the middle one.

The
	make err

command should print 

	Now we expect an error...

and exit with an error code 1.

Running all of the tests may require adding a few command-line
arguments if the paricular version of make does not support setting
the .MAKE or MAKEFILE macros such as this:

	make .MAKE=/usr/bin/make MAKEFILE=Makefile

However, as those macros are not required by the POSIX standard, you
don't need to worry if they are not being set by default.

 --------------- begin test results for FreeBSD 5.2-RELEASE ---------------
% /usr/bin/make
Hello,
*** Error code 1

Stop in /tmp/mdb.foo.
% /usr/bin/make plus
% /usr/bin/make plus
a command
+@echo "a command prefixed by '+' executes even with -n"
+@echo:No such file or directory
*** Error code 1

Stop in /tmp/mdb.foo.
% /usr/bin/make -n plus
echo a command
+@echo "a command prefixed by '+' executes even with -n"
echo another command
% /usr/bin/make -n .MAKE=/usr/bin/make subs
echo make -n
/usr/bin/make -f Makefile -n plus
echo make -n -j1
/usr/bin/make -f Makefile -n -j1 plus
% /usr/bin/make .MAKE=/usr/bin/make -n subs
echo make -n
/usr/bin/make -f Makefile -n plus
echo make -n -j1
/usr/bin/make -f Makefile -n -j1 plus
% /usr/bin/make err 
Now we expect an error...
*** Error code 1

Stop in /tmp/mdb.foo.
% /usr/bin/make -n err
(echo Now we expect an error...; exit 1)
echo "Oops! you shouldn't see this!"
% pwd
/tmp/mdb.foo
%
 --------------- end test reults for FreeBSD 5.2-RELEASE ---------------

>Fix:
Committed to the NetBSD cvs repository on Fri May 7 08:12:15 2004 UTC by sjg

Log message:

Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc

http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/compat.c.diff?r1=1.53&r2=1.54

http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/nonints.h.diff?r1=1.31&r2=1.32
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/job.c.diff?r1=1.84&r2=1.85
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/unit-tests/Makefile.diff?r1=1.12&r2=1.13
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/unit-tests/test.exp.diff?r1=1.11&r2=1.12
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/make/unit-tests/posix
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?11525.1083948957>