Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): add more explanation for undefined var...



details:   https://anonhg.NetBSD.org/src/rev/89fe9c3979e9
branches:  trunk
changeset: 938229:89fe9c3979e9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 04 20:28:15 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/cond-func-empty.mk |   5 +++-
 usr.bin/make/var.c                         |  33 ++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 14 deletions(-)

diffs (80 lines):

diff -r 62373231642f -r 89fe9c3979e9 usr.bin/make/unit-tests/cond-func-empty.mk
--- a/usr.bin/make/unit-tests/cond-func-empty.mk        Fri Sep 04 19:03:38 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-empty.mk        Fri Sep 04 20:28:15 2020 +0000
@@ -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
 # expression for emptiness.
@@ -29,6 +29,9 @@
 # after that the expression is no longer empty.  Because the variable
 # was undefined in the first place, the expression has the flag VAR_JUNK
 # 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
 # implementation details.
diff -r 62373231642f -r 89fe9c3979e9 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Sep 04 19:03:38 2020 +0000
+++ b/usr.bin/make/var.c        Fri Sep 04 20:28:15 2020 +0000
@@ -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
@@ -69,14 +69,14 @@
  */
 
 #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
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #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 /* not lint */
 #endif
@@ -3523,17 +3523,24 @@
                    Buf_Destroy(&namebuf, TRUE);
                    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
            Buf_Destroy(&namebuf, TRUE);
     }



Home | Main Index | Thread Index | Old Index