Module Name: src
Committed By: rillig
Date: Sun Jun 2 15:31:26 UTC 2024
Modified Files:
src/usr.bin/make: arch.c compat.c cond.c for.c job.c main.c make.c
make.h meta.c parse.c suff.c var.c
src/usr.bin/make/unit-tests: cond-func-empty.mk dep-var.exp dep-var.mk
parse-var.mk recursive.mk var-eval-short.exp varmod-ifelse.mk
varmod-loop.mk varparse-errors.mk
Log Message:
make: sync VarEvalMode constant names with their debug log names
To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/make/arch.c
cvs rdiff -u -r1.257 -r1.258 src/usr.bin/make/compat.c
cvs rdiff -u -r1.364 -r1.365 src/usr.bin/make/cond.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/for.c
cvs rdiff -u -r1.474 -r1.475 src/usr.bin/make/job.c
cvs rdiff -u -r1.623 -r1.624 src/usr.bin/make/main.c
cvs rdiff -u -r1.263 -r1.264 src/usr.bin/make/make.c
cvs rdiff -u -r1.337 -r1.338 src/usr.bin/make/make.h
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/make/meta.c
cvs rdiff -u -r1.729 -r1.730 src/usr.bin/make/parse.c
cvs rdiff -u -r1.379 -r1.380 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1118 -r1.1119 src/usr.bin/make/var.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/cond-func-empty.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/dep-var.exp
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/dep-var.mk
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/parse-var.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/recursive.mk
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/var-eval-short.exp \
src/usr.bin/make/unit-tests/varmod-loop.mk
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varparse-errors.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.218 src/usr.bin/make/arch.c:1.219
--- src/usr.bin/make/arch.c:1.218 Fri May 31 05:50:11 2024
+++ src/usr.bin/make/arch.c Sun Jun 2 15:31:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.219 2024/06/02 15:31:25 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.219 2024/06/02 15:31:25 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
@@ -209,7 +209,8 @@ Arch_ParseArchive(char **pp, GNodeList *
bool isError;
/* XXX: is expanded twice: once here and once below */
- result = Var_Parse(&nested_p, scope, VARE_UNDEFERR);
+ result = Var_Parse(&nested_p, scope,
+ VARE_EVAL_DEFINED);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
@@ -224,7 +225,7 @@ Arch_ParseArchive(char **pp, GNodeList *
spec[cp++ - spec] = '\0';
if (expandLib)
- Var_Expand(&lib, scope, VARE_UNDEFERR);
+ Var_Expand(&lib, scope, VARE_EVAL_DEFINED);
for (;;) {
/*
@@ -248,7 +249,7 @@ Arch_ParseArchive(char **pp, GNodeList *
const char *nested_p = cp;
result = Var_Parse(&nested_p, scope,
- VARE_UNDEFERR);
+ VARE_EVAL_DEFINED);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
@@ -293,7 +294,7 @@ Arch_ParseArchive(char **pp, GNodeList *
char *p;
const char *unexpandedMem = mem.str;
- Var_Expand(&mem, scope, VARE_UNDEFERR);
+ Var_Expand(&mem, scope, VARE_EVAL_DEFINED);
/*
* Now form an archive spec and recurse to deal with
Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.257 src/usr.bin/make/compat.c:1.258
--- src/usr.bin/make/compat.c:1.257 Sat May 25 21:07:48 2024
+++ src/usr.bin/make/compat.c Sun Jun 2 15:31:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.257 2024/05/25 21:07:48 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.258 2024/06/02 15:31:25 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.257 2024/05/25 21:07:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.258 2024/06/02 15:31:25 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@@ -252,7 +252,7 @@ Compat_RunCommand(const char *cmdp, GNod
doIt = false;
EvalStack_Push(gn->name, NULL, NULL);
- cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
+ cmdStart = Var_Subst(cmd, gn, VARE_EVAL);
EvalStack_Pop();
/* TODO: handle errors */
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.364 src/usr.bin/make/cond.c:1.365
--- src/usr.bin/make/cond.c:1.364 Sat May 25 00:00:25 2024
+++ src/usr.bin/make/cond.c Sun Jun 2 15:31:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.364 2024/05/25 00:00:25 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.365 2024/06/02 15:31:25 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.364 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.365 2024/06/02 15:31:25 rillig Exp $");
/*
* Conditional expressions conform to this grammar:
@@ -222,8 +222,8 @@ ParseWord(const char **pp, bool doEval)
break;
if (ch == '$') {
VarEvalMode emode = doEval
- ? VARE_UNDEFERR
- : VARE_PARSE_ONLY;
+ ? VARE_EVAL_DEFINED
+ : VARE_PARSE;
/*
* TODO: make Var_Parse complain about undefined
* variables.
@@ -396,9 +396,9 @@ CondParser_StringExpr(CondParser *par, c
const char *p;
bool atStart; /* true means an expression outside quotes */
- emode = doEval && quoted ? VARE_WANTRES
- : doEval ? VARE_UNDEFERR
- : VARE_PARSE_ONLY;
+ emode = doEval && quoted ? VARE_EVAL
+ : doEval ? VARE_EVAL_DEFINED
+ : VARE_PARSE;
p = par->p;
atStart = p == start;
@@ -651,8 +651,7 @@ CondParser_FuncCallEmpty(CondParser *par
return false;
p--; /* Make p[1] point to the '('. */
- val = Var_Parse(&p, SCOPE_CMDLINE,
- doEval ? VARE_WANTRES : VARE_PARSE_ONLY);
+ val = Var_Parse(&p, SCOPE_CMDLINE, doEval ? VARE_EVAL : VARE_PARSE);
/* TODO: handle errors */
if (val.str == var_Error)
Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.180 src/usr.bin/make/for.c:1.181
--- src/usr.bin/make/for.c:1.180 Sat May 25 00:00:25 2024
+++ src/usr.bin/make/for.c Sun Jun 2 15:31:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.180 2024/05/25 00:00:25 rillig Exp $ */
+/* $NetBSD: for.c,v 1.181 2024/06/02 15:31:25 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.180 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.181 2024/06/02 15:31:25 rillig Exp $");
typedef struct ForLoop {
@@ -197,7 +197,7 @@ ForLoop_ParseItems(ForLoop *f, const cha
cpp_skip_whitespace(&p);
- items = Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES);
+ items = Var_Subst(p, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
f->items = Substring_Words(items, false);
Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.474 src/usr.bin/make/job.c:1.475
--- src/usr.bin/make/job.c:1.474 Sat May 25 21:34:38 2024
+++ src/usr.bin/make/job.c Sun Jun 2 15:31:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.474 2024/05/25 21:34:38 rillig Exp $ */
+/* $NetBSD: job.c,v 1.475 2024/06/02 15:31:25 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -141,7 +141,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.474 2024/05/25 21:34:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.475 2024/06/02 15:31:25 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -902,7 +902,7 @@ JobWriteCommand(Job *job, ShellWriter *w
run = GNode_ShouldExecute(job->node);
EvalStack_Push(job->node->name, NULL, NULL);
- xcmd = Var_Subst(ucmd, job->node, VARE_WANTRES);
+ xcmd = Var_Subst(ucmd, job->node, VARE_EVAL);
EvalStack_Pop();
/* TODO: handle errors */
xcmdStart = xcmd;
@@ -1031,7 +1031,7 @@ JobSaveCommands(Job *job)
* expand the other variables as well; see deptgt-end.mk.
*/
EvalStack_Push(job->node->name, NULL, NULL);
- expanded_cmd = Var_Subst(cmd, job->node, VARE_WANTRES);
+ expanded_cmd = Var_Subst(cmd, job->node, VARE_EVAL);
EvalStack_Pop();
/* TODO: handle errors */
Lst_Append(&Targ_GetEndNode()->commands, expanded_cmd);
@@ -1070,7 +1070,7 @@ DebugFailedJob(const Job *job)
debug_printf("\t%s\n", cmd);
if (strchr(cmd, '$') != NULL) {
- char *xcmd = Var_Subst(cmd, job->node, VARE_WANTRES);
+ char *xcmd = Var_Subst(cmd, job->node, VARE_EVAL);
debug_printf("\t=> %s\n", xcmd);
free(xcmd);
}
@@ -2195,7 +2195,7 @@ Job_SetPrefix(void)
Global_Set(".MAKE.JOB.PREFIX", "---");
targPrefix = Var_Subst("${.MAKE.JOB.PREFIX}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
}
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.623 src/usr.bin/make/main.c:1.624
--- src/usr.bin/make/main.c:1.623 Sat Jun 1 20:19:41 2024
+++ src/usr.bin/make/main.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.623 2024/06/01 20:19:41 rillig Exp $ */
+/* $NetBSD: main.c,v 1.624 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.623 2024/06/01 20:19:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.624 2024/06/02 15:31:26 rillig Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -766,7 +766,7 @@ SetVarObjdir(bool writable, const char *
return false;
}
- Var_Expand(&path, SCOPE_GLOBAL, VARE_WANTRES);
+ Var_Expand(&path, SCOPE_GLOBAL, VARE_EVAL);
(void)Main_SetObjdir(writable, "%s%s", path.str, suffix);
@@ -808,8 +808,7 @@ siginfo(int signo MAKE_ATTR_UNUSED)
static void
MakeMode(void)
{
- char *mode = Var_Subst("${.MAKE.MODE:tl}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ char *mode = Var_Subst("${.MAKE.MODE:tl}", SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
if (mode[0] != '\0') {
@@ -832,14 +831,14 @@ static void
PrintVar(const char *varname, bool expandVars)
{
if (strchr(varname, '$') != NULL) {
- char *evalue = Var_Subst(varname, SCOPE_GLOBAL, VARE_WANTRES);
+ char *evalue = Var_Subst(varname, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
printf("%s\n", evalue);
free(evalue);
} else if (expandVars) {
char *expr = str_concat3("${", varname, "}");
- char *evalue = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
+ char *evalue = Var_Subst(expr, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
free(expr);
printf("%s\n", evalue);
@@ -865,7 +864,7 @@ GetBooleanExpr(const char *expr, bool fa
char *value;
bool res;
- value = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
+ value = Var_Subst(expr, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
res = ParseBoolean(value, fallback);
free(value);
@@ -1216,7 +1215,7 @@ InitMaxJobs(void)
!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOBS"))
return;
- value = Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_WANTRES);
+ value = Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
n = (int)strtol(value, NULL, 0);
if (n < 1) {
@@ -1251,7 +1250,7 @@ InitVpath(void)
if (!Var_Exists(SCOPE_CMDLINE, "VPATH"))
return;
- vpath = Var_Subst("${VPATH}", SCOPE_CMDLINE, VARE_WANTRES);
+ vpath = Var_Subst("${VPATH}", SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
path = vpath;
do {
@@ -1288,7 +1287,7 @@ ReadFirstDefaultMakefile(void)
StringList makefiles = LST_INIT;
StringListNode *ln;
char *prefs = Var_Subst("${.MAKE.MAKEFILE_PREFERENCE}",
- SCOPE_CMDLINE, VARE_WANTRES);
+ SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
AppendWords(&makefiles, prefs);
@@ -1495,7 +1494,7 @@ main_PrepareMaking(void)
/* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
if (!opts.noBuiltins || opts.printVars == PVM_NONE) {
makeDependfile = Var_Subst("${.MAKE.DEPENDFILE}",
- SCOPE_CMDLINE, VARE_WANTRES);
+ SCOPE_CMDLINE, VARE_EVAL);
if (makeDependfile[0] != '\0') {
/* TODO: handle errors */
doing_depend = true;
@@ -2084,7 +2083,7 @@ PrintOnError(GNode *gn, const char *msg)
{
char *errorVarsValues = Var_Subst(
"${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
printf("%s", errorVarsValues);
free(errorVarsValues);
@@ -2114,7 +2113,7 @@ Main_ExportMAKEFLAGS(bool first)
flags = Var_Subst(
"${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
- SCOPE_CMDLINE, VARE_WANTRES);
+ SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
if (flags[0] != '\0')
setenv("MAKEFLAGS", flags, 1);
@@ -2132,7 +2131,7 @@ getTmpdir(void)
/* Honor $TMPDIR if it is valid, strip a trailing '/'. */
tmpdir = Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {
Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.263 src/usr.bin/make/make.c:1.264
--- src/usr.bin/make/make.c:1.263 Sat May 25 00:00:25 2024
+++ src/usr.bin/make/make.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.263 2024/05/25 00:00:25 rillig Exp $ */
+/* $NetBSD: make.c,v 1.264 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -104,7 +104,7 @@
#include "job.h"
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: make.c,v 1.263 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.264 2024/06/02 15:31:26 rillig Exp $");
/* Sequence # to detect recursion. */
static unsigned int checked_seqno = 1;
@@ -443,7 +443,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
gn->uname = gn->name;
else
free(gn->name);
- gn->name = Var_Subst(gn->uname, pgn, VARE_WANTRES);
+ gn->name = Var_Subst(gn->uname, pgn, VARE_EVAL);
/* TODO: handle errors */
if (gn->uname != NULL && strcmp(gn->name, gn->uname) != 0) {
/* See if we have a target for this node. */
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.337 src/usr.bin/make/make.h:1.338
--- src/usr.bin/make/make.h:1.337 Sat Jun 1 06:26:36 2024
+++ src/usr.bin/make/make.h Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.337 2024/06/01 06:26:36 sjg Exp $ */
+/* $NetBSD: make.h,v 1.338 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -937,7 +937,7 @@ typedef enum VarEvalMode {
* TODO: Document what Var_Parse and Var_Subst return in this mode.
* As of 2021-03-15, they return unspecified, inconsistent results.
*/
- VARE_PARSE_ONLY,
+ VARE_PARSE,
/*
* Parse text in which '${...}' and '$(...)' are not parsed as
@@ -948,13 +948,13 @@ typedef enum VarEvalMode {
VARE_PARSE_BALANCED,
/* Parse and evaluate the expression. */
- VARE_WANTRES,
+ VARE_EVAL,
/*
* Parse and evaluate the expression. It is an error if a
* subexpression evaluates to undefined.
*/
- VARE_UNDEFERR,
+ VARE_EVAL_DEFINED,
/*
* Parse and evaluate the expression. Keep undefined variables as-is
@@ -967,13 +967,13 @@ typedef enum VarEvalMode {
* # way) is still undefined, the updated CFLAGS becomes
* # "-I.. $(.INCLUDES)".
*/
- VARE_EVAL_KEEP_UNDEF,
+ VARE_EVAL_KEEP_UNDEFINED,
/*
* Parse and evaluate the expression. Keep '$$' as '$$' and preserve
* undefined subexpressions.
*/
- VARE_KEEP_DOLLAR_UNDEF
+ VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED
} VarEvalMode;
typedef enum VarSetFlags {
Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.209 src/usr.bin/make/meta.c:1.210
--- src/usr.bin/make/meta.c:1.209 Sat May 25 21:34:38 2024
+++ src/usr.bin/make/meta.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.209 2024/05/25 21:34:38 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.210 2024/06/02 15:31:26 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -319,7 +319,7 @@ is_submake(const char *cmd, GNode *gn)
p_len = strlen(p_make);
}
if (strchr(cmd, '$') != NULL) {
- mp = Var_Subst(cmd, gn, VARE_WANTRES);
+ mp = Var_Subst(cmd, gn, VARE_EVAL);
/* TODO: handle errors */
cmd = mp;
}
@@ -365,7 +365,7 @@ printCMD(const char *ucmd, FILE *fp, GNo
{
FStr xcmd = FStr_InitRefer(ucmd);
- Var_Expand(&xcmd, gn, VARE_WANTRES);
+ Var_Expand(&xcmd, gn, VARE_EVAL);
fprintf(fp, "CMD %s\n", xcmd.str);
FStr_Done(&xcmd);
}
@@ -474,7 +474,7 @@ meta_create(BuildMon *pbm, GNode *gn)
if (metaVerbose) {
/* Describe the target we are building */
- char *mp = Var_Subst("${" MAKE_META_PREFIX "}", gn, VARE_WANTRES);
+ char *mp = Var_Subst("${" MAKE_META_PREFIX "}", gn, VARE_EVAL);
/* TODO: handle errors */
if (mp[0] != '\0')
fprintf(stdout, "%s\n", mp);
@@ -611,7 +611,7 @@ meta_mode_init(const char *make_mode)
* We consider ourselves master of all within ${.MAKE.META.BAILIWICK}
*/
metaBailiwickStr = Var_Subst("${.MAKE.META.BAILIWICK:O:u:tA}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
AppendWords(&metaBailiwick, metaBailiwickStr);
/*
@@ -620,7 +620,7 @@ meta_mode_init(const char *make_mode)
Global_Append(MAKE_META_IGNORE_PATHS,
"/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}");
metaIgnorePathsStr = Var_Subst("${" MAKE_META_IGNORE_PATHS ":O:u:tA}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
AppendWords(&metaIgnorePaths, metaIgnorePathsStr);
@@ -770,7 +770,7 @@ meta_job_output(Job *job, char *cp, cons
char *cp2;
meta_prefix = Var_Subst("${" MAKE_META_PREFIX "}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
if ((cp2 = strchr(meta_prefix, '$')) != NULL)
meta_prefix_len = (size_t)(cp2 - meta_prefix);
@@ -960,7 +960,7 @@ meta_ignore(GNode *gn, const char *p)
*/
Var_Set(gn, ".p.", p);
expr = "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}";
- pm = Var_Subst(expr, gn, VARE_WANTRES);
+ pm = Var_Subst(expr, gn, VARE_EVAL);
/* TODO: handle errors */
if (pm[0] != '\0') {
#ifdef DEBUG_META_MODE
@@ -979,7 +979,7 @@ meta_ignore(GNode *gn, const char *p)
snprintf(fname, sizeof fname,
"${%s:L:${%s:ts:}}",
p, MAKE_META_IGNORE_FILTER);
- fm = Var_Subst(fname, gn, VARE_WANTRES);
+ fm = Var_Subst(fname, gn, VARE_EVAL);
/* TODO: handle errors */
if (*fm == '\0') {
#ifdef DEBUG_META_MODE
@@ -1039,7 +1039,7 @@ meta_filter_cmd(GNode *gn, char *s)
Var_Set(gn, META_CMD_FILTER_VAR, s);
s = Var_Subst(
"${" META_CMD_FILTER_VAR ":${" MAKE_META_CMP_FILTER ":ts:}}",
- gn, VARE_WANTRES);
+ gn, VARE_EVAL);
return s;
}
@@ -1507,7 +1507,7 @@ meta_oodate(GNode *gn, bool oodate)
DEBUG2(META, "%s: %u: cannot compare command using .OODATE\n",
fname, lineno);
}
- cmd = Var_Subst(cmd, gn, VARE_UNDEFERR);
+ cmd = Var_Subst(cmd, gn, VARE_EVAL_DEFINED);
/* TODO: handle errors */
if ((cp = strchr(cmd, '\n')) != NULL) {
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.729 src/usr.bin/make/parse.c:1.730
--- src/usr.bin/make/parse.c:1.729 Sat Jun 1 06:26:36 2024
+++ src/usr.bin/make/parse.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.729 2024/06/01 06:26:36 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.730 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.729 2024/06/01 06:26:36 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.730 2024/06/02 15:31:26 rillig Exp $");
/* Detects a multiple-inclusion guard in a makefile. */
typedef enum {
@@ -603,7 +603,7 @@ HandleMessage(ParseErrorLevel level, con
return;
}
- xmsg = Var_Subst(umsg, SCOPE_CMDLINE, VARE_WANTRES);
+ xmsg = Var_Subst(umsg, SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
Parse_Error(level, "%s", xmsg);
@@ -909,8 +909,7 @@ ParseDependencyTargetWord(char **pp, con
break;
if (*p == '$') {
- FStr val = Var_Parse(&p, SCOPE_CMDLINE,
- VARE_PARSE_ONLY);
+ FStr val = Var_Parse(&p, SCOPE_CMDLINE, VARE_PARSE);
/* TODO: handle errors */
FStr_Done(&val);
} else
@@ -1795,7 +1794,7 @@ VarCheckSyntax(VarAssignOp op, const cha
if (opts.strict) {
if (op != VAR_SUBST && strchr(uvalue, '$') != NULL) {
char *parsedValue = Var_Subst(uvalue,
- scope, VARE_PARSE_ONLY);
+ scope, VARE_PARSE);
/* TODO: handle errors */
free(parsedValue);
}
@@ -1821,7 +1820,8 @@ VarAssign_EvalSubst(GNode *scope, const
if (!Var_ExistsExpand(scope, name))
Var_SetExpand(scope, name, "");
- evalue = Var_Subst(uvalue, scope, VARE_KEEP_DOLLAR_UNDEF);
+ evalue = Var_Subst(uvalue, scope,
+ VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED);
/* TODO: handle errors */
Var_SetExpand(scope, name, evalue);
@@ -1838,7 +1838,7 @@ VarAssign_EvalShell(const char *name, co
char *output, *error;
cmd = FStr_InitRefer(uvalue);
- Var_Expand(&cmd, SCOPE_CMDLINE, VARE_UNDEFERR);
+ Var_Expand(&cmd, SCOPE_CMDLINE, VARE_EVAL_DEFINED);
output = Cmd_Exec(cmd.str, &error);
Var_SetExpand(scope, name, output);
@@ -2020,7 +2020,7 @@ ParseInclude(char *directive)
*p = '\0';
- Var_Expand(&file, SCOPE_CMDLINE, VARE_WANTRES);
+ Var_Expand(&file, SCOPE_CMDLINE, VARE_EVAL);
IncludeFile(file.str, endc == '>', directive[0] == 'd', silent);
FStr_Done(&file);
}
@@ -2229,7 +2229,7 @@ ParseTraditionalInclude(char *line)
pp_skip_whitespace(&file);
- all_files = Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES);
+ all_files = Var_Subst(file, SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
for (file = all_files; !done; file = p + 1) {
@@ -2272,7 +2272,7 @@ ParseGmakeExport(char *line)
/*
* Expand the value before putting it in the environment.
*/
- value = Var_Subst(value, SCOPE_CMDLINE, VARE_WANTRES);
+ value = Var_Subst(value, SCOPE_CMDLINE, VARE_EVAL);
/* TODO: handle errors */
setenv(variable, value, 1);
@@ -2881,7 +2881,7 @@ ParseDependencyLine(char *line)
* empty string var_Error, which cannot be detected in the result of
* Var_Subst.
*/
- emode = opts.strict ? VARE_WANTRES : VARE_UNDEFERR;
+ emode = opts.strict ? VARE_EVAL : VARE_EVAL_DEFINED;
expanded_line = Var_Subst(line, SCOPE_CMDLINE, emode);
/* TODO: handle errors */
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.379 src/usr.bin/make/suff.c:1.380
--- src/usr.bin/make/suff.c:1.379 Sat May 25 08:03:19 2024
+++ src/usr.bin/make/suff.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.380 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.380 2024/06/02 15:31:26 rillig Exp $");
typedef List SuffixList;
typedef ListNode SuffixListNode;
@@ -1274,7 +1274,7 @@ ExpandChildrenRegular(char *p, GNode *pg
} else if (*p == '$') {
/* Skip over the expression. */
const char *nested_p = p;
- FStr junk = Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY);
+ FStr junk = Var_Parse(&nested_p, pgn, VARE_PARSE);
/* TODO: handle errors */
if (junk.str == var_Error) {
Parse_Error(PARSE_FATAL,
@@ -1344,7 +1344,7 @@ ExpandChildren(GNodeListNode *cln, GNode
}
DEBUG1(SUFF, "Expanding \"%s\"...", cgn->name);
- expanded = Var_Subst(cgn->name, pgn, VARE_UNDEFERR);
+ expanded = Var_Subst(cgn->name, pgn, VARE_EVAL_DEFINED);
/* TODO: handle errors */
{
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1118 src/usr.bin/make/var.c:1.1119
--- src/usr.bin/make/var.c:1.1118 Sun Jun 2 11:25:03 2024
+++ src/usr.bin/make/var.c Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1118 2024/06/02 11:25:03 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1119 2024/06/02 15:31:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -132,7 +132,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1118 2024/06/02 11:25:03 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1119 2024/06/02 15:31:26 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -278,11 +278,11 @@ char var_Error[] = "";
/*
* Special return value for Var_Parse, indicating an undefined variable in
- * a case where VARE_UNDEFERR is not set. This undefined variable is
+ * a case where VARE_EVAL_DEFINED is not set. This undefined variable is
* typically a dynamic variable such as ${.TARGET}, whose expansion needs to
* be deferred until it is defined in an actual target.
*
- * See VARE_EVAL_KEEP_UNDEF.
+ * See VARE_EVAL_KEEP_UNDEFINED.
*/
static char varUndefined[] = "";
@@ -324,7 +324,7 @@ GNode *SCOPE_INTERNAL;
static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE;
static const char VarEvalMode_Name[][32] = {
- "parse-only",
+ "parse",
"parse-balanced",
"eval",
"eval-defined",
@@ -612,7 +612,7 @@ Var_Undef(const char *arg)
return;
}
- expanded = Var_Subst(arg, SCOPE_GLOBAL, VARE_WANTRES);
+ expanded = Var_Subst(arg, SCOPE_GLOBAL, VARE_EVAL);
if (expanded == var_Error) {
/* TODO: Make this part of the code reachable. */
Parse_Error(PARSE_FATAL,
@@ -679,7 +679,7 @@ ExportVarEnv(Var *v, GNode *scope)
/* XXX: name is injected without escaping it */
expr = str_concat3("${", name, "}");
- val = Var_Subst(expr, scope, VARE_WANTRES);
+ val = Var_Subst(expr, scope, VARE_EVAL);
if (scope != SCOPE_GLOBAL) {
/* we will need to re-export the global version */
v = VarFind(name, SCOPE_GLOBAL, false);
@@ -788,7 +788,7 @@ Var_ReexportVars(GNode *scope)
}
xvarnames = Var_Subst("${.MAKE.EXPORTED:O:u}", SCOPE_GLOBAL,
- VARE_WANTRES);
+ VARE_EVAL);
/* TODO: handle errors */
if (xvarnames[0] != '\0') {
Words varnames = Str_Words(xvarnames, false);
@@ -828,7 +828,7 @@ ExportVars(const char *varnames, bool is
static void
ExportVarsExpand(const char *uvarnames, bool isExport, VarExportMode mode)
{
- char *xvarnames = Var_Subst(uvarnames, SCOPE_GLOBAL, VARE_WANTRES);
+ char *xvarnames = Var_Subst(uvarnames, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
ExportVars(xvarnames, isExport, mode);
free(xvarnames);
@@ -906,7 +906,7 @@ GetVarnamesToUnexport(bool isEnv, const
if (what != UNEXPORT_NAMED) {
char *expanded = Var_Subst("${.MAKE.EXPORTED:O:u}",
- SCOPE_GLOBAL, VARE_WANTRES);
+ SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
varnames = FStr_InitOwn(expanded);
}
@@ -937,7 +937,7 @@ UnexportVar(Substring varname, UnexportW
/* XXX: v->name is injected without escaping it */
char *expr = str_concat3(
"${.MAKE.EXPORTED:N", v->name.str, "}");
- char *filtered = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
+ char *filtered = Var_Subst(expr, SCOPE_GLOBAL, VARE_EVAL);
/* TODO: handle errors */
Global_Set(".MAKE.EXPORTED", filtered);
free(filtered);
@@ -1094,7 +1094,7 @@ Var_SetExpand(GNode *scope, const char *
assert(val != NULL);
- Var_Expand(&varname, scope, VARE_WANTRES);
+ Var_Expand(&varname, scope, VARE_EVAL);
if (varname.str[0] == '\0') {
DEBUG4(VAR,
@@ -1177,7 +1177,7 @@ Var_AppendExpand(GNode *scope, const cha
assert(val != NULL);
- Var_Expand(&xname, scope, VARE_WANTRES);
+ Var_Expand(&xname, scope, VARE_EVAL);
if (xname.str != name && xname.str[0] == '\0')
DEBUG4(VAR,
"%s: ignoring '%s += %s' "
@@ -1220,7 +1220,7 @@ Var_ExistsExpand(GNode *scope, const cha
FStr varname = FStr_InitRefer(name);
bool exists;
- Var_Expand(&varname, scope, VARE_WANTRES);
+ Var_Expand(&varname, scope, VARE_EVAL);
exists = Var_Exists(scope, varname.str);
FStr_Done(&varname);
return exists;
@@ -1286,32 +1286,33 @@ GNode_ValueDirect(GNode *gn, const char
static VarEvalMode
VarEvalMode_WithoutKeepDollar(VarEvalMode emode)
{
- return emode == VARE_KEEP_DOLLAR_UNDEF ? VARE_EVAL_KEEP_UNDEF : emode;
+ return emode == VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED
+ ? VARE_EVAL_KEEP_UNDEFINED : emode;
}
static VarEvalMode
VarEvalMode_UndefOk(VarEvalMode emode)
{
- return emode == VARE_UNDEFERR ? VARE_WANTRES : emode;
+ return emode == VARE_EVAL_DEFINED ? VARE_EVAL : emode;
}
static bool
VarEvalMode_ShouldEval(VarEvalMode emode)
{
- return emode != VARE_PARSE_ONLY;
+ return emode != VARE_PARSE;
}
static bool
VarEvalMode_ShouldKeepUndef(VarEvalMode emode)
{
- return emode == VARE_EVAL_KEEP_UNDEF ||
- emode == VARE_KEEP_DOLLAR_UNDEF;
+ return emode == VARE_EVAL_KEEP_UNDEFINED ||
+ emode == VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED;
}
static bool
VarEvalMode_ShouldKeepDollar(VarEvalMode emode)
{
- return emode == VARE_KEEP_DOLLAR_UNDEF;
+ return emode == VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED;
}
@@ -1440,7 +1441,7 @@ ModifyWord_SysVSubst(Substring word, Sep
}
rhs = FStr_InitRefer(args->rhs);
- Var_Expand(&rhs, args->scope, VARE_WANTRES);
+ Var_Expand(&rhs, args->scope, VARE_EVAL);
percent = args->lhsPercent ? strchr(rhs.str, '%') : NULL;
@@ -2362,7 +2363,7 @@ ApplyModifier_Loop(const char **pp, ModC
args.scope = expr->scope;
(*pp)++; /* Skip the first '@' */
- if (!ParseModifierPart(pp, '@', '@', VARE_PARSE_ONLY,
+ if (!ParseModifierPart(pp, '@', '@', VARE_PARSE,
ch, &tvarBuf, NULL, NULL))
return AMR_CLEANUP;
tvar = LazyBuf_DoneGet(&tvarBuf);
@@ -2432,7 +2433,7 @@ ParseModifier_Defined(const char **pp, M
if (*p == '$') {
FStr val = Var_Parse(&p, ch->expr->scope,
- shouldEval ? ch->expr->emode : VARE_PARSE_ONLY);
+ shouldEval ? ch->expr->emode : VARE_PARSE);
/* TODO: handle errors */
if (shouldEval)
LazyBuf_AddStr(buf, val.str);
@@ -3042,7 +3043,7 @@ ApplyModifier_ToSep(const char **pp, Mod
/*
* Even in parse-only mode, apply the side effects, since the side
* effects are neither observable nor is there a performance penalty.
- * Checking for wantRes for every single piece of code in here
+ * Checking for VARE_EVAL for every single piece of code in here
* would make the code in this function too hard to read.
*/
@@ -3419,8 +3420,8 @@ ApplyModifier_IfElse(const char **pp, Mo
LazyBuf thenBuf;
LazyBuf elseBuf;
- VarEvalMode then_emode = VARE_PARSE_ONLY;
- VarEvalMode else_emode = VARE_PARSE_ONLY;
+ VarEvalMode then_emode = VARE_PARSE;
+ VarEvalMode else_emode = VARE_PARSE;
CondResult cond_rc = CR_TRUE; /* just not CR_ERROR */
if (Expr_ShouldEval(expr)) {
@@ -3742,9 +3743,8 @@ ApplyModifier_SunShell(const char **pp,
static bool
ShouldLogInSimpleFormat(const Expr *expr)
{
- return (expr->emode == VARE_WANTRES ||
- expr->emode == VARE_UNDEFERR) &&
- expr->defined == DEF_REGULAR;
+ return (expr->emode == VARE_EVAL || expr->emode == VARE_EVAL_DEFINED)
+ && expr->defined == DEF_REGULAR;
}
static void
@@ -4230,7 +4230,7 @@ ParseVarnameShort(char varname, const ch
val = UndefinedShortVarValue(varname, scope);
if (val == NULL)
- val = emode == VARE_UNDEFERR ? var_Error : varUndefined;
+ val = emode == VARE_EVAL_DEFINED ? var_Error : varUndefined;
if (opts.strict && val == var_Error) {
Parse_Error(PARSE_FATAL,
@@ -4275,7 +4275,7 @@ EvalUndefined(bool dynamic, const char *
if (dynamic)
return FStr_InitOwn(bmake_strsedup(start, p));
- if (emode == VARE_UNDEFERR && opts.strict) {
+ if (emode == VARE_EVAL_DEFINED && opts.strict) {
Parse_Error(PARSE_FATAL,
"Variable \"%.*s\" is undefined",
(int)Substring_Length(varname), varname.start);
@@ -4283,7 +4283,7 @@ EvalUndefined(bool dynamic, const char *
}
return FStr_InitRefer(
- emode == VARE_UNDEFERR ? var_Error : varUndefined);
+ emode == VARE_EVAL_DEFINED ? var_Error : varUndefined);
}
/*
@@ -4436,7 +4436,7 @@ Var_Parse_U(const char **pp, VarEvalMode
if (*p != '}')
return false;
- *out_value = emode == VARE_PARSE_ONLY
+ *out_value = emode == VARE_PARSE
? FStr_InitRefer("")
: FStr_InitOwn(bmake_strsedup(*pp + 4, p));
*pp = p + 1;
@@ -4465,13 +4465,13 @@ Var_Parse_U(const char **pp, VarEvalMode
* return The value of the expression, never NULL.
* return var_Error if there was a parse error.
* return var_Error if the base variable of the expression was
- * undefined, emode is VARE_UNDEFERR, and none of
+ * undefined, emode is VARE_EVAL_DEFINED, and none of
* the modifiers turned the undefined expression into a
* defined expression.
* XXX: It is not guaranteed that an error message has
* been printed.
* return varUndefined if the base variable of the expression
- * was undefined, emode was not VARE_UNDEFERR,
+ * was undefined, emode was not VARE_EVAL_DEFINED,
* and none of the modifiers turned the undefined
* expression into a defined expression.
* XXX: It is not guaranteed that an error message has
@@ -4600,7 +4600,7 @@ Var_Parse(const char **pp, GNode *scope,
* instead.
*/
Expr_SetValueRefer(&expr,
- emode == VARE_UNDEFERR
+ emode == VARE_EVAL_DEFINED
? var_Error : varUndefined);
}
}
Index: src/usr.bin/make/unit-tests/cond-func-empty.mk
diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.24 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.25
--- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.24 Tue Dec 19 19:33:40 2023
+++ src/usr.bin/make/unit-tests/cond-func-empty.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-empty.mk,v 1.24 2023/12/19 19:33:40 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.25 2024/06/02 15:31:26 rillig Exp $
#
# Tests for the empty() function in .if conditions, which tests an
# expression for emptiness.
@@ -104,10 +104,10 @@ WORD= word
# Now the variable named " " gets a non-empty value, which demonstrates that
# neither leading nor trailing spaces are trimmed in the argument of the
-# function. If the spaces were trimmed, the variable name would be "" and
-# that variable is indeed undefined. Since CondParser_FuncCallEmpty calls
-# Var_Parse without VARE_UNDEFERR, the value of the undefined variable ""
-# would be returned as an empty string.
+# function. If the spaces were trimmed, the variable name would be "", and
+# that variable is indeed undefined. Since CondParser_FuncCallEmpty allows
+# subexpressions to be based on undefined variables, the value of the
+# undefined variable "" would be returned as an empty string.
${:U }= space
.if empty( )
. error
@@ -194,15 +194,15 @@ ${:U WORD }= variable name with spaces
# wrong variable name should have been discarded quickly after parsing it, to
# prevent it from doing any harm.
#
-# The expression was expanded, and this was wrong. The
-# expansion was done without VARE_WANTRES (called VARF_WANTRES back then)
-# though. This had the effect that the ${:U1} from the value of VARNAME
-# expanded to an empty string. This in turn created the seemingly recursive
-# definition VARNAME=${VARNAME}, and that definition was never meant to be
-# expanded.
+# The expression was evaluated, and this was wrong. The evaluation was done
+# without VARE_EVAL (called VARF_WANTRES back then) though. This had the
+# effect that the ${:U1} from the value of VARNAME evaluated to an empty
+# string. This in turn created the seemingly recursive definition
+# VARNAME=${VARNAME}, and that definition was evaluated even though it was
+# never meant to be evaluated.
#
-# This was fixed by expanding nested expressions in the variable name
-# only if the flag VARE_WANTRES is given.
+# This was fixed by evaluating nested expressions in the variable name only
+# when the whole expression was evaluated as well.
VARNAME= ${VARNAME${:U1}}
.if defined(VARNAME${:U2}) && !empty(VARNAME${:U2})
.endif
Index: src/usr.bin/make/unit-tests/dep-var.exp
diff -u src/usr.bin/make/unit-tests/dep-var.exp:1.6 src/usr.bin/make/unit-tests/dep-var.exp:1.7
--- src/usr.bin/make/unit-tests/dep-var.exp:1.6 Sun Nov 19 22:06:15 2023
+++ src/usr.bin/make/unit-tests/dep-var.exp Sun Jun 2 15:31:26 2024
@@ -16,9 +16,9 @@ Result of ${:U\$)} is "$)" (eval-defined
Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1
Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2
Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b
-Var_Parse: $INDIRECT_2-2-1 $): (parse-only)
+Var_Parse: $INDIRECT_2-2-1 $): (parse)
Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1
-Var_Parse: $): (parse-only)
+Var_Parse: $): (parse)
Global: .ALLTARGETS = all ${DEF2} a-${DEF2}-b ${UNDEF3} 1-${INDIRECT_1}-1 $$) undef1 def2 a-def2-b 1-2-$INDIRECT_2-2-1 $)
Global: .MAKEFLAGS = -r -k -d v -d
Global: .MAKEFLAGS = -r -k -d v -d 0
Index: src/usr.bin/make/unit-tests/dep-var.mk
diff -u src/usr.bin/make/unit-tests/dep-var.mk:1.11 src/usr.bin/make/unit-tests/dep-var.mk:1.12
--- src/usr.bin/make/unit-tests/dep-var.mk:1.11 Tue Dec 19 19:33:40 2023
+++ src/usr.bin/make/unit-tests/dep-var.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: dep-var.mk,v 1.11 2023/12/19 19:33:40 rillig Exp $
+# $NetBSD: dep-var.mk,v 1.12 2024/06/02 15:31:26 rillig Exp $
#
# Tests for variable references in dependency declarations.
#
@@ -84,8 +84,8 @@ all: $$$$)
# in normal mode since ParseDependency does not handle any errors after
# calling Var_Parse.
# expect: Var_Parse: ${:U\$)}: (eval-defined)
-# expect: Var_Parse: $INDIRECT_2-2-1 $): (parse-only)
-# expect: Var_Parse: $): (parse-only)
+# expect: Var_Parse: $INDIRECT_2-2-1 $): (parse)
+# expect: Var_Parse: $): (parse)
undef1 def2 a-def2-b 1-2-$$INDIRECT_2-2-1 ${:U\$)}:
@echo ${.TARGET:Q}
Index: src/usr.bin/make/unit-tests/parse-var.mk
diff -u src/usr.bin/make/unit-tests/parse-var.mk:1.9 src/usr.bin/make/unit-tests/parse-var.mk:1.10
--- src/usr.bin/make/unit-tests/parse-var.mk:1.9 Sun Nov 19 21:47:52 2023
+++ src/usr.bin/make/unit-tests/parse-var.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: parse-var.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: parse-var.mk,v 1.10 2024/06/02 15:31:26 rillig Exp $
#
# Tests for parsing expressions.
#
@@ -20,11 +20,11 @@
#
# VarEvalMode:
# parse
+# parse-balanced
# eval
-# eval-undeferr
-# eval-keep-dollar
-# eval-keep-undef
-# eval-keep-dollar-undef
+# eval-defined
+# eval-keep-undefined
+# eval-keep-dollar-and-undefined
#
# Global mode:
# without -dL
Index: src/usr.bin/make/unit-tests/recursive.mk
diff -u src/usr.bin/make/unit-tests/recursive.mk:1.7 src/usr.bin/make/unit-tests/recursive.mk:1.8
--- src/usr.bin/make/unit-tests/recursive.mk:1.7 Thu Oct 19 18:24:33 2023
+++ src/usr.bin/make/unit-tests/recursive.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: recursive.mk,v 1.7 2023/10/19 18:24:33 rillig Exp $
+# $NetBSD: recursive.mk,v 1.8 2024/06/02 15:31:26 rillig Exp $
#
# In -dL mode, a variable may get expanded before it makes sense.
# This would stop make from doing anything since the "recursive" error
@@ -6,7 +6,7 @@
#
# The purpose of evaluating that variable early was just to detect
# whether there are unclosed variables. The variable value is therefore
-# parsed with VARE_PARSE_ONLY for that purpose.
+# parsed with VARE_PARSE for that purpose.
#
.MAKEFLAGS: -dL
Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.25 src/usr.bin/make/unit-tests/var-eval-short.exp:1.26
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.25 Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/unit-tests/var-eval-short.exp Sun Jun 2 15:31:26 2024
@@ -2,26 +2,26 @@ make: "var-eval-short.mk" line 46: while
make: "var-eval-short.mk" line 46: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
Parsing line 159: .if 0 && ${0:?${FAIL}then:${FAIL}else}
CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
-Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
+Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse)
Parsing modifier ${0:?...}
-Var_Parse: ${FAIL}then:${FAIL}else} (parse-only)
+Var_Parse: ${FAIL}then:${FAIL}else} (parse)
Modifier part: "${FAIL}then"
-Var_Parse: ${FAIL}else} (parse-only)
+Var_Parse: ${FAIL}else} (parse)
Modifier part: "${FAIL}else"
-Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
+Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse, defined)
Parsing line 167: DEFINED= defined
Global: DEFINED = defined
Parsing line 168: .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
-Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
+Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse)
Parsing modifier ${DEFINED:L}
-Result of ${DEFINED:L} is "defined" (parse-only, regular)
+Result of ${DEFINED:L} is "defined" (parse, regular)
Parsing modifier ${DEFINED:?...}
-Var_Parse: ${FAIL}then:${FAIL}else} (parse-only)
+Var_Parse: ${FAIL}then:${FAIL}else} (parse)
Modifier part: "${FAIL}then"
-Var_Parse: ${FAIL}else} (parse-only)
+Var_Parse: ${FAIL}else} (parse)
Modifier part: "${FAIL}else"
-Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
+Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse, regular)
Parsing line 170: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d cpv -d
Index: src/usr.bin/make/unit-tests/varmod-loop.mk
diff -u src/usr.bin/make/unit-tests/varmod-loop.mk:1.25 src/usr.bin/make/unit-tests/varmod-loop.mk:1.26
--- src/usr.bin/make/unit-tests/varmod-loop.mk:1.25 Sat Jun 1 05:08:48 2024
+++ src/usr.bin/make/unit-tests/varmod-loop.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop.mk,v 1.25 2024/06/01 05:08:48 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.26 2024/06/02 15:31:26 rillig Exp $
#
# Tests for the expression modifier ':@var@body@', which replaces each word of
# the expression with the expanded body, which may contain references to the
@@ -93,11 +93,11 @@ USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@}
#
SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}
# The ':=' assignment operator evaluates the variable value using the mode
-# VARE_KEEP_DOLLAR_UNDEF, which means that some dollar signs are preserved,
-# but not all. The dollar signs in the top-level expression and in the
-# indirect ${8_DOLLARS} are preserved.
+# VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED, which means that some dollar signs are
+# preserved, but not all. The dollar signs in the top-level expression and in
+# the indirect ${8_DOLLARS} are preserved.
#
-# The variable modifier :@var@ does not preserve the dollar signs though, no
+# The modifier :@var@ does not preserve the dollar signs though, no
# matter in which context it is evaluated. What happens in detail is:
# First, the modifier part "${8_DOLLARS}" is parsed without expanding it.
# Next, each word of the value is expanded on its own, and at this moment
Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.28 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.29
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.28 Tue Apr 23 22:51:28 2024
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.28 2024/04/23 22:51:28 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.29 2024/06/02 15:31:26 rillig Exp $
#
# Tests for the ${cond:?then:else} variable modifier, which evaluates either
# the then-expression or the else-expression, depending on the condition.
@@ -77,7 +77,7 @@ COND:= ${${UNDEF} == "":?bad-assign:bad-
# conditional expression".
#
# XXX: The left-hand side is enclosed in quotes. This results in Var_Parse
-# being called without VARE_UNDEFERR. When ApplyModifier_IfElse
+# being called without VARE_EVAL_DEFINED. When ApplyModifier_IfElse
# returns AMR_CLEANUP as result, Var_Parse returns varUndefined since the
# value of the expression is still undefined. CondParser_String is
# then supposed to do proper error handling, but since varUndefined is local
Index: src/usr.bin/make/unit-tests/varparse-errors.mk
diff -u src/usr.bin/make/unit-tests/varparse-errors.mk:1.12 src/usr.bin/make/unit-tests/varparse-errors.mk:1.13
--- src/usr.bin/make/unit-tests/varparse-errors.mk:1.12 Sat Apr 20 10:18:56 2024
+++ src/usr.bin/make/unit-tests/varparse-errors.mk Sun Jun 2 15:31:26 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varparse-errors.mk,v 1.12 2024/04/20 10:18:56 rillig Exp $
+# $NetBSD: varparse-errors.mk,v 1.13 2024/06/02 15:31:26 rillig Exp $
# Tests for parsing and evaluating all kinds of expressions.
#
@@ -24,7 +24,7 @@ ERR_BAD_MOD= An ${:Uindirect:Z} expressi
ERR_EVAL= An evaluation error ${:Uvalue:C,.,\3,}.
# In a conditional, an expression that is not enclosed in quotes is
-# expanded using the mode VARE_UNDEFERR.
+# expanded using the mode VARE_EVAL_DEFINED.
# The variable itself must be defined.
# It may refer to undefined variables though.
.if ${REF_UNDEF} != "A reference to an undefined variable."