summaryrefslogtreecommitdiff
path: root/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'compat.c')
-rw-r--r--compat.c99
1 files changed, 44 insertions, 55 deletions
diff --git a/compat.c b/compat.c
index 1bce02bf5c08..2307e9f2d935 100644
--- a/compat.c
+++ b/compat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.173 2020/11/01 17:47:26 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.183 2020/11/15 22:31:03 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,15 +99,15 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.173 2020/11/01 17:47:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.183 2020/11/15 22:31:03 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
static int compatSigno;
/*
- * CompatDeleteTarget -- delete a failed, interrupted, or otherwise
- * duffed target if not inhibited by .PRECIOUS.
+ * CompatDeleteTarget -- delete the file of a failed, interrupted, or
+ * otherwise duffed target if not inhibited by .PRECIOUS.
*/
static void
CompatDeleteTarget(GNode *gn)
@@ -132,8 +132,6 @@ CompatDeleteTarget(GNode *gn)
static void
CompatInterrupt(int signo)
{
- GNode *gn;
-
CompatDeleteTarget(curTarg);
if (curTarg != NULL && !Targ_Precious(curTarg)) {
@@ -141,7 +139,7 @@ CompatInterrupt(int signo)
* Run .INTERRUPT only if hit with interrupt signal
*/
if (signo == SIGINT) {
- gn = Targ_FindNode(".INTERRUPT");
+ GNode *gn = Targ_FindNode(".INTERRUPT");
if (gn != NULL) {
Compat_Make(gn, gn);
}
@@ -206,7 +204,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
(void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
/* TODO: handle errors */
- if (*cmdStart == '\0') {
+ if (cmdStart[0] == '\0') {
free(cmdStart);
return 0;
}
@@ -225,20 +223,17 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
return 0;
}
- while (*cmd == '@' || *cmd == '-' || *cmd == '+') {
- switch (*cmd) {
- case '@':
+ for (;;) {
+ if (*cmd == '@')
silent = !DEBUG(LOUD);
- break;
- case '-':
+ else if (*cmd == '-')
errCheck = FALSE;
- break;
- case '+':
+ else if (*cmd == '+') {
doIt = TRUE;
- if (!shellName) /* we came here from jobs */
+ if (!shellName) /* we came here from jobs */
Shell_Init();
+ } else
break;
- }
cmd++;
}
@@ -248,7 +243,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
/*
* If we did not end up with a command, just skip it.
*/
- if (!*cmd)
+ if (cmd[0] == '\0')
return 0;
#if !defined(MAKE_NATIVE)
@@ -286,9 +281,9 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
* If we're not supposed to execute any commands, this is as far as
* we go...
*/
- if (!doIt && !GNode_ShouldExecute(gn)) {
+ if (!doIt && !GNode_ShouldExecute(gn))
return 0;
- }
+
DEBUG1(JOB, "Execute: '%s'\n", cmd);
if (useShell) {
@@ -297,20 +292,13 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
* because the command contains a "meta" character.
*/
static const char *shargv[5];
- int shargc;
- shargc = 0;
+ /* The following work for any of the builtin shell specs. */
+ int shargc = 0;
shargv[shargc++] = shellPath;
- /*
- * The following work for any of the builtin shell specs.
- */
- if (errCheck && shellErrFlag) {
+ if (errCheck && shellErrFlag)
shargv[shargc++] = shellErrFlag;
- }
- if (DEBUG(SHELL))
- shargv[shargc++] = "-xc";
- else
- shargv[shargc++] = "-c";
+ shargv[shargc++] = DEBUG(SHELL) ? "-xc" : "-c";
shargv[shargc++] = cmd;
shargv[shargc] = NULL;
av = shargv;
@@ -389,17 +377,19 @@ Compat_RunCommand(const char *cmdp, GNode *gn)
#endif
if (status != 0) {
if (DEBUG(ERROR)) {
- const char *cp;
+ const char *p = cmd;
debug_printf("\n*** Failed target: %s\n*** Failed command: ",
gn->name);
- for (cp = cmd; *cp; ) {
- if (ch_isspace(*cp)) {
+
+ /* Replace runs of whitespace with a single space, to reduce
+ * the amount of whitespace for multi-line command lines. */
+ while (*p != '\0') {
+ if (ch_isspace(*p)) {
debug_printf(" ");
- while (ch_isspace(*cp))
- cp++;
+ cpp_skip_whitespace(&p);
} else {
- debug_printf("%c", *cp);
- cp++;
+ debug_printf("%c", *p);
+ p++;
}
}
debug_printf("\n");
@@ -480,16 +470,17 @@ MakeNodes(GNodeList *gnodes, GNode *pgn)
void
Compat_Make(GNode *gn, GNode *pgn)
{
- if (!shellName) /* we came here from jobs */
+ if (shellName == NULL) /* we came here from jobs */
Shell_Init();
+
if (gn->made == UNMADE && (gn == pgn || !(pgn->type & OP_MADE))) {
/*
* First mark ourselves to be made, then apply whatever transformations
* the suffix module thinks are necessary. Once that's done, we can
* descend and make all our children. If any of them has an error
- * but the -k flag was given, our 'make' field will be set FALSE again.
- * This is our signal to not attempt to do anything but abort our
- * parent as well.
+ * but the -k flag was given, our 'make' field will be set to FALSE
+ * again. This is our signal to not attempt to do anything but abort
+ * our parent as well.
*/
gn->flags |= REMAKE;
gn->made = BEINGMADE;
@@ -509,10 +500,10 @@ Compat_Make(GNode *gn, GNode *pgn)
* All the children were made ok. Now youngestChild->mtime contains the
* modification time of the newest child, we need to find out if we
* exist and when we were modified last. The criteria for datedness
- * are defined by the Make_OODate function.
+ * are defined by GNode_IsOODate.
*/
DEBUG1(MAKE, "Examining %s...", gn->name);
- if (!Make_OODate(gn)) {
+ if (!GNode_IsOODate(gn)) {
gn->made = UPTODATE;
DEBUG0(MAKE, "up-to-date.\n");
goto cohorts;
@@ -523,9 +514,8 @@ Compat_Make(GNode *gn, GNode *pgn)
* If the user is just seeing if something is out-of-date, exit now
* to tell him/her "yes".
*/
- if (opts.queryFlag) {
+ if (opts.queryFlag)
exit(1);
- }
/*
* We need to be re-made. We also have to make sure we've got a $?
@@ -573,15 +563,15 @@ Compat_Make(GNode *gn, GNode *pgn)
if (gn->made != ERROR) {
/*
* If the node was made successfully, mark it so, update
- * its modification time and timestamp all its parents. Note
- * that for .ZEROTIME targets, the timestamping isn't done.
+ * its modification time and timestamp all its parents.
* This is to keep its state from affecting that of its parent.
*/
gn->made = MADE;
- pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
+ if (Make_Recheck(gn) == 0)
+ pgn->flags |= FORCE;
if (!(gn->type & OP_EXEC)) {
pgn->flags |= CHILDMADE;
- Make_TimeStamp(pgn, gn);
+ GNode_UpdateYoungestChild(pgn, gn);
}
} else if (opts.keepgoing) {
pgn->flags &= ~(unsigned)REMAKE;
@@ -604,15 +594,14 @@ Compat_Make(GNode *gn, GNode *pgn)
pgn->flags &= ~(unsigned)REMAKE;
break;
case MADE:
- if ((gn->type & OP_EXEC) == 0) {
+ if (!(gn->type & OP_EXEC)) {
pgn->flags |= CHILDMADE;
- Make_TimeStamp(pgn, gn);
+ GNode_UpdateYoungestChild(pgn, gn);
}
break;
case UPTODATE:
- if ((gn->type & OP_EXEC) == 0) {
- Make_TimeStamp(pgn, gn);
- }
+ if (!(gn->type & OP_EXEC))
+ GNode_UpdateYoungestChild(pgn, gn);
break;
default:
break;