Home | History | Annotate | Line # | Download | only in make
compat.c revision 1.34
      1  1.34       sjg /*	$NetBSD: compat.c,v 1.34 2001/06/01 20:33:37 sjg 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.1       cgd  * Copyright (c) 1988, 1989 by Adam de Boor
      6   1.1       cgd  * Copyright (c) 1989 by Berkeley Softworks
      7   1.1       cgd  * All rights reserved.
      8   1.1       cgd  *
      9   1.1       cgd  * This code is derived from software contributed to Berkeley by
     10   1.1       cgd  * Adam de Boor.
     11   1.1       cgd  *
     12   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     13   1.1       cgd  * modification, are permitted provided that the following conditions
     14   1.1       cgd  * are met:
     15   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     17   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     19   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     20   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     21   1.1       cgd  *    must display the following acknowledgement:
     22   1.1       cgd  *	This product includes software developed by the University of
     23   1.1       cgd  *	California, Berkeley and its contributors.
     24   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     25   1.1       cgd  *    may be used to endorse or promote products derived from this software
     26   1.1       cgd  *    without specific prior written permission.
     27   1.1       cgd  *
     28   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.1       cgd  * SUCH DAMAGE.
     39   1.1       cgd  */
     40   1.1       cgd 
     41  1.22     lukem #ifdef MAKE_BOOTSTRAP
     42  1.34       sjg static char rcsid[] = "$NetBSD: compat.c,v 1.34 2001/06/01 20:33:37 sjg Exp $";
     43  1.22     lukem #else
     44  1.21  christos #include <sys/cdefs.h>
     45   1.1       cgd #ifndef lint
     46  1.10  christos #if 0
     47  1.14  christos static char sccsid[] = "@(#)compat.c	8.2 (Berkeley) 3/19/94";
     48  1.10  christos #else
     49  1.34       sjg __RCSID("$NetBSD: compat.c,v 1.34 2001/06/01 20:33:37 sjg Exp $");
     50  1.10  christos #endif
     51   1.1       cgd #endif /* not lint */
     52  1.22     lukem #endif
     53   1.1       cgd 
     54   1.1       cgd /*-
     55   1.1       cgd  * compat.c --
     56   1.1       cgd  *	The routines in this file implement the full-compatibility
     57   1.1       cgd  *	mode of PMake. Most of the special functionality of PMake
     58   1.1       cgd  *	is available in this mode. Things not supported:
     59   1.1       cgd  *	    - different shells.
     60   1.1       cgd  *	    - friendly variable substitution.
     61   1.1       cgd  *
     62   1.1       cgd  * Interface:
     63   1.1       cgd  *	Compat_Run	    Initialize things for this module and recreate
     64   1.1       cgd  *	    	  	    thems as need creatin'
     65   1.1       cgd  */
     66   1.1       cgd 
     67   1.1       cgd #include    <stdio.h>
     68   1.1       cgd #include    <sys/types.h>
     69  1.11       jtc #include    <sys/stat.h>
     70   1.1       cgd #include    <sys/wait.h>
     71   1.1       cgd #include    <ctype.h>
     72  1.11       jtc #include    <errno.h>
     73  1.11       jtc #include    <signal.h>
     74   1.1       cgd #include    "make.h"
     75   1.5       cgd #include    "hash.h"
     76   1.5       cgd #include    "dir.h"
     77   1.5       cgd #include    "job.h"
     78   1.1       cgd 
     79   1.1       cgd /*
     80   1.1       cgd  * The following array is used to make a fast determination of which
     81   1.1       cgd  * characters are interpreted specially by the shell.  If a command
     82   1.1       cgd  * contains any of these characters, it is executed by the shell, not
     83   1.1       cgd  * directly by us.
     84   1.1       cgd  */
     85   1.1       cgd 
     86   1.1       cgd static char 	    meta[256];
     87   1.1       cgd 
     88   1.1       cgd static GNode	    *curTarg = NILGNODE;
     89   1.1       cgd static GNode	    *ENDNode;
     90   1.5       cgd static void CompatInterrupt __P((int));
     91   1.7       jtc static int CompatRunCommand __P((ClientData, ClientData));
     92   1.7       jtc static int CompatMake __P((ClientData, ClientData));
     93   1.1       cgd 
     94   1.1       cgd /*-
     95   1.1       cgd  *-----------------------------------------------------------------------
     96   1.1       cgd  * CompatInterrupt --
     97   1.1       cgd  *	Interrupt the creation of the current target and remove it if
     98   1.1       cgd  *	it ain't precious.
     99   1.1       cgd  *
    100   1.1       cgd  * Results:
    101   1.1       cgd  *	None.
    102   1.1       cgd  *
    103   1.1       cgd  * Side Effects:
    104   1.1       cgd  *	The target is removed and the process exits. If .INTERRUPT exists,
    105   1.1       cgd  *	its commands are run first WITH INTERRUPTS IGNORED..
    106   1.1       cgd  *
    107   1.1       cgd  *-----------------------------------------------------------------------
    108   1.1       cgd  */
    109   1.1       cgd static void
    110   1.1       cgd CompatInterrupt (signo)
    111   1.1       cgd     int	    signo;
    112   1.1       cgd {
    113   1.1       cgd     GNode   *gn;
    114  1.14  christos 
    115   1.1       cgd     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
    116   1.7       jtc 	char	  *p1;
    117   1.7       jtc 	char 	  *file = Var_Value (TARGET, curTarg, &p1);
    118   1.1       cgd 
    119  1.12  christos 	if (!noExecute && eunlink(file) != -1) {
    120  1.19   mycroft 	    Error("*** %s removed\n", file);
    121   1.1       cgd 	}
    122   1.7       jtc 	if (p1)
    123   1.7       jtc 	    free(p1);
    124   1.1       cgd 
    125   1.1       cgd 	/*
    126   1.1       cgd 	 * Run .INTERRUPT only if hit with interrupt signal
    127   1.1       cgd 	 */
    128   1.1       cgd 	if (signo == SIGINT) {
    129   1.1       cgd 	    gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    130   1.1       cgd 	    if (gn != NILGNODE) {
    131   1.1       cgd 		Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    132   1.1       cgd 	    }
    133   1.1       cgd 	}
    134   1.7       jtc 
    135   1.1       cgd     }
    136   1.7       jtc     exit (signo);
    137   1.1       cgd }
    138   1.1       cgd 
    139   1.1       cgd /*-
    141   1.1       cgd  *-----------------------------------------------------------------------
    142   1.1       cgd  * CompatRunCommand --
    143   1.1       cgd  *	Execute the next command for a target. If the command returns an
    144   1.1       cgd  *	error, the node's made field is set to ERROR and creation stops.
    145   1.1       cgd  *
    146   1.1       cgd  * Results:
    147   1.1       cgd  *	0 if the command succeeded, 1 if an error occurred.
    148   1.1       cgd  *
    149   1.1       cgd  * Side Effects:
    150   1.1       cgd  *	The node's 'made' field may be set to ERROR.
    151   1.1       cgd  *
    152   1.1       cgd  *-----------------------------------------------------------------------
    153   1.1       cgd  */
    154   1.7       jtc static int
    155   1.7       jtc CompatRunCommand (cmdp, gnp)
    156   1.7       jtc     ClientData    cmdp;	    	/* Command to execute */
    157   1.1       cgd     ClientData    gnp;    	/* Node from which the command came */
    158   1.1       cgd {
    159  1.24  christos     char    	  *cmdStart;	/* Start of expanded command */
    160   1.1       cgd     char 	  *cp, *bp;
    161   1.1       cgd     Boolean 	  silent,   	/* Don't print command */
    162  1.13  christos 		  errCheck; 	/* Check errors */
    163   1.1       cgd     int 	  reason;   	/* Reason for child's death */
    164   1.1       cgd     int	    	  status;   	/* Description of child's death */
    165   1.1       cgd     int	    	  cpid;	    	/* Child actually found */
    166   1.1       cgd     ReturnStatus  stat;	    	/* Status of fork */
    167   1.1       cgd     LstNode 	  cmdNode;  	/* Node where current command is located */
    168   1.1       cgd     char    	  **av;	    	/* Argument vector for thing to exec */
    169   1.1       cgd     int	    	  argc;	    	/* Number of arguments in av or 0 if not
    170   1.1       cgd 				 * dynamically allocated */
    171   1.1       cgd     Boolean 	  local;    	/* TRUE if command should be executed
    172   1.7       jtc 				 * locally */
    173   1.7       jtc     char	  *cmd = (char *) cmdp;
    174   1.1       cgd     GNode	  *gn = (GNode *) gnp;
    175  1.14  christos 
    176   1.6       cgd     /*
    177   1.6       cgd      * Avoid clobbered variable warnings by forcing the compiler
    178   1.6       cgd      * to ``unregister'' variables
    179   1.6       cgd      */
    180   1.6       cgd #if __GNUC__
    181   1.6       cgd     (void) &av;
    182   1.6       cgd     (void) &errCheck;
    183   1.1       cgd #endif
    184   1.1       cgd     silent = gn->type & OP_SILENT;
    185   1.1       cgd     errCheck = !(gn->type & OP_IGNORE);
    186   1.1       cgd 
    187   1.5       cgd     cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
    188   1.1       cgd     cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
    189   1.1       cgd 
    190  1.24  christos     /*
    191   1.1       cgd      * brk_string will return an argv with a NULL in av[0], thus causing
    192   1.1       cgd      * execvp to choke and die horribly. Besides, how can we execute a null
    193   1.1       cgd      * command? In any case, we warn the user that the command expanded to
    194   1.1       cgd      * nothing (is this the right thing to do?).
    195  1.14  christos      */
    196   1.1       cgd 
    197   1.7       jtc     if (*cmdStart == '\0') {
    198   1.1       cgd 	free(cmdStart);
    199   1.1       cgd 	Error("%s expands to empty string", cmd);
    200   1.1       cgd 	return(0);
    201   1.1       cgd     } else {
    202   1.1       cgd 	cmd = cmdStart;
    203   1.1       cgd     }
    204   1.1       cgd     Lst_Replace (cmdNode, (ClientData)cmdStart);
    205   1.1       cgd 
    206   1.1       cgd     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
    207   1.1       cgd 	(void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
    208   1.1       cgd 	return(0);
    209   1.1       cgd     } else if (strcmp(cmdStart, "...") == 0) {
    210   1.1       cgd 	gn->type |= OP_SAVE_CMDS;
    211   1.1       cgd 	return(0);
    212   1.1       cgd     }
    213   1.1       cgd 
    214   1.1       cgd     while ((*cmd == '@') || (*cmd == '-')) {
    215   1.1       cgd 	if (*cmd == '@') {
    216   1.1       cgd 	    silent = TRUE;
    217   1.1       cgd 	} else {
    218   1.1       cgd 	    errCheck = FALSE;
    219   1.1       cgd 	}
    220   1.1       cgd 	cmd++;
    221   1.1       cgd     }
    222   1.5       cgd 
    223   1.5       cgd     while (isspace((unsigned char)*cmd))
    224  1.14  christos 	cmd++;
    225   1.1       cgd 
    226   1.1       cgd     /*
    227   1.1       cgd      * Search for meta characters in the command. If there are no meta
    228   1.1       cgd      * characters, there's no need to execute a shell to execute the
    229   1.1       cgd      * command.
    230   1.5       cgd      */
    231   1.1       cgd     for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
    232   1.1       cgd 	continue;
    233   1.1       cgd     }
    234   1.1       cgd 
    235   1.1       cgd     /*
    236   1.1       cgd      * Print the command before echoing if we're not supposed to be quiet for
    237   1.1       cgd      * this one. We also print the command if -n given.
    238  1.31  sommerfe      */
    239   1.1       cgd     if (!silent || NoExecute(gn)) {
    240   1.1       cgd 	printf ("%s\n", cmd);
    241   1.1       cgd 	fflush(stdout);
    242   1.1       cgd     }
    243   1.1       cgd 
    244   1.1       cgd     /*
    245   1.1       cgd      * If we're not supposed to execute any commands, this is as far as
    246   1.1       cgd      * we go...
    247  1.31  sommerfe      */
    248   1.1       cgd     if (NoExecute(gn)) {
    249   1.1       cgd 	return (0);
    250  1.14  christos     }
    251   1.1       cgd 
    252   1.1       cgd     if (*cp != '\0') {
    253   1.1       cgd 	/*
    254   1.1       cgd 	 * If *cp isn't the null character, we hit a "meta" character and
    255   1.1       cgd 	 * need to pass the command off to the shell. We give the shell the
    256   1.1       cgd 	 * -e flag as well as -c if it's supposed to exit when it hits an
    257   1.1       cgd 	 * error.
    258   1.1       cgd 	 */
    259   1.1       cgd 	static char	*shargv[4] = { "/bin/sh" };
    260  1.34       sjg 
    261  1.34       sjg 	if (DEBUG(SHELL))
    262  1.34       sjg 		shargv[1] = (errCheck ? "-exc" : "-xc");
    263  1.34       sjg 	else
    264   1.1       cgd 		shargv[1] = (errCheck ? "-ec" : "-c");
    265   1.1       cgd 	shargv[2] = cmd;
    266   1.1       cgd 	shargv[3] = (char *)NULL;
    267   1.1       cgd 	av = shargv;
    268  1.24  christos 	argc = 0;
    269   1.1       cgd 	bp = NULL;
    270   1.1       cgd     } else {
    271   1.1       cgd 	/*
    272   1.1       cgd 	 * No meta-characters, so no need to exec a shell. Break the command
    273   1.1       cgd 	 * into words to form an argument vector we can execute.
    274  1.24  christos 	 */
    275   1.1       cgd 	av = brk_string(cmd, &argc, TRUE, &bp);
    276  1.14  christos     }
    277   1.1       cgd 
    278   1.1       cgd     local = TRUE;
    279   1.1       cgd 
    280   1.1       cgd     /*
    281   1.1       cgd      * Fork and execute the single command. If the fork fails, we abort.
    282   1.1       cgd      */
    283   1.1       cgd     cpid = vfork();
    284   1.1       cgd     if (cpid < 0) {
    285   1.1       cgd 	Fatal("Could not fork");
    286   1.1       cgd     }
    287  1.30       sjg     if (cpid == 0) {
    288  1.33  christos 	Check_Cwd(av);
    289  1.33  christos 	if (local)
    290  1.33  christos 	    (void)execvp(av[0], av);
    291   1.1       cgd 	else
    292  1.33  christos 	    (void)execv(av[0], av);
    293  1.23   thorpej 	execError(av[0]);
    294   1.1       cgd 	_exit(1);
    295  1.25     itohy     }
    296  1.25     itohy     if (bp) {
    297  1.25     itohy 	free(av);
    298  1.25     itohy 	free(bp);
    299   1.7       jtc     }
    300   1.7       jtc     free(cmdStart);
    301  1.14  christos     Lst_Replace (cmdNode, (ClientData) NULL);
    302   1.1       cgd 
    303   1.1       cgd     /*
    304   1.1       cgd      * The child is off and running. Now all we can do is wait...
    305   1.1       cgd      */
    306   1.1       cgd     while (1) {
    307  1.13  christos 
    308   1.1       cgd 	while ((stat = wait(&reason)) != cpid) {
    309   1.1       cgd 	    if (stat == -1 && errno != EINTR) {
    310   1.1       cgd 		break;
    311   1.1       cgd 	    }
    312  1.14  christos 	}
    313   1.1       cgd 
    314   1.1       cgd 	if (stat > -1) {
    315  1.13  christos 	    if (WIFSTOPPED(reason)) {
    316   1.1       cgd 		status = WSTOPSIG(reason);		/* stopped */
    317  1.13  christos 	    } else if (WIFEXITED(reason)) {
    318   1.1       cgd 		status = WEXITSTATUS(reason);		/* exited */
    319   1.1       cgd 		if (status != 0) {
    320   1.1       cgd 		    printf ("*** Error code %d", status);
    321   1.1       cgd 		}
    322  1.13  christos 	    } else {
    323   1.1       cgd 		status = WTERMSIG(reason);		/* signaled */
    324  1.14  christos 		printf ("*** Signal %d", status);
    325  1.14  christos 	    }
    326   1.1       cgd 
    327   1.1       cgd 
    328   1.1       cgd 	    if (!WIFEXITED(reason) || (status != 0)) {
    329   1.1       cgd 		if (errCheck) {
    330   1.1       cgd 		    gn->made = ERROR;
    331   1.1       cgd 		    if (keepgoing) {
    332   1.1       cgd 			/*
    333   1.1       cgd 			 * Abort the current target, but let others
    334   1.1       cgd 			 * continue.
    335   1.1       cgd 			 */
    336   1.1       cgd 			printf (" (continuing)\n");
    337   1.1       cgd 		    }
    338   1.1       cgd 		} else {
    339   1.1       cgd 		    /*
    340   1.1       cgd 		     * Continue executing commands for this target.
    341   1.1       cgd 		     * If we return 0, this will happen...
    342   1.1       cgd 		     */
    343   1.1       cgd 		    printf (" (ignored)\n");
    344   1.1       cgd 		    status = 0;
    345   1.1       cgd 		}
    346   1.1       cgd 	    }
    347   1.1       cgd 	    break;
    348  1.27  sommerfe 	} else {
    349   1.1       cgd 	    Fatal ("error in wait: %d: %s", stat, strerror(errno));
    350   1.1       cgd 	    /*NOTREACHED*/
    351   1.1       cgd 	}
    352   1.1       cgd     }
    353   1.1       cgd 
    354   1.1       cgd     return (status);
    355   1.1       cgd }
    356   1.1       cgd 
    357   1.1       cgd /*-
    359   1.1       cgd  *-----------------------------------------------------------------------
    360   1.1       cgd  * CompatMake --
    361   1.1       cgd  *	Make a target.
    362   1.1       cgd  *
    363   1.1       cgd  * Results:
    364   1.1       cgd  *	0
    365   1.1       cgd  *
    366   1.1       cgd  * Side Effects:
    367   1.1       cgd  *	If an error is detected and not being ignored, the process exits.
    368   1.1       cgd  *
    369   1.1       cgd  *-----------------------------------------------------------------------
    370   1.7       jtc  */
    371   1.7       jtc static int
    372   1.7       jtc CompatMake (gnp, pgnp)
    373   1.1       cgd     ClientData	gnp;	    /* The node to make */
    374   1.7       jtc     ClientData  pgnp;	    /* Parent to abort if necessary */
    375   1.7       jtc {
    376  1.16  christos     GNode *gn = (GNode *) gnp;
    377  1.17  christos     GNode *pgn = (GNode *) pgnp;
    378  1.18  christos 
    379  1.18  christos     if (pgn->type & OP_MADE) {
    380  1.17  christos 	(void) Dir_MTime(gn);
    381  1.15  christos 	gn->made = UPTODATE;
    382  1.15  christos     }
    383   1.1       cgd 
    384   1.1       cgd     if (gn->made == UNMADE) {
    385   1.1       cgd 	/*
    386   1.1       cgd 	 * First mark ourselves to be made, then apply whatever transformations
    387   1.1       cgd 	 * the suffix module thinks are necessary. Once that's done, we can
    388   1.1       cgd 	 * descend and make all our children. If any of them has an error
    389   1.1       cgd 	 * but the -k flag was given, our 'make' field will be set FALSE again.
    390   1.1       cgd 	 * This is our signal to not attempt to do anything but abort our
    391  1.26  christos 	 * parent as well.
    392   1.1       cgd 	 */
    393   1.1       cgd 	gn->flags |= REMAKE;
    394   1.1       cgd 	gn->made = BEINGMADE;
    395  1.26  christos 	Suff_FindDeps (gn);
    396   1.1       cgd 	Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
    397  1.26  christos 	if ((gn->flags & REMAKE) == 0) {
    398  1.28   mycroft 	    gn->made = ABORTED;
    399   1.1       cgd 	    pgn->flags &= ~REMAKE;
    400   1.1       cgd 	    goto cohorts;
    401   1.1       cgd 	}
    402   1.7       jtc 
    403   1.7       jtc 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    404   1.7       jtc 	    char *p1;
    405   1.7       jtc 	    Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
    406   1.1       cgd 	    if (p1)
    407  1.14  christos 		free(p1);
    408   1.1       cgd 	}
    409   1.1       cgd 
    410   1.1       cgd 	/*
    411   1.1       cgd 	 * All the children were made ok. Now cmtime contains the modification
    412   1.1       cgd 	 * time of the newest child, we need to find out if we exist and when
    413   1.1       cgd 	 * we were modified last. The criteria for datedness are defined by the
    414   1.1       cgd 	 * Make_OODate function.
    415   1.1       cgd 	 */
    416   1.1       cgd 	if (DEBUG(MAKE)) {
    417   1.1       cgd 	    printf("Examining %s...", gn->name);
    418   1.1       cgd 	}
    419   1.1       cgd 	if (! Make_OODate(gn)) {
    420   1.1       cgd 	    gn->made = UPTODATE;
    421   1.1       cgd 	    if (DEBUG(MAKE)) {
    422  1.28   mycroft 		printf("up-to-date.\n");
    423   1.1       cgd 	    }
    424   1.1       cgd 	    goto cohorts;
    425   1.1       cgd 	} else if (DEBUG(MAKE)) {
    426   1.1       cgd 	    printf("out-of-date.\n");
    427   1.1       cgd 	}
    428   1.1       cgd 
    429   1.1       cgd 	/*
    430   1.1       cgd 	 * If the user is just seeing if something is out-of-date, exit now
    431   1.1       cgd 	 * to tell him/her "yes".
    432  1.32       wiz 	 */
    433   1.1       cgd 	if (queryFlag) {
    434   1.1       cgd 	    exit (1);
    435   1.1       cgd 	}
    436   1.1       cgd 
    437   1.1       cgd 	/*
    438   1.1       cgd 	 * We need to be re-made. We also have to make sure we've got a $?
    439   1.1       cgd 	 * variable. To be nice, we also define the $> variable using
    440   1.1       cgd 	 * Make_DoAllVar().
    441  1.14  christos 	 */
    442   1.1       cgd 	Make_DoAllVar(gn);
    443   1.1       cgd 
    444   1.1       cgd 	/*
    445   1.1       cgd 	 * Alter our type to tell if errors should be ignored or things
    446   1.1       cgd 	 * should not be printed so CompatRunCommand knows what to do.
    447   1.1       cgd 	 */
    448   1.1       cgd 	if (Targ_Ignore (gn)) {
    449   1.1       cgd 	    gn->type |= OP_IGNORE;
    450   1.1       cgd 	}
    451   1.1       cgd 	if (Targ_Silent (gn)) {
    452   1.1       cgd 	    gn->type |= OP_SILENT;
    453   1.1       cgd 	}
    454   1.1       cgd 
    455   1.1       cgd 	if (Job_CheckCommands (gn, Fatal)) {
    456   1.1       cgd 	    /*
    457   1.1       cgd 	     * Our commands are ok, but we still have to worry about the -t
    458  1.20   mycroft 	     * flag...
    459   1.1       cgd 	     */
    460   1.1       cgd 	    if (!touchFlag || (gn->type & OP_MAKE)) {
    461   1.1       cgd 		curTarg = gn;
    462   1.1       cgd 		Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
    463   1.1       cgd 		curTarg = NILGNODE;
    464   1.1       cgd 	    } else {
    465   1.1       cgd 		Job_Touch (gn, gn->type & OP_SILENT);
    466   1.1       cgd 	    }
    467   1.1       cgd 	} else {
    468   1.1       cgd 	    gn->made = ERROR;
    469   1.1       cgd 	}
    470   1.1       cgd 
    471   1.1       cgd 	if (gn->made != ERROR) {
    472   1.1       cgd 	    /*
    473   1.1       cgd 	     * If the node was made successfully, mark it so, update
    474   1.1       cgd 	     * its modification time and timestamp all its parents. Note
    475   1.1       cgd 	     * that for .ZEROTIME targets, the timestamping isn't done.
    476   1.1       cgd 	     * This is to keep its state from affecting that of its parent.
    477  1.26  christos 	     */
    478   1.1       cgd 	    gn->made = MADE;
    479  1.26  christos 	    pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
    480   1.1       cgd 	    if (!(gn->type & OP_EXEC)) {
    481   1.1       cgd 		pgn->flags |= CHILDMADE;
    482   1.1       cgd 		Make_TimeStamp(pgn, gn);
    483  1.26  christos 	    }
    484   1.1       cgd 	} else if (keepgoing) {
    485  1.34       sjg 	    pgn->flags &= ~REMAKE;
    486   1.1       cgd 	} else {
    487   1.1       cgd 	    PrintOnError("\n\nStop.");
    488   1.1       cgd 	    exit (1);
    489   1.1       cgd 	}
    490   1.1       cgd     } else if (gn->made == ERROR) {
    491   1.1       cgd 	/*
    492   1.1       cgd 	 * Already had an error when making this beastie. Tell the parent
    493  1.26  christos 	 * to abort.
    494   1.1       cgd 	 */
    495   1.1       cgd 	pgn->flags &= ~REMAKE;
    496   1.7       jtc     } else {
    497   1.7       jtc 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    498   1.7       jtc 	    char *p1;
    499   1.7       jtc 	    Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
    500   1.1       cgd 	    if (p1)
    501   1.1       cgd 		free(p1);
    502   1.1       cgd 	}
    503   1.1       cgd 	switch(gn->made) {
    504   1.1       cgd 	    case BEINGMADE:
    505  1.26  christos 		Error("Graph cycles through %s\n", gn->name);
    506   1.1       cgd 		gn->made = ERROR;
    507   1.1       cgd 		pgn->flags &= ~REMAKE;
    508   1.1       cgd 		break;
    509  1.26  christos 	    case MADE:
    510   1.1       cgd 		if ((gn->type & OP_EXEC) == 0) {
    511   1.1       cgd 		    pgn->flags |= CHILDMADE;
    512   1.1       cgd 		    Make_TimeStamp(pgn, gn);
    513   1.1       cgd 		}
    514   1.1       cgd 		break;
    515   1.1       cgd 	    case UPTODATE:
    516   1.1       cgd 		if ((gn->type & OP_EXEC) == 0) {
    517   1.1       cgd 		    Make_TimeStamp(pgn, gn);
    518   1.5       cgd 		}
    519   1.5       cgd 		break;
    520   1.1       cgd 	    default:
    521   1.1       cgd 		break;
    522   1.1       cgd 	}
    523  1.28   mycroft     }
    524  1.28   mycroft 
    525   1.1       cgd cohorts:
    526   1.1       cgd     Lst_ForEach (gn->cohorts, CompatMake, pgnp);
    527  1.14  christos     return (0);
    528   1.1       cgd }
    529   1.1       cgd 
    530   1.1       cgd /*-
    532   1.1       cgd  *-----------------------------------------------------------------------
    533   1.1       cgd  * Compat_Run --
    534   1.1       cgd  *	Initialize this mode and start making.
    535   1.1       cgd  *
    536   1.1       cgd  * Results:
    537   1.1       cgd  *	None.
    538   1.1       cgd  *
    539   1.1       cgd  * Side Effects:
    540   1.1       cgd  *	Guess what?
    541   1.1       cgd  *
    542   1.1       cgd  *-----------------------------------------------------------------------
    543   1.1       cgd  */
    544   1.1       cgd void
    545   1.1       cgd Compat_Run(targs)
    546   1.5       cgd     Lst	    	  targs;    /* List of target nodes to re-create */
    547   1.1       cgd {
    548   1.1       cgd     char    	  *cp;	    /* Pointer to string of shell meta-characters */
    549   1.1       cgd     GNode   	  *gn = NULL;/* Current root target */
    550   1.1       cgd     int	    	  errors;   /* Number of targets not remade due to errors */
    551   1.1       cgd 
    552   1.1       cgd     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
    553   1.1       cgd 	signal(SIGINT, CompatInterrupt);
    554   1.1       cgd     }
    555   1.1       cgd     if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
    556   1.1       cgd 	signal(SIGTERM, CompatInterrupt);
    557   1.1       cgd     }
    558   1.1       cgd     if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
    559   1.1       cgd 	signal(SIGHUP, CompatInterrupt);
    560   1.1       cgd     }
    561   1.1       cgd     if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
    562   1.1       cgd 	signal(SIGQUIT, CompatInterrupt);
    563   1.5       cgd     }
    564   1.1       cgd 
    565   1.1       cgd     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
    566   1.1       cgd 	meta[(unsigned char) *cp] = 1;
    567   1.1       cgd     }
    568   1.1       cgd     /*
    569   1.1       cgd      * The null character serves as a sentinel in the string.
    570   1.1       cgd      */
    571   1.1       cgd     meta[0] = 1;
    572   1.1       cgd 
    573   1.1       cgd     ENDNode = Targ_FindNode(".END", TARG_CREATE);
    574   1.1       cgd     /*
    575   1.1       cgd      * If the user has defined a .BEGIN target, execute the commands attached
    576   1.1       cgd      * to it.
    577   1.1       cgd      */
    578   1.1       cgd     if (!queryFlag) {
    579  1.14  christos 	gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    580  1.34       sjg 	if (gn != NILGNODE) {
    581  1.14  christos 	    Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    582  1.14  christos             if (gn->made == ERROR) {
    583   1.1       cgd                 PrintOnError("\n\nStop.");
    584   1.1       cgd                 exit(1);
    585  1.15  christos             }
    586  1.15  christos 	}
    587  1.15  christos     }
    588  1.15  christos 
    589  1.15  christos     /*
    590  1.15  christos      * Expand .USE nodes right now, because they can modify the structure
    591   1.1       cgd      * of the tree.
    592   1.1       cgd      */
    593   1.1       cgd     Lst_Destroy(Make_ExpandUse(targs), NOFREE);
    594   1.1       cgd 
    595   1.1       cgd     /*
    596   1.1       cgd      * For each entry in the list of targets to create, call CompatMake on
    597   1.1       cgd      * it to create the thing. CompatMake will leave the 'made' field of gn
    598   1.1       cgd      * in one of several states:
    599   1.1       cgd      *	    UPTODATE	    gn was already up-to-date
    600   1.1       cgd      *	    MADE  	    gn was recreated successfully
    601   1.1       cgd      *	    ERROR 	    An error occurred while gn was being created
    602   1.1       cgd      *	    ABORTED	    gn was not remade because one of its inferiors
    603   1.1       cgd      *	    	  	    could not be made due to errors.
    604   1.1       cgd      */
    605   1.1       cgd     errors = 0;
    606   1.1       cgd     while (!Lst_IsEmpty (targs)) {
    607   1.1       cgd 	gn = (GNode *) Lst_DeQueue (targs);
    608   1.1       cgd 	CompatMake (gn, gn);
    609   1.1       cgd 
    610   1.1       cgd 	if (gn->made == UPTODATE) {
    611   1.1       cgd 	    printf ("`%s' is up to date.\n", gn->name);
    612   1.1       cgd 	} else if (gn->made == ABORTED) {
    613   1.1       cgd 	    printf ("`%s' not remade because of errors.\n", gn->name);
    614   1.1       cgd 	    errors += 1;
    615   1.1       cgd 	}
    616   1.1       cgd     }
    617   1.1       cgd 
    618   1.1       cgd     /*
    619   1.1       cgd      * If the user has defined a .END target, run its commands.
    620   1.1       cgd      */
    621   1.1       cgd     if (errors == 0) {
    622                 	Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
    623                     }
    624                 }
    625