Module Name:    src
Committed By:   sjg
Date:           Sun Dec 12 20:45:48 UTC 2021

Modified Files:
        src/usr.bin/make: make.1 nonints.h suff.c var.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/usr.bin/make/make.1
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.356 -r1.357 src/usr.bin/make/suff.c
cvs rdiff -u -r1.972 -r1.973 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/make.1
diff -u src/usr.bin/make/make.1:1.299 src/usr.bin/make/make.1:1.300
--- src/usr.bin/make/make.1:1.299	Tue Aug  3 07:12:50 2021
+++ src/usr.bin/make/make.1	Sun Dec 12 20:45:48 2021
@@ -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 @@ executes.
 .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

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.216 src/usr.bin/make/nonints.h:1.217
--- src/usr.bin/make/nonints.h:1.216	Sun Dec 12 15:44:41 2021
+++ src/usr.bin/make/nonints.h	Sun Dec 12 20:45:48 2021
@@ -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 @@ void Suff_FindDeps(GNode *);
 SearchPath *Suff_FindPath(GNode *);
 void Suff_SetNull(const char *);
 void Suff_PrintAll(void);
+const char *Suff_NamesStr(void);
 
 /* targ.c */
 void Targ_Init(void);

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.356 src/usr.bin/make/suff.c:1.357
--- src/usr.bin/make/suff.c:1.356	Thu Dec  9 20:13:09 2021
+++ src/usr.bin/make/suff.c	Sun Dec 12 20:45:48 2021
@@ -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 @@ Suff_PrintAll(void)
 			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);
+}

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.972 src/usr.bin/make/var.c:1.973
--- src/usr.bin/make/var.c:1.972	Sun Dec 12 16:41:39 2021
+++ src/usr.bin/make/var.c	Sun Dec 12 20:45:48 2021
@@ -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_SetWithFlags(GNode *scope, const cha
 			 */
 			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 @@ ParseVarnameLong(
 	 * 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) {

Reply via email to