From julio@meroh.net  Thu Nov  7 20:10:33 2013
Return-Path: <julio@meroh.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 1FA5BFE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  7 Nov 2013 20:10:33 +0000 (UTC)
	(envelope-from julio@meroh.net)
Received: from cdptpa-oedge-vip.email.rr.com (cdptpa-outbound-snat.email.rr.com [107.14.166.225])
	by mx1.freebsd.org (Postfix) with ESMTP id D8B372A68
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  7 Nov 2013 20:10:32 +0000 (UTC)
Received: from [108.176.158.82] ([108.176.158.82:65474] helo=portal.meroh.net)
	by cdptpa-oedge03 (envelope-from <julio@meroh.net>)
	(ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTP
	id 3C/B3-19454-0B3FB725; Thu, 07 Nov 2013 20:10:24 +0000
Received: from mastodon.meroh.net (mastodon.meroh.net [192.168.1.12])
	by portal.meroh.net (Postfix) with ESMTP id AE18CEFE67
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  7 Nov 2013 15:10:22 -0500 (EST)
Received: from mastodon.meroh.net (localhost [127.0.0.1])
	by mastodon.meroh.net (8.14.7/8.14.7) with ESMTP id rA7K8DHc007335
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 7 Nov 2013 15:08:13 -0500 (EST)
	(envelope-from jmmv@mastodon.meroh.net)
Received: (from jmmv@localhost)
	by mastodon.meroh.net (8.14.7/8.14.7/Submit) id rA7K8DQj007334;
	Thu, 7 Nov 2013 15:08:13 -0500 (EST)
	(envelope-from jmmv)
Message-Id: <201311072008.rA7K8DQj007334@mastodon.meroh.net>
Date: Thu, 7 Nov 2013 15:08:13 -0500 (EST)
From: Julio Merino <julio@meroh.net>
Reply-To: Julio Merino <julio@meroh.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: make(1) .undef does not work with variables set to a value
X-Send-Pr-Version: 3.114
X-GNATS-Notify:

>Number:         183762
>Category:       bin
>Synopsis:       make(1) .undef does not work with variables set to a value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 07 20:20:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Julio Merino
>Release:        FreeBSD 11.0-CURRENT powerpc
>Organization:
>Environment:
System: FreeBSD mastodon.meroh.net 11.0-CURRENT FreeBSD 11.0-CURRENT #2 r257556M: Sat Nov 2 17:24:33 EDT 2013 jmmv@mastodon.meroh.net:/usr/obj/usr/src/sys/GENERIC64 powerpc


	
>Description:
	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.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
