CVS commit: src/usr.bin/make

2024-04-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 28 15:10:19 UTC 2024

Modified Files:
src/usr.bin/make: buf.c buf.h var.c

Log Message:
make: don't reallocate memory after evaluating an expression

When an expression is evaluated, the resulting text is short-lived in
almost all cases.  In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/buf.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/make/buf.h
cvs rdiff -u -r1.1107 -r1.1108 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.



CVS commit: src/usr.bin/make

2024-04-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 28 15:10:19 UTC 2024

Modified Files:
src/usr.bin/make: buf.c buf.h var.c

Log Message:
make: don't reallocate memory after evaluating an expression

When an expression is evaluated, the resulting text is short-lived in
almost all cases.  In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/make/buf.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/make/buf.h
cvs rdiff -u -r1.1107 -r1.1108 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/buf.c
diff -u src/usr.bin/make/buf.c:1.57 src/usr.bin/make/buf.c:1.58
--- src/usr.bin/make/buf.c:1.57	Tue Dec 19 19:33:39 2023
+++ src/usr.bin/make/buf.c	Sun Apr 28 15:10:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.c,v 1.57 2023/12/19 19:33:39 rillig Exp $	*/
+/*	$NetBSD: buf.c,v 1.58 2024/04/28 15:10:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,7 +75,7 @@
 #include "make.h"
 
 /*	"@(#)buf.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: buf.c,v 1.57 2023/12/19 19:33:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.58 2024/04/28 15:10:19 rillig Exp $");
 
 /* Make space in the buffer for adding at least 16 more bytes. */
 void
@@ -187,30 +187,3 @@ Buf_DoneData(Buffer *buf)
 
 	return data;
 }
-
-#ifndef BUF_COMPACT_LIMIT
-# define BUF_COMPACT_LIMIT 128	/* worthwhile saving */
-#endif
-
-/*
- * Return the data from the buffer.
- * Leave the buffer itself in an indeterminate state.
- *
- * If the buffer size is much greater than its content,
- * a new buffer will be allocated and the old one freed.
- */
-char *
-Buf_DoneDataCompact(Buffer *buf)
-{
-#if BUF_COMPACT_LIMIT > 0
-	if (buf->cap - buf->len >= BUF_COMPACT_LIMIT) {
-		/* We trust realloc to be smart */
-		char *data = bmake_realloc(buf->data, buf->len + 1);
-		buf->data = NULL;
-		data[buf->len] = '\0';	/* XXX: unnecessary */
-		Buf_Done(buf);
-		return data;
-	}
-#endif
-	return Buf_DoneData(buf);
-}

Index: src/usr.bin/make/buf.h
diff -u src/usr.bin/make/buf.h:1.49 src/usr.bin/make/buf.h:1.50
--- src/usr.bin/make/buf.h:1.49	Tue Dec 19 19:33:39 2023
+++ src/usr.bin/make/buf.h	Sun Apr 28 15:10:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.h,v 1.49 2023/12/19 19:33:39 rillig Exp $	*/
+/*	$NetBSD: buf.h,v 1.50 2024/04/28 15:10:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -124,6 +124,5 @@ void Buf_Init(Buffer *);
 void Buf_InitSize(Buffer *, size_t);
 void Buf_Done(Buffer *);
 char *Buf_DoneData(Buffer *) MAKE_ATTR_USE;
-char *Buf_DoneDataCompact(Buffer *) MAKE_ATTR_USE;
 
 #endif

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1107 src/usr.bin/make/var.c:1.1108
--- src/usr.bin/make/var.c:1.1107	Sat Apr 27 21:26:23 2024
+++ src/usr.bin/make/var.c	Sun Apr 28 15:10:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1107 2024/04/27 21:26:23 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1108 2024/04/28 15:10:19 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.1107 2024/04/27 21:26:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1108 2024/04/28 15:10:19 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4731,7 +4731,7 @@ Var_Subst(const char *str, GNode *scope,
 			VarSubstPlain(, );
 	}
 
-	return Buf_DoneDataCompact();
+	return Buf_DoneData();
 }
 
 void



CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 21:26:23 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix comment about forcing a use-after-free

The previous expression didn't cause any bug, as the modifier
':@VAR@loop@' changed the value of the expression, thus making the
expression independent from the variable value.

Instead, the variable needs to be deleted from within an indirect
modifier, and that modifier needs to evaluate to an empty string, thus
doing nothing and preserving the original expression value.


To generate a diff of this commit:
cvs rdiff -u -r1.1106 -r1.1107 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.



CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 21:26:23 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix comment about forcing a use-after-free

The previous expression didn't cause any bug, as the modifier
':@VAR@loop@' changed the value of the expression, thus making the
expression independent from the variable value.

Instead, the variable needs to be deleted from within an indirect
modifier, and that modifier needs to evaluate to an empty string, thus
doing nothing and preserving the original expression value.


To generate a diff of this commit:
cvs rdiff -u -r1.1106 -r1.1107 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.1106 src/usr.bin/make/var.c:1.1107
--- src/usr.bin/make/var.c:1.1106	Sat Apr 27 20:41:32 2024
+++ src/usr.bin/make/var.c	Sat Apr 27 21:26:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1106 2024/04/27 20:41:32 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1107 2024/04/27 21:26:23 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.1106 2024/04/27 20:41:32 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1107 2024/04/27 21:26:23 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4542,7 +4542,7 @@ Var_Parse(const char **pp, GNode *scope,
 	 * while its value is still being used:
 	 *
 	 *	VAR=	value
-	 *	_:=	${VAR:${:U@VAR@loop@}:S,^,prefix,}
+	 *	_:=	${VAR:${:U:@VAR@@}:S,^,prefix,}
 	 *
 	 * The same effect might be achievable using the '::=' or the ':_'
 	 * modifiers.



CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 20:41:32 UTC 2024

Modified Files:
src/usr.bin/make: arch.c job.c make.h var.c
src/usr.bin/make/unit-tests: depsrc-end.mk depsrc-nopath.exp
depsrc-nopath.mk depsrc-phony.mk

Log Message:
make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code.  Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/make/arch.c
cvs rdiff -u -r1.469 -r1.470 src/usr.bin/make/job.c
cvs rdiff -u -r1.331 -r1.332 src/usr.bin/make/make.h
cvs rdiff -u -r1.1105 -r1.1106 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/depsrc-end.mk \
src/usr.bin/make/unit-tests/depsrc-nopath.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/depsrc-nopath.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/depsrc-phony.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 20:41:32 UTC 2024

Modified Files:
src/usr.bin/make: arch.c job.c make.h var.c
src/usr.bin/make/unit-tests: depsrc-end.mk depsrc-nopath.exp
depsrc-nopath.mk depsrc-phony.mk

Log Message:
make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code.  Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/make/arch.c
cvs rdiff -u -r1.469 -r1.470 src/usr.bin/make/job.c
cvs rdiff -u -r1.331 -r1.332 src/usr.bin/make/make.h
cvs rdiff -u -r1.1105 -r1.1106 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/depsrc-end.mk \
src/usr.bin/make/unit-tests/depsrc-nopath.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/depsrc-nopath.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/depsrc-phony.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.216 src/usr.bin/make/arch.c:1.217
--- src/usr.bin/make/arch.c:1.216	Sat Apr 27 17:33:46 2024
+++ src/usr.bin/make/arch.c	Sat Apr 27 20:41:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 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.216 2024/04/27 17:33:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -134,7 +134,7 @@ typedef struct ListNode ArchListNode;
 static ArchList archives;	/* The archives we've already examined */
 
 typedef struct Arch {
-	char *name;		/* Name of archive */
+	char *name;
 	HashTable members;	/* All the members of the archive described
  * by  key/value pairs */
 	char *fnametab;		/* Extended name table strings */
@@ -155,7 +155,6 @@ ArchFree(Arch *a)
 {
 	HashIter hi;
 
-	/* Free memory from hash entries */
 	HashIter_Init(, >members);
 	while (HashIter_Next() != NULL)
 		free(hi.entry->value);
@@ -168,32 +167,22 @@ ArchFree(Arch *a)
 #endif
 
 /* Return "archive(member)". */
-static char *
+MAKE_ATTR_NOINLINE static char *
 FullName(const char *archive, const char *member)
 {
-	size_t len1 = strlen(archive);
-	size_t len3 = strlen(member);
-	char *result = bmake_malloc(len1 + 1 + len3 + 1 + 1);
-	memcpy(result, archive, len1);
-	memcpy(result + len1, "(", 1);
-	memcpy(result + len1 + 1, member, len3);
-	memcpy(result + len1 + 1 + len3, ")", 1 + 1);
-	return result;
+	Buffer buf;
+	Buf_Init();
+	Buf_AddStr(, archive);
+	Buf_AddStr(, "(");
+	Buf_AddStr(, member);
+	Buf_AddStr(, ")");
+	return Buf_DoneData();
 }
 
 /*
  * Parse an archive specification such as "archive.a(member1 member2.${EXT})",
- * adding nodes for the expanded members to gns.  Nodes are created as
- * necessary.
- *
- * Input:
- *	pp		The start of the specification.
- *	gns		The list on which to place the nodes.
- *	scope		The scope in which to expand variables.
- *
- * Output:
- *	return		True if it was a valid specification.
- *	*pp		Points to the first non-space after the archive spec.
+ * adding nodes for the expanded members to gns.  If successful, advance pp
+ * beyond the archive specification and any trailing whitespace.
  */
 bool
 Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
@@ -274,12 +263,6 @@ Arch_ParseArchive(char **pp, GNodeList *
 			}
 		}
 
-		/*
-		 * If the specification ends without a closing parenthesis,
-		 * chances are there's something wrong (like a missing
-		 * backslash), so it's better to return failure than allow
-		 * such things to happen
-		 */
 		if (*cp == '\0') {
 			Parse_Error(PARSE_FATAL,
 			"No closing parenthesis "
@@ -287,9 +270,6 @@ Arch_ParseArchive(char **pp, GNodeList *
 			return false;
 		}
 
-		/*
-		 * If we didn't move anywhere, we must be done
-		 */
 		if (cp == mem.str)
 			break;
 
@@ -326,8 +306,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 /*
  * Must contain dynamic sources, so we can't
  * deal with it now. Just create an ARCHV node
- * for the thing and let SuffExpandChildren
- * handle it.
+ * and let SuffExpandChildren handle it.
  */
 gn = Targ_GetNode(fullName);
 gn->type |= OP_ARCHV;
@@ -364,13 +343,6 @@ Arch_ParseArchive(char **pp, GNodeList *
 			gn = Targ_GetNode(fullname);
 			free(fullname);
 
-			/*
-			 * We've found the node, but have to make sure the
-			 * rest of the world knows it's an archive member,
-			 * without having to constantly check for parentheses,
-			 * so we type the thing with the OP_ARCHV bit before

CVS commit: src/usr.bin/make/unit-tests

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 20:23:22 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: archive.exp archive.mk

Log Message:
tests/make: test detection of static library files


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/archive.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/archive.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/unit-tests/archive.exp
diff -u src/usr.bin/make/unit-tests/archive.exp:1.7 src/usr.bin/make/unit-tests/archive.exp:1.8
--- src/usr.bin/make/unit-tests/archive.exp:1.7	Fri Oct  9 06:44:42 2020
+++ src/usr.bin/make/unit-tests/archive.exp	Sat Apr 27 20:23:22 2024
@@ -25,4 +25,12 @@ depend-on-existing-member
 Making remove-archive
 rm -f libprog.a
 
+begin library
+Examining libbad.a...up-to-date.
+Examining -lbad...up-to-date.
+Examining libgood.a...library...up-to-date.
+Examining -lgood...library...up-to-date.
+Examining library...nonexistentPHONY node...out-of-date.
+Examining .END...nonexistent...nonexistent and no sources...out-of-date.
+end library
 exit status 0

Index: src/usr.bin/make/unit-tests/archive.mk
diff -u src/usr.bin/make/unit-tests/archive.mk:1.12 src/usr.bin/make/unit-tests/archive.mk:1.13
--- src/usr.bin/make/unit-tests/archive.mk:1.12	Fri Apr  9 14:42:00 2021
+++ src/usr.bin/make/unit-tests/archive.mk	Sat Apr 27 20:23:22 2024
@@ -1,4 +1,4 @@
-# $NetBSD: archive.mk,v 1.12 2021/04/09 14:42:00 christos Exp $
+# $NetBSD: archive.mk,v 1.13 2024/04/27 20:23:22 rillig Exp $
 #
 # Very basic demonstration of handling archives, based on the description
 # in PSD.doc/tutorial.ms.
@@ -24,6 +24,12 @@ all:
 	@${MAKE} -f ${MAKEFILE} depend-on-existing-member
 	@${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
 	@${MAKE} -f ${MAKEFILE} remove-archive
+	@${MAKE} -f ${MAKEFILE} set-up-library
+	@${MAKE} -f ${MAKEFILE} -dm library 2>&1 \
+	| sed -n '/^Examining/p' \
+	| sed 's,\.\.\.modified[^.]*,,'
+	@${MAKE} -f ${MAKEFILE} tear-down-library
+
 
 create-archive: ${ARCHIVE} pre post
 
@@ -58,3 +64,28 @@ pre: .USEBEFORE
 	@echo Making ${.TARGET} ${.OODATE:C,.+,out-of-date,W} ${.OODATE:O}
 post: .USE
 	@echo
+
+
+set-up-library: .PHONY
+	@echo "member" > member.txt
+	@echo "not a library" > libbad.a
+	@ar cr libgood.a member.txt
+	@echo "begin library"
+
+.if make(library)
+.SUFFIXES: .a
+.LIBS: .a
+.endif
+# The two lines for libgood contain the word "library", the two lines for
+# libbad don't.
+#
+# expect: Examining libbad.a...up-to-date.
+# expect: Examining -lbad...up-to-date.
+# expect: Examining libgood.a...library...up-to-date.
+# expect: Examining -lgood...library...up-to-date.
+library: .PHONY libbad.a -lbad libgood.a -lgood
+	: Making ${.TARGET} from ${.ALLSRC}
+
+tear-down-library: .PHONY
+	@echo "end library"
+	@rm member.txt libbad.a libgood.a



CVS commit: src/usr.bin/make/unit-tests

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 20:23:22 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: archive.exp archive.mk

Log Message:
tests/make: test detection of static library files


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/archive.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/archive.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 17:33:47 UTC 2024

Modified Files:
src/usr.bin/make: arch.c lst.c lst.h main.c meta.c parse.c targ.c

Log Message:
make: simplify freeing of lists


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/arch.c
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/lst.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/make/lst.h
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/make/main.c
cvs rdiff -u -r1.207 -r1.208 src/usr.bin/make/meta.c
cvs rdiff -u -r1.721 -r1.722 src/usr.bin/make/parse.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/targ.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/arch.c
diff -u src/usr.bin/make/arch.c:1.215 src/usr.bin/make/arch.c:1.216
--- src/usr.bin/make/arch.c:1.215	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/arch.c	Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 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.215 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -151,9 +151,8 @@ static int ArchSVR4Entry(Arch *, char *,
 
 #ifdef CLEANUP
 static void
-ArchFree(void *ap)
+ArchFree(Arch *a)
 {
-	Arch *a = ap;
 	HashIter hi;
 
 	/* Free memory from hash entries */
@@ -1070,7 +1069,11 @@ void
 Arch_End(void)
 {
 #ifdef CLEANUP
-	Lst_DoneCall(, ArchFree);
+	ArchListNode *ln;
+
+	for (ln = archives.first; ln != NULL; ln = ln->next)
+		ArchFree(ln->datum);
+	Lst_Done();
 #endif
 }
 

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.107 src/usr.bin/make/lst.c:1.108
--- src/usr.bin/make/lst.c:1.107	Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/lst.c	Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -60,13 +60,13 @@ Lst_Done(List *list)
 }
 
 void
-Lst_DoneCall(List *list, LstFreeProc freeProc)
+Lst_DoneFree(List *list)
 {
 	ListNode *ln, *next;
 
 	for (ln = list->first; ln != NULL; ln = next) {
 		next = ln->next;
-		freeProc(ln->datum);
+		free(ln->datum);
 		free(ln);
 	}
 }

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.104 src/usr.bin/make/lst.h:1.105
--- src/usr.bin/make/lst.h:1.104	Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/lst.h	Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.104 2023/12/29 20:43:58 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.105 2024/04/27 17:33:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -98,13 +98,10 @@ struct List {
 	ListNode *last;
 };
 
-/* Free the datum of a node, called before freeing the node itself. */
-typedef void LstFreeProc(void *);
-
-/* Free the list nodes, but not the list itself. */
+/* Free the list nodes. */
 void Lst_Done(List *);
-/* Free the list nodes, freeing the node data using the given function. */
-void Lst_DoneCall(List *, LstFreeProc);
+/* Free the list nodes, as well as each node's datum. */
+void Lst_DoneFree(List *);
 
 #define LST_INIT { NULL, NULL }
 

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.612 src/usr.bin/make/main.c:1.613
--- src/usr.bin/make/main.c:1.612	Sun Mar 10 02:53:37 2024
+++ src/usr.bin/make/main.c	Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.613 2024/04/27 17:33:46 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.612 2024/03/10 02:53:37 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.613 2024/04/27 17:33:46 rillig Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1199,7 +1199,7 @@ ReadBuiltinRules(void)
 		Fatal("%s: cannot open %s.",
 		progname, (const char *)sysMkFiles.first->datum);
 
-	Lst_DoneCall(, free);
+	Lst_DoneFree();
 }
 
 static void
@@ -1564,9 +1564,9 @@ static void
 main_CleanUp(void)
 {
 #ifdef CLEANUP
-	Lst_DoneCall(, free);
-	Lst_DoneCall(, free);
-	Lst_DoneCall(, free);
+	Lst_DoneFree();
+	Lst_DoneFree();
+	Lst_DoneFree();
 #endif
 
 	if (DEBUG(GRAPH2))

Index: 

CVS commit: src/usr.bin/make

2024-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 27 17:33:47 UTC 2024

Modified Files:
src/usr.bin/make: arch.c lst.c lst.h main.c meta.c parse.c targ.c

Log Message:
make: simplify freeing of lists


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/arch.c
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/lst.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/make/lst.h
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/make/main.c
cvs rdiff -u -r1.207 -r1.208 src/usr.bin/make/meta.c
cvs rdiff -u -r1.721 -r1.722 src/usr.bin/make/parse.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/targ.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 26 17:11:22 UTC 2024

Modified Files:
src/usr.bin/make: job.c
src/usr.bin/make/unit-tests: opt-debug-errors-jobs.exp

Log Message:
make: in parallel mode, print the directory in which a job failed

When multiple targets run in parallel, the "stopped in" line may be
several lines away from the "Failed target" line, making them hard to
correlate.


To generate a diff of this commit:
cvs rdiff -u -r1.468 -r1.469 src/usr.bin/make/job.c
cvs rdiff -u -r1.4 -r1.5 \
src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp

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/job.c
diff -u src/usr.bin/make/job.c:1.468 src/usr.bin/make/job.c:1.469
--- src/usr.bin/make/job.c:1.468	Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/job.c	Fri Apr 26 17:11:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.468 2024/04/20 10:18:55 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.469 2024/04/26 17:11:22 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.468 2024/04/20 10:18:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.469 2024/04/26 17:11:22 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1062,6 +1062,7 @@ DebugFailedJob(const Job *job)
 
 	debug_printf("\n");
 	debug_printf("*** Failed target: %s\n", job->node->name);
+	debug_printf("*** In directory: %s\n", curdir);
 	debug_printf("*** Failed commands:\n");
 	for (ln = job->node->commands.first; ln != NULL; ln = ln->next) {
 		const char *cmd = ln->datum;

Index: src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.4 src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.5
--- src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.4	Sun Nov 28 00:02:07 2021
+++ src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp	Fri Apr 26 17:11:22 2024
@@ -2,6 +2,7 @@ echo '3   spaces'; false
 3   spaces
 
 *** Failed target: fail-spaces
+*** In directory: 
 *** Failed commands:
 	echo '3   spaces'; false
 *** [fail-spaces] Error code 1
@@ -11,6 +12,7 @@ echo \  indented; false
   indented
 
 *** Failed target: fail-escaped-space
+*** In directory: 
 *** Failed commands:
 	echo \  indented; false
 *** [fail-escaped-space] Error code 1
@@ -22,6 +24,7 @@ line1
 line2
 
 *** Failed target: fail-newline
+*** In directory: 
 *** Failed commands:
 	echo 'line1${.newline}line2'; false
 	=> echo 'line1
@@ -33,6 +36,7 @@ echo 'line1 line2'; false
 line1 line2
 
 *** Failed target: fail-multiline
+*** In directory: 
 *** Failed commands:
 	echo 'line1 line2'; false
 *** [fail-multiline] Error code 1
@@ -42,6 +46,7 @@ echo	'word1'			 'word2'; false
 word1 word2
 
 *** Failed target: fail-multiline-intention
+*** In directory: 
 *** Failed commands:
 	echo	'word1'			 'word2'; false
 *** [fail-multiline-intention] Error code 1
@@ -49,6 +54,7 @@ word1 word2
 make: stopped in unit-tests
 
 *** Failed target: fail-vars
+*** In directory: 
 *** Failed commands:
 	@${COMPILE_C} ${COMPILE_C_FLAGS}
 	=> @false c-compiler flag1 -macro="several words"



CVS commit: src/usr.bin/make

2024-04-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 26 17:11:22 UTC 2024

Modified Files:
src/usr.bin/make: job.c
src/usr.bin/make/unit-tests: opt-debug-errors-jobs.exp

Log Message:
make: in parallel mode, print the directory in which a job failed

When multiple targets run in parallel, the "stopped in" line may be
several lines away from the "Failed target" line, making them hard to
correlate.


To generate a diff of this commit:
cvs rdiff -u -r1.468 -r1.469 src/usr.bin/make/job.c
cvs rdiff -u -r1.4 -r1.5 \
src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr 23 22:51:28 UTC 2024

Modified Files:
src/usr.bin/make: cond.c make.h parse.c var.c
src/usr.bin/make/unit-tests: cmd-errors-jobs.exp cmd-errors-jobs.mk
cmd-errors-lint.exp cmd-errors-lint.mk cmd-errors.exp cmd-errors.mk
cmdline-undefined.mk cmdline.mk comment.mk cond-cmp-string.mk
cond-func-defined.exp cond-func-defined.mk varmod-ifelse.mk
varmod-match.exp varmod-match.mk

Log Message:
make: clean up comments, code and tests


To generate a diff of this commit:
cvs rdiff -u -r1.362 -r1.363 src/usr.bin/make/cond.c
cvs rdiff -u -r1.330 -r1.331 src/usr.bin/make/make.h
cvs rdiff -u -r1.720 -r1.721 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1104 -r1.1105 src/usr.bin/make/var.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp \
src/usr.bin/make/unit-tests/cmd-errors-lint.exp \
src/usr.bin/make/unit-tests/cmd-errors.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-errors-lint.mk
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cmd-errors.exp \
src/usr.bin/make/unit-tests/cond-func-defined.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline-undefined.mk \
src/usr.bin/make/unit-tests/cmdline.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/comment.mk
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/cond-cmp-string.mk
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-func-defined.mk
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-match.exp
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/unit-tests/varmod-match.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/cond.c
diff -u src/usr.bin/make/cond.c:1.362 src/usr.bin/make/cond.c:1.363
--- src/usr.bin/make/cond.c:1.362	Wed Feb  7 07:21:22 2024
+++ src/usr.bin/make/cond.c	Tue Apr 23 22:51:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.362 2024/02/07 07:21:22 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.363 2024/04/23 22:51:28 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.362 2024/02/07 07:21:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.363 2024/04/23 22:51:28 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -424,13 +424,12 @@ CondParser_StringExpr(CondParser *par, c
  * Parse a string from an expression or an optionally quoted string,
  * on the left-hand and right-hand sides of comparisons.
  *
- * Results:
- *	Returns the string without any enclosing quotes, or NULL on error.
- *	Sets out_quoted if the leaf was a quoted string literal.
+ * Return the string without any enclosing quotes, or NULL on error.
+ * Sets out_quoted if the leaf was a quoted string literal.
  */
-static void
+static FStr
 CondParser_Leaf(CondParser *par, bool doEval, bool unquotedOK,
-		  FStr *out_str, bool *out_quoted)
+		bool *out_quoted)
 {
 	Buffer buf;
 	FStr str;
@@ -492,7 +491,7 @@ return_buf:
 	buf.data = NULL;
 return_str:
 	Buf_Done();
-	*out_str = str;
+	return str;
 }
 
 /*
@@ -602,7 +601,7 @@ CondParser_Comparison(CondParser *par, b
 	ComparisonOp op;
 	bool lhsQuoted, rhsQuoted;
 
-	CondParser_Leaf(par, doEval, par->leftUnquotedOK, , );
+	lhs = CondParser_Leaf(par, doEval, par->leftUnquotedOK, );
 	if (lhs.str == NULL)
 		goto done_lhs;
 
@@ -622,7 +621,7 @@ CondParser_Comparison(CondParser *par, b
 		goto done_lhs;
 	}
 
-	CondParser_Leaf(par, doEval, true, , );
+	rhs = CondParser_Leaf(par, doEval, true, );
 	t = rhs.str == NULL ? TOK_ERROR
 	: !doEval ? TOK_FALSE
 	: EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.330 src/usr.bin/make/make.h:1.331
--- src/usr.bin/make/make.h:1.330	Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/make.h	Tue Apr 23 22:51:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.330 2024/04/20 10:18:55 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.331 2024/04/23 22:51:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -399,7 +399,7 @@ typedef struct SearchPath {
 
 /*
  * A graph node represents a target that can possibly be made, including its
- * relation to other targets and a lot of other details.
+ * relation to other targets.
  */
 typedef struct GNode {
 	/* The target's name, such as "clean" or "make.c" */
@@ -581,8 +581,8 @@ extern GNode *SCOPE_GLOBAL;
 extern GNode *SCOPE_CMDLINE;
 
 /*
- * Value returned by Var_Parse when an error is encountered. It actually
- * points to an empty string, so naive callers needn't worry about it.
+ * Value returned by Var_Parse when an error is 

CVS commit: src/usr.bin/make

2024-04-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr 23 22:51:28 UTC 2024

Modified Files:
src/usr.bin/make: cond.c make.h parse.c var.c
src/usr.bin/make/unit-tests: cmd-errors-jobs.exp cmd-errors-jobs.mk
cmd-errors-lint.exp cmd-errors-lint.mk cmd-errors.exp cmd-errors.mk
cmdline-undefined.mk cmdline.mk comment.mk cond-cmp-string.mk
cond-func-defined.exp cond-func-defined.mk varmod-ifelse.mk
varmod-match.exp varmod-match.mk

Log Message:
make: clean up comments, code and tests


To generate a diff of this commit:
cvs rdiff -u -r1.362 -r1.363 src/usr.bin/make/cond.c
cvs rdiff -u -r1.330 -r1.331 src/usr.bin/make/make.h
cvs rdiff -u -r1.720 -r1.721 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1104 -r1.1105 src/usr.bin/make/var.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp \
src/usr.bin/make/unit-tests/cmd-errors-lint.exp \
src/usr.bin/make/unit-tests/cmd-errors.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-errors-lint.mk
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cmd-errors.exp \
src/usr.bin/make/unit-tests/cond-func-defined.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline-undefined.mk \
src/usr.bin/make/unit-tests/cmdline.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/comment.mk
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/cond-cmp-string.mk
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-func-defined.mk
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-match.exp
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/unit-tests/varmod-match.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 21 21:59:48 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: trim down code for parsing the :gmtime and :localtime modifiers

The :gmtime and :localtime modifiers are not used often and thus are not
time-critical. Exchange the custom code that parses an integer from a
substring for an additional memory allocation.

Thanks sjg@ for suggesting to avoid the custom parsing code.


To generate a diff of this commit:
cvs rdiff -u -r1.1103 -r1.1104 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.1103 src/usr.bin/make/var.c:1.1104
--- src/usr.bin/make/var.c:1.1103	Sun Apr 21 08:56:49 2024
+++ src/usr.bin/make/var.c	Sun Apr 21 21:59:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1103 2024/04/21 08:56:49 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1104 2024/04/21 21:59:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -137,7 +137,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1103 2024/04/21 08:56:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1104 2024/04/21 21:59:48 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2515,26 +2515,6 @@ TryParseTime(const char **pp, time_t *ou
 	return true;
 }
 
-static bool
-Substring_ParseTime(Substring s, time_t *out_time)
-{
-	const char *p;
-	unsigned long n;
-
-	n = 0;
-	for (p = s.start; p != s.end && ch_isdigit(*p); p++) {
-		unsigned long next = 10 * n + ((unsigned)*p - '0');
-		if (next < n)
-			return false;
-		n = next;
-	}
-	if (p == s.start || p != s.end)
-		return false;
-
-	*out_time = (time_t)n;	/* ignore possible truncation for now */
-	return true;
-}
-
 /* :gmtime and :localtime */
 static ApplyModifierResult
 ApplyModifier_Time(const char **pp, ModChain *ch)
@@ -2552,21 +2532,22 @@ ApplyModifier_Time(const char **pp, ModC
 	if (args[0] == '=') {
 		const char *p = args + 1;
 		LazyBuf buf;
+		FStr arg;
 		if (!ParseModifierPartSubst(, true, '\0', ch->expr->emode,
 		ch, , NULL, NULL))
 			return AMR_CLEANUP;
+		arg = LazyBuf_DoneGet();
 		if (ModChain_ShouldEval(ch)) {
-			Substring arg = LazyBuf_Get();
-			if (!Substring_ParseTime(arg, )) {
+			const char *arg_p = arg.str;
+			if (!TryParseTime(_p, ) || *arg_p != '\0') {
 Parse_Error(PARSE_FATAL,
-"Invalid time value \"%.*s\"",
-(int)Substring_Length(arg), arg.start);
-LazyBuf_Done();
+"Invalid time value \"%s\"", arg.str);
+FStr_Done();
 return AMR_CLEANUP;
 			}
 		} else
 			t = 0;
-		LazyBuf_Done();
+		FStr_Done();
 		*pp = p;
 	} else {
 		t = 0;



CVS commit: src/usr.bin/make

2024-04-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 21 21:59:48 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: trim down code for parsing the :gmtime and :localtime modifiers

The :gmtime and :localtime modifiers are not used often and thus are not
time-critical. Exchange the custom code that parses an integer from a
substring for an additional memory allocation.

Thanks sjg@ for suggesting to avoid the custom parsing code.


To generate a diff of this commit:
cvs rdiff -u -r1.1103 -r1.1104 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.



CVS commit: src/usr.bin/make

2024-04-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 21 08:56:49 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix out-of-bounds read when evaluating :gmtime and :localtime

The function TryParseTime takes a pointer to a string, but the LazyBuf
returns a Substring, which is not guaranteed to be null-terminated or
delimited.  In TryParseTime, calling strtoul on the Substring read past
the end of the substring.

Noticed in the NetBSD build in libntp, where the :gmtime modifier is
used in two places with the same timestamp value, of which the first was
evaluated correctly and the second wasn't.

The bug was introduced in var.c 1.1050 from 2023-05-09, when the
argument of the :gmtime and :localtime modifiers was allowed to be an
expression instead of an integer constant.


To generate a diff of this commit:
cvs rdiff -u -r1.1102 -r1.1103 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.1102 src/usr.bin/make/var.c:1.1103
--- src/usr.bin/make/var.c:1.1102	Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/var.c	Sun Apr 21 08:56:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1102 2024/04/20 10:18:55 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1103 2024/04/21 08:56:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -137,7 +137,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1102 2024/04/20 10:18:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1103 2024/04/21 08:56:49 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2515,6 +2515,26 @@ TryParseTime(const char **pp, time_t *ou
 	return true;
 }
 
+static bool
+Substring_ParseTime(Substring s, time_t *out_time)
+{
+	const char *p;
+	unsigned long n;
+
+	n = 0;
+	for (p = s.start; p != s.end && ch_isdigit(*p); p++) {
+		unsigned long next = 10 * n + ((unsigned)*p - '0');
+		if (next < n)
+			return false;
+		n = next;
+	}
+	if (p == s.start || p != s.end)
+		return false;
+
+	*out_time = (time_t)n;	/* ignore possible truncation for now */
+	return true;
+}
+
 /* :gmtime and :localtime */
 static ApplyModifierResult
 ApplyModifier_Time(const char **pp, ModChain *ch)
@@ -2537,8 +2557,7 @@ ApplyModifier_Time(const char **pp, ModC
 			return AMR_CLEANUP;
 		if (ModChain_ShouldEval(ch)) {
 			Substring arg = LazyBuf_Get();
-			const char *arg_p = arg.start;
-			if (!TryParseTime(_p, ) || arg_p != arg.end) {
+			if (!Substring_ParseTime(arg, )) {
 Parse_Error(PARSE_FATAL,
 "Invalid time value \"%.*s\"",
 (int)Substring_Length(arg), arg.start);



CVS commit: src/usr.bin/make

2024-04-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 21 08:56:49 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix out-of-bounds read when evaluating :gmtime and :localtime

The function TryParseTime takes a pointer to a string, but the LazyBuf
returns a Substring, which is not guaranteed to be null-terminated or
delimited.  In TryParseTime, calling strtoul on the Substring read past
the end of the substring.

Noticed in the NetBSD build in libntp, where the :gmtime modifier is
used in two places with the same timestamp value, of which the first was
evaluated correctly and the second wasn't.

The bug was introduced in var.c 1.1050 from 2023-05-09, when the
argument of the :gmtime and :localtime modifiers was allowed to be an
expression instead of an integer constant.


To generate a diff of this commit:
cvs rdiff -u -r1.1102 -r1.1103 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.



CVS commit: src/usr.bin/make

2024-04-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 20 10:18:56 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c make.h parse.c var.c
src/usr.bin/make/unit-tests: Makefile cmd-errors-jobs.exp
cmd-errors-jobs.mk cmd-errors-lint.exp cmd-errors.exp
cond-token-string.exp cond-token-string.mk deptgt.exp deptgt.mk
directive-for-errors.exp directive-for-errors.mk directive-for.exp
directive-for.mk directive-include.exp directive-include.mk
directive-undef.exp directive-undef.mk lint.exp moderrs.exp
opt-debug-lint.exp opt-debug-lint.mk var-eval-short.exp
var-eval-short.mk var-op-expand.exp var-op-expand.mk vardebug.exp
vardebug.mk varmisc.exp varmod-assign.exp varmod-assign.mk
varmod-edge.exp varmod-edge.mk varmod-gmtime.exp varmod-gmtime.mk
varmod-hash.exp varmod-ifelse.exp varmod-ifelse.mk
varmod-indirect.exp varmod-indirect.mk varmod-localtime.exp
varmod-localtime.mk varmod-loop-delete.exp varmod-loop-delete.mk
varmod-loop-varname.exp varmod-loop-varname.mk
varmod-match-escape.exp varmod-match-escape.mk varmod-match.exp
varmod-match.mk varmod-mtime.exp varmod-mtime.mk varmod-range.exp
varmod-range.mk varmod-subst-regex.exp varmod-subst.exp
varmod-to-separator.exp varmod-to-separator.mk varmod.exp varmod.mk
varparse-errors.exp varparse-errors.mk

Log Message:
make: provide more context information for parse/evaluate errors


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/usr.bin/make/compat.c
cvs rdiff -u -r1.467 -r1.468 src/usr.bin/make/job.c
cvs rdiff -u -r1.329 -r1.330 src/usr.bin/make/make.h
cvs rdiff -u -r1.719 -r1.720 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1101 -r1.1102 src/usr.bin/make/var.c
cvs rdiff -u -r1.342 -r1.343 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp \
src/usr.bin/make/unit-tests/cmd-errors-lint.exp \
src/usr.bin/make/unit-tests/varmod-subst.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cmd-errors.exp \
src/usr.bin/make/unit-tests/varmod-mtime.exp
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-token-string.exp \
src/usr.bin/make/unit-tests/directive-include.exp \
src/usr.bin/make/unit-tests/var-eval-short.mk \
src/usr.bin/make/unit-tests/varmod-range.exp \
src/usr.bin/make/unit-tests/varmod-to-separator.exp \
src/usr.bin/make/unit-tests/varparse-errors.mk
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-token-string.mk \
src/usr.bin/make/unit-tests/directive-for-errors.mk \
src/usr.bin/make/unit-tests/directive-undef.exp \
src/usr.bin/make/unit-tests/vardebug.mk \
src/usr.bin/make/unit-tests/varmod-mtime.mk
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/deptgt.exp \
src/usr.bin/make/unit-tests/varmod-match-escape.mk
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/deptgt.mk \
src/usr.bin/make/unit-tests/opt-debug-lint.mk \
src/usr.bin/make/unit-tests/varmod-edge.exp \
src/usr.bin/make/unit-tests/varmod-gmtime.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-for-errors.exp
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/unit-tests/directive-for.exp \
src/usr.bin/make/unit-tests/varmod-gmtime.mk
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/directive-for.mk \
src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/directive-include.mk \
src/usr.bin/make/unit-tests/directive-undef.mk \
src/usr.bin/make/unit-tests/varmod-localtime.exp \
src/usr.bin/make/unit-tests/varmod-to-separator.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/lint.exp \
src/usr.bin/make/unit-tests/varmod-hash.exp \
src/usr.bin/make/unit-tests/varmod-loop-delete.exp \
src/usr.bin/make/unit-tests/varmod-loop-delete.mk
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/unit-tests/moderrs.exp \
src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/opt-debug-lint.exp \
src/usr.bin/make/unit-tests/varmod-indirect.mk \
src/usr.bin/make/unit-tests/varmod-match-escape.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-op-expand.exp \
src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/unit-tests/var-op-expand.mk \
src/usr.bin/make/unit-tests/varmisc.exp \
src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.mk \
src/usr.bin/make/unit-tests/varmod-edge.mk \
src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u 

CVS commit: src/usr.bin/make

2024-04-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 20 10:18:56 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c make.h parse.c var.c
src/usr.bin/make/unit-tests: Makefile cmd-errors-jobs.exp
cmd-errors-jobs.mk cmd-errors-lint.exp cmd-errors.exp
cond-token-string.exp cond-token-string.mk deptgt.exp deptgt.mk
directive-for-errors.exp directive-for-errors.mk directive-for.exp
directive-for.mk directive-include.exp directive-include.mk
directive-undef.exp directive-undef.mk lint.exp moderrs.exp
opt-debug-lint.exp opt-debug-lint.mk var-eval-short.exp
var-eval-short.mk var-op-expand.exp var-op-expand.mk vardebug.exp
vardebug.mk varmisc.exp varmod-assign.exp varmod-assign.mk
varmod-edge.exp varmod-edge.mk varmod-gmtime.exp varmod-gmtime.mk
varmod-hash.exp varmod-ifelse.exp varmod-ifelse.mk
varmod-indirect.exp varmod-indirect.mk varmod-localtime.exp
varmod-localtime.mk varmod-loop-delete.exp varmod-loop-delete.mk
varmod-loop-varname.exp varmod-loop-varname.mk
varmod-match-escape.exp varmod-match-escape.mk varmod-match.exp
varmod-match.mk varmod-mtime.exp varmod-mtime.mk varmod-range.exp
varmod-range.mk varmod-subst-regex.exp varmod-subst.exp
varmod-to-separator.exp varmod-to-separator.mk varmod.exp varmod.mk
varparse-errors.exp varparse-errors.mk

Log Message:
make: provide more context information for parse/evaluate errors


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/usr.bin/make/compat.c
cvs rdiff -u -r1.467 -r1.468 src/usr.bin/make/job.c
cvs rdiff -u -r1.329 -r1.330 src/usr.bin/make/make.h
cvs rdiff -u -r1.719 -r1.720 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1101 -r1.1102 src/usr.bin/make/var.c
cvs rdiff -u -r1.342 -r1.343 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp \
src/usr.bin/make/unit-tests/cmd-errors-lint.exp \
src/usr.bin/make/unit-tests/varmod-subst.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cmd-errors.exp \
src/usr.bin/make/unit-tests/varmod-mtime.exp
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-token-string.exp \
src/usr.bin/make/unit-tests/directive-include.exp \
src/usr.bin/make/unit-tests/var-eval-short.mk \
src/usr.bin/make/unit-tests/varmod-range.exp \
src/usr.bin/make/unit-tests/varmod-to-separator.exp \
src/usr.bin/make/unit-tests/varparse-errors.mk
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-token-string.mk \
src/usr.bin/make/unit-tests/directive-for-errors.mk \
src/usr.bin/make/unit-tests/directive-undef.exp \
src/usr.bin/make/unit-tests/vardebug.mk \
src/usr.bin/make/unit-tests/varmod-mtime.mk
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/deptgt.exp \
src/usr.bin/make/unit-tests/varmod-match-escape.mk
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/deptgt.mk \
src/usr.bin/make/unit-tests/opt-debug-lint.mk \
src/usr.bin/make/unit-tests/varmod-edge.exp \
src/usr.bin/make/unit-tests/varmod-gmtime.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-for-errors.exp
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/make/unit-tests/directive-for.exp \
src/usr.bin/make/unit-tests/varmod-gmtime.mk
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/directive-for.mk \
src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/directive-include.mk \
src/usr.bin/make/unit-tests/directive-undef.mk \
src/usr.bin/make/unit-tests/varmod-localtime.exp \
src/usr.bin/make/unit-tests/varmod-to-separator.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/lint.exp \
src/usr.bin/make/unit-tests/varmod-hash.exp \
src/usr.bin/make/unit-tests/varmod-loop-delete.exp \
src/usr.bin/make/unit-tests/varmod-loop-delete.mk
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/make/unit-tests/moderrs.exp \
src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/opt-debug-lint.exp \
src/usr.bin/make/unit-tests/varmod-indirect.mk \
src/usr.bin/make/unit-tests/varmod-match-escape.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-op-expand.exp \
src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/unit-tests/var-op-expand.mk \
src/usr.bin/make/unit-tests/varmisc.exp \
src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.mk \
src/usr.bin/make/unit-tests/varmod-edge.mk \
src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u 

CVS commit: src/usr.bin/make

2024-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 14 15:21:20 UTC 2024

Modified Files:
src/usr.bin/make: str.c

Log Message:
make: make string matching platform-independent

Previously, whether the character range '[a-ä]' matched, depended on the
signedness of the plain 'char' type.  Since make operates on byte
strings and does not support UTF-8 or other multi-byte character
encodings, this edge case is not expected to occur in practice.

No change in the unit tests as this edge case is not covered by tests.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/make/str.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/str.c
diff -u src/usr.bin/make/str.c:1.102 src/usr.bin/make/str.c:1.103
--- src/usr.bin/make/str.c:1.102	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/str.c	Sun Apr 14 15:21:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.102 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.103 2024/04/14 15:21:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.102 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.103 2024/04/14 15:21:20 rillig Exp $");
 
 
 static HashTable interned_strings;
@@ -297,26 +297,6 @@ Str_Words(const char *str, bool expand)
 }
 
 /*
- * XXX: In the extreme edge case that one of the characters is from the basic
- * execution character set and the other isn't, the result of the comparison
- * differs depending on whether plain char is signed or unsigned.
- *
- * An example is the character range from \xE4 to 'a', where \xE4 may come
- * from U+00E4 'Latin small letter A with diaeresis'.
- *
- * If char is signed, \xE4 evaluates to -28, the first half of the condition
- * becomes -28 <= '0' && '0' <= 'a', which evaluates to true.
- *
- * If char is unsigned, \xE4 evaluates to 228, the second half of the
- * condition becomes 'a' <= '0' && '0' <= 228, which evaluates to false.
- */
-static bool
-in_range(char e1, char c, char e2)
-{
-	return (e1 <= c && c <= e2) || (e2 <= c && c <= e1);
-}
-
-/*
  * Test if a string matches a pattern like "*.[ch]". The pattern matching
  * characters are '*', '?' and '[]', as in fnmatch(3).
  *
@@ -360,7 +340,11 @@ match_fixed_length:
 return res;
 			}
 			if (pat[1] == '-') {
-if (in_range(pat[0], *str, pat[2]))
+unsigned char e1 = (unsigned char)pat[0];
+unsigned char c = (unsigned char)*str;
+unsigned char e2 = (unsigned char)pat[2];
+if ((e1 <= c && c <= e2)
+|| (e2 <= c && c <= e1))
 	goto end_of_char_list;
 pat += 2;
 			}



CVS commit: src/usr.bin/make

2024-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 14 15:21:20 UTC 2024

Modified Files:
src/usr.bin/make: str.c

Log Message:
make: make string matching platform-independent

Previously, whether the character range '[a-ä]' matched, depended on the
signedness of the plain 'char' type.  Since make operates on byte
strings and does not support UTF-8 or other multi-byte character
encodings, this edge case is not expected to occur in practice.

No change in the unit tests as this edge case is not covered by tests.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/make/str.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 14 12:30:48 UTC 2024

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: directive-export-impl.exp
directive-for-escape.exp opt-debug-parse.exp var-eval-short.exp
varmod-loop.exp varname-dot-shell.exp

Log Message:
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.


To generate a diff of this commit:
cvs rdiff -u -r1.718 -r1.719 src/usr.bin/make/parse.c
cvs rdiff -u -r1.17 -r1.18 \
src/usr.bin/make/unit-tests/directive-export-impl.exp
cvs rdiff -u -r1.23 -r1.24 \
src/usr.bin/make/unit-tests/directive-for-escape.exp \
src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/opt-debug-parse.exp
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/unit-tests/varmod-loop.exp
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/varname-dot-shell.exp

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/parse.c
diff -u src/usr.bin/make/parse.c:1.718 src/usr.bin/make/parse.c:1.719
--- src/usr.bin/make/parse.c:1.718	Mon Apr  1 12:26:02 2024
+++ src/usr.bin/make/parse.c	Sun Apr 14 12:30:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.718 2024/04/01 12:26:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.719 2024/04/14 12:30:47 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.718 2024/04/01 12:26:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.719 2024/04/14 12:30:47 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -2607,6 +2607,7 @@ ReadHighLevelLine(void)
 		if (line == NULL)
 			return NULL;
 
+		DEBUG2(PARSE, "Parsing line %u: %s\n", curFile->lineno, line);
 		if (curFile->guardState != GS_NO
 		&& ((curFile->guardState == GS_START && line[0] != '.')
 			|| curFile->guardState == GS_DONE))
@@ -2929,8 +2930,6 @@ Parse_File(const char *name, int fd)
 
 	do {
 		while ((line = ReadHighLevelLine()) != NULL) {
-			DEBUG2(PARSE, "Parsing line %u: %s\n",
-			CurFile()->lineno, line);
 			ParseLine(line);
 		}
 	} while (ParseEOF());

Index: src/usr.bin/make/unit-tests/directive-export-impl.exp
diff -u src/usr.bin/make/unit-tests/directive-export-impl.exp:1.17 src/usr.bin/make/unit-tests/directive-export-impl.exp:1.18
--- src/usr.bin/make/unit-tests/directive-export-impl.exp:1.17	Thu Mar  3 19:36:35 2022
+++ src/usr.bin/make/unit-tests/directive-export-impl.exp	Sun Apr 14 12:30:47 2024
@@ -10,6 +10,7 @@ Pattern for ':N' is "*"
 ModifyWords: split "<>" into 1 word
 Result of ${UT_VAR:N*} is ""
 ParseDependency(: )
+Parsing line 42: .if ${:!echo "\$UT_VAR"!} != "<>"
 CondParser_Eval: ${:!echo "\$UT_VAR"!} != "<>"
 Var_Parse: ${:!echo "\$UT_VAR"!} != "<>" (eval-defined)
 Evaluating modifier ${:!...} on value "" (eval-defined, undefined)
@@ -34,6 +35,7 @@ Result of ${UT_VAR:N*} is ""
 ParseDependency(: )
 Parsing line 54: REF=		defined
 Global: REF = defined
+Parsing line 58: .if ${:!echo "\$UT_VAR"!} != ""
 CondParser_Eval: ${:!echo "\$UT_VAR"!} != ""
 Var_Parse: ${:!echo "\$UT_VAR"!} != "" (eval-defined)
 Evaluating modifier ${:!...} on value "" (eval-defined, undefined)

Index: src/usr.bin/make/unit-tests/directive-for-escape.exp
diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.23 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.24
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.23	Sun Nov 19 22:06:15 2023
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Sun Apr 14 12:30:47 2024
@@ -106,6 +106,7 @@ make: "directive-for-escape.mk" line 228
 For: end for 1
 For: loop body with i = "
 ":
+Parsing line 244: .for i in "${.newline}"
 For: end for 1
 Parse_PushInput: .for loop in directive-for-escape.mk, line 244
 make: "directive-for-escape.mk" line 244: newline in .for value
Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.23 src/usr.bin/make/unit-tests/var-eval-short.exp:1.24
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.23	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/var-eval-short.exp	Sun Apr 14 12:30:47 2024
@@ -1,5 +1,6 @@
 make: "var-eval-short.mk" line 46: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar
 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)
 Parsing modifier ${0:?...}
@@ -10,6 +11,7 @@ Modifier part: "${FAIL}else"
 Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
 Parsing line 167: DEFINED=	defined
 Global: 

CVS commit: src/usr.bin/make

2024-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 14 12:30:48 UTC 2024

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: directive-export-impl.exp
directive-for-escape.exp opt-debug-parse.exp var-eval-short.exp
varmod-loop.exp varname-dot-shell.exp

Log Message:
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.


To generate a diff of this commit:
cvs rdiff -u -r1.718 -r1.719 src/usr.bin/make/parse.c
cvs rdiff -u -r1.17 -r1.18 \
src/usr.bin/make/unit-tests/directive-export-impl.exp
cvs rdiff -u -r1.23 -r1.24 \
src/usr.bin/make/unit-tests/directive-for-escape.exp \
src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/opt-debug-parse.exp
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/unit-tests/varmod-loop.exp
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/varname-dot-shell.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-04-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr  2 15:05:15 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: opt-keep-going-indirect.mk

Log Message:
tests/make: pass PATH onto child processes

This fixes the tests on some Cygwin variant where the shell does not
initialize the PATH environment variable when it's missing.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/usr.bin/make/unit-tests/opt-keep-going-indirect.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/unit-tests/opt-keep-going-indirect.mk
diff -u src/usr.bin/make/unit-tests/opt-keep-going-indirect.mk:1.2 src/usr.bin/make/unit-tests/opt-keep-going-indirect.mk:1.3
--- src/usr.bin/make/unit-tests/opt-keep-going-indirect.mk:1.2	Sat Feb 12 20:05:36 2022
+++ src/usr.bin/make/unit-tests/opt-keep-going-indirect.mk	Tue Apr  2 15:05:15 2024
@@ -1,4 +1,4 @@
-# $NetBSD: opt-keep-going-indirect.mk,v 1.2 2022/02/12 20:05:36 rillig Exp $
+# $NetBSD: opt-keep-going-indirect.mk,v 1.3 2024/04/02 15:05:15 rillig Exp $
 #
 # Tests for the -k command line option, which stops building a target as soon
 # as an error is detected, but continues building the other, independent
@@ -49,19 +49,19 @@
 # to the child processes.
 all:
 	@echo 'direct compat'
-	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct; echo "exited $$?"
+	@set +e; env -i "PATH=$$PATH" ${MAKE} -r -f ${MAKEFILE} -k direct; echo "exited $$?"
 	@echo
 
 	@echo 'direct jobs'
-	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct -j1; echo "exited $$?"
+	@set +e; env -i "PATH=$$PATH" ${MAKE} -r -f ${MAKEFILE} -k direct -j1; echo "exited $$?"
 	@echo
 
 	@echo 'indirect compat'
-	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect; echo "exited $$?"
+	@set +e; env -i "PATH=$$PATH" ${MAKE} -r -f ${MAKEFILE} -k indirect; echo "exited $$?"
 	@echo
 
 	@echo 'indirect jobs'
-	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect -j1; echo "exited $$?"
+	@set +e; env -i "PATH=$$PATH" ${MAKE} -r -f ${MAKEFILE} -k indirect -j1; echo "exited $$?"
 	@echo
 
 indirect: direct



CVS commit: src/usr.bin/make/unit-tests

2024-04-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr  2 15:05:15 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: opt-keep-going-indirect.mk

Log Message:
tests/make: pass PATH onto child processes

This fixes the tests on some Cygwin variant where the shell does not
initialize the PATH environment variable when it's missing.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/usr.bin/make/unit-tests/opt-keep-going-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-04-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr  2 11:11:00 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: opt-chdir.exp opt-chdir.mk

Log Message:
tests/make: remove test for overly long chdir argument

On Cygwin, the path '/././..././' is normalized before being passed to
the child 'make' process. Since overly long pathnames are not required
to be supported on all platforms, remove the test.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/opt-chdir.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/opt-chdir.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/unit-tests/opt-chdir.exp
diff -u src/usr.bin/make/unit-tests/opt-chdir.exp:1.3 src/usr.bin/make/unit-tests/opt-chdir.exp:1.4
--- src/usr.bin/make/unit-tests/opt-chdir.exp:1.3	Sun Dec 27 11:47:04 2020
+++ src/usr.bin/make/unit-tests/opt-chdir.exp	Tue Apr  2 11:11:00 2024
@@ -1,5 +1,3 @@
-make: chdir /././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././
 ././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././.
 /././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././
 

CVS commit: src/usr.bin/make/unit-tests

2024-04-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr  2 11:11:00 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: opt-chdir.exp opt-chdir.mk

Log Message:
tests/make: remove test for overly long chdir argument

On Cygwin, the path '/././..././' is normalized before being passed to
the child 'make' process. Since overly long pathnames are not required
to be supported on all platforms, remove the test.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/opt-chdir.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/opt-chdir.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr  1 12:33:28 UTC 2024

Modified Files:
src/usr.bin/make: for.c

Log Message:
make: remove unreachable code in handling .for loops


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.178 src/usr.bin/make/for.c:1.179
--- src/usr.bin/make/for.c:1.178	Sun Jan 21 15:02:17 2024
+++ src/usr.bin/make/for.c	Mon Apr  1 12:33:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.178 2024/01/21 15:02:17 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.179 2024/04/01 12:33:27 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.178 2024/01/21 15:02:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.179 2024/04/01 12:33:27 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -196,11 +196,7 @@ ForLoop_ParseItems(ForLoop *f, const cha
 	cpp_skip_whitespace();
 
 	items = Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES);
-	if (items == var_Error) {
-		/* TODO: Make this part of the code reachable. */
-		Parse_Error(PARSE_FATAL, "Error in .for loop items");
-		return false;
-	}
+	/* TODO: handle errors */
 
 	f->items = Substring_Words(items, false);
 	free(items);
@@ -490,12 +486,11 @@ ForLoop_SubstBody(ForLoop *f, unsigned i
 			p += 2;
 			ForLoop_SubstVarLong(f, firstItem, body,
 			, endc, );
-		} else if (p[1] != '\0') {
+		} else {
 			ForLoop_SubstVarShort(f, firstItem, body,
 			p + 1, );
 			p += 2;
-		} else
-			break;
+		}
 	}
 
 	Buf_AddRange(body, mark, end);



CVS commit: src/usr.bin/make

2024-04-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr  1 12:33:28 UTC 2024

Modified Files:
src/usr.bin/make: for.c

Log Message:
make: remove unreachable code in handling .for loops


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/make/for.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr  1 12:26:02 UTC 2024

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: directive-for-null.exp
directive-for-null.mk opt-file.exp opt-file.mk

Log Message:
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.


To generate a diff of this commit:
cvs rdiff -u -r1.717 -r1.718 src/usr.bin/make/parse.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-for-null.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-for-null.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/opt-file.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/opt-file.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-04-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr  1 12:26:02 UTC 2024

Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: directive-for-null.exp
directive-for-null.mk opt-file.exp opt-file.mk

Log Message:
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.


To generate a diff of this commit:
cvs rdiff -u -r1.717 -r1.718 src/usr.bin/make/parse.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-for-null.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-for-null.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/opt-file.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/opt-file.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/parse.c
diff -u src/usr.bin/make/parse.c:1.717 src/usr.bin/make/parse.c:1.718
--- src/usr.bin/make/parse.c:1.717	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/parse.c	Mon Apr  1 12:26:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.717 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.718 2024/04/01 12:26:02 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.717 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.718 2024/04/01 12:26:02 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -2368,7 +2368,7 @@ ParseRawLine(IncludedFile *curFile, char
 		ch = *p;
 		if (ch == '\0' || (ch == '\\' && p[1] == '\0')) {
 			Parse_Error(PARSE_FATAL, "Zero byte read from file");
-			return PRLR_ERROR;
+			exit(2);
 		}
 
 		/* Treat next character after '\' as literal. */

Index: src/usr.bin/make/unit-tests/directive-for-null.exp
diff -u src/usr.bin/make/unit-tests/directive-for-null.exp:1.2 src/usr.bin/make/unit-tests/directive-for-null.exp:1.3
--- src/usr.bin/make/unit-tests/directive-for-null.exp:1.2	Thu Dec  9 20:13:10 2021
+++ src/usr.bin/make/unit-tests/directive-for-null.exp	Mon Apr  1 12:26:02 2024
@@ -1,9 +1,5 @@
 make: "(stdin)" line 2: Zero byte read from file
-make: "(stdin)" line 2: Unexpected end of file in .for loop
-make: "(stdin)" line 3: Zero byte read from file
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-*** Error code 1 (continuing)
+*** Error code 2 (continuing)
 
 Stop.
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/directive-for-null.mk
diff -u src/usr.bin/make/unit-tests/directive-for-null.mk:1.3 src/usr.bin/make/unit-tests/directive-for-null.mk:1.4
--- src/usr.bin/make/unit-tests/directive-for-null.mk:1.3	Sun Jun 12 15:03:27 2022
+++ src/usr.bin/make/unit-tests/directive-for-null.mk	Mon Apr  1 12:26:02 2024
@@ -1,18 +1,8 @@
-# $NetBSD: directive-for-null.mk,v 1.3 2022/06/12 15:03:27 rillig Exp $
+# $NetBSD: directive-for-null.mk,v 1.4 2024/04/01 12:26:02 rillig Exp $
 #
 # Test for parsing a .for loop that accidentally contains a null byte.
 #
-# As of 2020-12-19, there are 3 error messages:
-#
-#	make: "(stdin)" line 2: Zero byte read from file
-#	make: "(stdin)" line 2: Unexpected end of file in for loop.
-#	make: "(stdin)" line 3: Zero byte read from file
-#
-# The one about "end of file" might be misleading but is due to the
-# implementation.  On both errors and EOF, ParseRawLine returns NULL.
-#
-# The one about the "zero byte" in line 3 is surprising since the only
-# line that contains a null byte is line 2.
+# expect: make: "(stdin)" line 2: Zero byte read from file
 
 all: .PHONY
 	@printf '%s\n' \

Index: src/usr.bin/make/unit-tests/opt-file.exp
diff -u src/usr.bin/make/unit-tests/opt-file.exp:1.7 src/usr.bin/make/unit-tests/opt-file.exp:1.8
--- src/usr.bin/make/unit-tests/opt-file.exp:1.7	Tue Dec 22 08:51:30 2020
+++ src/usr.bin/make/unit-tests/opt-file.exp	Mon Apr  1 12:26:02 2024
@@ -2,9 +2,7 @@ value
 value
 line-with-trailing-whitespace
 make: "(stdin)" line 1: Zero byte read from file
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-*** Error code 1 (continuing)
+*** Error code 2 (continuing)
 `all' not remade because of errors.
 
 Stop.

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.15 src/usr.bin/make/unit-tests/opt-file.mk:1.16
--- src/usr.bin/make/unit-tests/opt-file.mk:1.15	Sat Mar 26 13:32:31 2022
+++ src/usr.bin/make/unit-tests/opt-file.mk	Mon Apr  1 12:26:02 2024
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.15 2022/03/26 13:32:31 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.16 2024/04/01 12:26:02 rillig Exp $
 #
 # Tests for the -f command line option, which adds a makefile to the list of
 # files that are parsed.
@@ -79,7 +79,7 @@ line-with-trailing-whitespace: .PHONY
 #	exit status 0
 #
 #	2008 to 2010:
-#	make: 

CVS commit: src/usr.bin/make

2024-03-09 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Mar 10 02:53:38 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.1 make.h targ.c

Log Message:
make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/usr.bin/make/compat.c
cvs rdiff -u -r1.466 -r1.467 src/usr.bin/make/job.c
cvs rdiff -u -r1.611 -r1.612 src/usr.bin/make/main.c
cvs rdiff -u -r1.374 -r1.375 src/usr.bin/make/make.1
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/make/make.h
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/targ.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/compat.c
diff -u src/usr.bin/make/compat.c:1.253 src/usr.bin/make/compat.c:1.254
--- src/usr.bin/make/compat.c:1.253	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/compat.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.253 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: compat.c,v 1.254 2024/03/10 02:53:37 sjg 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.253 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.254 2024/03/10 02:53:37 sjg Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -390,6 +390,8 @@ Compat_RunCommand(const char *cmdp, GNod
 meta_job_error(NULL, gn, false, status);
 #endif
 			gn->made = ERROR;
+			if (WIFEXITED(reason))
+gn->exit_status = status;
 			if (opts.keepgoing) {
 /*
  * Abort the current target,

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.466 src/usr.bin/make/job.c:1.467
--- src/usr.bin/make/job.c:1.466	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/job.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.466 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg 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.466 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2044,6 +2044,8 @@ JobReapChild(pid_t pid, int status, bool
 
 	job->status = JOB_ST_FINISHED;
 	job->exit_status = status;
+	if (WIFEXITED(status))
+		job->node->exit_status = WEXITSTATUS(status);
 
 	JobFinish(job, status);
 }

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.611 src/usr.bin/make/main.c:1.612
--- src/usr.bin/make/main.c:1.611	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/main.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.611 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg 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.611 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -2037,10 +2037,13 @@ static void
 SetErrorVars(GNode *gn)
 {
 	StringListNode *ln;
+	char sts[16];
 
 	/*
 	 * We can print this even if there is no .ERROR target.
 	 */
+	snprintf(sts, sizeof(sts), "%d", gn->exit_status);
+	Global_Set(".ERROR_EXIT", sts);
 	Global_Set(".ERROR_TARGET", gn->name);
 	Global_Delete(".ERROR_CMD");
 

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.374 src/usr.bin/make/make.1:1.375
--- src/usr.bin/make/make.1:1.374	Thu Jan 25 21:00:59 2024
+++ src/usr.bin/make/make.1	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.374 2024/01/25 21:00:59 sjg Exp $
+.\"	$NetBSD: make.1,v 1.375 2024/03/10 02:53:37 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 January 24, 2024
+.Dd March 9, 2024
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -879,6 +879,9 @@ Is used in error handling, see
 .It Va .ERROR_CWD
 Is used in error handling, see
 .Va MAKE_PRINT_VAR_ON_ERROR .
+.It Va .ERROR_EXIT
+Is used in error handling, see
+.Va MAKE_PRINT_VAR_ON_ERROR .
 .It Va .ERROR_META_FILE
 Is used in error handling in
 .Dq meta
@@ -1185,6 +1188,8 @@ When
 stops due to an error, it sets
 .Sq Va .ERROR_TARGET
 to the name of the target that failed,
+.Sq Va .ERROR_EXIT
+to the exit status of the failed target,
 .Sq Va 

CVS commit: src/usr.bin/make

2024-03-09 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Mar 10 02:53:38 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.1 make.h targ.c

Log Message:
make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/usr.bin/make/compat.c
cvs rdiff -u -r1.466 -r1.467 src/usr.bin/make/job.c
cvs rdiff -u -r1.611 -r1.612 src/usr.bin/make/main.c
cvs rdiff -u -r1.374 -r1.375 src/usr.bin/make/make.1
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/make/make.h
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/targ.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-03-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 23:07:58 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables.  To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/var-scope-local.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-03-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar  5 23:07:58 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables.  To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/var-scope-local.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/unit-tests/var-scope-local.exp
diff -u src/usr.bin/make/unit-tests/var-scope-local.exp:1.8 src/usr.bin/make/unit-tests/var-scope-local.exp:1.9
--- src/usr.bin/make/unit-tests/var-scope-local.exp:1.8	Fri Mar  1 20:15:59 2024
+++ src/usr.bin/make/unit-tests/var-scope-local.exp	Tue Mar  5 23:07:58 2024
@@ -60,19 +60,12 @@ dir/subdir/inference-rule-chain.ir-to: *
 : Making var-scope-local.c out of nothing.
 : Making var-scope-local.o from var-scope-local.c.
 : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".".
-: Making var-scope-local-assign.o with VAR="local".
-var-scope-local-assign.o env has VAR='local'
-: Making var-scope-local-append.o with VAR="local to var-scope-local-append.o".
-var-scope-local-append.o env has VAR='local to var-scope-local-append.o'
-: Making var-scope-local-append-global.o with VAR="global+local".
-var-scope-local-append-global.o env has VAR='global+local'
-: Making var-scope-local-default.o with VAR="global".
-var-scope-local-default.o env has VAR='global'
-: Making var-scope-local-subst.o with VAR="global+local".
-var-scope-local-subst.o env has VAR='global+local'
-: Making var-scope-local-shell.o with VAR="output".
-var-scope-local-shell.o env has VAR='output'
-: var-scope-local-use.o uses .USE VAR="global"
-var-scope-local-use.o env has VAR='global'
+Making var-scope-local-assign.o with make 'local' and env 'local'.
+Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
+Making var-scope-local-append-global.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-default.o with make 'global' and env 'global'.
+Making var-scope-local-subst.o with make 'global+local' and env 'global+local'.
+Making var-scope-local-shell.o with make 'output' and env 'output'.
+Making .USE var-scope-local-use.o with make 'global' and env 'global'.
 : all overwritten
 exit status 0

Index: src/usr.bin/make/unit-tests/var-scope-local.mk
diff -u src/usr.bin/make/unit-tests/var-scope-local.mk:1.10 src/usr.bin/make/unit-tests/var-scope-local.mk:1.11
--- src/usr.bin/make/unit-tests/var-scope-local.mk:1.10	Fri Mar  1 20:15:59 2024
+++ src/usr.bin/make/unit-tests/var-scope-local.mk	Tue Mar  5 23:07:58 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-scope-local.mk,v 1.10 2024/03/01 20:15:59 sjg Exp $
+# $NetBSD: var-scope-local.mk,v 1.11 2024/03/05 23:07:58 rillig Exp $
 #
 # Tests for target-local variables, such as ${.TARGET} or $@.  These variables
 # are relatively short-lived as they are created just before making the
@@ -199,8 +199,7 @@ var-scope-local-append-global.o \
 var-scope-local-default.o \
 var-scope-local-subst.o \
 var-scope-local-shell.o:
-	: Making ${.TARGET} with VAR="${VAR}".
-	@echo "${.TARGET} env has VAR='$$VAR'"
+	@echo "Making ${.TARGET} with make '"${VAR:Q}"' and env '$$VAR'."
 
 # Target-local variables are enabled by default.  Force them to be enabled
 # just in case a test above has disabled them.
@@ -215,7 +214,7 @@ VAR=	global
 # irrelevant.
 #
 # expect-reset
-# expect: : Making var-scope-local-assign.o with VAR="local".
+# expect: Making var-scope-local-assign.o with make 'local' and env 'local'.
 var-scope-local-assign.o: VAR= local
 
 # Assignments using '+=' do *not* look up the global value, instead they only
@@ -225,7 +224,7 @@ var-scope-local-append.o: VAR+= local
 # behaves as expected.  Note that the expression '${.TARGET}' is not resolved
 # when parsing the dependency line, its evaluation is deferred until the
 # target is actually made.
-# expect: : Making var-scope-local-append.o with VAR="local to var-scope-local-append.o".
+# expect: Making var-scope-local-append.o with make 'local to var-scope-local-append.o' and env 'local to var-scope-local-append.o'.
 var-scope-local-append.o: VAR += to ${.TARGET}
 # To access the value of a global variable, use an expression.  This
 # expression is expanded before parsing the whole dependency line.  Since the
@@ -235,7 +234,7 @@ var-scope-local-append.o: VAR += to ${.T
 # not influence the parsing of the variable assignment.  The effective
 # variable assignment, after expanding the whole line first, is thus
 # 'VAR= global+local'.
-# expect: : Making 

CVS commit: src/usr.bin/make/unit-tests

2024-03-01 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Mar  1 20:15:59 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
make: update var-scope-local test

Show what VAR value is in environment of target script.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/var-scope-local.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/unit-tests/var-scope-local.exp
diff -u src/usr.bin/make/unit-tests/var-scope-local.exp:1.7 src/usr.bin/make/unit-tests/var-scope-local.exp:1.8
--- src/usr.bin/make/unit-tests/var-scope-local.exp:1.7	Wed Dec 20 09:03:09 2023
+++ src/usr.bin/make/unit-tests/var-scope-local.exp	Fri Mar  1 20:15:59 2024
@@ -61,11 +61,18 @@ dir/subdir/inference-rule-chain.ir-to: *
 : Making var-scope-local.o from var-scope-local.c.
 : Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".".
 : Making var-scope-local-assign.o with VAR="local".
+var-scope-local-assign.o env has VAR='local'
 : Making var-scope-local-append.o with VAR="local to var-scope-local-append.o".
+var-scope-local-append.o env has VAR='local to var-scope-local-append.o'
 : Making var-scope-local-append-global.o with VAR="global+local".
+var-scope-local-append-global.o env has VAR='global+local'
 : Making var-scope-local-default.o with VAR="global".
+var-scope-local-default.o env has VAR='global'
 : Making var-scope-local-subst.o with VAR="global+local".
+var-scope-local-subst.o env has VAR='global+local'
 : Making var-scope-local-shell.o with VAR="output".
+var-scope-local-shell.o env has VAR='output'
 : var-scope-local-use.o uses .USE VAR="global"
+var-scope-local-use.o env has VAR='global'
 : all overwritten
 exit status 0

Index: src/usr.bin/make/unit-tests/var-scope-local.mk
diff -u src/usr.bin/make/unit-tests/var-scope-local.mk:1.9 src/usr.bin/make/unit-tests/var-scope-local.mk:1.10
--- src/usr.bin/make/unit-tests/var-scope-local.mk:1.9	Wed Dec 20 09:03:09 2023
+++ src/usr.bin/make/unit-tests/var-scope-local.mk	Fri Mar  1 20:15:59 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-scope-local.mk,v 1.9 2023/12/20 09:03:09 rillig Exp $
+# $NetBSD: var-scope-local.mk,v 1.10 2024/03/01 20:15:59 sjg Exp $
 #
 # Tests for target-local variables, such as ${.TARGET} or $@.  These variables
 # are relatively short-lived as they are created just before making the
@@ -200,12 +200,14 @@ var-scope-local-default.o \
 var-scope-local-subst.o \
 var-scope-local-shell.o:
 	: Making ${.TARGET} with VAR="${VAR}".
+	@echo "${.TARGET} env has VAR='$$VAR'"
 
 # Target-local variables are enabled by default.  Force them to be enabled
 # just in case a test above has disabled them.
 .MAKE.TARGET_LOCAL_VARIABLES= yes
 
 VAR=	global
+.export VAR
 
 # If the sources of a dependency line look like a variable assignment, make
 # treats them as such.  There is only a single variable assignment per
@@ -264,6 +266,7 @@ var-scope-local-shell.o: VAR != echo out
 # expect: : var-scope-local-use.o uses .USE VAR="global"
 a_use: .USE VAR=use
 	: ${.TARGET} uses .USE VAR="${VAR}"
+	@echo "${.TARGET} env has VAR='$$VAR'"
 
 all: var-scope-local-use.o
 var-scope-local-use.o: a_use



CVS commit: src/usr.bin/make/unit-tests

2024-03-01 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Mar  1 20:15:59 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
make: update var-scope-local test

Show what VAR value is in environment of target script.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/var-scope-local.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/var-scope-local.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:53:30 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix type mismatch in lint's strict bool mode (since today)


To generate a diff of this commit:
cvs rdiff -u -r1.1100 -r1.1101 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.1100 src/usr.bin/make/var.c:1.1101
--- src/usr.bin/make/var.c:1.1100	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/var.c	Fri Mar  1 17:53:30 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1100 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.1101 2024/03/01 17:53:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -137,7 +137,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1100 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1101 2024/03/01 17:53:30 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -612,9 +612,9 @@ ExportVarEnv(Var *v, GNode *scope)
 	expr = str_concat3("${", name, "}");
 	val = Var_Subst(expr, scope, VARE_WANTRES);
 	if (scope != SCOPE_GLOBAL) {
-		/* we will need to re-rexport the Global version */
+		/* we will need to re-export the global version */
 		v = VarFind(name, SCOPE_GLOBAL, false);
-		if (v)
+		if (v != NULL)
 			v->exported = false;
 	}
 	/* TODO: handle errors */



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:53:30 UTC 2024

Modified Files:
src/usr.bin/make: var.c

Log Message:
make: fix type mismatch in lint's strict bool mode (since today)


To generate a diff of this commit:
cvs rdiff -u -r1.1100 -r1.1101 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.



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:47:05 UTC 2024

Modified Files:
src/usr.bin/make: test-variants.mk

Log Message:
make: remove test variant for NO_REGEX

The compile-time toggle was removed in var.c 1.1099 from 2024-02-07.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/test-variants.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/test-variants.mk
diff -u src/usr.bin/make/test-variants.mk:1.5 src/usr.bin/make/test-variants.mk:1.6
--- src/usr.bin/make/test-variants.mk:1.5	Thu Jan 19 19:55:27 2023
+++ src/usr.bin/make/test-variants.mk	Fri Mar  1 17:47:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: test-variants.mk,v 1.5 2023/01/19 19:55:27 rillig Exp $
+# $NetBSD: test-variants.mk,v 1.6 2024/03/01 17:47:05 rillig Exp $
 #
 # Build several variants of make and run the tests on them.
 #
@@ -81,15 +81,6 @@ TESTS+=			maxpathlen
 CPPFLAGS.maxpathlen=	-DMAXPATHLEN=20
 SKIP.maxpathlen=	yes
 
-# In this variant, the unit tests using the modifier ':C' fail, as expected.
-#
-TESTS+=			no-regex
-CPPFLAGS.no-regex=	-DNO_REGEX
-SKIP_TESTS.no-regex=	archive cond-short deptgt-makeflags dollar export-all
-SKIP_TESTS.no-regex+=	moderrs modmatch modmisc var-eval-short
-SKIP_TESTS.no-regex+=	varmod-select-words varmod-subst varmod-subst-regex
-SKIP_TESTS.no-regex+=	varname-dot-make-pid varname-dot-make-ppid
-
 # NetBSD 8.0 x86_64 says:
 # In file included from /usr/include/sys/param.h:115:0,
 # from arch.c:135:



CVS commit: src/usr.bin/make

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:47:05 UTC 2024

Modified Files:
src/usr.bin/make: test-variants.mk

Log Message:
make: remove test variant for NO_REGEX

The compile-time toggle was removed in var.c 1.1099 from 2024-02-07.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/test-variants.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-03-01 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Mar  1 16:41:42 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.h var.c

Log Message:
make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.253 src/usr.bin/make/compat.c
cvs rdiff -u -r1.465 -r1.466 src/usr.bin/make/job.c
cvs rdiff -u -r1.610 -r1.611 src/usr.bin/make/main.c
cvs rdiff -u -r1.327 -r1.328 src/usr.bin/make/make.h
cvs rdiff -u -r1.1099 -r1.1100 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/compat.c
diff -u src/usr.bin/make/compat.c:1.252 src/usr.bin/make/compat.c:1.253
--- src/usr.bin/make/compat.c:1.252	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/compat.c	Fri Mar  1 16:41:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.252 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.253 2024/03/01 16:41:42 sjg 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.252 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.253 2024/03/01 16:41:42 sjg Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -326,7 +326,7 @@ Compat_RunCommand(const char *cmdp, GNod
 		meta_compat_start();
 #endif
 
-	Var_ReexportVars();
+	Var_ReexportVars(gn);
 
 	compatChild = cpid = vfork();
 	if (cpid < 0)

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.465 src/usr.bin/make/job.c:1.466
--- src/usr.bin/make/job.c:1.465	Sun Jan  7 11:39:04 2024
+++ src/usr.bin/make/job.c	Fri Mar  1 16:41:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.465 2024/01/07 11:39:04 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.466 2024/03/01 16:41:42 sjg 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.465 2024/01/07 11:39:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.466 2024/03/01 16:41:42 sjg Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1420,7 +1420,7 @@ JobExec(Job *job, char **argv)
 	/* Pre-emptively mark job running, pid still zero though */
 	job->status = JOB_ST_RUNNING;
 
-	Var_ReexportVars();
+	Var_ReexportVars(job->node);
 
 	cpid = vfork();
 	if (cpid == -1)

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.610 src/usr.bin/make/main.c:1.611
--- src/usr.bin/make/main.c:1.610	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/main.c	Fri Mar  1 16:41:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.610 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.611 2024/03/01 16:41:42 sjg 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.610 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.611 2024/03/01 16:41:42 sjg Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1735,7 +1735,7 @@ Cmd_Exec(const char *cmd, char **error)
 		return bmake_strdup("");
 	}
 
-	Var_ReexportVars();
+	Var_ReexportVars(SCOPE_GLOBAL);
 
 	switch (cpid = vfork()) {
 	case 0:

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.327 src/usr.bin/make/make.h:1.328
--- src/usr.bin/make/make.h:1.327	Sun Dec 17 09:02:26 2023
+++ src/usr.bin/make/make.h	Fri Mar  1 16:41:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.327 2023/12/17 09:02:26 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.328 2024/03/01 16:41:42 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -1011,7 +1011,7 @@ char *Var_Subst(const char *, GNode *, V
 void Var_Expand(FStr *, GNode *, VarEvalMode);
 void Var_Stats(void);
 void Var_Dump(GNode *);
-void Var_ReexportVars(void);
+void Var_ReexportVars(GNode *);
 void Var_Export(VarExportMode, const char *);
 void Var_ExportVars(const char *);
 void Var_UnExport(bool, const char *);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1099 src/usr.bin/make/var.c:1.1100
--- src/usr.bin/make/var.c:1.1099	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/var.c	Fri Mar  1 16:41:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1099 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1100 2024/03/01 16:41:42 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -137,7 +137,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 

CVS commit: src/usr.bin/make

2024-03-01 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Mar  1 16:41:42 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.h var.c

Log Message:
make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.253 src/usr.bin/make/compat.c
cvs rdiff -u -r1.465 -r1.466 src/usr.bin/make/job.c
cvs rdiff -u -r1.610 -r1.611 src/usr.bin/make/main.c
cvs rdiff -u -r1.327 -r1.328 src/usr.bin/make/make.h
cvs rdiff -u -r1.1099 -r1.1100 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.



CVS commit: src/usr.bin/make

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 07:21:22 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: remove redundant comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.361 -r1.362 src/usr.bin/make/cond.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/cond.c
diff -u src/usr.bin/make/cond.c:1.361 src/usr.bin/make/cond.c:1.362
--- src/usr.bin/make/cond.c:1.361	Sun Jan 21 16:32:41 2024
+++ src/usr.bin/make/cond.c	Wed Feb  7 07:21:22 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.361 2024/01/21 16:32:41 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.362 2024/02/07 07:21:22 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.361 2024/01/21 16:32:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.362 2024/02/07 07:21:22 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -394,7 +394,7 @@ CondParser_StringExpr(CondParser *par, c
 {
 	VarEvalMode emode;
 	const char *p;
-	bool atStart;
+	bool atStart;		/* true means an expression outside quotes */
 
 	emode = doEval && quoted ? VARE_WANTRES
 	: doEval ? VARE_UNDEFERR
@@ -411,11 +411,6 @@ CondParser_StringExpr(CondParser *par, c
 	}
 	par->p = p;
 
-	/*
-	 * If the '$' started the string literal (which means no quotes), and
-	 * the expression is followed by a space, a comparison operator or
-	 * the end of the expression, we are done.
-	 */
 	if (atStart && is_separator(par->p[0]))
 		return false;
 
@@ -509,26 +504,12 @@ EvalTruthy(CondParser *par, const char *
 {
 	double num;
 
-	/* For .ifxxx "...", check for non-empty string. */
 	if (quoted)
 		return value[0] != '\0';
-
-	/* For .ifxxx , compare against zero */
 	if (TryParseNumber(value, ))
 		return num != 0.0;
-
-	/*
-	 * For .if ${...}, check for non-empty string.  This is different
-	 * from the evaluation function from that .if variant, which would
-	 * test whether a variable of the given name were defined.
-	 */
-	/*
-	 * XXX: Whitespace should count as empty, just as in
-	 * CondParser_FuncCallEmpty.
-	 */
 	if (par->plain)
 		return value[0] != '\0';
-
 	return par->evalBare(value) != par->negateEvalBare;
 }
 



CVS commit: src/usr.bin/make

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 07:21:22 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: remove redundant comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.361 -r1.362 src/usr.bin/make/cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 06:43:02 UTC 2024

Modified Files:
src/usr.bin/make: arch.c config.h main.c parse.c suff.c var.c

Log Message:
make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/make/arch.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/config.h
cvs rdiff -u -r1.609 -r1.610 src/usr.bin/make/main.c
cvs rdiff -u -r1.716 -r1.717 src/usr.bin/make/parse.c
cvs rdiff -u -r1.377 -r1.378 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1098 -r1.1099 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/arch.c
diff -u src/usr.bin/make/arch.c:1.214 src/usr.bin/make/arch.c:1.215
--- src/usr.bin/make/arch.c:1.214	Sun Nov 19 22:50:11 2023
+++ src/usr.bin/make/arch.c	Wed Feb  7 06:43:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.214 2023/11/19 22:50:11 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 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.214 2023/11/19 22:50:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -978,11 +978,7 @@ Arch_FindLib(GNode *gn, SearchPath *path
 	gn->path = Dir_FindFile(libName, path);
 	free(libName);
 
-#ifdef LIBRARIES
 	Var_Set(gn, TARGET, gn->name);
-#else
-	Var_Set(gn, TARGET, GNode_Path(gn));
-#endif
 }
 
 /* ARGSUSED */

Index: src/usr.bin/make/config.h
diff -u src/usr.bin/make/config.h:1.28 src/usr.bin/make/config.h:1.29
--- src/usr.bin/make/config.h:1.28	Fri Dec 11 22:53:08 2020
+++ src/usr.bin/make/config.h	Wed Feb  7 06:43:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: config.h,v 1.28 2020/12/11 22:53:08 rillig Exp $	*/
+/*	$NetBSD: config.h,v 1.29 2024/02/07 06:43:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -73,20 +73,6 @@
  */
 
 /*
- * INCLUDES
- * LIBRARIES
- *	These control the handling of the .INCLUDES and .LIBS variables.
- *
- *	If INCLUDES is defined, the .INCLUDES variable will be filled
- *	from the search paths of those suffixes which are marked by
- *	.INCLUDES dependency lines. Similarly for LIBRARIES and .LIBS.
- *
- *	See varname-dot-include.mk and varname-dot-libs.mk for more details.
- */
-#define INCLUDES
-#define LIBRARIES
-
-/*
  * LIBSUFF
  *	Is the suffix used to denote libraries and is used by the Suff module
  *	to find the search path on which to seek any -l targets.
@@ -108,40 +94,6 @@
  */
 #define RECHECK
 
-/*
- * POSIX
- *	Adhere to the POSIX 1003.2 draft for the make(1) program.
- *	- Use MAKEFLAGS instead of MAKE to pick arguments from the
- *	  environment.
- */
-#define POSIX
-
-/*
- * SYSVINCLUDE
- *	Recognize system V like include directives [include "filename"]
- *	(required by POSIX 2018)
- * SYSVVARSUB
- *	Recognize system V like ${VAR:x=y} variable substitutions
- *	(required by POSIX 2018)
- */
-#define SYSVINCLUDE
-#define SYSVVARSUB
-
-/*
- * GMAKEEXPORT
- *	Recognize gmake like variable export directives [export =]
- */
-#define GMAKEEXPORT
-
-/*
- * SUNSHCMD
- *	Recognize SunOS and Solaris:
- *		VAR :sh= CMD	# Assign VAR to the command substitution of CMD
- *		${VAR:sh}	# Return the command substitution of the value
- *# of ${VAR}
- */
-#define SUNSHCMD
-
 #if defined(MAKE_NATIVE) && !defined(__ELF__)
 # ifndef RANLIBMAG
 #  define RANLIBMAG "__.SYMDEF"

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.609 src/usr.bin/make/main.c:1.610
--- src/usr.bin/make/main.c:1.609	Sun Jan  7 01:33:57 2024
+++ src/usr.bin/make/main.c	Wed Feb  7 06:43:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.609 2024/01/07 01:33:57 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.610 2024/02/07 06:43:02 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.609 2024/01/07 01:33:57 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.610 2024/02/07 06:43:02 rillig Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1418,20 +1418,11 @@ main_Init(int argc, char **argv)
 #endif
 	Dir_Init();
 
-#ifdef POSIX
 	{
 		char *makeflags = explode(getenv("MAKEFLAGS"));
 		Main_ParseArgLine(makeflags);
 		free(makeflags);
 	}
-#else
-	/*
-	 * First snag any flags out of the MAKE 

CVS commit: src/usr.bin/make

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 06:43:02 UTC 2024

Modified Files:
src/usr.bin/make: arch.c config.h main.c parse.c suff.c var.c

Log Message:
make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/make/arch.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/config.h
cvs rdiff -u -r1.609 -r1.610 src/usr.bin/make/main.c
cvs rdiff -u -r1.716 -r1.717 src/usr.bin/make/parse.c
cvs rdiff -u -r1.377 -r1.378 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1098 -r1.1099 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.



CVS commit: src/usr.bin/make

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 10:03:10 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.


To generate a diff of this commit:
cvs rdiff -u -r1.1097 -r1.1098 src/usr.bin/make/var.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-indirect.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/var.c
diff -u src/usr.bin/make/var.c:1.1097 src/usr.bin/make/var.c:1.1098
--- src/usr.bin/make/var.c:1.1097	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/var.c	Sun Feb  4 10:03:10 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3863,7 +3863,7 @@ ApplyModifiersIndirect(ModChain *ch, con
 	DEBUG3(VAR, "Indirect modifier \"%s\" from \"%.*s\"\n",
 	mods.str, (int)(p - *pp), *pp);
 
-	if (mods.str[0] != '\0') {
+	if (ModChain_ShouldEval(ch) && mods.str[0] != '\0') {
 		const char *modsp = mods.str;
 		ApplyModifiers(expr, , '\0', '\0');
 		if (Expr_Str(expr) == var_Error || *modsp != '\0') {

Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.27
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb  4 10:03:10 2024
@@ -38,12 +38,6 @@ Parsing line 197: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d 0
-make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
-make: "varmod-indirect.mk" line 282: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 282: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
-make: "varmod-indirect.mk" line 288: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 288: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.18
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17	Sun Feb  4 09:56:24 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb  4 10:03:10 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.17 2024/02/04 09:56:24 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.18 2024/02/04 10:03:10 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -258,7 +258,7 @@ _:=	before ${UNDEF:${:UZ}} after
 
 # In parse-only mode, the indirect modifiers must not be evaluated.
 #
-# Before var.c TODO from 2024-02-04, the expression for an indirect modifier
+# Before var.c 1.1098 from 2024-02-04, the expression for an indirect modifier
 # was partially evaluated (only the variable value, without applying any
 # modifiers) and then interpreted as modifiers to the main expression.
 #
@@ -270,20 +270,13 @@ _:=	before ${UNDEF:${:UZ}} after
 # The expression ${M_invalid} starts with the value "Z", which is an unknown
 # modifier.  Trying to apply this unknown modifier generated a warning.
 M_invalid=	Z
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid}})
 .if 0 && ${VAR:${M_invalid}}
 .endif
-# The expression ${M_invalid} starts with the value "Z", and if its modifiers
-# were evaluated, would result in "N*Z", which is a valid modifier.  The
-# modifiers were not applied though, keeping the invalid value "Z".
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
+# The ':S' modifier does not change the expression value in parse-only mode,
+# keeping the "Z", which is then skipped in parse-only mode.
 .if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
 .endif
 # The ':@' modifier does not change the expression value in parse-only mode,
-# keeping the "Z".
-# expect+2: Unknown modifier "Z"
-# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
+# keeping the 

CVS commit: src/usr.bin/make

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 10:03:10 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.


To generate a diff of this commit:
cvs rdiff -u -r1.1097 -r1.1098 src/usr.bin/make/var.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 09:56:24 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
make: in parse-only mode, don't evaluate modifiers

Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily.  This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.


To generate a diff of this commit:
cvs rdiff -u -r1.1096 -r1.1097 src/usr.bin/make/var.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varmod-indirect.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/var.c
diff -u src/usr.bin/make/var.c:1.1096 src/usr.bin/make/var.c:1.1097
--- src/usr.bin/make/var.c:1.1096	Sat Feb  3 00:20:23 2024
+++ src/usr.bin/make/var.c	Sun Feb  4 09:56:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1096 2024/02/03 00:20:23 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1096 2024/02/03 00:20:23 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2274,6 +2274,9 @@ ModifyWords(ModChain *ch,
 	size_t i;
 	Substring word;
 
+	if (!ModChain_ShouldEval(ch))
+		return;
+
 	if (oneBigWord) {
 		SepBuf_Init(, ch->sep);
 		/* XXX: performance: Substring_InitStr calls strlen */
@@ -2806,8 +2809,7 @@ ApplyModifier_Mtime(const char **pp, Mod
 			goto invalid_argument;
 		*pp = p;
 	}
-	if (ModChain_ShouldEval(ch))
-		ModifyWords(ch, ModifyWord_Mtime, , ch->oneBigWord);
+	ModifyWords(ch, ModifyWord_Mtime, , ch->oneBigWord);
 	return args.rc;
 
 invalid_argument:
@@ -3552,8 +3554,7 @@ ApplyModifier_WordFunc(const char **pp, 
 		return AMR_UNKNOWN;
 	(*pp)++;
 
-	if (ModChain_ShouldEval(ch))
-		ModifyWords(ch, modifyWord, NULL, ch->oneBigWord);
+	ModifyWords(ch, modifyWord, NULL, ch->oneBigWord);
 
 	return AMR_OK;
 }

Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.26
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.25	Sun Feb  4 09:29:50 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb  4 09:56:24 2024
@@ -40,8 +40,10 @@ Global: .MAKEFLAGS =  -r -k -d 0 -d pv -
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d 0
 make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
 make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
-make: "varmod-indirect.mk" line 287: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 287: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
+make: "varmod-indirect.mk" line 282: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 282: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
+make: "varmod-indirect.mk" line 288: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 288: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.16 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.17
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.16	Sun Feb  4 09:29:50 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb  4 09:56:24 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.16 2024/02/04 09:29:50 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.17 2024/02/04 09:56:24 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -258,7 +258,7 @@ _:=	before ${UNDEF:${:UZ}} after
 
 # In parse-only mode, the indirect modifiers must not be evaluated.
 #
-# Before var.c 1.1097 from 2024-02-04, the expression for an indirect modifier
+# Before var.c TODO from 2024-02-04, the expression for an indirect modifier
 # was partially evaluated (only the variable value, without applying any
 # modifiers) and then interpreted as modifiers to the main expression.
 #
@@ -277,7 +277,8 @@ M_invalid=	Z
 # The expression ${M_invalid} starts with the value "Z", and if its modifiers
 # were evaluated, would result in "N*Z", which is a valid modifier.  The
 # modifiers were not applied though, keeping the invalid value "Z".
-# FIXME: As of var.c 1.1096, the modifier ':S' _is_ actually evaluated.
+# expect+2: Unknown modifier "Z"
+# expect+1: Malformed 

CVS commit: src/usr.bin/make

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 09:56:24 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
make: in parse-only mode, don't evaluate modifiers

Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily.  This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.


To generate a diff of this commit:
cvs rdiff -u -r1.1096 -r1.1097 src/usr.bin/make/var.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varmod-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 09:29:50 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
tests/make: extend test for wrong evaluation in parse-only mode


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-indirect.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/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.24 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.25
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.24	Sun Feb  4 08:51:57 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb  4 09:29:50 2024
@@ -38,8 +38,10 @@ Parsing line 197: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d 0
-make: "varmod-indirect.mk" line 274: Unknown modifier "Z"
-make: "varmod-indirect.mk" line 274: Malformed conditional (0 && ${VAR:${M_invalid}})
+make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
+make: "varmod-indirect.mk" line 287: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 287: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.15 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.16
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.15	Sun Feb  4 08:51:57 2024
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb  4 09:29:50 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.15 2024/02/04 08:51:57 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.16 2024/02/04 09:29:50 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -258,8 +258,9 @@ _:=	before ${UNDEF:${:UZ}} after
 
 # In parse-only mode, the indirect modifiers must not be evaluated.
 #
-# Before var.c 1.1096 from 2024-02-04, the expression for an indirect modifier
-# was evaluated.
+# Before var.c 1.1097 from 2024-02-04, the expression for an indirect modifier
+# was partially evaluated (only the variable value, without applying any
+# modifiers) and then interpreted as modifiers to the main expression.
 #
 # The expression ${:UZ} starts with the value "", and in parse-only mode, the
 # modifier ':UZ' does not modify the expression value.  This results in an
@@ -273,3 +274,15 @@ M_invalid=	Z
 # expect+1: Malformed conditional (0 && ${VAR:${M_invalid}})
 .if 0 && ${VAR:${M_invalid}}
 .endif
+# The expression ${M_invalid} starts with the value "Z", and if its modifiers
+# were evaluated, would result in "N*Z", which is a valid modifier.  The
+# modifiers were not applied though, keeping the invalid value "Z".
+# FIXME: As of var.c 1.1096, the modifier ':S' _is_ actually evaluated.
+.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
+.endif
+# The ':@' modifier does not change the expression value in parse-only mode,
+# keeping the "Z".
+# expect+2: Unknown modifier "Z"
+# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
+.if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}
+.endif



CVS commit: src/usr.bin/make/unit-tests

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 09:29:50 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
tests/make: extend test for wrong evaluation in parse-only mode


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 08:51:57 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
tests/make: indirect modifiers are evaluated in parse-only mode

Found by sjg@.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod-indirect.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/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.23 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.24
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.23	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb  4 08:51:57 2024
@@ -38,6 +38,8 @@ Parsing line 197: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d
 Global: .MAKEFLAGS =  -r -k -d 0 -d pv -d 0
+make: "varmod-indirect.mk" line 274: Unknown modifier "Z"
+make: "varmod-indirect.mk" line 274: Malformed conditional (0 && ${VAR:${M_invalid}})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.14 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.15
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.14	Sun Nov 19 22:32:44 2023
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb  4 08:51:57 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.14 2023/11/19 22:32:44 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.15 2024/02/04 08:51:57 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -255,4 +255,21 @@ _:=	before ${UNDEF:${:UZ}} after
 .  error
 .endif
 
-all:
+
+# In parse-only mode, the indirect modifiers must not be evaluated.
+#
+# Before var.c 1.1096 from 2024-02-04, the expression for an indirect modifier
+# was evaluated.
+#
+# The expression ${:UZ} starts with the value "", and in parse-only mode, the
+# modifier ':UZ' does not modify the expression value.  This results in an
+# empty string for the indirect modifiers, generating no warning.
+.if 0 && ${VAR:${:UZ}}
+.endif
+# The expression ${M_invalid} starts with the value "Z", which is an unknown
+# modifier.  Trying to apply this unknown modifier generated a warning.
+M_invalid=	Z
+# expect+2: Unknown modifier "Z"
+# expect+1: Malformed conditional (0 && ${VAR:${M_invalid}})
+.if 0 && ${VAR:${M_invalid}}
+.endif



CVS commit: src/usr.bin/make/unit-tests

2024-02-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb  4 08:51:57 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk

Log Message:
tests/make: indirect modifiers are evaluated in parse-only mode

Found by sjg@.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod-indirect.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-02-02 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sat Feb  3 00:20:23 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod.exp varmod.mk

Log Message:
make: state of save_dollars affects what is a parse error

When save_dollars is false it is not a parse error to
encounter $$ rather than \$.


To generate a diff of this commit:
cvs rdiff -u -r1.1095 -r1.1096 src/usr.bin/make/var.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod.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/var.c
diff -u src/usr.bin/make/var.c:1.1095 src/usr.bin/make/var.c:1.1096
--- src/usr.bin/make/var.c:1.1095	Sun Jan 21 15:02:17 2024
+++ src/usr.bin/make/var.c	Sat Feb  3 00:20:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1095 2024/01/21 15:02:17 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1096 2024/02/03 00:20:23 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1095 2024/01/21 15:02:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1096 2024/02/03 00:20:23 sjg Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4147,12 +4147,12 @@ IsShortVarnameValid(char varname, const 
 	if (!opts.strict)
 		return false;	/* XXX: Missing error message */
 
-	if (varname == '$')
+	if (varname == '$' && save_dollars)
 		Parse_Error(PARSE_FATAL,
 		"To escape a dollar, use \\$, not $$, at \"%s\"", start);
 	else if (varname == '\0')
 		Parse_Error(PARSE_FATAL, "Dollar followed by nothing");
-	else
+	else if (save_dollars)
 		Parse_Error(PARSE_FATAL,
 		"Invalid variable name '%c', at \"%s\"", varname, start);
 

Index: src/usr.bin/make/unit-tests/varmod.exp
diff -u src/usr.bin/make/unit-tests/varmod.exp:1.7 src/usr.bin/make/unit-tests/varmod.exp:1.8
--- src/usr.bin/make/unit-tests/varmod.exp:1.7	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod.exp	Sat Feb  3 00:20:23 2024
@@ -1,8 +1,8 @@
-make: "varmod.mk" line 98: To escape a dollar, use \$, not $$, at "$$:L} != """
-make: "varmod.mk" line 98: Invalid variable name ':', at "$:L} != """
-make: "varmod.mk" line 104: Dollar followed by nothing
-make: "varmod.mk" line 114: Missing delimiter ':' after modifier "P"
-make: "varmod.mk" line 116: Missing argument for ".error"
+make: "varmod.mk" line 101: To escape a dollar, use \$, not $$, at "$$:L} != """
+make: "varmod.mk" line 101: Invalid variable name ':', at "$:L} != """
+make: "varmod.mk" line 107: Dollar followed by nothing
+make: "varmod.mk" line 117: Missing delimiter ':' after modifier "P"
+make: "varmod.mk" line 119: Missing argument for ".error"
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod.mk
diff -u src/usr.bin/make/unit-tests/varmod.mk:1.9 src/usr.bin/make/unit-tests/varmod.mk:1.10
--- src/usr.bin/make/unit-tests/varmod.mk:1.9	Sun Nov 19 21:47:52 2023
+++ src/usr.bin/make/unit-tests/varmod.mk	Sat Feb  3 00:20:23 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: varmod.mk,v 1.10 2024/02/03 00:20:23 sjg Exp $
 #
 # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
 #
@@ -56,6 +56,9 @@
 # | `u`  | strict   || yes  |
 # | `from=to`| greedy   | SysV, fallback | N/A  |
 
+# These tests assume
+.MAKE.SAVE_DOLLARS = yes
+
 DOLLAR1=	$$
 DOLLAR2=	${:U\$}
 



CVS commit: src/usr.bin/make

2024-02-02 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sat Feb  3 00:20:23 UTC 2024

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod.exp varmod.mk

Log Message:
make: state of save_dollars affects what is a parse error

When save_dollars is false it is not a parse error to
encounter $$ rather than \$.


To generate a diff of this commit:
cvs rdiff -u -r1.1095 -r1.1096 src/usr.bin/make/var.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/make

2024-01-25 Thread Simon Gerraty
On Thu, 25 Jan 2024 20:02:00 +0100, Roland Illig writes:
>>> Modified Files:
>>> src/usr.bin/make: make.1
>>>
>>> Log Message:
>>> Indicate that for :U newval is optional
>>
>> I think this is more confusing than helpful.
>
>I agree. Make doesn't distinguish between an empty string and an absent
>string here, so the wording in the manual page should be kept equally
>simple.

Not a question of what make likes or not, but what users glean from the
man page (those that don't also read the source).

The change was prompted by a user (not a make novice by any means)
complaining that :Unewval and the description provides no clue
that just :U is actually valid.

>If anything, you might mention that newval may be empty, but then you'd

I think I started with that, but then figured someone sufficiently
pedantic might consider that not the same as no value being provided ;-)

>have to add the same wording in many other places, for consistency:

>* the variable name in ${:Uvalue}

This is covered by the above no?

>* the two branches of the ':?' modifier in ${cond:?}

true

>* the pattern matching modifiers after ':S,from,to' (1gW)
>* the variable name in the variable assignment '!=3Dcmd'
>* the argument of a function call in '.if defined()'
>
>Most of these cases don't need this wording, and the '!=3Dcmd' case

Agreed, the :S usage at least is sufficiently familiar to anyone who's
used sed(1) to not need elaboration.

Is there perhaps a general statement somewhere (I may have missed it)
that could cover all these and be cited to pedantic users?
Eg to the effect of perhaps, unless stated otherwise arguments to
modifiers are optional or can be empty.

I don't think its there and is hard to word succinctly.

Thanks
--sjg



Re: CVS commit: src/usr.bin/make

2024-01-25 Thread Simon Gerraty
On Thu, 25 Jan 2024 21:12:20 +0100, Roland Illig writes:
>them all. Due to this, I'd go with:
>
>> .It Cm \&:U\| Ns Ar newval
>> If the variable is undefined,
>> .Ar newval
>> (which may be empty) is the value.

That's almost exactly what I had in my 1st cut ;-)
Will do.

>Then, add the same wording to ':D' and maybe to ':N' (since ':N' is a
>shortcut for the more common ':M*') but not to ':M' itself (as that
>would always result in an empty string, making it uninteresting).

Will take a look, but not so sure.

--sjg


CVS commit: src/usr.bin/make

2024-01-25 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Thu Jan 25 21:00:59 UTC 2024

Modified Files:
src/usr.bin/make: make.1

Log Message:
Note that in both :U and :D newval may be empty


To generate a diff of this commit:
cvs rdiff -u -r1.373 -r1.374 src/usr.bin/make/make.1

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.373 src/usr.bin/make/make.1:1.374
--- src/usr.bin/make/make.1:1.373	Thu Jan 25 07:35:46 2024
+++ src/usr.bin/make/make.1	Thu Jan 25 21:00:59 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.373 2024/01/25 07:35:46 sjg Exp $
+.\"	$NetBSD: make.1,v 1.374 2024/01/25 21:00:59 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -1772,11 +1772,11 @@ is used to save the result of the
 .Ql :S
 modifier which is later referenced using the index values from
 .Ql :range .
-.It Cm \&:U\| Ns Oo Ar newval Oc
+.It Cm \&:U\| Ns Ar newval
 If the variable is undefined,
 the optional
 .Ar newval
-is the value.
+(which may be empty) is the value.
 If the variable is defined, the existing value is returned.
 This is another ODE make feature.
 It is handy for setting per-target CFLAGS for instance:
@@ -1786,7 +1786,7 @@ If a value is only required if the varia
 .It Cm \&:D\| Ns Ar newval
 If the variable is defined,
 .Ar newval
-is the value.
+(which may be empty) is the value.
 .It Cm \&:L
 The name of the variable is the value.
 .It Cm \&:P



CVS commit: src/usr.bin/make

2024-01-25 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Thu Jan 25 21:00:59 UTC 2024

Modified Files:
src/usr.bin/make: make.1

Log Message:
Note that in both :U and :D newval may be empty


To generate a diff of this commit:
cvs rdiff -u -r1.373 -r1.374 src/usr.bin/make/make.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/make

2024-01-25 Thread Roland Illig
About optional arguments to modifiers, such as in ${VAR:U}:

Am 25.01.2024 um 20:54 schrieb Simon Gerraty:
> Is there perhaps a general statement somewhere (I may have missed it)
> that could cover all these and be cited to pedantic users?
> Eg to the effect of perhaps, unless stated otherwise arguments to
> modifiers are optional or can be empty.
>
> I don't think its there and is hard to word succinctly.

No, I searched through the manual page but didn't find one.

Also, there are so many syntactic quirks and edge cases in make that I
don't think there's an easy to grasp single-line statement that covers
them all. Due to this, I'd go with:

> .It Cm \&:U\| Ns Ar newval
> If the variable is undefined,
> .Ar newval
> (which may be empty) is the value.

Then, add the same wording to ':D' and maybe to ':N' (since ':N' is a
shortcut for the more common ':M*') but not to ':M' itself (as that
would always result in an empty string, making it uninteresting).

Roland



Re: CVS commit: src/usr.bin/make

2024-01-25 Thread Roland Illig
Am 25.01.2024 um 14:25 schrieb Valery Ushakov:
> On Thu, Jan 25, 2024 at 07:35:46 +, Simon J. Gerraty wrote:
>
>> Modified Files:
>>  src/usr.bin/make: make.1
>>
>> Log Message:
>> Indicate that for :U newval is optional
>
> I think this is more confusing than helpful.

I agree. Make doesn't distinguish between an empty string and an absent
string here, so the wording in the manual page should be kept equally
simple.

If anything, you might mention that newval may be empty, but then you'd
have to add the same wording in many other places, for consistency:

* the variable name in ${:Uvalue}
* the two branches of the ':?' modifier in ${cond:?}
* the pattern matching modifiers after ':S,from,to' (1gW)
* the variable name in the variable assignment '!=cmd'
* the argument of a function call in '.if defined()'

Most of these cases don't need this wording, and the '!=cmd' case
shouldn't be documented at all, as it is a dirty hack.

Roland



CVS commit: src/usr.bin/make

2024-01-24 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Thu Jan 25 07:35:46 UTC 2024

Modified Files:
src/usr.bin/make: make.1

Log Message:
Indicate that for :U newval is optional


To generate a diff of this commit:
cvs rdiff -u -r1.372 -r1.373 src/usr.bin/make/make.1

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.372 src/usr.bin/make/make.1:1.373
--- src/usr.bin/make/make.1:1.372	Sun Dec 24 16:48:30 2023
+++ src/usr.bin/make/make.1	Thu Jan 25 07:35:46 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.372 2023/12/24 16:48:30 sjg Exp $
+.\"	$NetBSD: make.1,v 1.373 2024/01/25 07:35:46 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 December 24, 2023
+.Dd January 24, 2024
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1772,8 +1772,9 @@ is used to save the result of the
 .Ql :S
 modifier which is later referenced using the index values from
 .Ql :range .
-.It Cm \&:U\| Ns Ar newval
+.It Cm \&:U\| Ns Oo Ar newval Oc
 If the variable is undefined,
+the optional
 .Ar newval
 is the value.
 If the variable is defined, the existing value is returned.



CVS commit: src/usr.bin/make

2024-01-24 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Thu Jan 25 07:35:46 UTC 2024

Modified Files:
src/usr.bin/make: make.1

Log Message:
Indicate that for :U newval is optional


To generate a diff of this commit:
cvs rdiff -u -r1.372 -r1.373 src/usr.bin/make/make.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 16:32:41 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: refactor CondParser_Term to be inlinable

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.360 -r1.361 src/usr.bin/make/cond.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/cond.c
diff -u src/usr.bin/make/cond.c:1.360 src/usr.bin/make/cond.c:1.361
--- src/usr.bin/make/cond.c:1.360	Sun Jan 21 15:22:55 2024
+++ src/usr.bin/make/cond.c	Sun Jan 21 16:32:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.360 2024/01/21 15:22:55 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.361 2024/01/21 16:32:41 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.360 2024/01/21 15:22:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.361 2024/01/21 16:32:41 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -867,12 +867,13 @@ CondParser_Term(CondParser *par, bool do
 {
 	CondResult res;
 	Token t;
+	bool neg = false;
 
-	t = CondParser_Token(par, doEval);
-	if (t == TOK_TRUE)
-		return CR_TRUE;
-	if (t == TOK_FALSE)
-		return CR_FALSE;
+	while ((t = CondParser_Token(par, doEval)) == TOK_NOT)
+		neg = !neg;
+
+	if (t == TOK_TRUE || t == TOK_FALSE)
+		return neg == (t == TOK_FALSE) ? CR_TRUE : CR_FALSE;
 
 	if (t == TOK_LPAREN) {
 		res = CondParser_Or(par, doEval);
@@ -880,16 +881,7 @@ CondParser_Term(CondParser *par, bool do
 			return CR_ERROR;
 		if (CondParser_Token(par, doEval) != TOK_RPAREN)
 			return CR_ERROR;
-		return res;
-	}
-
-	if (t == TOK_NOT) {
-		res = CondParser_Term(par, doEval);
-		if (res == CR_TRUE)
-			res = CR_FALSE;
-		else if (res == CR_FALSE)
-			res = CR_TRUE;
-		return res;
+		return neg == (res == CR_FALSE) ? CR_TRUE : CR_FALSE;
 	}
 
 	return CR_ERROR;



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 16:32:41 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: refactor CondParser_Term to be inlinable

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.360 -r1.361 src/usr.bin/make/cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 15:22:55 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: clean up parsing of conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/usr.bin/make/cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 15:22:55 UTC 2024

Modified Files:
src/usr.bin/make: cond.c

Log Message:
make: clean up parsing of conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/usr.bin/make/cond.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/cond.c
diff -u src/usr.bin/make/cond.c:1.359 src/usr.bin/make/cond.c:1.360
--- src/usr.bin/make/cond.c:1.359	Fri Dec 29 12:59:43 2023
+++ src/usr.bin/make/cond.c	Sun Jan 21 15:22:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.359 2023/12/29 12:59:43 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.360 2024/01/21 15:22:55 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.359 2023/12/29 12:59:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.360 2024/01/21 15:22:55 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -937,20 +937,6 @@ CondParser_Or(CondParser *par, bool doEv
 	return res;
 }
 
-static CondResult
-CondParser_Eval(CondParser *par)
-{
-	CondResult res;
-
-	DEBUG1(COND, "CondParser_Eval: %s\n", par->p);
-
-	res = CondParser_Or(par, true);
-	if (res != CR_ERROR && CondParser_Token(par, false) != TOK_EOF)
-		return CR_ERROR;
-
-	return res;
-}
-
 /*
  * Evaluate the condition, including any side effects from the
  * expressions in the condition. The condition consists of &&, ||, !,
@@ -974,7 +960,10 @@ CondEvalExpression(const char *cond, boo
 	par.curr = TOK_NONE;
 	par.printedError = false;
 
-	rval = CondParser_Eval();
+	DEBUG1(COND, "CondParser_Eval: %s\n", par.p);
+	rval = CondParser_Or(, true);
+	if (par.curr != TOK_EOF)
+		rval = CR_ERROR;
 
 	if (rval == CR_ERROR && eprint && !par.printedError)
 		Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", cond);



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 15:02:17 UTC 2024

Modified Files:
src/usr.bin/make: for.c var.c

Log Message:
make: clean up redundant 'const' from automatic variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/make/for.c
cvs rdiff -u -r1.1094 -r1.1095 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/for.c
diff -u src/usr.bin/make/for.c:1.177 src/usr.bin/make/for.c:1.178
--- src/usr.bin/make/for.c:1.177	Sun Nov 19 22:50:11 2023
+++ src/usr.bin/make/for.c	Sun Jan 21 15:02:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.177 2023/11/19 22:50:11 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.178 2024/01/21 15:02:17 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.177 2023/11/19 22:50:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.178 2024/01/21 15:02:17 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -434,7 +434,7 @@ static void
 ForLoop_SubstVarShort(ForLoop *f, unsigned int firstItem, Buffer *body,
 		  const char *p, const char **inout_mark)
 {
-	const char ch = *p;
+	char ch = *p;
 	const char **vars;
 	size_t i;
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1094 src/usr.bin/make/var.c:1.1095
--- src/usr.bin/make/var.c:1.1094	Sun Jan  7 11:39:04 2024
+++ src/usr.bin/make/var.c	Sun Jan 21 15:02:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1094 2024/01/07 11:39:04 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1095 2024/01/21 15:02:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1094 2024/01/07 11:39:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1095 2024/01/21 15:02:17 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4279,7 +4279,7 @@ ParseVarnameLong(
 	bool dynamic = false;
 
 	const char *p = *pp;
-	const char *const start = p;
+	const char *start = p;
 	char endc = startc == '(' ? ')' : '}';
 
 	p += 2;			/* skip "${" or "$(" or "y(" */



CVS commit: src/usr.bin/make

2024-01-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 21 15:02:17 UTC 2024

Modified Files:
src/usr.bin/make: for.c var.c

Log Message:
make: clean up redundant 'const' from automatic variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/make/for.c
cvs rdiff -u -r1.1094 -r1.1095 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.



CVS commit: src/usr.bin/make/unit-tests

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 11:42:22 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.exp varmod-assign.mk

Log Message:
tests/make: test the '::=' modifier in target scope


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.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/unit-tests/varmod-assign.exp
diff -u src/usr.bin/make/unit-tests/varmod-assign.exp:1.18 src/usr.bin/make/unit-tests/varmod-assign.exp:1.19
--- src/usr.bin/make/unit-tests/varmod-assign.exp:1.18	Fri Dec 29 15:47:03 2023
+++ src/usr.bin/make/unit-tests/varmod-assign.exp	Sun Jan  7 11:42:22 2024
@@ -50,4 +50,11 @@ make: Unfinished modifier for "ASSIGN" (
 ok=word
 make: " echo word; false " returned non-zero status
 err=previous
+Command: TARGET_CMD_VAR = cmd-value
+Global: TARGET_GLOBAL_VAR = global-value
+target: TARGET_TARGET_VAR = target-value
+target: TARGET_TARGET_VAR = new-value
+Global: TARGET_GLOBAL_VAR = new-value
+Global: TARGET_ENV_VAR = new-value
+target: TARGET_NEW_VAR = new-value
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.18 src/usr.bin/make/unit-tests/varmod-assign.mk:1.19
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.18	Sun Dec 31 10:09:01 2023
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Sun Jan  7 11:42:22 2024
@@ -1,8 +1,10 @@
-# $NetBSD: varmod-assign.mk,v 1.18 2023/12/31 10:09:01 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.19 2024/01/07 11:42:22 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
 
+.if !make(target)
+
 all:	mod-assign-empty
 all:	mod-assign-parse
 all:	mod-assign-shell-error
@@ -162,7 +164,6 @@ ${VARNAME}=	initial-value	# Sets 'VAR.${
 .MAKEFLAGS: CMD_CMD_VAR=cmd-value
 CMD_GLOBAL_VAR=global-value
 export CMD_ENV_VAR=env-value
-
 .MAKEFLAGS: -dv
 # expect-reset
 # expect: Command: CMD_CMD_VAR = new-value
@@ -178,23 +179,30 @@ export CMD_ENV_VAR=env-value
 .endif
 .MAKEFLAGS: -d0
 
+# Run the 'target' test in a separate sub-make, with reduced debug logging.
+all: run-target
+run-target: .PHONY
+	@${MAKE} -r -f ${MAKEFILE} -dv target 2>&1 | grep ': TARGET_'
 
-# In target scope, assignments only happen in a few cases.  To extract the
-# debug log for this test, the debug log would have to be enabled for the
-# other targets as well, thus producing lots of irrelevant output.
+.else # make(target)
+
+# The commands of a target are evaluated in target scope.  An assignment
+# modifier that creates a new variable creates it in the target scope.
+# Existing variables are updated in their previous scope, and environment
+# variables are created in the global scope, as in other situations.
 #
-# Running './make -r -f varmod-assign.mk target | grep ": TARGET"' results in:
-#	target: TARGET_TARGET_VAR = new-value
-#	Global: TARGET_GLOBAL_VAR = new-value
-#	Global: TARGET_ENV_VAR = new-value
-#	target: TARGET_NEW_VAR = new-value
+# expect: target: TARGET_TARGET_VAR = new-value
+# expect: Global: TARGET_GLOBAL_VAR = new-value
+# expect: Global: TARGET_ENV_VAR = new-value
+# expect: target: TARGET_NEW_VAR = new-value
 .MAKEFLAGS: TARGET_CMD_VAR=cmd-value
 TARGET_GLOBAL_VAR=global-value
 export TARGET_ENV_VAR=env-value
-.MAKEFLAGS: ${make(target):?-dv:}
 target: .PHONY TARGET_TARGET_VAR=target-value
 	: ${TARGET_TARGET_VAR::=new-value}
 	: ${TARGET_CMD_VAR::=new-value}
 	: ${TARGET_GLOBAL_VAR::=new-value}
 	: ${TARGET_ENV_VAR::=new-value}
 	: ${TARGET_NEW_VAR::=new-value}
+
+.endif



CVS commit: src/usr.bin/make/unit-tests

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 11:42:22 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.exp varmod-assign.mk

Log Message:
tests/make: test the '::=' modifier in target scope


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/varmod-assign.exp \
src/usr.bin/make/unit-tests/varmod-assign.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 11:39:04 UTC 2024

Modified Files:
src/usr.bin/make: job.c parse.c var.c
src/usr.bin/make/unit-tests: varparse-undef-partial.mk

Log Message:
make: clean up comments, constify shell name


To generate a diff of this commit:
cvs rdiff -u -r1.464 -r1.465 src/usr.bin/make/job.c
cvs rdiff -u -r1.715 -r1.716 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1093 -r1.1094 src/usr.bin/make/var.c
cvs rdiff -u -r1.4 -r1.5 \
src/usr.bin/make/unit-tests/varparse-undef-partial.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 11:39:04 UTC 2024

Modified Files:
src/usr.bin/make: job.c parse.c var.c
src/usr.bin/make/unit-tests: varparse-undef-partial.mk

Log Message:
make: clean up comments, constify shell name


To generate a diff of this commit:
cvs rdiff -u -r1.464 -r1.465 src/usr.bin/make/job.c
cvs rdiff -u -r1.715 -r1.716 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1093 -r1.1094 src/usr.bin/make/var.c
cvs rdiff -u -r1.4 -r1.5 \
src/usr.bin/make/unit-tests/varparse-undef-partial.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/job.c
diff -u src/usr.bin/make/job.c:1.464 src/usr.bin/make/job.c:1.465
--- src/usr.bin/make/job.c:1.464	Sun Jan  7 01:33:57 2024
+++ src/usr.bin/make/job.c	Sun Jan  7 11:39:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.464 2024/01/07 01:33:57 sjg Exp $	*/
+/*	$NetBSD: job.c,v 1.465 2024/01/07 11:39:04 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.464 2024/01/07 01:33:57 sjg Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.465 2024/01/07 11:39:04 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2474,16 +2474,9 @@ Job_ParseShell(char *line)
 			}
 		}
 	} else {
-		/*
-		 * The user provided a path. If s/he gave nothing else
-		 * (fullSpec is false), try and find a matching shell in the
-		 * ones we know of. Else we just take the specification at
-		 * its word and copy it to a new location. In either case,
-		 * we need to record the path the user gave for the shell.
-		 */
-		char *name = path + (str_basename(path) - path);
 		shellPath = path;
-		shellName = newShell.name != NULL ? newShell.name : name;
+		shellName = newShell.name != NULL ? newShell.name
+		: str_basename(path);
 		if (!fullSpec) {
 			if ((sh = FindShellByName(shellName)) == NULL) {
 Parse_Error(PARSE_WARNING,

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.715 src/usr.bin/make/parse.c:1.716
--- src/usr.bin/make/parse.c:1.715	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/parse.c	Sun Jan  7 11:39:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.715 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.716 2024/01/07 11:39:04 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.715 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.716 2024/01/07 11:39:04 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -115,9 +115,7 @@ typedef enum {
 	GS_NO			/* the file is not guarded */
 } GuardState;
 
-/*
- * A file being read.
- */
+/* A file being parsed. */
 typedef struct IncludedFile {
 	FStr name;		/* absolute or relative to the cwd */
 	unsigned lineno;	/* 1-based */
@@ -2901,13 +2899,6 @@ ParseDependencyLine(char *line)
 static void
 ParseLine(char *line)
 {
-	/*
-	 * Lines that begin with '.' can be pretty much anything:
-	 *	- directives like '.include' or '.if',
-	 *	- suffix rules like '.c.o:',
-	 *	- dependencies for filenames that start with '.',
-	 *	- variable assignments like '.tmp=value'.
-	 */
 	if (line[0] == '.' && ParseDirective(line))
 		return;
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1093 src/usr.bin/make/var.c:1.1094
--- src/usr.bin/make/var.c:1.1093	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/var.c	Sun Jan  7 11:39:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1093 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1094 2024/01/07 11:39:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1093 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1094 2024/01/07 11:39:04 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1859,15 +1859,15 @@ FormatTime(const char *fmt, time_t t, bo
  * Some modifiers such as ':sh' or '::=' have noticeable side effects though.
  *
  * Evaluating the modifier usually takes the current value of the
- * expression from ch->expr->value, or the variable name from ch->var->name
+ * expression from ch->expr->value, or the variable name from ch->var->name,
  * and stores the result back in ch->expr->value via Expr_SetValueOwn or
  * Expr_SetValueRefer.
  *
- * If evaluating fails (as of 2020-08-23), an error message is printed using
- * Error.  This function has no side effects, it really just prints the error
- * message.  Processing the expression continues as if everything were ok.
- * TODO: This should be fixed by adding proper 

CVS commit: src/usr.bin/make/unit-tests

2024-01-06 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Jan  7 02:07:44 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: Makefile

Log Message:
make: unit-tests handle TEST_MAKE:T != make

We need to allow for ${TEST_MAKE:T}[1-9]: etc when
TEST_MAKE is not 'make'


To generate a diff of this commit:
cvs rdiff -u -r1.341 -r1.342 src/usr.bin/make/unit-tests/Makefile

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.341 src/usr.bin/make/unit-tests/Makefile:1.342
--- src/usr.bin/make/unit-tests/Makefile:1.341	Sat Sep  9 16:41:04 2023
+++ src/usr.bin/make/unit-tests/Makefile	Sun Jan  7 02:07:44 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.341 2023/09/09 16:41:04 sjg Exp $
+# $NetBSD: Makefile,v 1.342 2024/01/07 02:07:44 sjg Exp $
 #
 # Unit tests for make(1)
 #
@@ -747,6 +747,7 @@ _SED_CMDS+=	-e 's,${.OBJDIR},,g'
 _SED_CMDS+=	-e 's,^${TEST_MAKE:T:S,.,\\.,g}[][0-9]*:,make:,'
 _SED_CMDS+=	-e 's,${TEST_MAKE:S,.,\\.,g},make,'
 _SED_CMDS+=	-e 's,^usage: ${TEST_MAKE:T:S,.,\\.,g} ,usage: make ,'
+_SED_CMDS+=	-e 's,${TEST_MAKE:T:S,.,\\.,g}\(\[[1-9][0-9]*\]:\),make\1,'
 _SED_CMDS+=	-e 's,/,,g'
 _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g}/,,g'
 _SED_CMDS+=	-e '/MAKE_VERSION/d'



CVS commit: src/usr.bin/make/unit-tests

2024-01-06 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Jan  7 02:07:44 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: Makefile

Log Message:
make: unit-tests handle TEST_MAKE:T != make

We need to allow for ${TEST_MAKE:T}[1-9]: etc when
TEST_MAKE is not 'make'


To generate a diff of this commit:
cvs rdiff -u -r1.341 -r1.342 src/usr.bin/make/unit-tests/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-06 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Jan  7 01:33:58 UTC 2024

Modified Files:
src/usr.bin/make: job.c main.c
src/usr.bin/make/unit-tests: jobs-error-indirect.exp
jobs-error-nested-make.exp jobs-error-nested.exp var-recursive.exp

Log Message:
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.463 -r1.464 src/usr.bin/make/job.c
cvs rdiff -u -r1.608 -r1.609 src/usr.bin/make/main.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/jobs-error-indirect.exp \
src/usr.bin/make/unit-tests/jobs-error-nested.exp
cvs rdiff -u -r1.3 -r1.4 \
src/usr.bin/make/unit-tests/jobs-error-nested-make.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-recursive.exp

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/job.c
diff -u src/usr.bin/make/job.c:1.463 src/usr.bin/make/job.c:1.464
--- src/usr.bin/make/job.c:1.463	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/job.c	Sun Jan  7 01:33:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.463 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.464 2024/01/07 01:33:57 sjg 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.463 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.464 2024/01/07 01:33:57 sjg Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1379,7 +1379,7 @@ Job_CheckCommands(GNode *gn, void (*abor
 		return false;
 	}
 
-	abortProc("%s: don't know how to make %s. Stop", progname, gn->name);
+	abortProc("don't know how to make %s. Stop", gn->name);
 	return false;
 }
 

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.608 src/usr.bin/make/main.c:1.609
--- src/usr.bin/make/main.c:1.608	Fri Jan  5 23:22:06 2024
+++ src/usr.bin/make/main.c	Sun Jan  7 01:33:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.608 2024/01/05 23:22:06 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.609 2024/01/07 01:33:57 sjg 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.608 2024/01/05 23:22:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.609 2024/01/07 01:33:57 sjg Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1851,6 +1851,7 @@ Fatal(const char *fmt, ...)
 		Job_Wait();
 
 	(void)fflush(stdout);
+	fprintf(stderr, "%s: ", progname);
 	va_start(ap, fmt);
 	(void)vfprintf(stderr, fmt, ap);
 	va_end(ap);

Index: src/usr.bin/make/unit-tests/jobs-error-indirect.exp
diff -u src/usr.bin/make/unit-tests/jobs-error-indirect.exp:1.1 src/usr.bin/make/unit-tests/jobs-error-indirect.exp:1.2
--- src/usr.bin/make/unit-tests/jobs-error-indirect.exp:1.1	Tue Dec  1 17:50:04 2020
+++ src/usr.bin/make/unit-tests/jobs-error-indirect.exp	Sun Jan  7 01:33:57 2024
@@ -2,7 +2,7 @@ false
 *** [indirect] Error code 1
 
 make: stopped in unit-tests
-1 error
+make: 1 error
 
 make: stopped in unit-tests
 exit status 2
Index: src/usr.bin/make/unit-tests/jobs-error-nested.exp
diff -u src/usr.bin/make/unit-tests/jobs-error-nested.exp:1.1 src/usr.bin/make/unit-tests/jobs-error-nested.exp:1.2
--- src/usr.bin/make/unit-tests/jobs-error-nested.exp:1.1	Tue Dec  1 17:50:04 2020
+++ src/usr.bin/make/unit-tests/jobs-error-nested.exp	Sun Jan  7 01:33:57 2024
@@ -3,13 +3,13 @@ false
 *** [nested] Error code 1
 
 make: stopped in unit-tests
-1 error
+make: 1 error
 
 make: stopped in unit-tests
 *** [all] Error code 2
 
 make: stopped in unit-tests
-1 error
+make: 1 error
 
 make: stopped in unit-tests
 exit status 2

Index: src/usr.bin/make/unit-tests/jobs-error-nested-make.exp
diff -u src/usr.bin/make/unit-tests/jobs-error-nested-make.exp:1.3 src/usr.bin/make/unit-tests/jobs-error-nested-make.exp:1.4
--- src/usr.bin/make/unit-tests/jobs-error-nested-make.exp:1.3	Fri Jan  8 21:46:50 2021
+++ src/usr.bin/make/unit-tests/jobs-error-nested-make.exp	Sun Jan  7 01:33:57 2024
@@ -3,7 +3,7 @@ false
 *** [nested] Error code 1
 
 make: stopped in unit-tests
-1 error
+make: 1 error
 
 make: stopped in unit-tests
 

Index: src/usr.bin/make/unit-tests/var-recursive.exp
diff -u src/usr.bin/make/unit-tests/var-recursive.exp:1.6 src/usr.bin/make/unit-tests/var-recursive.exp:1.7
--- src/usr.bin/make/unit-tests/var-recursive.exp:1.6	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/var-recursive.exp	Sun Jan  7 01:33:57 2024
@@ -1,19 +1,19 @@
 make: 

CVS commit: src/usr.bin/make

2024-01-06 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Jan  7 01:33:58 UTC 2024

Modified Files:
src/usr.bin/make: job.c main.c
src/usr.bin/make/unit-tests: jobs-error-indirect.exp
jobs-error-nested-make.exp jobs-error-nested.exp var-recursive.exp

Log Message:
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.463 -r1.464 src/usr.bin/make/job.c
cvs rdiff -u -r1.608 -r1.609 src/usr.bin/make/main.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/jobs-error-indirect.exp \
src/usr.bin/make/unit-tests/jobs-error-nested.exp
cvs rdiff -u -r1.3 -r1.4 \
src/usr.bin/make/unit-tests/jobs-error-nested-make.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-recursive.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 23:36:45 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-op-shell.mk

Log Message:
tests/make: test long shell commands via Cmd_Exec


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/var-op-shell.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/unit-tests/var-op-shell.mk
diff -u src/usr.bin/make/unit-tests/var-op-shell.mk:1.7 src/usr.bin/make/unit-tests/var-op-shell.mk:1.8
--- src/usr.bin/make/unit-tests/var-op-shell.mk:1.7	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/var-op-shell.mk	Fri Jan  5 23:36:45 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-op-shell.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $
+# $NetBSD: var-op-shell.mk,v 1.8 2024/01/05 23:36:45 rillig Exp $
 #
 # Tests for the != variable assignment operator, which runs its right-hand
 # side through the shell.
@@ -91,4 +91,22 @@ OUTPUT!=	echo ''
 OUTPUT!=	echo ''
 .MAKEFLAGS: -d0
 
+
+# Since main.c 1.607 from 2024-01-05, long shell commands are not run directly
+# via '$shell -c $command', they are first written to a temporary file that is
+# then fed to the shell via '$shell $tmpfile'.
+OUTPUT_SHORT!=	echo "$$0"
+OUTPUT_LONG!=	echo "$$0" || : ${:U:range=1000}
+# When running '$shell -c $command', '$0' in the shell evaluates to the name
+# of the shell.
+.if ${OUTPUT_SHORT} != ${.SHELL:T}
+.  error
+.endif
+# When running '$shell $tmpfile', '$0' in the shell evaluates to the name of
+# the temporary file.
+.if !${OUTPUT_LONG:M*/make*}
+.  error
+.endif
+
+
 all:



CVS commit: src/usr.bin/make/unit-tests

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 23:36:45 UTC 2024

Modified Files:
src/usr.bin/make/unit-tests: var-op-shell.mk

Log Message:
tests/make: test long shell commands via Cmd_Exec


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/var-op-shell.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 23:22:06 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.c parse.c str.c suff.c
var.c

Log Message:
make: miscellaneous cleanups


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/compat.c
cvs rdiff -u -r1.462 -r1.463 src/usr.bin/make/job.c
cvs rdiff -u -r1.607 -r1.608 src/usr.bin/make/main.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/make.c
cvs rdiff -u -r1.714 -r1.715 src/usr.bin/make/parse.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/make/str.c
cvs rdiff -u -r1.376 -r1.377 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1092 -r1.1093 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.



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 23:22:06 UTC 2024

Modified Files:
src/usr.bin/make: compat.c job.c main.c make.c parse.c str.c suff.c
var.c

Log Message:
make: miscellaneous cleanups


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/compat.c
cvs rdiff -u -r1.462 -r1.463 src/usr.bin/make/job.c
cvs rdiff -u -r1.607 -r1.608 src/usr.bin/make/main.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/make.c
cvs rdiff -u -r1.714 -r1.715 src/usr.bin/make/parse.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/make/str.c
cvs rdiff -u -r1.376 -r1.377 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1092 -r1.1093 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/compat.c
diff -u src/usr.bin/make/compat.c:1.251 src/usr.bin/make/compat.c:1.252
--- src/usr.bin/make/compat.c:1.251	Tue Dec 26 20:09:42 2023
+++ src/usr.bin/make/compat.c	Fri Jan  5 23:22:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.251 2023/12/26 20:09:42 sjg Exp $	*/
+/*	$NetBSD: compat.c,v 1.252 2024/01/05 23:22:06 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.251 2023/12/26 20:09:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.252 2024/01/05 23:22:06 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -107,10 +107,8 @@ CompatDeleteTarget(GNode *gn)
 	if (gn != NULL && !GNode_IsPrecious(gn) &&
 	(gn->type & OP_PHONY) == 0) {
 		const char *file = GNode_VarTarget(gn);
-
-		if (!opts.noExecute && unlink_file(file) == 0) {
+		if (!opts.noExecute && unlink_file(file) == 0)
 			Error("*** %s removed", file);
-		}
 	}
 }
 
@@ -132,9 +130,8 @@ CompatInterrupt(int signo)
 		/* Run .INTERRUPT only if hit with interrupt signal. */
 		if (signo == SIGINT) {
 			GNode *gn = Targ_FindNode(".INTERRUPT");
-			if (gn != NULL) {
+			if (gn != NULL)
 Compat_Make(gn, gn);
-			}
 		}
 	}
 
@@ -360,9 +357,8 @@ Compat_RunCommand(const char *cmdp, GNod
 	while ((retstat = wait()) != cpid) {
 		if (retstat > 0)
 			JobReapChild(retstat, reason, false); /* not ours? */
-		if (retstat == -1 && errno != EINTR) {
+		if (retstat == -1 && errno != EINTR)
 			break;
-		}
 	}
 
 	if (retstat < 0)

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.462 src/usr.bin/make/job.c:1.463
--- src/usr.bin/make/job.c:1.462	Fri Dec 29 12:59:43 2023
+++ src/usr.bin/make/job.c	Fri Jan  5 23:22:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.462 2023/12/29 12:59:43 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.463 2024/01/05 23:22:06 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.462 2023/12/29 12:59:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.463 2024/01/05 23:22:06 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -928,12 +928,10 @@ JobWriteCommand(Job *job, ShellWriter *w
 	escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd);
 
 	if (!cmdFlags.echo) {
-		if (job->echo && run && shell->hasEchoCtl) {
+		if (job->echo && run && shell->hasEchoCtl)
 			ShellWriter_EchoOff(wr);
-		} else {
-			if (shell->hasErrCtl)
-cmdFlags.echo = true;
-		}
+		else if (shell->hasErrCtl)
+			cmdFlags.echo = true;
 	}
 
 	if (cmdFlags.ignerr) {
@@ -2182,11 +2180,10 @@ Shell_GetNewline(void)
 void
 Job_SetPrefix(void)
 {
-	if (targPrefix != NULL) {
+	if (targPrefix != NULL)
 		free(targPrefix);
-	} else if (!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOB.PREFIX")) {
+	else if (!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOB.PREFIX"))
 		Global_Set(".MAKE.JOB.PREFIX", "---");
-	}
 
 	targPrefix = Var_Subst("${.MAKE.JOB.PREFIX}",
 	SCOPE_GLOBAL, VARE_WANTRES);
@@ -2484,18 +2481,9 @@ Job_ParseShell(char *line)
 		 * its word and copy it to a new location. In either case,
 		 * we need to record the path the user gave for the shell.
 		 */
+		char *name = path + (str_basename(path) - path);
 		shellPath = path;
-		path = strrchr(path, '/');
-		if (path == NULL) {
-			path = UNCONST(shellPath);
-		} else {
-			path++;
-		}
-		if (newShell.name != NULL) {
-			shellName = newShell.name;
-		} else {
-			shellName = path;
-		}
+		shellName = newShell.name != NULL ? newShell.name : name;
 		if (!fullSpec) {
 			if ((sh = FindShellByName(shellName)) == NULL) {
 Parse_Error(PARSE_WARNING,
@@ -2592,11 +2580,10 @@ Job_Finish(void)
 	GNode *endNode = Targ_GetEndNode();
 	if (!Lst_IsEmpty(>commands) ||
 	!Lst_IsEmpty(>children)) {
-		if (job_errors != 0) {
+		if (job_errors != 0)
 			Error("Errors reported so .END ignored");
-		} else {
+		else
 			JobRun(endNode);
-		}
 	}
 	return 

CVS commit: src/usr.bin/make

2024-01-05 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Jan  5 22:20:07 UTC 2024

Modified Files:
src/usr.bin/make: main.c

Log Message:
Cmd_Exec use tempfile if cmd is too big

To avoid blowing commandline/env limits, if "cmd"
is more than 1000 bytes, write it to a file and pass that
to shell.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.606 -r1.607 src/usr.bin/make/main.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/main.c
diff -u src/usr.bin/make/main.c:1.606 src/usr.bin/make/main.c:1.607
--- src/usr.bin/make/main.c:1.606	Wed Dec 27 00:45:37 2023
+++ src/usr.bin/make/main.c	Fri Jan  5 22:20:07 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.606 2023/12/27 00:45:37 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.607 2024/01/05 22:20:07 sjg 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.606 2023/12/27 00:45:37 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.607 2024/01/05 22:20:07 sjg Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1705,14 +1705,38 @@ Cmd_Exec(const char *cmd, char **error)
 	char *output;
 	char *p;
 	int saved_errno;
+	char cmd_file[MAXPATHLEN];
+	size_t cmd_len;
+	int cmd_fd = -1;
 
 	if (shellPath == NULL)
 		Shell_Init();
 
+	cmd_len = strlen(cmd);
+	if (cmd_len > 1000) {
+		cmd_fd = mkTempFile(NULL, cmd_file, sizeof(cmd_file));
+		if (cmd_fd >= 0) {
+			ssize_t n;
+
+			n = write(cmd_fd, cmd, cmd_len);
+			close(cmd_fd);
+			if (n < (ssize_t)cmd_len) {
+unlink(cmd_file);
+cmd_fd = -1;
+			}
+		}
+	}
+
 	args[0] = shellName;
-	args[1] = "-c";
-	args[2] = cmd;
-	args[3] = NULL;
+	if (cmd_fd >= 0) {
+		args[1] = cmd_file;
+		args[2] = NULL;
+	} else {
+		cmd_file[0] = '\0';
+		args[1] = "-c";
+		args[2] = cmd;
+		args[3] = NULL;
+	}
 	DEBUG1(VAR, "Capturing the output of command \"%s\"\n", cmd);
 
 	if (pipe(pipefds) == -1) {
@@ -1775,6 +1799,8 @@ Cmd_Exec(const char *cmd, char **error)
 		"Couldn't read shell's output for \"", cmd, "\"");
 	else
 		*error = NULL;
+	if (cmd_file[0] != '\0')
+		unlink(cmd_file);
 	return output;
 }
 
@@ -2129,7 +2155,7 @@ getTmpdir(void)
 
 /*
  * Create and open a temp file using "pattern".
- * If out_fname is provided, set it to a copy of the filename created.
+ * If tfile is provided, set it to a copy of the filename created.
  * Otherwise unlink the file once open.
  */
 int



CVS commit: src/usr.bin/make

2024-01-05 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Jan  5 22:20:07 UTC 2024

Modified Files:
src/usr.bin/make: main.c

Log Message:
Cmd_Exec use tempfile if cmd is too big

To avoid blowing commandline/env limits, if "cmd"
is more than 1000 bytes, write it to a file and pass that
to shell.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.606 -r1.607 src/usr.bin/make/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 21:56:55 UTC 2024

Modified Files:
src/usr.bin/make: str.h var.c

Log Message:
make: clean up string functions

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/str.h
cvs rdiff -u -r1.1091 -r1.1092 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/str.h
diff -u src/usr.bin/make/str.h:1.18 src/usr.bin/make/str.h:1.19
--- src/usr.bin/make/str.h:1.18	Fri Jan  5 21:51:27 2024
+++ src/usr.bin/make/str.h	Fri Jan  5 21:56:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.18 2024/01/05 21:51:27 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.19 2024/01/05 21:56:55 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -76,27 +76,24 @@ typedef struct StrMatchResult {
 } StrMatchResult;
 
 
+/* Return a string that is the sole owner of str. */
 MAKE_INLINE FStr
-FStr_Init(const char *str, void *freeIt)
+FStr_InitOwn(char *str)
 {
 	FStr fstr;
 	fstr.str = str;
-	fstr.freeIt = freeIt;
+	fstr.freeIt = str;
 	return fstr;
 }
 
-/* Return a string that is the sole owner of str. */
-MAKE_INLINE FStr
-FStr_InitOwn(char *str)
-{
-	return FStr_Init(str, str);
-}
-
 /* Return a string that refers to the shared str. */
 MAKE_INLINE FStr
 FStr_InitRefer(const char *str)
 {
-	return FStr_Init(str, NULL);
+	FStr fstr;
+	fstr.str = str;
+	fstr.freeIt = NULL;
+	return fstr;
 }
 
 MAKE_INLINE void
@@ -190,7 +187,7 @@ Substring_SkipFirst(Substring sub, char 
 }
 
 MAKE_STATIC const char *
-Substring_LastIndex(Substring sub, char ch)
+Substring_FindLast(Substring sub, char ch)
 {
 	const char *p;
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1091 src/usr.bin/make/var.c:1.1092
--- src/usr.bin/make/var.c:1.1091	Fri Jan  5 21:51:27 2024
+++ src/usr.bin/make/var.c	Fri Jan  5 21:56:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1091 2024/01/05 21:51:27 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1092 2024/01/05 21:56:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1091 2024/01/05 21:51:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1092 2024/01/05 21:56:55 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1328,7 +1328,7 @@ ModifyWord_Tail(Substring word, SepBuf *
 static void
 ModifyWord_Suffix(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
-	const char *lastDot = Substring_LastIndex(word, '.');
+	const char *lastDot = Substring_FindLast(word, '.');
 	if (lastDot != NULL)
 		SepBuf_AddRange(buf, lastDot + 1, word.end);
 }
@@ -1339,7 +1339,7 @@ ModifyWord_Root(Substring word, SepBuf *
 {
 	const char *lastDot, *end;
 
-	lastDot = Substring_LastIndex(word, '.');
+	lastDot = Substring_FindLast(word, '.');
 	end = lastDot != NULL ? lastDot : word.end;
 	SepBuf_AddRange(buf, word.start, end);
 }



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 21:56:55 UTC 2024

Modified Files:
src/usr.bin/make: str.h var.c

Log Message:
make: clean up string functions

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/str.h
cvs rdiff -u -r1.1091 -r1.1092 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.



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 21:51:27 UTC 2024

Modified Files:
src/usr.bin/make: str.h var.c

Log Message:
make: inline Substring_Sub

Remove redundant assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/str.h
cvs rdiff -u -r1.1090 -r1.1091 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/str.h
diff -u src/usr.bin/make/str.h:1.17 src/usr.bin/make/str.h:1.18
--- src/usr.bin/make/str.h:1.17	Fri Jun 23 04:56:54 2023
+++ src/usr.bin/make/str.h	Fri Jan  5 21:51:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.17 2023/06/23 04:56:54 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.18 2024/01/05 21:51:27 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -154,14 +154,6 @@ Substring_Eq(Substring sub, Substring st
 	   memcmp(sub.start, str.start, len) == 0;
 }
 
-MAKE_STATIC Substring
-Substring_Sub(Substring sub, size_t start, size_t end)
-{
-	assert(start <= Substring_Length(sub));
-	assert(end <= Substring_Length(sub));
-	return Substring_Init(sub.start + start, sub.start + end);
-}
-
 MAKE_STATIC bool
 Substring_HasPrefix(Substring sub, Substring prefix)
 {

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1090 src/usr.bin/make/var.c:1.1091
--- src/usr.bin/make/var.c:1.1090	Fri Dec 29 14:57:00 2023
+++ src/usr.bin/make/var.c	Fri Jan  5 21:51:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1090 2023/12/29 14:57:00 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1091 2024/01/05 21:51:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1090 2023/12/29 14:57:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1091 2024/01/05 21:51:27 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4222,7 +4222,8 @@ FindLocalLegacyVar(Substring varname, GN
 	if (strchr("@%?*!<>", varname.start[0]) == NULL)
 		return NULL;
 
-	v = VarFindSubstring(Substring_Sub(varname, 0, 1), scope, false);
+	v = VarFindSubstring(Substring_Init(varname.start, varname.start + 1),
+	scope, false);
 	if (v == NULL)
 		return NULL;
 



CVS commit: src/usr.bin/make

2024-01-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jan  5 21:51:27 UTC 2024

Modified Files:
src/usr.bin/make: str.h var.c

Log Message:
make: inline Substring_Sub

Remove redundant assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/str.h
cvs rdiff -u -r1.1090 -r1.1091 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.



CVS commit: src/usr.bin/make

2024-01-03 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Wed Jan  3 20:24:16 UTC 2024

Modified Files:
src/usr.bin/make: parse.c

Log Message:
make: do not add newline to an empty buffer

When LoadFile reads from /dev/null the buffer will be empty,
appending "\n" just results in an unnecessary extra call
to ParseRawLine.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.713 -r1.714 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.713 src/usr.bin/make/parse.c:1.714
--- src/usr.bin/make/parse.c:1.713	Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/parse.c	Wed Jan  3 20:24:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.713 2023/12/29 20:43:58 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg 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.713 2023/12/29 20:43:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -383,7 +383,7 @@ LoadFile(const char *path, int fd)
 	}
 	assert(buf.len <= buf.cap);
 
-	if (!Buf_EndsWith(, '\n'))
+	if (buf.len > 0 && !Buf_EndsWith(, '\n'))
 		Buf_AddByte(, '\n');
 
 	return buf;		/* may not be null-terminated */



CVS commit: src/usr.bin/make

2024-01-03 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Wed Jan  3 20:24:16 UTC 2024

Modified Files:
src/usr.bin/make: parse.c

Log Message:
make: do not add newline to an empty buffer

When LoadFile reads from /dev/null the buffer will be empty,
appending "\n" just results in an unnecessary extra call
to ParseRawLine.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.713 -r1.714 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make/unit-tests

2023-12-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 31 10:09:01 UTC 2023

Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.mk

Log Message:
tests/make: finish incomplete sentence in test for assignment modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-assign.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/unit-tests/varmod-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.17 src/usr.bin/make/unit-tests/varmod-assign.mk:1.18
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.17	Fri Dec 29 15:47:03 2023
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Sun Dec 31 10:09:01 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign.mk,v 1.17 2023/12/29 15:47:03 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.18 2023/12/31 10:09:01 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
@@ -155,8 +155,10 @@ ${VARNAME}=	initial-value	# Sets 'VAR.${
 .MAKEFLAGS: -d0
 
 
-# Conditional directives are evaluated in command line scope.  Any assignment
-# modifiers in these conditions create or
+# Conditional directives are evaluated in command line scope.  An assignment
+# modifier that creates a new variable creates it in the command line scope.
+# Existing variables are updated in their previous scope, and environment
+# variables are created in the global scope, as in other situations.
 .MAKEFLAGS: CMD_CMD_VAR=cmd-value
 CMD_GLOBAL_VAR=global-value
 export CMD_ENV_VAR=env-value
@@ -181,8 +183,7 @@ export CMD_ENV_VAR=env-value
 # debug log for this test, the debug log would have to be enabled for the
 # other targets as well, thus producing lots of irrelevant output.
 #
-# Running './make -r -f varmod-assign.mk target' results in:
-#	target: TARGET_TARGET_VAR = target-value
+# Running './make -r -f varmod-assign.mk target | grep ": TARGET"' results in:
 #	target: TARGET_TARGET_VAR = new-value
 #	Global: TARGET_GLOBAL_VAR = new-value
 #	Global: TARGET_ENV_VAR = new-value
@@ -191,7 +192,7 @@ export CMD_ENV_VAR=env-value
 TARGET_GLOBAL_VAR=global-value
 export TARGET_ENV_VAR=env-value
 .MAKEFLAGS: ${make(target):?-dv:}
-target: TARGET_TARGET_VAR=target-value
+target: .PHONY TARGET_TARGET_VAR=target-value
 	: ${TARGET_TARGET_VAR::=new-value}
 	: ${TARGET_CMD_VAR::=new-value}
 	: ${TARGET_GLOBAL_VAR::=new-value}



CVS commit: src/usr.bin/make/unit-tests

2023-12-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 31 10:09:01 UTC 2023

Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.mk

Log Message:
tests/make: finish incomplete sentence in test for assignment modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-assign.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 15:00:56 UTC 2023

Modified Files:
src/usr.bin/make: suff.c

Log Message:
make: clean up freeing of suffixes

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.375 -r1.376 src/usr.bin/make/suff.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/suff.c
diff -u src/usr.bin/make/suff.c:1.375 src/usr.bin/make/suff.c:1.376
--- src/usr.bin/make/suff.c:1.375	Sat Dec 30 13:28:06 2023
+++ src/usr.bin/make/suff.c	Sat Dec 30 15:00:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.375 2023/12/30 13:28:06 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.376 2023/12/30 15:00:56 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.375 2023/12/30 13:28:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.376 2023/12/30 15:00:56 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -364,7 +364,6 @@ SuffixList_Unref(SuffixList *list, Suffi
 	}
 }
 
-/* Free up all memory associated with the given suffix structure. */
 static void
 Suffix_Free(Suffix *suff)
 {
@@ -390,12 +389,6 @@ Suffix_Free(Suffix *suff)
 	free(suff);
 }
 
-static void
-SuffFree(void *p)
-{
-	Suffix_Free(p);
-}
-
 /* Remove the suffix from the list, and free if it is otherwise unused. */
 static void
 SuffixList_Remove(SuffixList *list, Suffix *suff)
@@ -405,7 +398,7 @@ SuffixList_Remove(SuffixList *list, Suff
 		/* XXX: can lead to suff->refCount == -1 */
 		SuffixList_Unref(, suff);
 		DEBUG1(SUFF, "Removing suffix \"%s\"\n", suff->name);
-		SuffFree(suff);
+		Suffix_Free(suff);
 	}
 }
 
@@ -482,7 +475,7 @@ Suff_ClearSuffixes(void)
 	Lst_Init();
 	sNum = 0;
 	if (nullSuff != NULL)
-		SuffFree(nullSuff);
+		Suffix_Free(nullSuff);
 	emptySuff = nullSuff = Suffix_New("");
 
 	SearchPath_AddAll(nullSuff->searchPath, );
@@ -2054,16 +2047,21 @@ Suff_Init(void)
 	Suff_ClearSuffixes();
 }
 
-
 /* Clean up the suffixes module. */
 void
 Suff_End(void)
 {
 #ifdef CLEANUP
-	Lst_DoneCall(, SuffFree);
-	Lst_DoneCall(, SuffFree);
+	SuffixListNode *ln;
+
+	for (ln = sufflist.first; ln != NULL; ln = ln->next)
+		Suffix_Free(ln->datum);
+	Lst_Done();
+	for (ln = suffClean.first; ln != NULL; ln = ln->next)
+		Suffix_Free(ln->datum);
+	Lst_Done();
 	if (nullSuff != NULL)
-		SuffFree(nullSuff);
+		Suffix_Free(nullSuff);
 	Lst_Done();
 #endif
 }



CVS commit: src/usr.bin/make

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 15:00:56 UTC 2023

Modified Files:
src/usr.bin/make: suff.c

Log Message:
make: clean up freeing of suffixes

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.375 -r1.376 src/usr.bin/make/suff.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 13:28:06 UTC 2023

Modified Files:
src/usr.bin/make: suff.c

Log Message:
make: remove unused field from suffix

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.374 -r1.375 src/usr.bin/make/suff.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/suff.c
diff -u src/usr.bin/make/suff.c:1.374 src/usr.bin/make/suff.c:1.375
--- src/usr.bin/make/suff.c:1.374	Fri Dec 29 18:53:24 2023
+++ src/usr.bin/make/suff.c	Sat Dec 30 13:28:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.374 2023/12/29 18:53:24 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.375 2023/12/30 13:28:06 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.374 2023/12/29 18:53:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.375 2023/12/30 13:28:06 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -142,8 +142,6 @@ static GNodeList transforms = LST_INIT;
  */
 static int sNum = 0;
 
-typedef List SuffixListList;
-
 /*
  * A suffix such as ".c" or ".o" that may be used in suffix transformation
  * rules such as ".c.o:".
@@ -185,14 +183,6 @@ typedef struct Suffix {
 	SuffixList parents;
 	/* Suffixes we have a transformation from */
 	SuffixList children;
-	/*
-	 * Lists in which this suffix is referenced.
-	 *
-	 * XXX: These lists are used nowhere, they are just appended to, for
-	 * no apparent reason.  They do have the side effect of increasing
-	 * refCount though.
-	 */
-	SuffixListList ref;
 } Suffix;
 
 /*
@@ -392,7 +382,6 @@ Suffix_Free(Suffix *suff)
 		suff->name, suff->refCount);
 #endif
 
-	Lst_Done(>ref);
 	Lst_Done(>children);
 	Lst_Done(>parents);
 	SearchPath_Free(suff->searchPath);
@@ -440,12 +429,10 @@ SuffixList_Insert(SuffixList *list, Suff
 		DEBUG2(SUFF, "inserting \"%s\" (%d) at end of list\n",
 		suff->name, suff->sNum);
 		Lst_Append(list, Suffix_Ref(suff));
-		Lst_Append(>ref, list);
 	} else if (listSuff->sNum != suff->sNum) {
 		DEBUG4(SUFF, "inserting \"%s\" (%d) before \"%s\" (%d)\n",
 		suff->name, suff->sNum, listSuff->name, listSuff->sNum);
 		Lst_InsertBefore(list, ln, Suffix_Ref(suff));
-		Lst_Append(>ref, list);
 	} else {
 		DEBUG2(SUFF, "\"%s\" (%d) is already there\n",
 		suff->name, suff->sNum);
@@ -469,7 +456,6 @@ Suffix_New(const char *name)
 	suff->searchPath = SearchPath_New();
 	Lst_Init(>children);
 	Lst_Init(>parents);
-	Lst_Init(>ref);
 	suff->sNum = sNum++;
 	suff->include = false;
 	suff->library = false;
@@ -821,19 +807,7 @@ UpdateTargets(Suffix *suff)
 	}
 }
 
-/*
- * Add the suffix to the end of the list of known suffixes.
- * Should we restructure the suffix graph? Make doesn't.
- *
- * A GNode is created for the suffix (XXX: this sounds completely wrong) and
- * a Suffix structure is created and added to the suffixes list unless the
- * suffix was already known.
- * The mainNode passed can be modified if a target mutated into a
- * transform and that target happened to be the main target.
- *
- * Input:
- *	name		the name of the suffix to add
- */
+/* Add the suffix to the end of the list of known suffixes. */
 void
 Suff_AddSuffix(const char *name)
 {



CVS commit: src/usr.bin/make

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 13:28:06 UTC 2023

Modified Files:
src/usr.bin/make: suff.c

Log Message:
make: remove unused field from suffix

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.374 -r1.375 src/usr.bin/make/suff.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/make

2023-12-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Dec 29 20:43:58 UTC 2023

Modified Files:
src/usr.bin/make: lst.c lst.h parse.c

Log Message:
make: unexport list memory management functions

They are only used in a single source file.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/lst.c
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/make/lst.h
cvs rdiff -u -r1.712 -r1.713 src/usr.bin/make/parse.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/lst.c
diff -u src/usr.bin/make/lst.c:1.106 src/usr.bin/make/lst.c:1.107
--- src/usr.bin/make/lst.c:1.106	Sat Feb 26 11:57:21 2022
+++ src/usr.bin/make/lst.c	Fri Dec 29 20:43:58 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.106 2022/02/26 11:57:21 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.106 2022/02/26 11:57:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -48,15 +48,6 @@ LstNodeNew(ListNode *prev, ListNode *nex
 	return ln;
 }
 
-/* Create and initialize a new, empty list. */
-List *
-Lst_New(void)
-{
-	List *list = bmake_malloc(sizeof *list);
-	Lst_Init(list);
-	return list;
-}
-
 void
 Lst_Done(List *list)
 {
@@ -80,15 +71,6 @@ Lst_DoneCall(List *list, LstFreeProc fre
 	}
 }
 
-/* Free a list and all its nodes. The node data are not freed though. */
-void
-Lst_Free(List *list)
-{
-
-	Lst_Done(list);
-	free(list);
-}
-
 /* Insert a new node with the datum before the given node. */
 void
 Lst_InsertBefore(List *list, ListNode *ln, void *datum)

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.103 src/usr.bin/make/lst.h:1.104
--- src/usr.bin/make/lst.h:1.103	Thu Mar  3 19:55:27 2022
+++ src/usr.bin/make/lst.h	Fri Dec 29 20:43:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.103 2022/03/03 19:55:27 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.104 2023/12/29 20:43:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,16 +101,10 @@ struct List {
 /* Free the datum of a node, called before freeing the node itself. */
 typedef void LstFreeProc(void *);
 
-/* Create or destroy a list */
-
-/* Create a new list. */
-List *Lst_New(void) MAKE_ATTR_USE;
 /* Free the list nodes, but not the list itself. */
 void Lst_Done(List *);
 /* Free the list nodes, freeing the node data using the given function. */
 void Lst_DoneCall(List *, LstFreeProc);
-/* Free the list, leaving the node data unmodified. */
-void Lst_Free(List *);
 
 #define LST_INIT { NULL, NULL }
 

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.712 src/usr.bin/make/parse.c:1.713
--- src/usr.bin/make/parse.c:1.712	Tue Dec 19 19:33:39 2023
+++ src/usr.bin/make/parse.c	Fri Dec 29 20:43:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.712 2023/12/19 19:33:39 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.713 2023/12/29 20:43:58 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.712 2023/12/19 19:33:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.713 2023/12/29 20:43:58 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -312,6 +312,23 @@ enum PosixState posix_state = PS_NOT_YET
 
 static HashTable /* full file name -> Guard */ guards;
 
+
+static List *
+Lst_New(void)
+{
+	List *list = bmake_malloc(sizeof *list);
+	Lst_Init(list);
+	return list;
+}
+
+static void
+Lst_Free(List *list)
+{
+
+	Lst_Done(list);
+	free(list);
+}
+
 static IncludedFile *
 GetInclude(size_t i)
 {



CVS commit: src/usr.bin/make

2023-12-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Dec 29 20:43:58 UTC 2023

Modified Files:
src/usr.bin/make: lst.c lst.h parse.c

Log Message:
make: unexport list memory management functions

They are only used in a single source file.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/make/lst.c
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/make/lst.h
cvs rdiff -u -r1.712 -r1.713 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



  1   2   3   4   5   6   7   8   9   10   >