Subject: bin/34967: make(1) let's variables in Makefile override the command line
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <rillig@NetBSD.org>
List: netbsd-bugs
Date: 11/02/2006 09:00:00
>Number:         34967
>Category:       bin
>Synopsis:       make(1) let's variables in Makefile override the command line
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 02 09:00:00 +0000 2006
>Originator:     Roland Illig
>Release:        3.0
>Organization:
>Environment:
>Description:
POSIX says:

"Macros defined in the makefile(s) shall not override macro definitions from source 1 or source 2."

NetBSD's make does not conform to this definition, but it should.

The non-conforming behavior only occurs in extensions to the standard, but I didn't expect this at all.

Roland

>How-To-Repeat:
#
# usage: make -f vars.mk all COMPILERS="from the command line"
#

#
# Get the variable's value at load time.
#

via_shell!=		echo ${COMPILERS:Q}
via_assignment:=	${COMPILERS}
via_for_loop:=		# empty
.for c in ${COMPILERS}
via_for_loop+=		${c}
.endfor

#
# Try to overwrite the variable.
#

COMPILERS=		from the Makefile

#
# Check the value of the variable.
#

via_shell_2!=		echo ${COMPILERS:Q}
via_assignment_2:=	${COMPILERS}
via_for_loop_2:=	# empty
.for c in ${COMPILERS}
via_for_loop_2+=	${c}
.endfor

#
# The truth comes out ...
#

all:
	@echo "before:"
	@echo "  via_shell: "${via_shell:Q}
	@echo "  via_assignment: "${via_assignment:Q}
	@echo "  via_for_loop: "${via_for_loop:Q}
	@echo ""
	@echo "after:"
	@echo "  via_shell: "${via_shell_2:Q}
	@echo "  via_assignment: "${via_assignment_2:Q}
	@echo "  via_for_loop: "${via_for_loop_2:Q}
	@echo ""
	@echo "direct use:"
	@echo "  "${COMPILERS:Q}

>Fix: