Bug 183762

Summary: make(1) .undef does not work with variables set to a value
Product: Base System Reporter: Julio Merino <julio>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me    
Priority: Normal    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Julio Merino 2013-11-07 20:20:00 UTC
	The .undef directive of make(1) does not seem to work on a
	variable that has been defined to a value (even if empty) either
	via the environment or a command-line argument to make.  However
	.undef works on variables that have been defined using make's
	-D flag and variables defined in the same Makefile.

	I have found this while debugging build issues in bsd.own.mk.
	Makefile.inc1 has to pass -DNO_* to make in order to explicitly
	disable some features during the build bootstrap.  However, if
	the user explicitly sets WITH_* from the command line (without
	using -D), the build fails because it finds both WITH_* and
	WITHOUT_* defined.

	I believe .undef is buggy and hence the reason for this PR.  And
	if it is not a bug, make(1) probably deserves some note about
	this as well as the build documentation (maybe in src.conf(5))
	to warn about this.

How-To-Repeat: 	Sample Makefile:

-----
.if defined(DEFINE_VAR_IN_MAKEFILE)
VAR=foo
.endif

.undef VAR

all:
.if defined(VAR)
	@echo defined
.else
	@echo undefined
.endif
-----

	And sample invocations:

-----
$ make
undefined
$ make -DVAR
undefined
$ make -DDEFINE_VAR_IN_MAKEFILE
undefined
$ make VAR=
defined
$ VAR= make
defined
-----

	The last two cases shown above are unexpected behavior to me.
	I would expect the ".undef VAR" to take effect at all times.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:38 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped