Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Add .SUFFIXES as read-only variable.



details:   https://anonhg.NetBSD.org/src/rev/7aa206da464f
branches:  trunk
changeset: 1027592:7aa206da464f
user:      sjg <sjg%NetBSD.org@localhost>
date:      Sun Dec 12 20:45:48 2021 +0000

description:
Add .SUFFIXES as read-only variable.

References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig

diffstat:

 usr.bin/make/make.1    |   7 +++++--
 usr.bin/make/nonints.h |   3 ++-
 usr.bin/make/suff.c    |  21 +++++++++++++++++++--
 usr.bin/make/var.c     |  18 ++++++++++++++----
 4 files changed, 40 insertions(+), 9 deletions(-)

diffs (130 lines):

diff -r 21442a683774 -r 7aa206da464f usr.bin/make/make.1
--- a/usr.bin/make/make.1       Sun Dec 12 20:33:21 2021 +0000
+++ b/usr.bin/make/make.1       Sun Dec 12 20:45:48 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.299 2021/08/03 07:12:50 wiz Exp $
+.\"    $NetBSD: make.1,v 1.300 2021/12/12 20:45:48 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    from: @(#)make.1        8.4 (Berkeley) 3/19/94
 .\"
-.Dd August 3, 2021
+.Dd December 12, 2021
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1162,6 +1162,9 @@
 .It Ev .SHELL
 The pathname of the shell used to run target scripts.
 It is read-only.
+.It Ev .SUFFIXES
+The list of known suffixes.
+It is read-only.
 .It Ev .TARGETS
 The list of targets explicitly specified on the command line, if any.
 .It Ev VPATH
diff -r 21442a683774 -r 7aa206da464f usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 12 20:33:21 2021 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 12 20:45:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.216 2021/12/12 15:44:41 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.217 2021/12/12 20:45:48 sjg Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -184,6 +184,7 @@
 SearchPath *Suff_FindPath(GNode *);
 void Suff_SetNull(const char *);
 void Suff_PrintAll(void);
+const char *Suff_NamesStr(void);
 
 /* targ.c */
 void Targ_Init(void);
diff -r 21442a683774 -r 7aa206da464f usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sun Dec 12 20:33:21 2021 +0000
+++ b/usr.bin/make/suff.c       Sun Dec 12 20:45:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.356 2021/12/09 20:13:09 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.357 2021/12/12 20:45:48 sjg 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.356 2021/12/09 20:13:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.357 2021/12/12 20:45:48 sjg Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -2177,3 +2177,20 @@
                        PrintTransformation(ln->datum);
        }
 }
+
+const char *
+Suff_NamesStr(void)
+{
+       Buffer buf;
+       SuffixListNode *ln;
+       Suffix *suff;
+
+       Buf_InitSize(&buf, 16);
+       for (ln = sufflist.first; ln != NULL; ln = ln->next) {
+               suff = ln->datum;
+               if (ln != sufflist.first)
+                       Buf_AddByte(&buf, ' ');
+               Buf_AddStr(&buf, suff->name);
+       }
+       return Buf_DoneData(&buf);
+}
diff -r 21442a683774 -r 7aa206da464f usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 12 20:33:21 2021 +0000
+++ b/usr.bin/make/var.c        Sun Dec 12 20:45:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.972 2021/12/12 16:41:39 sjg Exp $    */
+/*     $NetBSD: var.c,v 1.973 2021/12/12 20:45:48 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.972 2021/12/12 16:41:39 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.973 2021/12/12 20:45:48 sjg Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -977,6 +977,12 @@
                         */
                        Var_Delete(SCOPE_GLOBAL, name);
                }
+               if (strcmp(name, ".SUFFIXES") == 0) {
+                       /* special: treat as readOnly */
+                       DEBUG3(VAR, "%s: %s = %s ignored (read-only)\n",
+                           scope->name, name, val);
+                       return;
+               }
                v = VarAdd(name, val, scope, flags);
        } else {
                if (v->readOnly && !(flags & VAR_SET_READONLY)) {
@@ -4400,8 +4406,12 @@
         * either at ':' or at endc. */
 
        if (v == NULL) {
-               v = FindLocalLegacyVar(name, scope,
-                   out_true_extraModifiers);
+               if (Substring_Equals(name, ".SUFFIXES"))
+                       v = VarNew(Substring_Str(name),
+                           Suff_NamesStr(), false, true);
+               else
+                       v = FindLocalLegacyVar(name, scope,
+                           out_true_extraModifiers);
        }
 
        if (v == NULL) {



Home | Main Index | Thread Index | Old Index