summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-07-29 14:29:23 +0000
committerharti <harti@FreeBSD.org>2004-07-29 14:29:23 +0000
commit0db0c049544bc4a655f7d5507925d5e8fc791934 (patch)
tree1b3c9d7d8acc8e298f77ed6d6293d0d878e6cdae /usr.bin/make
parent382d8a7db30af3cd51ffd86e32fc98350419aeb0 (diff)
downloadFreeBSD-src-0db0c049544bc4a655f7d5507925d5e8fc791934.zip
FreeBSD-src-0db0c049544bc4a655f7d5507925d5e8fc791934.tar.gz
Implement POSIX's '+' flag for command lines. This flag causes a line
to be executed even when -n is given on the command line to make. This is very handy for calls to submakes. This is slightly changed from the original patch as obtained from NetBSD. The NetBSD variant prints lines which have both '+' and '@' when -n is specified. The commited version always obeys '@'. Bump MAKE_VERSION so Makefiles can use this conditionally. PR: standards/66357 (partly) Submitted by: Mark Baushke <mdb@juniper.net> Obtained from: NetBSD
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/Makefile2
-rw-r--r--usr.bin/make/compat.c67
-rw-r--r--usr.bin/make/job.c25
-rw-r--r--usr.bin/make/make.112
-rw-r--r--usr.bin/make/nonints.h1
5 files changed, 75 insertions, 32 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index 1163282..2b3e22b 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -15,7 +15,7 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
NOSHARED?= YES
-CFLAGS+=-DMAKE_VERSION=\"5200209170\"
+CFLAGS+=-DMAKE_VERSION=\"5200407290\"
.if defined(_UPGRADING)
CFLAGS+=-D__FBSDID=__RCSID
.endif
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c
index f4b50d5..79531ef 100644
--- a/usr.bin/make/compat.c
+++ b/usr.bin/make/compat.c
@@ -80,7 +80,6 @@ static char meta[256];
static GNode *curTarg = NULL;
static GNode *ENDNode;
static void CompatInterrupt(int);
-static int CompatRunCommand(void *, void *);
static int CompatMake(void *, void *);
static int shellneed(char *);
@@ -88,6 +87,20 @@ static char *sh_builtin[] = {
"alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
"unalias", "umask", "unset", "wait", ":", 0};
+static void
+CompatInit(void)
+{
+ char *cp; /* Pointer to string of shell meta-characters */
+
+ for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
+ meta[(unsigned char) *cp] = 1;
+ }
+ /*
+ * The null character serves as a sentinel in the string.
+ */
+ meta[0] = 1;
+}
+
/*-
*-----------------------------------------------------------------------
* CompatInterrupt --
@@ -123,7 +136,7 @@ CompatInterrupt (int signo)
if (signo == SIGINT) {
gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
if (gn != NULL) {
- Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
+ Lst_ForEach(gn->commands, Compat_RunCommand, (void *)gn);
}
}
@@ -162,7 +175,7 @@ shellneed (char *cmd)
/*-
*-----------------------------------------------------------------------
- * CompatRunCommand --
+ * Compat_RunCommand --
* Execute the next command for a target. If the command returns an
* error, the node's made field is set to ERROR and creation stops.
* The node from which the command came is also given.
@@ -175,12 +188,13 @@ shellneed (char *cmd)
*
*-----------------------------------------------------------------------
*/
-static int
-CompatRunCommand (void *cmdp, void *gnp)
+int
+Compat_RunCommand (void *cmdp, void *gnp)
{
char *cmdStart; /* Start of expanded command */
char *cp;
Boolean silent, /* Don't print command */
+ doit, /* Execute even in -n */
errCheck; /* Check errors */
int reason; /* Reason for child's death */
int status; /* Description of child's death */
@@ -204,6 +218,7 @@ CompatRunCommand (void *cmdp, void *gnp)
#endif
silent = gn->type & OP_SILENT;
errCheck = !(gn->type & OP_IGNORE);
+ doit = FALSE;
cmdNode = Lst_Member (gn->commands, (void *)cmd);
cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
@@ -232,11 +247,22 @@ CompatRunCommand (void *cmdp, void *gnp)
return(0);
}
- while ((*cmd == '@') || (*cmd == '-')) {
- if (*cmd == '@') {
+ while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
+ switch (*cmd) {
+
+ case '@':
silent = DEBUG(LOUD) ? FALSE : TRUE;
- } else {
+ break;
+
+ case '-':
errCheck = FALSE;
+ break;
+
+ case '+':
+ doit = TRUE;
+ if (!meta[0]) /* we came here from jobs */
+ CompatInit();
+ break;
}
cmd++;
}
@@ -255,9 +281,9 @@ CompatRunCommand (void *cmdp, void *gnp)
/*
* Print the command before echoing if we're not supposed to be quiet for
- * this one. We also print the command if -n given.
+ * this one. We also print the command if -n given, but not if '+'.
*/
- if (!silent || noExecute) {
+ if (!silent || (noExecute && !doit)) {
printf ("%s\n", cmd);
fflush(stdout);
}
@@ -266,7 +292,7 @@ CompatRunCommand (void *cmdp, void *gnp)
* If we're not supposed to execute any commands, this is as far as
* we go...
*/
- if (noExecute) {
+ if (!doit && noExecute) {
return (0);
}
@@ -470,7 +496,7 @@ CompatMake (void *gnp, void *pgnp)
/*
* Alter our type to tell if errors should be ignored or things
- * should not be printed so CompatRunCommand knows what to do.
+ * should not be printed so Compat_RunCommand knows what to do.
*/
if (Targ_Ignore (gn)) {
gn->type |= OP_IGNORE;
@@ -486,7 +512,7 @@ CompatMake (void *gnp, void *pgnp)
*/
if (!touchFlag) {
curTarg = gn;
- Lst_ForEach (gn->commands, CompatRunCommand, (void *)gn);
+ Lst_ForEach (gn->commands, Compat_RunCommand, (void *)gn);
curTarg = NULL;
} else {
Job_Touch (gn, gn->type & OP_SILENT);
@@ -625,10 +651,11 @@ CompatMake (void *gnp, void *pgnp)
void
Compat_Run(Lst targs)
{
- char *cp; /* Pointer to string of shell meta-characters */
GNode *gn = NULL;/* Current root target */
int errors; /* Number of targets not remade due to errors */
+ CompatInit();
+
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
signal(SIGINT, CompatInterrupt);
}
@@ -642,14 +669,6 @@ Compat_Run(Lst targs)
signal(SIGQUIT, CompatInterrupt);
}
- for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
- meta[(unsigned char) *cp] = 1;
- }
- /*
- * The null character serves as a sentinel in the string.
- */
- meta[0] = 1;
-
ENDNode = Targ_FindNode(".END", TARG_CREATE);
/*
* If the user has defined a .BEGIN target, execute the commands attached
@@ -658,7 +677,7 @@ Compat_Run(Lst targs)
if (!queryFlag) {
gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
if (gn != NULL) {
- Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
+ Lst_ForEach(gn->commands, Compat_RunCommand, (void *)gn);
if (gn->made == ERROR) {
printf("\n\nStop.\n");
exit(1);
@@ -693,6 +712,6 @@ Compat_Run(Lst targs)
* If the user has defined a .END target, run its commands.
*/
if (errors == 0) {
- Lst_ForEach(ENDNode->commands, CompatRunCommand, (void *)gn);
+ Lst_ForEach(ENDNode->commands, Compat_RunCommand, (void *)gn);
}
}
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 4f43e7f..8f0310b 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -550,13 +550,30 @@ JobPrintCommand(void *cmdp, void *jobp)
cmdTemplate = "%s\n";
/*
- * Check for leading @' and -'s to control echoing and error checking.
+ * Check for leading @', -' or +'s to control echoing, error checking,
+ * and execution on -n.
*/
- while (*cmd == '@' || *cmd == '-') {
- if (*cmd == '@') {
+ while (*cmd == '@' || *cmd == '-' || *cmd == '+') {
+ switch (*cmd) {
+
+ case '@':
shutUp = DEBUG(LOUD) ? FALSE : TRUE;
- } else {
+ break;
+
+ case '-':
errOff = TRUE;
+ break;
+
+ case '+':
+ if (noSpecials) {
+ /*
+ * We're not actually exececuting anything...
+ * but this one needs to be - use compat mode just for it.
+ */
+ Compat_RunCommand(cmdp, job->node);
+ return (0);
+ }
+ break;
}
cmd++;
}
diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1
index a55c5bc..97e7423 100644
--- a/usr.bin/make/make.1
+++ b/usr.bin/make/make.1
@@ -320,10 +320,11 @@ dependencies may be followed by a creation script, unless the
.Sq Ic ::
operator is used.
.Pp
-If the first or first two characters of the command line are
-.Sq Ic @
-and/or
+If the first characters of the command line are
+.Sq Ic @ ,
.Sq Ic \- ,
+and/or
+.Sq Ic + ,
the command is treated specially.
A
.Sq Ic @
@@ -331,6 +332,11 @@ causes the command not to be echoed before it is executed.
A
.Sq Ic \-
causes any non-zero exit status of the command line to be ignored.
+A
+.Sq Ic +
+causes the command to be executed even if
+.Fl n
+is specified on the command line.
.Sh VARIABLE ASSIGNMENTS
Variables in
.Nm
diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h
index 02746de..e2da28e 100644
--- a/usr.bin/make/nonints.h
+++ b/usr.bin/make/nonints.h
@@ -52,6 +52,7 @@ void Arch_End(void);
/* compat.c */
void Compat_Run(Lst);
+int Compat_RunCommand(void *, void *);
/* cond.c */
int Cond_Eval(char *);
OpenPOWER on IntegriCloud