make(1): add more explanation for undefined variable expressions

This commit is contained in:
rillig 2020-09-04 20:28:15 +00:00
parent a1d05e1e9e
commit 26222804bc
2 changed files with 24 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: cond-func-empty.mk,v 1.3 2020/09/03 17:13:42 rillig Exp $ # $NetBSD: cond-func-empty.mk,v 1.4 2020/09/04 20:28:16 rillig Exp $
# #
# Tests for the empty() function in .if conditions, which tests a variable # Tests for the empty() function in .if conditions, which tests a variable
# expression for emptiness. # expression for emptiness.
@ -29,6 +29,9 @@ WORD= word
# after that the expression is no longer empty. Because the variable # after that the expression is no longer empty. Because the variable
# was undefined in the first place, the expression has the flag VAR_JUNK # was undefined in the first place, the expression has the flag VAR_JUNK
# but not VAR_KEEP, therefore it is still considered undefined. # but not VAR_KEEP, therefore it is still considered undefined.
# Only very few variable modifiers turn an undefined variable expression
# into a defined variable expression. The :U and :D modifiers belong to
# that group, but :S doesn't (see VAR_KEEP).
# #
# XXX: This is hard to explain to someone who doesn't know these # XXX: This is hard to explain to someone who doesn't know these
# implementation details. # implementation details.

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $ */ /* $NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/ */
#ifndef MAKE_NATIVE #ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $"; static char rcsid[] = "$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $";
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else #else
__RCSID("$NetBSD: var.c,v 1.486 2020/09/03 18:53:46 rillig Exp $"); __RCSID("$NetBSD: var.c,v 1.487 2020/09/04 20:28:15 rillig Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#endif #endif
@ -3523,17 +3523,24 @@ Var_Parse(const char * const str, GNode *ctxt, VarEvalFlags eflags,
Buf_Destroy(&namebuf, TRUE); Buf_Destroy(&namebuf, TRUE);
return (eflags & VARE_UNDEFERR) ? var_Error : varNoError; return (eflags & VARE_UNDEFERR) ? var_Error : varNoError;
} }
} else {
/*
* Still need to get to the end of the variable specification,
* so kludge up a Var structure for the modifications
*/
v = bmake_malloc(sizeof(Var));
v->name = varname;
Buf_Init(&v->val, 1);
v->flags = VAR_JUNK;
Buf_Destroy(&namebuf, FALSE);
} }
/* The variable expression is based on an undefined variable.
* Most modifiers leave this expression in the "undefined" state
* (VAR_JUNK), only some modifiers like :D, :U, :L, :P turn this
* undefined expression into a defined expression.
*
* At the end, after applying all modifiers, if the expression is
* still undefined after applying all the modifiers, var_Error is
* returned. Until then, the expression needs a variable struct,
* for all the modifiers that need access to the variable name,
* such as :L or :?.
*/
v = bmake_malloc(sizeof(Var));
v->name = varname;
Buf_Init(&v->val, 1);
v->flags = VAR_JUNK;
Buf_Destroy(&namebuf, FALSE);
} else } else
Buf_Destroy(&namebuf, TRUE); Buf_Destroy(&namebuf, TRUE);
} }