Home | History | Annotate | Line # | Download | only in make
compat.c revision 1.89.2.3
      1  1.89.2.3       tls /*	$NetBSD: compat.c,v 1.89.2.3 2014/08/20 00:05:00 tls Exp $	*/
      2      1.10  christos 
      3       1.1       cgd /*
      4       1.1       cgd  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
      5      1.47       agc  * All rights reserved.
      6      1.47       agc  *
      7      1.47       agc  * This code is derived from software contributed to Berkeley by
      8      1.47       agc  * Adam de Boor.
      9      1.47       agc  *
     10      1.47       agc  * Redistribution and use in source and binary forms, with or without
     11      1.47       agc  * modification, are permitted provided that the following conditions
     12      1.47       agc  * are met:
     13      1.47       agc  * 1. Redistributions of source code must retain the above copyright
     14      1.47       agc  *    notice, this list of conditions and the following disclaimer.
     15      1.47       agc  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.47       agc  *    notice, this list of conditions and the following disclaimer in the
     17      1.47       agc  *    documentation and/or other materials provided with the distribution.
     18      1.47       agc  * 3. Neither the name of the University nor the names of its contributors
     19      1.47       agc  *    may be used to endorse or promote products derived from this software
     20      1.47       agc  *    without specific prior written permission.
     21      1.47       agc  *
     22      1.47       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23      1.47       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24      1.47       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25      1.47       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26      1.47       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27      1.47       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28      1.47       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29      1.47       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30      1.47       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31      1.47       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32      1.47       agc  * SUCH DAMAGE.
     33      1.47       agc  */
     34      1.47       agc 
     35      1.47       agc /*
     36       1.1       cgd  * Copyright (c) 1988, 1989 by Adam de Boor
     37       1.1       cgd  * Copyright (c) 1989 by Berkeley Softworks
     38       1.1       cgd  * All rights reserved.
     39       1.1       cgd  *
     40       1.1       cgd  * This code is derived from software contributed to Berkeley by
     41       1.1       cgd  * Adam de Boor.
     42       1.1       cgd  *
     43       1.1       cgd  * Redistribution and use in source and binary forms, with or without
     44       1.1       cgd  * modification, are permitted provided that the following conditions
     45       1.1       cgd  * are met:
     46       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     47       1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     48       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     50       1.1       cgd  *    documentation and/or other materials provided with the distribution.
     51       1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     52       1.1       cgd  *    must display the following acknowledgement:
     53       1.1       cgd  *	This product includes software developed by the University of
     54       1.1       cgd  *	California, Berkeley and its contributors.
     55       1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     56       1.1       cgd  *    may be used to endorse or promote products derived from this software
     57       1.1       cgd  *    without specific prior written permission.
     58       1.1       cgd  *
     59       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60       1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61       1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62       1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63       1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64       1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65       1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66       1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67       1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68       1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69       1.1       cgd  * SUCH DAMAGE.
     70       1.1       cgd  */
     71       1.1       cgd 
     72      1.53      ross #ifndef MAKE_NATIVE
     73  1.89.2.3       tls static char rcsid[] = "$NetBSD: compat.c,v 1.89.2.3 2014/08/20 00:05:00 tls Exp $";
     74      1.22     lukem #else
     75      1.21  christos #include <sys/cdefs.h>
     76       1.1       cgd #ifndef lint
     77      1.10  christos #if 0
     78      1.14  christos static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
     79      1.10  christos #else
     80  1.89.2.3       tls __RCSID("$NetBSD: compat.c,v 1.89.2.3 2014/08/20 00:05:00 tls Exp $");
     81      1.10  christos #endif
     82       1.1       cgd #endif /* not lint */
     83      1.22     lukem #endif
     84       1.1       cgd 
     85       1.1       cgd /*-
     86       1.1       cgd  * compat.c --
     87       1.1       cgd  *	The routines in this file implement the full-compatibility
     88       1.1       cgd  *	mode of PMake. Most of the special functionality of PMake
     89       1.1       cgd  *	is available in this mode. Things not supported:
     90       1.1       cgd  *	    - different shells.
     91       1.1       cgd  *	    - friendly variable substitution.
     92       1.1       cgd  *
     93       1.1       cgd  * Interface:
     94       1.1       cgd  *	Compat_Run	    Initialize things for this module and recreate
     95       1.1       cgd  *	    	  	    thems as need creatin'
     96       1.1       cgd  */
     97       1.1       cgd 
     98       1.1       cgd #include    <sys/types.h>
     99      1.11       jtc #include    <sys/stat.h>
    100       1.1       cgd #include    <sys/wait.h>
    101      1.44       wiz 
    102       1.1       cgd #include    <ctype.h>
    103      1.11       jtc #include    <errno.h>
    104      1.11       jtc #include    <signal.h>
    105      1.44       wiz #include    <stdio.h>
    106      1.44       wiz 
    107       1.1       cgd #include    "make.h"
    108       1.5       cgd #include    "hash.h"
    109       1.5       cgd #include    "dir.h"
    110       1.5       cgd #include    "job.h"
    111      1.43     bjh21 #include    "pathnames.h"
    112       1.1       cgd 
    113       1.1       cgd /*
    114       1.1       cgd  * The following array is used to make a fast determination of which
    115       1.1       cgd  * characters are interpreted specially by the shell.  If a command
    116       1.1       cgd  * contains any of these characters, it is executed by the shell, not
    117       1.1       cgd  * directly by us.
    118       1.1       cgd  */
    119       1.1       cgd 
    120       1.1       cgd static char 	    meta[256];
    121       1.1       cgd 
    122      1.72       dsl static GNode	    *curTarg = NULL;
    123       1.1       cgd static GNode	    *ENDNode;
    124      1.89       wiz static void CompatInterrupt(int);
    125       1.1       cgd 
    126      1.54       sjg static void
    127      1.54       sjg Compat_Init(void)
    128      1.54       sjg {
    129      1.54       sjg     const char *cp;
    130      1.54       sjg 
    131      1.54       sjg     Shell_Init();		/* setup default shell */
    132      1.54       sjg 
    133  1.89.2.3       tls     for (cp = "~#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
    134      1.54       sjg 	meta[(unsigned char) *cp] = 1;
    135      1.54       sjg     }
    136      1.54       sjg     /*
    137      1.54       sjg      * The null character serves as a sentinel in the string.
    138      1.54       sjg      */
    139      1.54       sjg     meta[0] = 1;
    140      1.54       sjg }
    141      1.54       sjg 
    142       1.1       cgd /*-
    143       1.1       cgd  *-----------------------------------------------------------------------
    144       1.1       cgd  * CompatInterrupt --
    145       1.1       cgd  *	Interrupt the creation of the current target and remove it if
    146       1.1       cgd  *	it ain't precious.
    147       1.1       cgd  *
    148       1.1       cgd  * Results:
    149       1.1       cgd  *	None.
    150       1.1       cgd  *
    151       1.1       cgd  * Side Effects:
    152       1.1       cgd  *	The target is removed and the process exits. If .INTERRUPT exists,
    153       1.1       cgd  *	its commands are run first WITH INTERRUPTS IGNORED..
    154       1.1       cgd  *
    155       1.1       cgd  *-----------------------------------------------------------------------
    156       1.1       cgd  */
    157       1.1       cgd static void
    158      1.44       wiz CompatInterrupt(int signo)
    159       1.1       cgd {
    160       1.1       cgd     GNode   *gn;
    161      1.14  christos 
    162      1.72       dsl     if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
    163       1.7       jtc 	char	  *p1;
    164      1.56  christos 	char 	  *file = Var_Value(TARGET, curTarg, &p1);
    165       1.1       cgd 
    166      1.12  christos 	if (!noExecute && eunlink(file) != -1) {
    167      1.42  christos 	    Error("*** %s removed", file);
    168       1.1       cgd 	}
    169       1.7       jtc 	if (p1)
    170       1.7       jtc 	    free(p1);
    171       1.1       cgd 
    172       1.1       cgd 	/*
    173       1.1       cgd 	 * Run .INTERRUPT only if hit with interrupt signal
    174       1.1       cgd 	 */
    175       1.1       cgd 	if (signo == SIGINT) {
    176       1.1       cgd 	    gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    177      1.72       dsl 	    if (gn != NULL) {
    178      1.57  christos 		Compat_Make(gn, gn);
    179       1.1       cgd 	    }
    180       1.1       cgd 	}
    181       1.7       jtc 
    182       1.1       cgd     }
    183      1.87       sjg     if (signo == SIGQUIT)
    184      1.87       sjg 	_exit(signo);
    185      1.87       sjg     bmake_signal(signo, SIG_DFL);
    186      1.88       sjg     kill(myPid, signo);
    187       1.1       cgd }
    188       1.1       cgd 
    189       1.1       cgd /*-
    191       1.1       cgd  *-----------------------------------------------------------------------
    192       1.1       cgd  * CompatRunCommand --
    193       1.1       cgd  *	Execute the next command for a target. If the command returns an
    194       1.1       cgd  *	error, the node's made field is set to ERROR and creation stops.
    195      1.44       wiz  *
    196      1.44       wiz  * Input:
    197      1.44       wiz  *	cmdp		Command to execute
    198      1.44       wiz  *	gnp		Node from which the command came
    199       1.1       cgd  *
    200       1.1       cgd  * Results:
    201       1.1       cgd  *	0 if the command succeeded, 1 if an error occurred.
    202       1.1       cgd  *
    203       1.1       cgd  * Side Effects:
    204       1.1       cgd  *	The node's 'made' field may be set to ERROR.
    205       1.1       cgd  *
    206       1.1       cgd  *-----------------------------------------------------------------------
    207      1.54       sjg  */
    208      1.75       dsl int
    209       1.1       cgd CompatRunCommand(void *cmdp, void *gnp)
    210       1.1       cgd {
    211      1.24  christos     char    	  *cmdStart;	/* Start of expanded command */
    212       1.1       cgd     char 	  *cp, *bp;
    213      1.64  christos     Boolean 	  silent,   	/* Don't print command */
    214      1.64  christos 	    	  doIt;		/* Execute even if -n */
    215      1.13  christos     volatile Boolean errCheck; 	/* Check errors */
    216       1.1       cgd     int 	  reason;   	/* Reason for child's death */
    217      1.76  dholland     int	    	  status;   	/* Description of child's death */
    218      1.76  dholland     pid_t	  cpid;	    	/* Child actually found */
    219       1.1       cgd     pid_t	  retstat;    	/* Result of wait */
    220      1.64  christos     LstNode 	  cmdNode;  	/* Node where current command is located */
    221      1.64  christos     const char  ** volatile av;	/* Argument vector for thing to exec */
    222      1.71  christos     char	** volatile mav;/* Copy of the argument vector for freeing */
    223       1.1       cgd     int	    	  argc;	    	/* Number of arguments in av or 0 if not
    224       1.1       cgd 				 * dynamically allocated */
    225       1.1       cgd     Boolean 	  local;    	/* TRUE if command should be executed
    226      1.62       apb 				 * locally */
    227      1.62       apb     Boolean 	  useShell;    	/* TRUE if command should be executed
    228      1.64  christos 				 * using a shell */
    229      1.60  christos     char	  * volatile cmd = (char *)cmdp;
    230       1.1       cgd     GNode	  *gn = (GNode *)gnp;
    231       1.1       cgd 
    232       1.1       cgd     silent = gn->type & OP_SILENT;
    233      1.54       sjg     errCheck = !(gn->type & OP_IGNORE);
    234      1.54       sjg     doIt = FALSE;
    235      1.65       dsl 
    236      1.56  christos     cmdNode = Lst_Member(gn->commands, cmd);
    237       1.1       cgd     cmdStart = Var_Subst(NULL, cmd, gn, FALSE);
    238       1.1       cgd 
    239      1.24  christos     /*
    240       1.1       cgd      * brk_string will return an argv with a NULL in av[0], thus causing
    241       1.1       cgd      * execvp to choke and die horribly. Besides, how can we execute a null
    242       1.1       cgd      * command? In any case, we warn the user that the command expanded to
    243       1.1       cgd      * nothing (is this the right thing to do?).
    244      1.14  christos      */
    245       1.1       cgd 
    246       1.7       jtc     if (*cmdStart == '\0') {
    247       1.1       cgd 	free(cmdStart);
    248       1.1       cgd 	return(0);
    249      1.74       dsl     }
    250      1.65       dsl     cmd = cmdStart;
    251       1.1       cgd     Lst_Replace(cmdNode, cmdStart);
    252       1.1       cgd 
    253      1.65       dsl     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
    254       1.1       cgd 	(void)Lst_AtEnd(ENDNode->commands, cmdStart);
    255      1.74       dsl 	return(0);
    256      1.74       dsl     }
    257       1.1       cgd     if (strcmp(cmdStart, "...") == 0) {
    258       1.1       cgd 	gn->type |= OP_SAVE_CMDS;
    259       1.1       cgd 	return(0);
    260       1.1       cgd     }
    261      1.54       sjg 
    262      1.54       sjg     while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
    263      1.54       sjg 	switch (*cmd) {
    264      1.69       sjg 	case '@':
    265      1.54       sjg 	    silent = DEBUG(LOUD) ? FALSE : TRUE;
    266      1.54       sjg 	    break;
    267       1.1       cgd 	case '-':
    268      1.54       sjg 	    errCheck = FALSE;
    269      1.54       sjg 	    break;
    270      1.54       sjg 	case '+':
    271      1.54       sjg 	    doIt = TRUE;
    272      1.54       sjg 	    if (!meta[0])		/* we came here from jobs */
    273      1.54       sjg 		Compat_Init();
    274       1.1       cgd 	    break;
    275       1.1       cgd 	}
    276       1.1       cgd 	cmd++;
    277       1.1       cgd     }
    278       1.5       cgd 
    279       1.5       cgd     while (isspace((unsigned char)*cmd))
    280      1.14  christos 	cmd++;
    281      1.86       sjg 
    282      1.86       sjg     /*
    283      1.86       sjg      * If we did not end up with a command, just skip it.
    284      1.86       sjg      */
    285      1.86       sjg     if (!*cmd)
    286      1.86       sjg 	return (0);
    287      1.62       apb 
    288      1.62       apb #if !defined(MAKE_NATIVE)
    289      1.62       apb     /*
    290      1.62       apb      * In a non-native build, the host environment might be weird enough
    291      1.62       apb      * that it's necessary to go through a shell to get the correct
    292      1.62       apb      * behaviour.  Or perhaps the shell has been replaced with something
    293      1.62       apb      * that does extra logging, and that should not be bypassed.
    294      1.62       apb      */
    295      1.62       apb     useShell = TRUE;
    296       1.1       cgd #else
    297       1.1       cgd     /*
    298       1.1       cgd      * Search for meta characters in the command. If there are no meta
    299       1.1       cgd      * characters, there's no need to execute a shell to execute the
    300       1.1       cgd      * command.
    301       1.5       cgd      */
    302       1.1       cgd     for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
    303       1.1       cgd 	continue;
    304      1.62       apb     }
    305      1.62       apb     useShell = (*cp != '\0');
    306       1.1       cgd #endif
    307       1.1       cgd 
    308       1.1       cgd     /*
    309       1.1       cgd      * Print the command before echoing if we're not supposed to be quiet for
    310       1.1       cgd      * this one. We also print the command if -n given.
    311      1.31  sommerfe      */
    312      1.59  christos     if (!silent || NoExecute(gn)) {
    313       1.1       cgd 	printf("%s\n", cmd);
    314       1.1       cgd 	fflush(stdout);
    315       1.1       cgd     }
    316       1.1       cgd 
    317       1.1       cgd     /*
    318       1.1       cgd      * If we're not supposed to execute any commands, this is as far as
    319       1.1       cgd      * we go...
    320      1.54       sjg      */
    321       1.1       cgd     if (!doIt && NoExecute(gn)) {
    322       1.1       cgd 	return (0);
    323      1.74       dsl     }
    324      1.74       dsl     if (DEBUG(JOB))
    325      1.14  christos 	fprintf(debug_file, "Execute: '%s'\n", cmd);
    326      1.73  christos 
    327      1.62       apb again:
    328       1.1       cgd     if (useShell) {
    329      1.62       apb 	/*
    330      1.62       apb 	 * We need to pass the command off to the shell, typically
    331       1.1       cgd 	 * because the command contains a "meta" character.
    332  1.89.2.3       tls 	 */
    333  1.89.2.3       tls 	static const char *shargv[5];
    334       1.1       cgd 	int shargc;
    335  1.89.2.3       tls 
    336  1.89.2.3       tls 	shargc = 0;
    337      1.46       sjg 	shargv[shargc++] = shellPath;
    338      1.46       sjg 	/*
    339      1.46       sjg 	 * The following work for any of the builtin shell specs.
    340  1.89.2.3       tls 	 */
    341  1.89.2.3       tls 	if (errCheck && shellErrFlag) {
    342  1.89.2.3       tls 	    shargv[shargc++] = shellErrFlag;
    343      1.34       sjg 	}
    344  1.89.2.3       tls 	if (DEBUG(SHELL))
    345      1.34       sjg 		shargv[shargc++] = "-xc";
    346  1.89.2.3       tls 	else
    347  1.89.2.3       tls 		shargv[shargc++] = "-c";
    348  1.89.2.3       tls 	shargv[shargc++] = cmd;
    349       1.1       cgd 	shargv[shargc++] = NULL;
    350       1.1       cgd 	av = shargv;
    351      1.24  christos 	argc = 0;
    352      1.61  christos 	bp = NULL;
    353       1.1       cgd 	mav = NULL;
    354       1.1       cgd     } else {
    355       1.1       cgd 	/*
    356       1.1       cgd 	 * No meta-characters, so no need to exec a shell. Break the command
    357       1.1       cgd 	 * into words to form an argument vector we can execute.
    358      1.73  christos 	 */
    359      1.73  christos 	mav = brk_string(cmd, &argc, TRUE, &bp);
    360      1.73  christos 	if (mav == NULL) {
    361      1.73  christos 		useShell = 1;
    362      1.73  christos 		goto again;
    363      1.83  christos 	}
    364       1.1       cgd 	av = (void *)mav;
    365      1.14  christos     }
    366       1.1       cgd 
    367       1.1       cgd     local = TRUE;
    368      1.81       sjg 
    369      1.81       sjg #ifdef USE_META
    370      1.81       sjg     if (useMeta) {
    371      1.81       sjg 	meta_compat_start();
    372      1.81       sjg     }
    373      1.81       sjg #endif
    374       1.1       cgd 
    375       1.1       cgd     /*
    376       1.1       cgd      * Fork and execute the single command. If the fork fails, we abort.
    377      1.78       sjg      */
    378       1.1       cgd     cpid = vFork();
    379       1.1       cgd     if (cpid < 0) {
    380       1.1       cgd 	Fatal("Could not fork");
    381       1.1       cgd     }
    382      1.68       sjg     if (cpid == 0) {
    383      1.81       sjg 	Var_ExportVars();
    384      1.81       sjg #ifdef USE_META
    385      1.81       sjg 	if (useMeta) {
    386      1.81       sjg 	    meta_compat_child();
    387      1.81       sjg 	}
    388      1.33  christos #endif
    389      1.45  christos 	if (local)
    390      1.33  christos 	    (void)execvp(av[0], (char *const *)UNCONST(av));
    391      1.45  christos 	else
    392      1.41        pk 	    (void)execv(av[0], (char *const *)UNCONST(av));
    393      1.23   thorpej 	execError("exec", av[0]);
    394       1.1       cgd 	_exit(1);
    395      1.61  christos     }
    396      1.61  christos     if (mav)
    397      1.61  christos 	free(mav);
    398      1.25     itohy     if (bp)
    399      1.65       dsl 	free(bp);
    400      1.14  christos     Lst_Replace(cmdNode, NULL);
    401      1.81       sjg 
    402      1.81       sjg #ifdef USE_META
    403      1.81       sjg     if (useMeta) {
    404      1.81       sjg 	meta_compat_parent();
    405      1.81       sjg     }
    406      1.81       sjg #endif
    407       1.1       cgd 
    408       1.1       cgd     /*
    409       1.1       cgd      * The child is off and running. Now all we can do is wait...
    410      1.71  christos      */
    411       1.1       cgd     while (1) {
    412      1.37   reinoud 
    413      1.80       sjg 	while ((retstat = wait(&reason)) != cpid) {
    414      1.80       sjg 	    if (retstat > 0)
    415      1.37   reinoud 		JobReapChild(retstat, reason, FALSE); /* not ours? */
    416       1.1       cgd 	    if (retstat == -1 && errno != EINTR) {
    417       1.1       cgd 		break;
    418       1.1       cgd 	    }
    419      1.14  christos 	}
    420      1.37   reinoud 
    421       1.1       cgd 	if (retstat > -1) {
    422      1.13  christos 	    if (WIFSTOPPED(reason)) {
    423       1.1       cgd 		status = WSTOPSIG(reason);		/* stopped */
    424      1.13  christos 	    } else if (WIFEXITED(reason)) {
    425      1.81       sjg 		status = WEXITSTATUS(reason);		/* exited */
    426      1.81       sjg #if defined(USE_META) && defined(USE_FILEMON_ONCE)
    427      1.81       sjg 		if (useMeta) {
    428      1.81       sjg 		    meta_cmd_finish(NULL);
    429      1.81       sjg 		}
    430       1.1       cgd #endif
    431      1.52      jmmv 		if (status != 0) {
    432      1.63       dsl 		    if (DEBUG(ERROR)) {
    433      1.52      jmmv 		        fprintf(debug_file, "\n*** Failed target:  %s\n*** Failed command: ",
    434      1.52      jmmv 			    gn->name);
    435      1.52      jmmv 		        for (cp = cmd; *cp; ) {
    436      1.63       dsl     			    if (isspace((unsigned char)*cp)) {
    437      1.52      jmmv 				fprintf(debug_file, " ");
    438      1.52      jmmv 			        while (isspace((unsigned char)*cp))
    439      1.52      jmmv 				    cp++;
    440      1.63       dsl 			    } else {
    441      1.52      jmmv 				fprintf(debug_file, "%c", *cp);
    442      1.52      jmmv 			        cp++;
    443      1.52      jmmv 			    }
    444      1.63       dsl 		        }
    445      1.51     lukem 			fprintf(debug_file, "\n");
    446      1.77       sjg 		    }
    447       1.1       cgd 		    printf("*** Error code %d", status);
    448       1.1       cgd 		}
    449      1.13  christos 	    } else {
    450      1.59  christos 		status = WTERMSIG(reason);		/* signaled */
    451      1.14  christos 		printf("*** Signal %d", status);
    452      1.14  christos 	    }
    453       1.1       cgd 
    454       1.1       cgd 
    455       1.1       cgd 	    if (!WIFEXITED(reason) || (status != 0)) {
    456      1.81       sjg 		if (errCheck) {
    457      1.81       sjg #ifdef USE_META
    458      1.81       sjg 		    if (useMeta) {
    459      1.81       sjg 			meta_job_error(NULL, gn, 0, status);
    460      1.81       sjg 		    }
    461       1.1       cgd #endif
    462       1.1       cgd 		    gn->made = ERROR;
    463       1.1       cgd 		    if (keepgoing) {
    464       1.1       cgd 			/*
    465       1.1       cgd 			 * Abort the current target, but let others
    466       1.1       cgd 			 * continue.
    467      1.59  christos 			 */
    468       1.1       cgd 			printf(" (continuing)\n");
    469       1.1       cgd 		    }
    470       1.1       cgd 		} else {
    471       1.1       cgd 		    /*
    472       1.1       cgd 		     * Continue executing commands for this target.
    473       1.1       cgd 		     * If we return 0, this will happen...
    474      1.59  christos 		     */
    475       1.1       cgd 		    printf(" (ignored)\n");
    476       1.1       cgd 		    status = 0;
    477       1.1       cgd 		}
    478       1.1       cgd 	    }
    479       1.1       cgd 	    break;
    480      1.56  christos 	} else {
    481       1.1       cgd 	    Fatal("error in wait: %d: %s", retstat, strerror(errno));
    482       1.1       cgd 	    /*NOTREACHED*/
    483       1.1       cgd 	}
    484      1.50     lukem     }
    485       1.1       cgd     free(cmdStart);
    486       1.1       cgd 
    487       1.1       cgd     return (status);
    488       1.1       cgd }
    489       1.1       cgd 
    490       1.1       cgd /*-
    492       1.1       cgd  *-----------------------------------------------------------------------
    493       1.1       cgd  * Compat_Make --
    494      1.44       wiz  *	Make a target.
    495      1.44       wiz  *
    496      1.44       wiz  * Input:
    497      1.44       wiz  *	gnp		The node to make
    498       1.1       cgd  *	pgnp		Parent to abort if necessary
    499       1.1       cgd  *
    500       1.1       cgd  * Results:
    501       1.1       cgd  *	0
    502       1.1       cgd  *
    503       1.1       cgd  * Side Effects:
    504       1.1       cgd  *	If an error is detected and not being ignored, the process exits.
    505       1.1       cgd  *
    506      1.57  christos  *-----------------------------------------------------------------------
    507      1.75       dsl  */
    508       1.1       cgd int
    509      1.60  christos Compat_Make(void *gnp, void *pgnp)
    510      1.60  christos {
    511      1.16  christos     GNode *gn = (GNode *)gnp;
    512      1.57  christos     GNode *pgn = (GNode *)pgnp;
    513      1.57  christos 
    514      1.40        pk     if (!meta[0])		/* we came here from jobs */
    515       1.1       cgd 	Compat_Init();
    516       1.1       cgd     if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
    517       1.1       cgd 	/*
    518       1.1       cgd 	 * First mark ourselves to be made, then apply whatever transformations
    519       1.1       cgd 	 * the suffix module thinks are necessary. Once that's done, we can
    520       1.1       cgd 	 * descend and make all our children. If any of them has an error
    521       1.1       cgd 	 * but the -k flag was given, our 'make' field will be set FALSE again.
    522       1.1       cgd 	 * This is our signal to not attempt to do anything but abort our
    523      1.26  christos 	 * parent as well.
    524       1.1       cgd 	 */
    525      1.38        pk 	gn->flags |= REMAKE;
    526      1.56  christos 	gn->made = BEINGMADE;
    527      1.65       dsl 	if ((gn->type & OP_MADE) == 0)
    528      1.26  christos 	    Suff_FindDeps(gn);
    529       1.1       cgd 	Lst_ForEach(gn->children, Compat_Make, gn);
    530      1.26  christos 	if ((gn->flags & REMAKE) == 0) {
    531      1.28   mycroft 	    gn->made = ABORTED;
    532       1.1       cgd 	    pgn->flags &= ~REMAKE;
    533       1.1       cgd 	    goto cohorts;
    534      1.72       dsl 	}
    535       1.7       jtc 
    536      1.56  christos 	if (Lst_Member(gn->iParents, pgn) != NULL) {
    537       1.7       jtc 	    char *p1;
    538       1.7       jtc 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
    539       1.1       cgd 	    if (p1)
    540      1.14  christos 		free(p1);
    541       1.1       cgd 	}
    542      1.82  christos 
    543      1.82  christos 	/*
    544      1.82  christos 	 * All the children were made ok. Now cmgn->mtime contains the
    545      1.82  christos 	 * modification time of the newest child, we need to find out if we
    546       1.1       cgd 	 * exist and when we were modified last. The criteria for datedness
    547       1.1       cgd 	 * are defined by the Make_OODate function.
    548      1.63       dsl 	 */
    549       1.1       cgd 	if (DEBUG(MAKE)) {
    550       1.1       cgd 	    fprintf(debug_file, "Examining %s...", gn->name);
    551       1.1       cgd 	}
    552       1.1       cgd 	if (! Make_OODate(gn)) {
    553      1.63       dsl 	    gn->made = UPTODATE;
    554       1.1       cgd 	    if (DEBUG(MAKE)) {
    555      1.28   mycroft 		fprintf(debug_file, "up-to-date.\n");
    556       1.1       cgd 	    }
    557      1.63       dsl 	    goto cohorts;
    558       1.1       cgd 	} else if (DEBUG(MAKE)) {
    559       1.1       cgd 	    fprintf(debug_file, "out-of-date.\n");
    560       1.1       cgd 	}
    561       1.1       cgd 
    562       1.1       cgd 	/*
    563       1.1       cgd 	 * If the user is just seeing if something is out-of-date, exit now
    564       1.1       cgd 	 * to tell him/her "yes".
    565      1.59  christos 	 */
    566       1.1       cgd 	if (queryFlag) {
    567       1.1       cgd 	    exit(1);
    568       1.1       cgd 	}
    569       1.1       cgd 
    570       1.1       cgd 	/*
    571       1.1       cgd 	 * We need to be re-made. We also have to make sure we've got a $?
    572       1.1       cgd 	 * variable. To be nice, we also define the $> variable using
    573       1.1       cgd 	 * Make_DoAllVar().
    574      1.14  christos 	 */
    575       1.1       cgd 	Make_DoAllVar(gn);
    576       1.1       cgd 
    577       1.1       cgd 	/*
    578       1.1       cgd 	 * Alter our type to tell if errors should be ignored or things
    579      1.56  christos 	 * should not be printed so CompatRunCommand knows what to do.
    580       1.1       cgd 	 */
    581       1.1       cgd 	if (Targ_Ignore(gn)) {
    582      1.56  christos 	    gn->type |= OP_IGNORE;
    583       1.1       cgd 	}
    584       1.1       cgd 	if (Targ_Silent(gn)) {
    585       1.1       cgd 	    gn->type |= OP_SILENT;
    586      1.56  christos 	}
    587       1.1       cgd 
    588       1.1       cgd 	if (Job_CheckCommands(gn, Fatal)) {
    589       1.1       cgd 	    /*
    590       1.1       cgd 	     * Our commands are ok, but we still have to worry about the -t
    591      1.20   mycroft 	     * flag...
    592       1.1       cgd 	     */
    593      1.81       sjg 	    if (!touchFlag || (gn->type & OP_MAKE)) {
    594      1.81       sjg 		curTarg = gn;
    595      1.81       sjg #ifdef USE_META
    596      1.81       sjg 		if (useMeta && !NoExecute(gn)) {
    597      1.81       sjg 		    meta_job_start(NULL, gn);
    598      1.65       dsl 		}
    599      1.72       dsl #endif
    600       1.1       cgd 		Lst_ForEach(gn->commands, CompatRunCommand, gn);
    601      1.71  christos 		curTarg = NULL;
    602       1.1       cgd 	    } else {
    603       1.1       cgd 		Job_Touch(gn, gn->type & OP_SILENT);
    604       1.1       cgd 	    }
    605       1.1       cgd 	} else {
    606      1.81       sjg 	    gn->made = ERROR;
    607      1.81       sjg 	}
    608      1.81       sjg #ifdef USE_META
    609      1.81       sjg 	if (useMeta && !NoExecute(gn)) {
    610      1.81       sjg 	    meta_job_finish(NULL);
    611       1.1       cgd 	}
    612       1.1       cgd #endif
    613       1.1       cgd 
    614       1.1       cgd 	if (gn->made != ERROR) {
    615       1.1       cgd 	    /*
    616       1.1       cgd 	     * If the node was made successfully, mark it so, update
    617       1.1       cgd 	     * its modification time and timestamp all its parents. Note
    618       1.1       cgd 	     * that for .ZEROTIME targets, the timestamping isn't done.
    619       1.1       cgd 	     * This is to keep its state from affecting that of its parent.
    620      1.26  christos 	     */
    621       1.1       cgd 	    gn->made = MADE;
    622      1.26  christos 	    pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
    623       1.1       cgd 	    if (!(gn->type & OP_EXEC)) {
    624       1.1       cgd 		pgn->flags |= CHILDMADE;
    625       1.1       cgd 		Make_TimeStamp(pgn, gn);
    626      1.26  christos 	    }
    627       1.1       cgd 	} else if (keepgoing) {
    628      1.77       sjg 	    pgn->flags &= ~REMAKE;
    629      1.59  christos 	} else {
    630       1.1       cgd 	    PrintOnError(gn, "\n\nStop.");
    631       1.1       cgd 	    exit(1);
    632       1.1       cgd 	}
    633       1.1       cgd     } else if (gn->made == ERROR) {
    634       1.1       cgd 	/*
    635       1.1       cgd 	 * Already had an error when making this beastie. Tell the parent
    636      1.26  christos 	 * to abort.
    637       1.1       cgd 	 */
    638      1.72       dsl 	pgn->flags &= ~REMAKE;
    639       1.7       jtc     } else {
    640      1.56  christos 	if (Lst_Member(gn->iParents, pgn) != NULL) {
    641       1.7       jtc 	    char *p1;
    642       1.7       jtc 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
    643       1.1       cgd 	    if (p1)
    644       1.1       cgd 		free(p1);
    645       1.1       cgd 	}
    646      1.42  christos 	switch(gn->made) {
    647       1.1       cgd 	    case BEINGMADE:
    648      1.26  christos 		Error("Graph cycles through %s", gn->name);
    649       1.1       cgd 		gn->made = ERROR;
    650       1.1       cgd 		pgn->flags &= ~REMAKE;
    651       1.1       cgd 		break;
    652      1.26  christos 	    case MADE:
    653       1.1       cgd 		if ((gn->type & OP_EXEC) == 0) {
    654       1.1       cgd 		    pgn->flags |= CHILDMADE;
    655       1.1       cgd 		    Make_TimeStamp(pgn, gn);
    656       1.1       cgd 		}
    657       1.1       cgd 		break;
    658       1.1       cgd 	    case UPTODATE:
    659       1.1       cgd 		if ((gn->type & OP_EXEC) == 0) {
    660       1.1       cgd 		    Make_TimeStamp(pgn, gn);
    661       1.5       cgd 		}
    662       1.5       cgd 		break;
    663       1.1       cgd 	    default:
    664       1.1       cgd 		break;
    665       1.1       cgd 	}
    666      1.28   mycroft     }
    667      1.57  christos 
    668       1.1       cgd cohorts:
    669       1.1       cgd     Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
    670      1.14  christos     return (0);
    671       1.1       cgd }
    672       1.1       cgd 
    673       1.1       cgd /*-
    675       1.1       cgd  *-----------------------------------------------------------------------
    676      1.44       wiz  * Compat_Run --
    677      1.44       wiz  *	Initialize this mode and start making.
    678      1.44       wiz  *
    679       1.1       cgd  * Input:
    680       1.1       cgd  *	targs		List of target nodes to re-create
    681       1.1       cgd  *
    682       1.1       cgd  * Results:
    683       1.1       cgd  *	None.
    684       1.1       cgd  *
    685       1.1       cgd  * Side Effects:
    686       1.1       cgd  *	Guess what?
    687       1.1       cgd  *
    688      1.44       wiz  *-----------------------------------------------------------------------
    689       1.1       cgd  */
    690       1.5       cgd void
    691       1.1       cgd Compat_Run(Lst targs)
    692      1.46       sjg {
    693      1.54       sjg     GNode   	  *gn = NULL;/* Current root target */
    694       1.1       cgd     int	    	  errors;   /* Number of targets not remade due to errors */
    695      1.79       sjg 
    696      1.79       sjg     Compat_Init();
    697       1.1       cgd 
    698      1.79       sjg     if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
    699      1.79       sjg 	bmake_signal(SIGINT, CompatInterrupt);
    700       1.1       cgd     }
    701      1.79       sjg     if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
    702      1.79       sjg 	bmake_signal(SIGTERM, CompatInterrupt);
    703       1.1       cgd     }
    704      1.79       sjg     if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
    705      1.79       sjg 	bmake_signal(SIGHUP, CompatInterrupt);
    706       1.1       cgd     }
    707       1.1       cgd     if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
    708       1.1       cgd 	bmake_signal(SIGQUIT, CompatInterrupt);
    709      1.58  christos     }
    710       1.1       cgd 
    711       1.1       cgd     ENDNode = Targ_FindNode(".END", TARG_CREATE);
    712       1.1       cgd     ENDNode->type = OP_SPECIAL;
    713       1.1       cgd     /*
    714       1.1       cgd      * If the user has defined a .BEGIN target, execute the commands attached
    715       1.1       cgd      * to it.
    716      1.72       dsl      */
    717      1.57  christos     if (!queryFlag) {
    718      1.14  christos 	gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    719      1.77       sjg 	if (gn != NULL) {
    720      1.14  christos 	    Compat_Make(gn, gn);
    721      1.14  christos             if (gn->made == ERROR) {
    722       1.1       cgd                 PrintOnError(gn, "\n\nStop.");
    723       1.1       cgd                 exit(1);
    724      1.15  christos             }
    725      1.15  christos 	}
    726      1.15  christos     }
    727      1.15  christos 
    728      1.15  christos     /*
    729      1.66       dsl      * Expand .USE nodes right now, because they can modify the structure
    730       1.1       cgd      * of the tree.
    731       1.1       cgd      */
    732      1.57  christos     Make_ExpandUse(targs);
    733      1.57  christos 
    734       1.1       cgd     /*
    735       1.1       cgd      * For each entry in the list of targets to create, call Compat_Make on
    736       1.1       cgd      * it to create the thing. Compat_Make will leave the 'made' field of gn
    737       1.1       cgd      * in one of several states:
    738       1.1       cgd      *	    UPTODATE	    gn was already up-to-date
    739       1.1       cgd      *	    MADE  	    gn was recreated successfully
    740       1.1       cgd      *	    ERROR 	    An error occurred while gn was being created
    741       1.1       cgd      *	    ABORTED	    gn was not remade because one of its inferiors
    742       1.1       cgd      *	    	  	    could not be made due to errors.
    743      1.59  christos      */
    744      1.57  christos     errors = 0;
    745       1.1       cgd     while (!Lst_IsEmpty (targs)) {
    746       1.1       cgd 	gn = (GNode *)Lst_DeQueue(targs);
    747      1.59  christos 	Compat_Make(gn, gn);
    748       1.1       cgd 
    749      1.59  christos 	if (gn->made == UPTODATE) {
    750       1.1       cgd 	    printf("`%s' is up to date.\n", gn->name);
    751       1.1       cgd 	} else if (gn->made == ABORTED) {
    752       1.1       cgd 	    printf("`%s' not remade because of errors.\n", gn->name);
    753       1.1       cgd 	    errors += 1;
    754       1.1       cgd 	}
    755       1.1       cgd     }
    756       1.1       cgd 
    757       1.1       cgd     /*
    758      1.57  christos      * If the user has defined a .END target, run its commands.
    759      1.36       sjg      */
    760      1.77       sjg     if (errors == 0) {
    761      1.36       sjg 	Compat_Make(ENDNode, ENDNode);
    762      1.36       sjg 	if (gn->made == ERROR) {
    763       1.1       cgd 	    PrintOnError(gn, "\n\nStop.");
    764       1.1       cgd 	    exit(1);
    765                     	}
    766                         }
    767                     }
    768