2020-07-08 18:32:15 +00:00
|
|
|
|
/* $NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $ */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
|
* Adam de Boor.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Copyright (c) 1988, 1989 by Adam de Boor
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
|
* Adam de Boor.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifndef MAKE_NATIVE
|
2020-07-08 18:32:15 +00:00
|
|
|
|
static char rcsid[] = "$NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $";
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#else
|
|
|
|
|
#include <sys/cdefs.h>
|
1996-10-06 15:57:15 +00:00
|
|
|
|
#ifndef lint
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#if 0
|
|
|
|
|
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
|
|
|
|
|
#else
|
2020-07-08 18:32:15 +00:00
|
|
|
|
__RCSID("$NetBSD: compat.c,v 1.113 2020/07/03 08:13:23 rillig Exp $");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
#endif /* not lint */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
* compat.c --
|
|
|
|
|
* The routines in this file implement the full-compatibility
|
|
|
|
|
* mode of PMake. Most of the special functionality of PMake
|
|
|
|
|
* is available in this mode. Things not supported:
|
|
|
|
|
* - different shells.
|
|
|
|
|
* - friendly variable substitution.
|
|
|
|
|
*
|
|
|
|
|
* Interface:
|
|
|
|
|
* Compat_Run Initialize things for this module and recreate
|
|
|
|
|
* thems as need creatin'
|
|
|
|
|
*/
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
#include <sys/types.h>
|
1997-07-06 06:54:14 +00:00
|
|
|
|
#include <sys/stat.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#include "wait.h"
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
#include <ctype.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
#include "make.h"
|
|
|
|
|
#include "hash.h"
|
|
|
|
|
#include "dir.h"
|
|
|
|
|
#include "job.h"
|
2015-10-21 22:14:23 +00:00
|
|
|
|
#include "metachar.h"
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#include "pathnames.h"
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
static GNode *curTarg = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
static GNode *ENDNode;
|
2012-06-25 22:20:51 +00:00
|
|
|
|
static void CompatInterrupt(int);
|
2017-07-24 00:52:52 +00:00
|
|
|
|
static pid_t compatChild;
|
|
|
|
|
static int compatSigno;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
2016-12-19 21:50:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* CompatDeleteTarget -- delete a failed, interrupted, or otherwise
|
|
|
|
|
* duffed target if not inhibited by .PRECIOUS.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
CompatDeleteTarget(GNode *gn)
|
|
|
|
|
{
|
|
|
|
|
if ((gn != NULL) && !Targ_Precious (gn)) {
|
|
|
|
|
char *p1;
|
|
|
|
|
char *file = Var_Value(TARGET, gn, &p1);
|
|
|
|
|
|
|
|
|
|
if (!noExecute && eunlink(file) != -1) {
|
|
|
|
|
Error("*** %s removed", file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(p1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* CompatInterrupt --
|
|
|
|
|
* Interrupt the creation of the current target and remove it if
|
|
|
|
|
* it ain't precious.
|
|
|
|
|
*
|
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* The target is removed and the process exits. If .INTERRUPT exists,
|
|
|
|
|
* its commands are run first WITH INTERRUPTS IGNORED..
|
|
|
|
|
*
|
2016-12-19 21:50:59 +00:00
|
|
|
|
* XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've
|
|
|
|
|
* left the logic alone for now. - dholland 20160826
|
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2012-06-08 21:57:36 +00:00
|
|
|
|
CompatInterrupt(int signo)
|
1996-10-06 15:57:15 +00:00
|
|
|
|
{
|
|
|
|
|
GNode *gn;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
2016-12-19 21:50:59 +00:00
|
|
|
|
CompatDeleteTarget(curTarg);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
2016-12-19 21:50:59 +00:00
|
|
|
|
if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Run .INTERRUPT only if hit with interrupt signal
|
|
|
|
|
*/
|
|
|
|
|
if (signo == SIGINT) {
|
|
|
|
|
gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (gn != NULL) {
|
|
|
|
|
Compat_Make(gn, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (signo == SIGQUIT)
|
|
|
|
|
_exit(signo);
|
2017-07-24 00:52:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* If there is a child running, pass the signal on
|
|
|
|
|
* we will exist after it has exited.
|
|
|
|
|
*/
|
|
|
|
|
compatSigno = signo;
|
|
|
|
|
if (compatChild > 0) {
|
|
|
|
|
KILLPG(compatChild, signo);
|
|
|
|
|
} else {
|
|
|
|
|
bmake_signal(signo, SIG_DFL);
|
|
|
|
|
kill(myPid, signo);
|
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* CompatRunCommand --
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Input:
|
|
|
|
|
* cmdp Command to execute
|
|
|
|
|
* gnp Node from which the command came
|
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* Results:
|
|
|
|
|
* 0 if the command succeeded, 1 if an error occurred.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* The node's 'made' field may be set to ERROR.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
int
|
|
|
|
|
CompatRunCommand(void *cmdp, void *gnp)
|
1996-10-06 15:57:15 +00:00
|
|
|
|
{
|
|
|
|
|
char *cmdStart; /* Start of expanded command */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
char *cp, *bp;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
Boolean silent, /* Don't print command */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
doIt; /* Execute even if -n */
|
|
|
|
|
volatile Boolean errCheck; /* Check errors */
|
|
|
|
|
WAIT_T reason; /* Reason for child's death */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
int status; /* Description of child's death */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pid_t cpid; /* Child actually found */
|
|
|
|
|
pid_t retstat; /* Result of wait */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
LstNode cmdNode; /* Node where current command is located */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
const char ** volatile av; /* Argument vector for thing to exec */
|
|
|
|
|
char ** volatile mav;/* Copy of the argument vector for freeing */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
int argc; /* Number of arguments in av or 0 if not
|
|
|
|
|
* dynamically allocated */
|
|
|
|
|
Boolean local; /* TRUE if command should be executed
|
|
|
|
|
* locally */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Boolean useShell; /* TRUE if command should be executed
|
|
|
|
|
* using a shell */
|
|
|
|
|
char * volatile cmd = (char *)cmdp;
|
|
|
|
|
GNode *gn = (GNode *)gnp;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
silent = gn->type & OP_SILENT;
|
|
|
|
|
errCheck = !(gn->type & OP_IGNORE);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
doIt = FALSE;
|
2020-07-08 18:32:15 +00:00
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
cmdNode = Lst_Member(gn->commands, cmd);
|
2016-03-11 00:37:02 +00:00
|
|
|
|
cmdStart = Var_Subst(NULL, cmd, gn, VARF_WANTRES);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* brk_string will return an argv with a NULL in av[0], thus causing
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* execvp to choke and die horribly. Besides, how can we execute a null
|
|
|
|
|
* command? In any case, we warn the user that the command expanded to
|
|
|
|
|
* nothing (is this the right thing to do?).
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
if (*cmdStart == '\0') {
|
|
|
|
|
free(cmdStart);
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
cmd = cmdStart;
|
|
|
|
|
Lst_Replace(cmdNode, cmdStart);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
(void)Lst_AtEnd(ENDNode->commands, cmdStart);
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
}
|
|
|
|
|
if (strcmp(cmdStart, "...") == 0) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->type |= OP_SAVE_CMDS;
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
|
|
|
|
|
switch (*cmd) {
|
|
|
|
|
case '@':
|
|
|
|
|
silent = DEBUG(LOUD) ? FALSE : TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
1996-10-06 15:57:15 +00:00
|
|
|
|
errCheck = FALSE;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case '+':
|
|
|
|
|
doIt = TRUE;
|
2015-10-21 22:14:23 +00:00
|
|
|
|
if (!shellName) /* we came here from jobs */
|
|
|
|
|
Shell_Init();
|
2012-06-08 21:57:36 +00:00
|
|
|
|
break;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
cmd++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (isspace((unsigned char)*cmd))
|
|
|
|
|
cmd++;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we did not end up with a command, just skip it.
|
|
|
|
|
*/
|
|
|
|
|
if (!*cmd)
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
#if !defined(MAKE_NATIVE)
|
|
|
|
|
/*
|
|
|
|
|
* In a non-native build, the host environment might be weird enough
|
|
|
|
|
* that it's necessary to go through a shell to get the correct
|
|
|
|
|
* behaviour. Or perhaps the shell has been replaced with something
|
|
|
|
|
* that does extra logging, and that should not be bypassed.
|
|
|
|
|
*/
|
|
|
|
|
useShell = TRUE;
|
|
|
|
|
#else
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Search for meta characters in the command. If there are no meta
|
|
|
|
|
* characters, there's no need to execute a shell to execute the
|
|
|
|
|
* command.
|
2015-10-21 22:14:23 +00:00
|
|
|
|
*
|
|
|
|
|
* Additionally variable assignments and empty commands
|
|
|
|
|
* go to the shell. Therefore treat '=' and ':' like shell
|
|
|
|
|
* meta characters as documented in make(1).
|
1996-10-06 15:57:15 +00:00
|
|
|
|
*/
|
2020-07-08 18:32:15 +00:00
|
|
|
|
|
2015-10-21 22:14:23 +00:00
|
|
|
|
useShell = needshell(cmd, FALSE);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print the command before echoing if we're not supposed to be quiet for
|
|
|
|
|
* this one. We also print the command if -n given.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (!silent || NoExecute(gn)) {
|
|
|
|
|
printf("%s\n", cmd);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we're not supposed to execute any commands, this is as far as
|
|
|
|
|
* we go...
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (!doIt && NoExecute(gn)) {
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (DEBUG(JOB))
|
|
|
|
|
fprintf(debug_file, "Execute: '%s'\n", cmd);
|
|
|
|
|
|
|
|
|
|
again:
|
|
|
|
|
if (useShell) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* We need to pass the command off to the shell, typically
|
|
|
|
|
* because the command contains a "meta" character.
|
1996-10-06 15:57:15 +00:00
|
|
|
|
*/
|
2013-08-02 05:23:57 +00:00
|
|
|
|
static const char *shargv[5];
|
|
|
|
|
int shargc;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
2013-08-02 05:23:57 +00:00
|
|
|
|
shargc = 0;
|
|
|
|
|
shargv[shargc++] = shellPath;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
/*
|
|
|
|
|
* The following work for any of the builtin shell specs.
|
|
|
|
|
*/
|
2013-09-05 15:49:22 +00:00
|
|
|
|
if (errCheck && shellErrFlag) {
|
2013-08-02 05:23:57 +00:00
|
|
|
|
shargv[shargc++] = shellErrFlag;
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (DEBUG(SHELL))
|
2013-08-02 05:23:57 +00:00
|
|
|
|
shargv[shargc++] = "-xc";
|
2012-06-08 21:57:36 +00:00
|
|
|
|
else
|
2013-08-02 05:23:57 +00:00
|
|
|
|
shargv[shargc++] = "-c";
|
|
|
|
|
shargv[shargc++] = cmd;
|
|
|
|
|
shargv[shargc++] = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
av = shargv;
|
|
|
|
|
argc = 0;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
bp = NULL;
|
|
|
|
|
mav = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* No meta-characters, so no need to exec a shell. Break the command
|
|
|
|
|
* into words to form an argument vector we can execute.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
mav = brk_string(cmd, &argc, TRUE, &bp);
|
|
|
|
|
if (mav == NULL) {
|
|
|
|
|
useShell = 1;
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
|
|
|
|
av = (void *)mav;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
local = TRUE;
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta) {
|
|
|
|
|
meta_compat_start();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-07-08 18:32:15 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Fork and execute the single command. If the fork fails, we abort.
|
|
|
|
|
*/
|
2017-07-24 00:52:52 +00:00
|
|
|
|
compatChild = cpid = vFork();
|
1996-10-06 15:57:15 +00:00
|
|
|
|
if (cpid < 0) {
|
|
|
|
|
Fatal("Could not fork");
|
|
|
|
|
}
|
|
|
|
|
if (cpid == 0) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Var_ExportVars();
|
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta) {
|
|
|
|
|
meta_compat_child();
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
if (local)
|
|
|
|
|
(void)execvp(av[0], (char *const *)UNCONST(av));
|
|
|
|
|
else
|
|
|
|
|
(void)execv(av[0], (char *const *)UNCONST(av));
|
|
|
|
|
execError("exec", av[0]);
|
|
|
|
|
_exit(1);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2016-03-11 00:37:02 +00:00
|
|
|
|
|
|
|
|
|
free(mav);
|
|
|
|
|
free(bp);
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Lst_Replace(cmdNode, NULL);
|
|
|
|
|
|
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta) {
|
2020-05-20 19:34:48 +00:00
|
|
|
|
meta_compat_parent(cpid);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* The child is off and running. Now all we can do is wait...
|
|
|
|
|
*/
|
|
|
|
|
while (1) {
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
while ((retstat = wait(&reason)) != cpid) {
|
|
|
|
|
if (retstat > 0)
|
|
|
|
|
JobReapChild(retstat, reason, FALSE); /* not ours? */
|
|
|
|
|
if (retstat == -1 && errno != EINTR) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
if (retstat > -1) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
if (WIFSTOPPED(reason)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
status = WSTOPSIG(reason); /* stopped */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else if (WIFEXITED(reason)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
status = WEXITSTATUS(reason); /* exited */
|
|
|
|
|
#if defined(USE_META) && defined(USE_FILEMON_ONCE)
|
|
|
|
|
if (useMeta) {
|
|
|
|
|
meta_cmd_finish(NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
if (status != 0) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (DEBUG(ERROR)) {
|
|
|
|
|
fprintf(debug_file, "\n*** Failed target: %s\n*** Failed command: ",
|
|
|
|
|
gn->name);
|
|
|
|
|
for (cp = cmd; *cp; ) {
|
|
|
|
|
if (isspace((unsigned char)*cp)) {
|
|
|
|
|
fprintf(debug_file, " ");
|
|
|
|
|
while (isspace((unsigned char)*cp))
|
|
|
|
|
cp++;
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(debug_file, "%c", *cp);
|
|
|
|
|
cp++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(debug_file, "\n");
|
|
|
|
|
}
|
|
|
|
|
printf("*** Error code %d", status);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
status = WTERMSIG(reason); /* signaled */
|
|
|
|
|
printf("*** Signal %d", status);
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
if (!WIFEXITED(reason) || (status != 0)) {
|
|
|
|
|
if (errCheck) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta) {
|
|
|
|
|
meta_job_error(NULL, gn, 0, status);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->made = ERROR;
|
|
|
|
|
if (keepgoing) {
|
|
|
|
|
/*
|
|
|
|
|
* Abort the current target, but let others
|
|
|
|
|
* continue.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
printf(" (continuing)\n");
|
2016-12-19 21:50:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
if (deleteOnError) {
|
|
|
|
|
CompatDeleteTarget(gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Continue executing commands for this target.
|
|
|
|
|
* If we return 0, this will happen...
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
printf(" (ignored)\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
status = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Fatal("error in wait: %d: %s", retstat, strerror(errno));
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
free(cmdStart);
|
2017-07-24 00:52:52 +00:00
|
|
|
|
compatChild = 0;
|
|
|
|
|
if (compatSigno) {
|
|
|
|
|
bmake_signal(compatSigno, SIG_DFL);
|
|
|
|
|
kill(myPid, compatSigno);
|
|
|
|
|
}
|
2020-07-08 18:32:15 +00:00
|
|
|
|
|
|
|
|
|
return status;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Compat_Make --
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* Make a target.
|
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Input:
|
|
|
|
|
* gnp The node to make
|
|
|
|
|
* pgnp Parent to abort if necessary
|
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* Results:
|
|
|
|
|
* 0
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* If an error is detected and not being ignored, the process exits.
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
int
|
|
|
|
|
Compat_Make(void *gnp, void *pgnp)
|
1996-10-06 15:57:15 +00:00
|
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
|
GNode *gn = (GNode *)gnp;
|
|
|
|
|
GNode *pgn = (GNode *)pgnp;
|
|
|
|
|
|
2015-10-21 22:14:23 +00:00
|
|
|
|
if (!shellName) /* we came here from jobs */
|
|
|
|
|
Shell_Init();
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
gn->flags |= REMAKE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->made = BEINGMADE;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if ((gn->type & OP_MADE) == 0)
|
|
|
|
|
Suff_FindDeps(gn);
|
|
|
|
|
Lst_ForEach(gn->children, Compat_Make, gn);
|
|
|
|
|
if ((gn->flags & REMAKE) == 0) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->made = ABORTED;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags &= ~REMAKE;
|
|
|
|
|
goto cohorts;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (Lst_Member(gn->iParents, pgn) != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
char *p1;
|
2020-07-08 18:32:15 +00:00
|
|
|
|
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
2016-03-11 00:37:02 +00:00
|
|
|
|
free(p1);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* All the children were made ok. Now cmgn->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.
|
1996-10-06 15:57:15 +00:00
|
|
|
|
*/
|
|
|
|
|
if (DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
fprintf(debug_file, "Examining %s...", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
if (! Make_OODate(gn)) {
|
|
|
|
|
gn->made = UPTODATE;
|
|
|
|
|
if (DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
fprintf(debug_file, "up-to-date.\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
goto cohorts;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else if (DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
fprintf(debug_file, "out-of-date.\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the user is just seeing if something is out-of-date, exit now
|
|
|
|
|
* to tell him/her "yes".
|
|
|
|
|
*/
|
|
|
|
|
if (queryFlag) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
exit(1);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We need to be re-made. We also have to make sure we've got a $?
|
|
|
|
|
* variable. To be nice, we also define the $> variable using
|
|
|
|
|
* Make_DoAllVar().
|
|
|
|
|
*/
|
|
|
|
|
Make_DoAllVar(gn);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Alter our type to tell if errors should be ignored or things
|
|
|
|
|
* should not be printed so CompatRunCommand knows what to do.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (Targ_Ignore(gn)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->type |= OP_IGNORE;
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (Targ_Silent(gn)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->type |= OP_SILENT;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (Job_CheckCommands(gn, Fatal)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Our commands are ok, but we still have to worry about the -t
|
|
|
|
|
* flag...
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (!touchFlag || (gn->type & OP_MAKE)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
curTarg = gn;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta && !NoExecute(gn)) {
|
|
|
|
|
meta_job_start(NULL, gn);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
Lst_ForEach(gn->commands, CompatRunCommand, gn);
|
|
|
|
|
curTarg = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Job_Touch(gn, gn->type & OP_SILENT);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
gn->made = ERROR;
|
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
#ifdef USE_META
|
|
|
|
|
if (useMeta && !NoExecute(gn)) {
|
2016-05-20 16:19:56 +00:00
|
|
|
|
if (meta_job_finish(NULL) != 0)
|
|
|
|
|
gn->made = ERROR;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
* This is to keep its state from affecting that of its parent.
|
|
|
|
|
*/
|
|
|
|
|
gn->made = MADE;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
if (!(gn->type & OP_EXEC)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags |= CHILDMADE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
Make_TimeStamp(pgn, gn);
|
|
|
|
|
}
|
|
|
|
|
} else if (keepgoing) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags &= ~REMAKE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else {
|
2016-12-19 21:50:59 +00:00
|
|
|
|
PrintOnError(gn, "\nStop.");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
exit(1);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (gn->made == ERROR) {
|
|
|
|
|
/*
|
|
|
|
|
* Already had an error when making this beastie. Tell the parent
|
|
|
|
|
* to abort.
|
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags &= ~REMAKE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (Lst_Member(gn->iParents, pgn) != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
char *p1;
|
2020-07-08 18:32:15 +00:00
|
|
|
|
Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
2016-03-11 00:37:02 +00:00
|
|
|
|
free(p1);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
switch(gn->made) {
|
|
|
|
|
case BEINGMADE:
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Error("Graph cycles through %s", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
gn->made = ERROR;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags &= ~REMAKE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
break;
|
|
|
|
|
case MADE:
|
|
|
|
|
if ((gn->type & OP_EXEC) == 0) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
pgn->flags |= CHILDMADE;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
Make_TimeStamp(pgn, gn);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case UPTODATE:
|
|
|
|
|
if ((gn->type & OP_EXEC) == 0) {
|
|
|
|
|
Make_TimeStamp(pgn, gn);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
|
cohorts:
|
|
|
|
|
Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
|
2020-07-08 18:32:15 +00:00
|
|
|
|
return 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*-
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
* Compat_Run --
|
|
|
|
|
* Initialize this mode and start making.
|
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Input:
|
|
|
|
|
* targs List of target nodes to re-create
|
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* Results:
|
|
|
|
|
* None.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Guess what?
|
|
|
|
|
*
|
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Compat_Run(Lst targs)
|
1996-10-06 15:57:15 +00:00
|
|
|
|
{
|
|
|
|
|
GNode *gn = NULL;/* Current root target */
|
|
|
|
|
int errors; /* Number of targets not remade due to errors */
|
|
|
|
|
|
2015-10-21 22:14:23 +00:00
|
|
|
|
if (!shellName)
|
|
|
|
|
Shell_Init();
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
|
|
|
|
|
bmake_signal(SIGINT, CompatInterrupt);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
|
|
|
|
|
bmake_signal(SIGTERM, CompatInterrupt);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
|
|
|
|
bmake_signal(SIGHUP, CompatInterrupt);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
|
|
|
|
|
bmake_signal(SIGQUIT, CompatInterrupt);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ENDNode = Targ_FindNode(".END", TARG_CREATE);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
ENDNode->type = OP_SPECIAL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* If the user has defined a .BEGIN target, execute the commands attached
|
|
|
|
|
* to it.
|
|
|
|
|
*/
|
|
|
|
|
if (!queryFlag) {
|
|
|
|
|
gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
if (gn != NULL) {
|
|
|
|
|
Compat_Make(gn, gn);
|
|
|
|
|
if (gn->made == ERROR) {
|
2016-12-19 21:50:59 +00:00
|
|
|
|
PrintOnError(gn, "\nStop.");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
|
* Expand .USE nodes right now, because they can modify the structure
|
|
|
|
|
* of the tree.
|
|
|
|
|
*/
|
|
|
|
|
Make_ExpandUse(targs);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* For each entry in the list of targets to create, call Compat_Make on
|
|
|
|
|
* it to create the thing. Compat_Make will leave the 'made' field of gn
|
1996-10-06 15:57:15 +00:00
|
|
|
|
* in one of several states:
|
|
|
|
|
* UPTODATE gn was already up-to-date
|
|
|
|
|
* MADE gn was recreated successfully
|
|
|
|
|
* ERROR An error occurred while gn was being created
|
|
|
|
|
* ABORTED gn was not remade because one of its inferiors
|
|
|
|
|
* could not be made due to errors.
|
|
|
|
|
*/
|
|
|
|
|
errors = 0;
|
|
|
|
|
while (!Lst_IsEmpty (targs)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
gn = (GNode *)Lst_DeQueue(targs);
|
|
|
|
|
Compat_Make(gn, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
if (gn->made == UPTODATE) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
printf("`%s' is up to date.\n", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
} else if (gn->made == ABORTED) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
printf("`%s' not remade because of errors.\n", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
errors += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the user has defined a .END target, run its commands.
|
|
|
|
|
*/
|
|
|
|
|
if (errors == 0) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
Compat_Make(ENDNode, ENDNode);
|
|
|
|
|
if (gn->made == ERROR) {
|
2016-12-19 21:50:59 +00:00
|
|
|
|
PrintOnError(gn, "\nStop.");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|