Module Name: src
Committed By: rillig
Date: Thu Oct 22 05:35:21 UTC 2020
Modified Files:
src/usr.bin/make: var.c
Log Message:
make(1): extract CanonicalVarname from VarFind
To generate a diff of this commit:
cvs rdiff -u -r1.579 -r1.580 src/usr.bin/make/var.c
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/var.c
diff -u src/usr.bin/make/var.c:1.579 src/usr.bin/make/var.c:1.580
--- src/usr.bin/make/var.c:1.579 Tue Oct 20 23:15:23 2020
+++ src/usr.bin/make/var.c Thu Oct 22 05:35:21 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.579 2020/10/20 23:15:23 rillig Exp $ */
+/* $NetBSD: var.c,v 1.580 2020/10/22 05:35:21 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.579 2020/10/20 23:15:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.580 2020/10/22 05:35:21 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -286,35 +286,9 @@ VarNew(const char *name, void *name_free
return var;
}
-/*-
- *-----------------------------------------------------------------------
- * VarFind --
- * Find the given variable in the given context and any other contexts
- * indicated.
- *
- * Input:
- * name name to find
- * ctxt context in which to find it
- * flags FIND_GLOBAL look in VAR_GLOBAL as well
- * FIND_CMD look in VAR_CMD as well
- * FIND_ENV look in the environment as well
- *
- * Results:
- * A pointer to the structure describing the desired variable or
- * NULL if the variable does not exist.
- *-----------------------------------------------------------------------
- */
-static Var *
-VarFind(const char *name, GNode *ctxt, VarFindFlags flags)
+static const char *
+CanonicalVarname(const char *name)
{
- Var *var;
-
- /*
- * If the variable name begins with a '.', it could very well be one of
- * the local ones. We check the name against all the local variables
- * and substitute the short version in for 'name' if it matches one of
- * them.
- */
if (*name == '.' && ch_isupper(name[1])) {
switch (name[1]) {
case 'A':
@@ -340,7 +314,7 @@ VarFind(const char *name, GNode *ctxt, V
name = PREFIX;
break;
case 'S':
- if (strcmp(name, ".SHELL") == 0 ) {
+ if (strcmp(name, ".SHELL") == 0) {
if (!shellPath)
Shell_Init();
}
@@ -352,11 +326,41 @@ VarFind(const char *name, GNode *ctxt, V
}
}
-#if 0
- /* for compatibility with gmake */
- if (name[0] == '^' && name[1] == '\0')
- name = ALLSRC;
-#endif
+ /* GNU make has an additional alias $^ == ${.ALLSRC}. */
+
+ return name;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * VarFind --
+ * Find the given variable in the given context and any other contexts
+ * indicated.
+ *
+ * Input:
+ * name name to find
+ * ctxt context in which to find it
+ * flags FIND_GLOBAL look in VAR_GLOBAL as well
+ * FIND_CMD look in VAR_CMD as well
+ * FIND_ENV look in the environment as well
+ *
+ * Results:
+ * A pointer to the structure describing the desired variable or
+ * NULL if the variable does not exist.
+ *-----------------------------------------------------------------------
+ */
+static Var *
+VarFind(const char *name, GNode *ctxt, VarFindFlags flags)
+{
+ Var *var;
+
+ /*
+ * If the variable name begins with a '.', it could very well be one of
+ * the local ones. We check the name against all the local variables
+ * and substitute the short version in for 'name' if it matches one of
+ * them.
+ */
+ name = CanonicalVarname(name);
/*
* First look for the variable in the given context. If it's not there,