Merge bmake-20220418

o ignore '.POSIX:' if not in first non-comment line
        of Makefile as specified by POSIX.
        add unit-tests for above.

Merge commit '92bfae0e6bd53a7a0d6fe55e70a916d86cf26e8b'
This commit is contained in:
Simon J. Gerraty 2022-04-22 13:40:29 -07:00
commit 2f2a5ecdf8
25 changed files with 391 additions and 129 deletions

View File

@ -1,3 +1,21 @@
2022-04-18 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20220418
Merge with NetBSD make, pick up
o ignore '.POSIX:' if not in first non-comment line
of Makefile as specified by POSIX.
add unit-tests for above.
o meta.c: make it easier to find usage of identifiers
o targ.c: add .USEBEFORE to Targ_PrintType
2022-04-14 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20220414
* unit-tests/Makefile: simplify checks for shells with
BROKEN_TESTS, this helps with other Linux distros that
use dash.
2022-03-30 Simon J Gerraty <sjg@beast.crufty.net> 2022-03-30 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20220330 * VERSION (_MAKE_VERSION): 20220330

View File

@ -274,6 +274,8 @@ unit-tests/deptgt-path.exp
unit-tests/deptgt-path.mk unit-tests/deptgt-path.mk
unit-tests/deptgt-phony.exp unit-tests/deptgt-phony.exp
unit-tests/deptgt-phony.mk unit-tests/deptgt-phony.mk
unit-tests/deptgt-posix.exp
unit-tests/deptgt-posix.mk
unit-tests/deptgt-precious.exp unit-tests/deptgt-precious.exp
unit-tests/deptgt-precious.mk unit-tests/deptgt-precious.mk
unit-tests/deptgt-shell.exp unit-tests/deptgt-shell.exp

View File

@ -1,2 +1,2 @@
# keep this compatible with sh and make # keep this compatible with sh and make
_MAKE_VERSION=20220330 _MAKE_VERSION=20220418

View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.307 2022/03/26 15:39:58 sjg Exp $ .\" $NetBSD: make.1,v 1.308 2022/04/18 15:06:27 rillig Exp $
.\" .\"
.\" Copyright (c) 1990, 1993 .\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\" .\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\" .\"
.Dd March 24, 2022 .Dd April 18, 2022
.Dt BMAKE 1 .Dt BMAKE 1
.Os .Os
.Sh NAME .Sh NAME
@ -2291,17 +2291,15 @@ Apply the
.Ic .PHONY .Ic .PHONY
attribute to any specified sources. attribute to any specified sources.
.It Ic .POSIX .It Ic .POSIX
This should be the first non-comment line in a Makefile. If this is the first non-comment line in the main makefile,
It results in the variable the variable
.Va %POSIX .Va %POSIX
being defined with the value is set to the value
.Ql 1003.2 . .Ql 1003.2
The first time and the makefile
.Ic .POSIX .Ql <posix.mk>
is encountered, the makefile is included if it exists,
.Ql posix.mk to provide POSIX-compatible default rules.
will be included if possible,
to provide POSIX compatible default rules.
If If
.Nm .Nm
is run with the is run with the

View File

@ -1468,12 +1468,11 @@ BMAKE(1) FreeBSD General Commands Manual BMAKE(1)
.PHONY Apply the .PHONY attribute to any specified sources. .PHONY Apply the .PHONY attribute to any specified sources.
.POSIX This should be the first non-comment line in a Makefile. It re- .POSIX If this is the first non-comment line in the main makefile, the
sults in the variable %POSIX being defined with the value variable %POSIX is set to the value `1003.2' and the makefile
`1003.2'. The first time .POSIX is encountered, the makefile `<posix.mk>' is included if it exists, to provide POSIX-compati-
`posix.mk' will be included if possible, to provide POSIX com- ble default rules. If bmake is run with the -r flag, then only
patible default rules. If bmake is run with the -r flag, then `posix.mk' will contribute to the default rules.
only `posix.mk' will contribute to the default rules.
.PRECIOUS .PRECIOUS
Apply the .PRECIOUS attribute to any specified sources. If no Apply the .PRECIOUS attribute to any specified sources. If no
@ -1629,4 +1628,4 @@ BMAKE(1) FreeBSD General Commands Manual BMAKE(1)
There is no way of escaping a space character in a filename. There is no way of escaping a space character in a filename.
FreeBSD 13.0 March 24, 2022 FreeBSD 13.0 FreeBSD 13.0 April 18, 2022 FreeBSD 13.0

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.333 2022/03/03 19:46:31 rillig Exp $ */ /* $NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -95,7 +95,7 @@
#include "dir.h" #include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
MAKE_RCSID("$NetBSD: cond.c,v 1.333 2022/03/03 19:46:31 rillig Exp $"); MAKE_RCSID("$NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $");
/* /*
* Conditional expressions conform to this grammar: * Conditional expressions conform to this grammar:
@ -710,7 +710,7 @@ CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token)
return true; return true;
} }
/* Parse a function call expression, such as 'defined(${file})'. */ /* Parse a function call expression, such as 'exists(${file})'. */
static bool static bool
CondParser_FuncCall(CondParser *par, bool doEval, Token *out_token) CondParser_FuncCall(CondParser *par, bool doEval, Token *out_token)
{ {

View File

@ -84,7 +84,7 @@ if [ -z "$ECHO" ]; then
test -s $TF.rm && xargs rm -f < $TF.rm test -s $TF.rm && xargs rm -f < $TF.rm
$GIT add -A $GIT add -A
$GIT diff --staged | tee $SB/tmp/bmake-import.diff $GIT diff --staged | tee $SB/tmp/bmake-import.diff
{ echo "$GIT tag -a vendor/NetBSD/bmake/$VERSION" { echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION"
echo "echo \"When ready do: $GIT push --follow-tags\"" echo "echo \"When ready do: $GIT push --follow-tags\""
} > $SB/tmp/bmake-post.sh } > $SB/tmp/bmake-post.sh
echo "After you commit, run $SB/tmp/bmake-post.sh" echo "After you commit, run $SB/tmp/bmake-post.sh"

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.579 2022/03/22 23:37:09 rillig Exp $ */ /* $NetBSD: main.c,v 1.580 2022/04/18 15:06:27 rillig Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -111,7 +111,7 @@
#include "trace.h" #include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: main.c,v 1.579 2022/03/22 23:37:09 rillig Exp $"); MAKE_RCSID("$NetBSD: main.c,v 1.580 2022/04/18 15:06:27 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint) #if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. " "The Regents of the University of California. "
@ -1507,6 +1507,7 @@ main_ReadFiles(void)
if (!opts.noBuiltins) if (!opts.noBuiltins)
ReadBuiltinRules(); ReadBuiltinRules();
posix_state = PS_MAYBE_NEXT_LINE;
if (!Lst_IsEmpty(&opts.makefiles)) if (!Lst_IsEmpty(&opts.makefiles))
ReadAllMakefiles(&opts.makefiles); ReadAllMakefiles(&opts.makefiles);
else else

View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.307 2022/03/26 15:39:58 sjg Exp $ .\" $NetBSD: make.1,v 1.308 2022/04/18 15:06:27 rillig Exp $
.\" .\"
.\" Copyright (c) 1990, 1993 .\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\" .\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\" .\"
.Dd March 24, 2022 .Dd April 18, 2022
.Dt MAKE 1 .Dt MAKE 1
.Os .Os
.Sh NAME .Sh NAME
@ -2302,17 +2302,15 @@ Apply the
.Ic .PHONY .Ic .PHONY
attribute to any specified sources. attribute to any specified sources.
.It Ic .POSIX .It Ic .POSIX
This should be the first non-comment line in a Makefile. If this is the first non-comment line in the main makefile,
It results in the variable the variable
.Va %POSIX .Va %POSIX
being defined with the value is set to the value
.Ql 1003.2 . .Ql 1003.2
The first time and the makefile
.Ic .POSIX .Ql <posix.mk>
is encountered, the makefile is included if it exists,
.Ql posix.mk to provide POSIX-compatible default rules.
will be included if possible,
to provide POSIX compatible default rules.
If If
.Nm .Nm
is run with the is run with the

View File

@ -1,4 +1,4 @@
/* $NetBSD: make.h,v 1.299 2022/03/26 14:02:40 rillig Exp $ */ /* $NetBSD: make.h,v 1.300 2022/04/18 15:06:27 rillig Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -522,6 +522,17 @@ typedef struct GNode {
unsigned lineno; unsigned lineno;
} GNode; } GNode;
/*
* Keep track of whether to include <posix.mk> when parsing the line
* '.POSIX:'.
*/
extern enum PosixState {
PS_NOT_YET,
PS_MAYBE_NEXT_LINE,
PS_NOW_OR_NEVER,
PS_TOO_LATE
} posix_state;
/* Error levels for diagnostics during parsing. */ /* Error levels for diagnostics during parsing. */
typedef enum ParseErrorLevel { typedef enum ParseErrorLevel {
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: meta.c,v 1.199 2022/03/04 23:17:16 sjg Exp $ */ /* $NetBSD: meta.c,v 1.200 2022/04/15 12:28:16 rillig Exp $ */
/* /*
* Implement 'meta' mode. * Implement 'meta' mode.
@ -387,12 +387,10 @@ printCMDs(GNode *gn, FILE *fp)
/* /*
* Certain node types never get a .meta file * Certain node types never get a .meta file
*/ */
#define SKIP_META_TYPE(_type) do { \ #define SKIP_META_TYPE(flag, str) do { \
if ((gn->type & __CONCAT(OP_, _type))) { \ if ((gn->type & (flag))) { \
if (verbose) { \ if (verbose) \
debug_printf("Skipping meta for %s: .%s\n", \ debug_printf("Skipping meta for %s: .%s\n", gn->name, str); \
gn->name, __STRING(_type)); \
} \
return false; \ return false; \
} \ } \
} while (false) } while (false)
@ -413,12 +411,12 @@ meta_needed(GNode *gn, const char *dname,
/* This may be a phony node which we don't want meta data for... */ /* This may be a phony node which we don't want meta data for... */
/* Skip .meta for .BEGIN, .END, .ERROR etc as well. */ /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */
/* Or it may be explicitly flagged as .NOMETA */ /* Or it may be explicitly flagged as .NOMETA */
SKIP_META_TYPE(NOMETA); SKIP_META_TYPE(OP_NOMETA, "NOMETA");
/* Unless it is explicitly flagged as .META */ /* Unless it is explicitly flagged as .META */
if (!(gn->type & OP_META)) { if (!(gn->type & OP_META)) {
SKIP_META_TYPE(PHONY); SKIP_META_TYPE(OP_PHONY, "PHONY");
SKIP_META_TYPE(SPECIAL); SKIP_META_TYPE(OP_SPECIAL, "SPECIAL");
SKIP_META_TYPE(MAKE); SKIP_META_TYPE(OP_MAKE, "MAKE");
} }
/* Check if there are no commands to execute. */ /* Check if there are no commands to execute. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $ */ /* $NetBSD: parse.c,v 1.670 2022/04/18 16:09:05 sjg Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -121,7 +121,7 @@
#include "pathnames.h" #include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $"); MAKE_RCSID("$NetBSD: parse.c,v 1.670 2022/04/18 16:09:05 sjg Exp $");
/* /*
* A file being read. * A file being read.
@ -309,6 +309,7 @@ static const struct {
{ ".WAIT", SP_WAIT, OP_NONE }, { ".WAIT", SP_WAIT, OP_NONE },
}; };
enum PosixState posix_state = PS_NOT_YET;
static IncludedFile * static IncludedFile *
GetInclude(size_t i) GetInclude(size_t i)
@ -1267,23 +1268,14 @@ HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
break; break;
#ifdef POSIX #ifdef POSIX
case SP_POSIX: case SP_POSIX:
Global_Set("%POSIX", "1003.2"); if (posix_state == PS_NOW_OR_NEVER) {
{
static bool first_posix = true;
/* /*
* Since .POSIX: should be the first * With '-r', 'posix.mk' (if it exists)
* operative line in a makefile, * can effectively substitute for 'sys.mk',
* if '-r' flag is used, no default rules have * otherwise it is an extension.
* been read yet, in which case 'posix.mk' can
* be a substiute for 'sys.mk'.
* If '-r' is not used, then 'posix.mk' acts
* as an extension of 'sys.mk'.
*/ */
if (first_posix) { Global_Set("%POSIX", "1003.2");
first_posix = false; IncludeFile("posix.mk", true, false, true);
IncludeFile("posix.mk", true, false, true);
}
} }
break; break;
#endif #endif
@ -2605,6 +2597,10 @@ ReadHighLevelLine(void)
for (;;) { for (;;) {
line = ReadLowLevelLine(LK_NONEMPTY); line = ReadLowLevelLine(LK_NONEMPTY);
if (posix_state == PS_MAYBE_NEXT_LINE)
posix_state = PS_NOW_OR_NEVER;
else
posix_state = PS_TOO_LATE;
if (line == NULL) if (line == NULL)
return NULL; return NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.176 2022/01/07 20:50:35 rillig Exp $ */ /* $NetBSD: targ.c,v 1.177 2022/04/15 12:19:28 rillig Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -107,7 +107,7 @@
#include "dir.h" #include "dir.h"
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: targ.c,v 1.176 2022/01/07 20:50:35 rillig Exp $"); MAKE_RCSID("$NetBSD: targ.c,v 1.177 2022/04/15 12:19:28 rillig Exp $");
/* /*
* All target nodes that appeared on the left-hand side of one of the * All target nodes that appeared on the left-hand side of one of the
@ -410,6 +410,7 @@ Targ_PrintType(GNodeType type)
{ OP_IGNORE, false, "IGNORE" }, { OP_IGNORE, false, "IGNORE" },
{ OP_EXEC, false, "EXEC" }, { OP_EXEC, false, "EXEC" },
{ OP_USE, false, "USE" }, { OP_USE, false, "USE" },
{ OP_USEBEFORE, false, "USEBEFORE" },
{ OP_OPTIONAL, false, "OPTIONAL" }, { OP_OPTIONAL, false, "OPTIONAL" },
}; };
size_t i; size_t i;

View File

@ -1,6 +1,6 @@
# $Id: Makefile,v 1.178 2022/03/26 23:10:27 sjg Exp $ # $Id: Makefile,v 1.180 2022/04/18 21:25:37 sjg Exp $
# #
# $NetBSD: Makefile,v 1.311 2022/03/26 12:44:57 rillig Exp $ # $NetBSD: Makefile,v 1.312 2022/04/18 15:06:28 rillig Exp $
# #
# Unit tests for make(1) # Unit tests for make(1)
# #
@ -142,6 +142,7 @@ TESTS+= deptgt-order
TESTS+= deptgt-path TESTS+= deptgt-path
TESTS+= deptgt-path-suffix TESTS+= deptgt-path-suffix
TESTS+= deptgt-phony TESTS+= deptgt-phony
TESTS+= deptgt-posix
TESTS+= deptgt-precious TESTS+= deptgt-precious
TESTS+= deptgt-shell TESTS+= deptgt-shell
TESTS+= deptgt-silent TESTS+= deptgt-silent
@ -440,31 +441,26 @@ TESTS+= varparse-mod
TESTS+= varparse-undef-partial TESTS+= varparse-undef-partial
TESTS+= varquote TESTS+= varquote
# for now at least # some shells have quirks
.if ${.SHELL:T} == "ksh" _shell := ${.SHELL:tA:T}
.if ${_shell} == "dash"
# dash fails -x output
BROKEN_TESTS+= opt-debug-x-trace
.elif ${_shell} == "ksh"
BROKEN_TESTS+= sh-flags BROKEN_TESTS+= sh-flags
.endif .endif
.if ${.MAKE.OS:NDarwin} == "" .if ${.MAKE.OS:NDarwin} == ""
BROKEN_TESTS+= shell-ksh BROKEN_TESTS+= shell-ksh
.endif .endif
.if ${.MAKE.OS} == "Linux" && ${.SHELL:tA:T} != "bash"
.if exists(/etc/os-release)
distro!= . /etc/os-release && echo $$NAME
.endif
# dash fails -x output
# .SHELL is not bash so may be dash
# if distro is Ubuntu or we cannot tell, assume the worst
.if ${distro:U:NUbuntu} == ""
BROKEN_TESTS+= opt-debug-x-trace
.endif
.endif
.if ${.MAKE.OS} == "SCO_SV" .if ${.MAKE.OS} == "SCO_SV"
BROKEN_TESTS+= \ BROKEN_TESTS+= \
opt-debug-graph[23] \ opt-debug-graph[23] \
varmod-localtime \ varmod-localtime \
varmod-to-separator \ varmod-to-separator \
.if ${.SHELL:T} == "bash" .if ${_shell} == "bash"
BROKEN_TESTS+= job-output-null BROKEN_TESTS+= job-output-null
.else .else
BROKEN_TESTS+= \ BROKEN_TESTS+= \

View File

@ -2,5 +2,9 @@ first 1
first 2 first 2
second 1 second 1
second 2 second 2
first-first 1
first-first 2
first-second 1
first-second 2
directly directly
exit status 0 exit status 0

View File

@ -1,7 +1,11 @@
# $NetBSD: depsrc-use.mk,v 1.5 2021/12/28 14:22:51 rillig Exp $ # $NetBSD: depsrc-use.mk,v 1.6 2022/04/18 14:38:24 rillig Exp $
# #
# Tests for the special source .USE in dependency declarations, # Tests for the special source .USE in dependency declarations,
# which allows to append common commands to other targets. # which allows to append common commands to other targets.
#
# See also:
# .USEBEFORE
# depsrc-usebefore.mk
# Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally # Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally
# regarded as a candidate for the main target. On the other hand, a .USE # regarded as a candidate for the main target. On the other hand, a .USE
@ -10,9 +14,15 @@ not-a-main-candidate: .USE
all: action directly all: action directly
first: .USE first: .USE first-first first-second
@echo first 1 # Using ${.TARGET} here would expand to "action" @echo first 1 # Using ${.TARGET} here would expand to "action"
@echo first 2 @echo first 2
first-first: .USE
@echo first-first 1
@echo first-first 2
first-second: .USE
@echo first-second 1
@echo first-second 2
second: .USE second: .USE
@echo second 1 @echo second 1
@ -22,7 +32,7 @@ second: .USE
# This may happen as the result of expanding a .for loop. # This may happen as the result of expanding a .for loop.
empty: .USE empty: .USE
# It's possible but uncommon to directly make a .USEBEFORE target. # It's possible but uncommon to directly make a .USE target.
directly: .USE directly: .USE
@echo directly @echo directly

View File

@ -1,6 +1,42 @@
first 1 after-2-before-2 1
first 2 after-2-before-2 2
second 1 after-2-before-1 1
second 2 after-2-before-1 2
directly after-1-before-2 1
after-1-before-2 2
after-1-before-1 1
after-1-before-1 2
before-2-before-2 1
before-2-before-2 2
before-2-before-1 1
before-2-before-1 2
before-1-before-2 1
before-1-before-2 2
before-1-before-1 1
before-1-before-1 2
before-2 1
before-2 2
before-1 1
before-1 2
after-1 1
after-1 2
after-2 1
after-2 2
before-1-after-1 1
before-1-after-1 2
before-1-after-2 1
before-1-after-2 2
before-2-after-1 1
before-2-after-1 2
before-2-after-2 1
before-2-after-2 2
after-1-after-1 1
after-1-after-1 2
after-1-after-2 1
after-1-after-2 2
after-2-after-1 1
after-2-after-1 2
after-2-after-2 1
after-2-after-2 2
`directly' is up to date.
exit status 0 exit status 0

View File

@ -1,8 +1,14 @@
# $NetBSD: depsrc-usebefore.mk,v 1.7 2021/12/28 14:22:51 rillig Exp $ # $NetBSD: depsrc-usebefore.mk,v 1.9 2022/04/18 14:41:42 rillig Exp $
# #
# Tests for the special source .USEBEFORE in dependency declarations, # Tests for the special source .USEBEFORE in dependency declarations,
# which allows to prepend common commands to other targets. # which allows to prepend common commands to other targets.
# #
# If a target depends on several .USE or .USEBEFORE nodes, the commands get
# appended or prepended in declaration order. For .USE nodes, this is the
# expected order, for .USEBEFORE nodes the order is somewhat reversed, and for
# .USE or .USEBEFORE nodes that depend on other .USE or .USEBEFORE nodes, it
# gets even more complicated.
#
# See also: # See also:
# .USE # .USE
# depsrc-use.mk # depsrc-use.mk
@ -12,22 +18,98 @@
# target was not. # target was not.
not-a-main-candidate: .USEBEFORE not-a-main-candidate: .USEBEFORE
all: action directly all:
@${MAKE} -r -f ${MAKEFILE} ordering
@${MAKE} -r -f ${MAKEFILE} directly
first: .USEBEFORE ordering: before-1 before-2 after-1 after-2
@echo first 1 # Using ${.TARGET} here would expand to "action"
@echo first 2 # Using ${.TARGET} here would expand to "action"
second: .USEBEFORE before-1: .USEBEFORE before-1-before-1 before-1-before-2 before-1-after-1 before-1-after-2
@echo second 1 @echo before-1 1
@echo second 2 @echo before-1 2
before-1-before-1: .USEBEFORE
@echo before-1-before-1 1
@echo before-1-before-1 2
before-1-before-2: .USEBEFORE
@echo before-1-before-2 1
@echo before-1-before-2 2
before-1-after-1: .USE
@echo before-1-after-1 1
@echo before-1-after-1 2
before-1-after-2: .USE
@echo before-1-after-2 1
@echo before-1-after-2 2
before-2: .USEBEFORE before-2-before-1 before-2-before-2 before-2-after-1 before-2-after-2
@echo before-2 1
@echo before-2 2
before-2-before-1: .USEBEFORE
@echo before-2-before-1 1
@echo before-2-before-1 2
before-2-before-2: .USEBEFORE
@echo before-2-before-2 1
@echo before-2-before-2 2
before-2-after-1: .USE
@echo before-2-after-1 1
@echo before-2-after-1 2
before-2-after-2: .USE
@echo before-2-after-2 1
@echo before-2-after-2 2
after-1: .USE after-1-before-1 after-1-before-2 after-1-after-1 after-1-after-2
@echo after-1 1
@echo after-1 2
after-1-before-1: .USEBEFORE
@echo after-1-before-1 1
@echo after-1-before-1 2
after-1-before-2: .USEBEFORE
@echo after-1-before-2 1
@echo after-1-before-2 2
after-1-after-1: .USE
@echo after-1-after-1 1
@echo after-1-after-1 2
after-1-after-2: .USE
@echo after-1-after-2 1
@echo after-1-after-2 2
after-2: .USE after-2-before-1 after-2-before-2 after-2-after-1 after-2-after-2
@echo after-2 1
@echo after-2 2
after-2-before-1: .USEBEFORE
@echo after-2-before-1 1
@echo after-2-before-1 2
after-2-before-2: .USEBEFORE
@echo after-2-before-2 1
@echo after-2-before-2 2
after-2-after-1: .USE
@echo after-2-after-1 1
@echo after-2-after-1 2
after-2-after-2: .USE
@echo after-2-after-2 1
@echo after-2-after-2 2
# It is possible but uncommon to have a .USEBEFORE target with no commands. # It is possible but uncommon to have a .USEBEFORE target with no commands.
# This may happen as the result of expanding a .for loop. # This may happen as the result of expanding a .for loop.
empty: .USEBEFORE empty: .USEBEFORE
# It is possible but uncommon to directly make a .USEBEFORE target. # It is technically possible to directly make a .USEBEFORE target, but it
# doesn't make sense since GNode_IsOODate considers such a target to always be
# up to date.
directly: .USEBEFORE directly: .USEBEFORE
@echo directly @echo directly
action: second first empty

View File

@ -0,0 +1 @@
exit status 0

View File

@ -0,0 +1,116 @@
# $NetBSD: deptgt-posix.mk,v 1.2 2022/04/18 15:59:39 sjg Exp $
#
# Tests for the special target '.POSIX', which enables POSIX mode.
#
# As of 2022-04-18, this only means that the variable '%POSIX' is defined and
# that the variables and rules specified by POSIX replace the default ones.
# This is done by loading <posix.mk>, if available. That file is not included
# in NetBSD, but only in the bmake distribution. As of 2022-04-18, POSIX
# support is not complete.
#
# Implementation node: this test needs to be isolated from the usual test
# to prevent unit-tests/posix.mk from interfering with the posix.mk from the
# system directory that this test uses.
#
# See also:
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
TESTTMP= ${TMPDIR:U/tmp}/make.test.deptgt-posix
SYSDIR= ${TESTTMP}/sysdir
MAIN_MK= ${TESTTMP}/main.mk
INCLUDED_MK= ${TESTTMP}/included.mk
all: .PHONY
.SILENT:
set-up-sysdir: .USEBEFORE
mkdir -p ${SYSDIR}
printf '%s\n' > ${SYSDIR}/sys.mk \
'CC=sys-cc' \
'SEEN_SYS_MK=yes'
printf '%s\n' > ${SYSDIR}/posix.mk \
'CC=posix-cc'
check-is-posix: .USE
printf '%s\n' >> ${MAIN_MK} \
'.if $${CC} != "posix-cc"' \
'. error' \
'.endif' \
'.if $${%POSIX} != "1003.2"' \
'. error' \
'.endif' \
'all: .PHONY'
check-not-posix: .USE
printf '%s\n' >> ${MAIN_MK} \
'.if $${CC} != "sys-cc"' \
'. error' \
'.endif' \
'.if defined(%POSIX)' \
'. error' \
'.endif' \
'all: .PHONY'
check-not-seen-sys-mk: .USE
printf '%s\n' >> ${MAIN_MK} \
'.if defined(SEEN_SYS_MK)' \
'. error' \
'.endif'
run: .USE
(cd "${TESTTMP}" && MAKEFLAGS=${MAKEFLAGS.${.TARGET}:Q} ${MAKE} \
-m "${SYSDIR}" -f ${MAIN_MK:T})
rm -rf ${TESTTMP}
# If the main makefile has a '.for' loop as its first non-comment line, a
# strict reading of POSIX 2018 makes the makefile non-conforming.
all: after-for
after-for: .PHONY set-up-sysdir check-not-posix run
printf '%s\n' > ${MAIN_MK} \
'# comment' \
'' \
'.for i in once' \
'.POSIX:' \
'.endfor'
# If the main makefile has an '.if' conditional as its first non-comment line,
# a strict reading of POSIX 2018 makes the makefile non-conforming.
all: after-if
after-if: .PHONY set-up-sysdir check-not-posix run
printf '%s\n' > ${MAIN_MK} \
'# comment' \
'' \
'.if 1' \
'.POSIX:' \
'.endif'
# If the main makefile first includes another makefile and that included
# makefile tries to switch to POSIX mode, that's too late.
all: in-included-file
in-included-file: .PHONY set-up-sysdir check-not-posix run
printf 'include included.mk\n' > ${MAIN_MK}
printf '.POSIX:\n' > ${INCLUDED_MK}
# If the main makefile switches to POSIX mode in its very first line, before
# and comment lines or empty lines, that works.
all: in-first-line
in-first-line: .PHONY set-up-sysdir check-is-posix run
printf '%s\n' > ${MAIN_MK} \
'.POSIX:'
# The only allowed lines before switching to POSIX mode are comment lines.
# POSIX defines that empty and blank lines are called comment lines as well.
all: after-comment-lines
after-comment-lines: .PHONY set-up-sysdir check-is-posix run
printf '%s\n' > ${MAIN_MK} \
'# comment' \
'' \
'.POSIX:'
# Running make with the option '-r' skips the builtin rules from <sys.mk>.
# In that mode, '.POSIX:' just loads <posix.mk>, which works as well.
MAKEFLAGS.no-builtins= -r
all: no-builtins
no-builtins: .PHONY set-up-sysdir check-is-posix check-not-seen-sys-mk run
printf '%s\n' > ${MAIN_MK} \
'.POSIX:'

View File

@ -1,4 +1,4 @@
# $NetBSD: deptgt-silent-jobs.mk,v 1.2 2022/02/12 11:14:48 rillig Exp $ # $NetBSD: deptgt-silent-jobs.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
# #
# Ensure that the special dependency target '.SILENT' only affects the amount # Ensure that the special dependency target '.SILENT' only affects the amount
# of output, but not the kind of error handling. # of output, but not the kind of error handling.
@ -28,7 +28,6 @@ compat:
@${MAKE} -r -f ${MAKEFILE} test VARIANT=compat @${MAKE} -r -f ${MAKEFILE} test VARIANT=compat
# expect: jobs: testing 1 # expect: jobs: testing 1
# expect: echo 'jobs: testing 2'
# expect: jobs: testing 2 # expect: jobs: testing 2
# expect: jobs: testing 3 # expect: jobs: testing 3
jobs: jobs:

View File

@ -1,4 +1,4 @@
# $NetBSD: opt-debug-cond.mk,v 1.2 2022/01/23 16:09:38 rillig Exp $ # $NetBSD: opt-debug-cond.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
# #
# Tests for the -dc command line option, which adds debug logging for the # Tests for the -dc command line option, which adds debug logging for the
# evaluation of conditional expressions, such as in .if directives and # evaluation of conditional expressions, such as in .if directives and
@ -7,11 +7,11 @@
.MAKEFLAGS: -dc .MAKEFLAGS: -dc
# expect: CondParser_Eval: ${:U12345} > ${:U55555} # expect: CondParser_Eval: ${:U12345} > ${:U55555}
# expect: lhs = 12345.000000, rhs = 55555.000000, op = > # expect: Comparing 12345.000000 > 55555.000000
.if ${:U12345} > ${:U55555} .if ${:U12345} > ${:U55555}
# expect: CondParser_Eval: "string" != "string" # expect: CondParser_Eval: "string" != "string"
# expect: lhs = "string", rhs = "string", op = != # expect: Comparing "string" != "string"
.elif "string" != "string" .elif "string" != "string"
# expect: CondParser_Eval: "nonempty" # expect: CondParser_Eval: "nonempty"

View File

@ -1,4 +1,4 @@
# $NetBSD: varname-dot-suffixes.mk,v 1.2 2022/01/15 12:35:18 rillig Exp $ # $NetBSD: varname-dot-suffixes.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $
# #
# Tests for the special "variable" .SUFFIXES, which lists the suffixes that # Tests for the special "variable" .SUFFIXES, which lists the suffixes that
# have been registered for use in suffix transformation rules. Suffixes are # have been registered for use in suffix transformation rules. Suffixes are
@ -51,7 +51,7 @@
# Deleting .SUFFIXES has no effect since there is no actual variable of that # Deleting .SUFFIXES has no effect since there is no actual variable of that
# name. # name.
.MAKEFLAGS: -dv .MAKEFLAGS: -dv
# expect: Global:delete .SUFFIXES (not found) # expect: Global: delete .SUFFIXES (not found)
.undef .SUFFIXES .undef .SUFFIXES
.MAKEFLAGS: -d0 .MAKEFLAGS: -d0
.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz"
@ -97,7 +97,7 @@ _:= ${preserve:L:_=.SUFFIXES}
# expect: Command: .SUFFIXES = 1 ignored (read-only) # expect: Command: .SUFFIXES = 1 ignored (read-only)
# expect: Command: .SUFFIXES = 2 ignored (read-only) # expect: Command: .SUFFIXES = 2 ignored (read-only)
# XXX: Missing space after ':' # XXX: Missing space after ':'
# expect: Command:delete .SUFFIXES (not found) # expect: Command: delete .SUFFIXES (not found)
.if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" .if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz"
. error . error
.endif .endif

View File

@ -7,7 +7,7 @@ SRCTOP?= ${.CURDIR:H:H}
# things set by configure # things set by configure
_MAKE_VERSION?=20220330 _MAKE_VERSION?=20220418
prefix?= /usr prefix?= /usr
srcdir= ${SRCTOP}/contrib/bmake srcdir= ${SRCTOP}/contrib/bmake

View File

@ -2,9 +2,9 @@
# See contrib/bmake/bsd.after-import.mk # See contrib/bmake/bsd.after-import.mk
# #
# $FreeBSD$ # $FreeBSD$
# $Id: Makefile,v 1.178 2022/03/26 23:10:27 sjg Exp $ # $Id: Makefile,v 1.180 2022/04/18 21:25:37 sjg Exp $
# #
# $NetBSD: Makefile,v 1.311 2022/03/26 12:44:57 rillig Exp $ # $NetBSD: Makefile,v 1.312 2022/04/18 15:06:28 rillig Exp $
# #
# Unit tests for make(1) # Unit tests for make(1)
# #
@ -146,6 +146,7 @@ TESTS+= deptgt-order
TESTS+= deptgt-path TESTS+= deptgt-path
TESTS+= deptgt-path-suffix TESTS+= deptgt-path-suffix
TESTS+= deptgt-phony TESTS+= deptgt-phony
TESTS+= deptgt-posix
TESTS+= deptgt-precious TESTS+= deptgt-precious
TESTS+= deptgt-shell TESTS+= deptgt-shell
TESTS+= deptgt-silent TESTS+= deptgt-silent
@ -444,31 +445,26 @@ TESTS+= varparse-mod
TESTS+= varparse-undef-partial TESTS+= varparse-undef-partial
TESTS+= varquote TESTS+= varquote
# for now at least # some shells have quirks
.if ${.SHELL:T} == "ksh" _shell := ${.SHELL:tA:T}
.if ${_shell} == "dash"
# dash fails -x output
BROKEN_TESTS+= opt-debug-x-trace
.elif ${_shell} == "ksh"
BROKEN_TESTS+= sh-flags BROKEN_TESTS+= sh-flags
.endif .endif
.if ${.MAKE.OS:NDarwin} == "" .if ${.MAKE.OS:NDarwin} == ""
BROKEN_TESTS+= shell-ksh BROKEN_TESTS+= shell-ksh
.endif .endif
.if ${.MAKE.OS} == "Linux" && ${.SHELL:tA:T} != "bash"
.if exists(/etc/os-release)
distro!= . /etc/os-release && echo $$NAME
.endif
# dash fails -x output
# .SHELL is not bash so may be dash
# if distro is Ubuntu or we cannot tell, assume the worst
.if ${distro:U:NUbuntu} == ""
BROKEN_TESTS+= opt-debug-x-trace
.endif
.endif
.if ${.MAKE.OS} == "SCO_SV" .if ${.MAKE.OS} == "SCO_SV"
BROKEN_TESTS+= \ BROKEN_TESTS+= \
opt-debug-graph[23] \ opt-debug-graph[23] \
varmod-localtime \ varmod-localtime \
varmod-to-separator \ varmod-to-separator \
.if ${.SHELL:T} == "bash" .if ${_shell} == "bash"
BROKEN_TESTS+= job-output-null BROKEN_TESTS+= job-output-null
.else .else
BROKEN_TESTS+= \ BROKEN_TESTS+= \