| 1 | /*
|
|---|
| 2 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
|---|
| 3 | * Copyright (c) 1988, 1989 by Adam de Boor
|
|---|
| 4 | * Copyright (c) 1989 by Berkeley Softworks
|
|---|
| 5 | * All rights reserved.
|
|---|
| 6 | *
|
|---|
| 7 | * This code is derived from software contributed to Berkeley by
|
|---|
| 8 | * Adam de Boor.
|
|---|
| 9 | *
|
|---|
| 10 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 11 | * modification, are permitted provided that the following conditions
|
|---|
| 12 | * are met:
|
|---|
| 13 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 14 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 15 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 16 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 17 | * documentation and/or other materials provided with the distribution.
|
|---|
| 18 | * 3. All advertising materials mentioning features or use of this software
|
|---|
| 19 | * must display the following acknowledgement:
|
|---|
| 20 | * This product includes software developed by the University of
|
|---|
| 21 | * California, Berkeley and its contributors.
|
|---|
| 22 | * 4. Neither the name of the University nor the names of its contributors
|
|---|
| 23 | * may be used to endorse or promote products derived from this software
|
|---|
| 24 | * without specific prior written permission.
|
|---|
| 25 | *
|
|---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|---|
| 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|---|
| 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|---|
| 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|---|
| 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|---|
| 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|---|
| 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|---|
| 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|---|
| 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|---|
| 36 | * SUCH DAMAGE.
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | #ifndef lint
|
|---|
| 40 | #if 0
|
|---|
| 41 | static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
|
|---|
| 42 | #else
|
|---|
| 43 | static const char rcsid[] =
|
|---|
| 44 | "$FreeBSD: src/usr.bin/make/compat.c,v 1.16.2.2 2000/07/01 12:24:21 ps Exp $";
|
|---|
| 45 | #endif
|
|---|
| 46 | #define KLIBFILEDEF rcsid
|
|---|
| 47 | #endif /* not lint */
|
|---|
| 48 |
|
|---|
| 49 | /*-
|
|---|
| 50 | * compat.c --
|
|---|
| 51 | * The routines in this file implement the full-compatibility
|
|---|
| 52 | * mode of PMake. Most of the special functionality of PMake
|
|---|
| 53 | * is available in this mode. Things not supported:
|
|---|
| 54 | * - different shells.
|
|---|
| 55 | * - friendly variable substitution.
|
|---|
| 56 | *
|
|---|
| 57 | * Interface:
|
|---|
| 58 | * Compat_Run Initialize things for this module and recreate
|
|---|
| 59 | * thems as need creatin'
|
|---|
| 60 | */
|
|---|
| 61 |
|
|---|
| 62 | #include <stdio.h>
|
|---|
| 63 | #include <sys/types.h>
|
|---|
| 64 | #include <sys/stat.h>
|
|---|
| 65 | #ifdef __IBMC__
|
|---|
| 66 | #else
|
|---|
| 67 | #include <sys/wait.h>
|
|---|
| 68 | #endif
|
|---|
| 69 | #if defined(__EMX__)
|
|---|
| 70 | #include <sys/process.h>
|
|---|
| 71 | #endif
|
|---|
| 72 | #if defined(OS2) && defined(__IBMC__)
|
|---|
| 73 | #include <process.h>
|
|---|
| 74 | #endif
|
|---|
| 75 | #include <ctype.h>
|
|---|
| 76 | #include <errno.h>
|
|---|
| 77 | #include <signal.h>
|
|---|
| 78 | #include "make.h"
|
|---|
| 79 | #include "hash.h"
|
|---|
| 80 | #include "dir.h"
|
|---|
| 81 | #include "job.h"
|
|---|
| 82 |
|
|---|
| 83 | /*
|
|---|
| 84 | * The following array is used to make a fast determination of which
|
|---|
| 85 | * characters are interpreted specially by the shell. If a command
|
|---|
| 86 | * contains any of these characters, it is executed by the shell, not
|
|---|
| 87 | * directly by us.
|
|---|
| 88 | */
|
|---|
| 89 |
|
|---|
| 90 | static char meta[256];
|
|---|
| 91 |
|
|---|
| 92 | static GNode *curTarg = NILGNODE;
|
|---|
| 93 | static GNode *ENDNode;
|
|---|
| 94 | static void CompatInterrupt __P((int));
|
|---|
| 95 | static int CompatRunCommand __P((ClientData, ClientData));
|
|---|
| 96 | static int CompatMake __P((ClientData, ClientData));
|
|---|
| 97 |
|
|---|
| 98 | static char *sh_builtin[] = {
|
|---|
| 99 | "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
|
|---|
| 100 | "unalias", "umask", "unset", "wait", ":", 0};
|
|---|
| 101 |
|
|---|
| 102 | /*-
|
|---|
| 103 | *-----------------------------------------------------------------------
|
|---|
| 104 | * CompatInterrupt --
|
|---|
| 105 | * Interrupt the creation of the current target and remove it if
|
|---|
| 106 | * it ain't precious.
|
|---|
| 107 | *
|
|---|
| 108 | * Results:
|
|---|
| 109 | * None.
|
|---|
| 110 | *
|
|---|
| 111 | * Side Effects:
|
|---|
| 112 | * The target is removed and the process exits. If .INTERRUPT exists,
|
|---|
| 113 | * its commands are run first WITH INTERRUPTS IGNORED..
|
|---|
| 114 | *
|
|---|
| 115 | *-----------------------------------------------------------------------
|
|---|
| 116 | */
|
|---|
| 117 | static void
|
|---|
| 118 | CompatInterrupt (signo)
|
|---|
| 119 | int signo;
|
|---|
| 120 | {
|
|---|
| 121 | GNode *gn;
|
|---|
| 122 |
|
|---|
| 123 | if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
|
|---|
| 124 | char *p1;
|
|---|
| 125 | char *file = Var_Value (TARGET, curTarg, &p1);
|
|---|
| 126 |
|
|---|
| 127 | if (!noExecute && eunlink(file) != -1) {
|
|---|
| 128 | printf ("*** %s removed\n", file);
|
|---|
| 129 | }
|
|---|
| 130 | efree(p1);
|
|---|
| 131 |
|
|---|
| 132 | /*
|
|---|
| 133 | * Run .INTERRUPT only if hit with interrupt signal
|
|---|
| 134 | */
|
|---|
| 135 | if (signo == SIGINT) {
|
|---|
| 136 | gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
|
|---|
| 137 | if (gn != NILGNODE) {
|
|---|
| 138 | Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | }
|
|---|
| 143 | #if !(defined(OS2) && defined(__IBMC__))
|
|---|
| 144 | if (signo == SIGQUIT)
|
|---|
| 145 | exit(signo);
|
|---|
| 146 | #endif
|
|---|
| 147 | (void) signal(signo, SIG_DFL);
|
|---|
| 148 | (void) kill(getpid(), signo);
|
|---|
| 149 | }
|
|---|
| 150 | |
|---|
| 151 |
|
|---|
| 152 | /*-
|
|---|
| 153 | *-----------------------------------------------------------------------
|
|---|
| 154 | * shellneed --
|
|---|
| 155 | *
|
|---|
| 156 | * Results:
|
|---|
| 157 | * Returns 1 if a specified line must be executed by the shell,
|
|---|
| 158 | * 0 if it can be run via execve, and -1 if the command is a no-op.
|
|---|
| 159 | *
|
|---|
| 160 | * Side Effects:
|
|---|
| 161 | * None.
|
|---|
| 162 | *
|
|---|
| 163 | *-----------------------------------------------------------------------
|
|---|
| 164 | */
|
|---|
| 165 | static int
|
|---|
| 166 | shellneed (cmd)
|
|---|
| 167 | char *cmd;
|
|---|
| 168 | {
|
|---|
| 169 | char **av, **p;
|
|---|
| 170 | int ac;
|
|---|
| 171 |
|
|---|
| 172 | av = brk_string(cmd, &ac, TRUE);
|
|---|
| 173 | for(p = sh_builtin; *p != 0; p++)
|
|---|
| 174 | if (strcmp(av[1], *p) == 0)
|
|---|
| 175 | return (1);
|
|---|
| 176 | return (0);
|
|---|
| 177 | }
|
|---|
| 178 | |
|---|
| 179 |
|
|---|
| 180 | /*-
|
|---|
| 181 | *-----------------------------------------------------------------------
|
|---|
| 182 | * CompatRunCommand --
|
|---|
| 183 | * Execute the next command for a target. If the command returns an
|
|---|
| 184 | * error, the node's made field is set to ERROR and creation stops.
|
|---|
| 185 | *
|
|---|
| 186 | * Results:
|
|---|
| 187 | * 0 if the command succeeded, 1 if an error occurred.
|
|---|
| 188 | *
|
|---|
| 189 | * Side Effects:
|
|---|
| 190 | * The node's 'made' field may be set to ERROR.
|
|---|
| 191 | *
|
|---|
| 192 | *-----------------------------------------------------------------------
|
|---|
| 193 | */
|
|---|
| 194 | static int
|
|---|
| 195 | CompatRunCommand (cmdp, gnp)
|
|---|
| 196 | ClientData cmdp; /* Command to execute */
|
|---|
| 197 | ClientData gnp; /* Node from which the command came */
|
|---|
| 198 | {
|
|---|
| 199 | char *cmdStart; /* Start of expanded command */
|
|---|
| 200 | register char *cp;
|
|---|
| 201 | Boolean silent, /* Don't print command */
|
|---|
| 202 | errCheck; /* Check errors */
|
|---|
| 203 | int reason; /* Reason for child's death */
|
|---|
| 204 | int status; /* Description of child's death */
|
|---|
| 205 | int cpid; /* Child actually found */
|
|---|
| 206 | ReturnStatus stat; /* Status of fork */
|
|---|
| 207 | LstNode cmdNode; /* Node where current command is located */
|
|---|
| 208 | char **av; /* Argument vector for thing to exec */
|
|---|
| 209 | int argc; /* Number of arguments in av or 0 if not
|
|---|
| 210 | * dynamically allocated */
|
|---|
| 211 | Boolean local; /* TRUE if command should be executed
|
|---|
| 212 | * locally */
|
|---|
| 213 | int internal; /* Various values.. */
|
|---|
| 214 | char *cmd = (char *) cmdp;
|
|---|
| 215 | GNode *gn = (GNode *) gnp;
|
|---|
| 216 |
|
|---|
| 217 | /*
|
|---|
| 218 | * Avoid clobbered variable warnings by forcing the compiler
|
|---|
| 219 | * to ``unregister'' variables
|
|---|
| 220 | */
|
|---|
| 221 | #if __GNUC__
|
|---|
| 222 | (void) &av;
|
|---|
| 223 | (void) &errCheck;
|
|---|
| 224 | #endif
|
|---|
| 225 | silent = gn->type & OP_SILENT;
|
|---|
| 226 | errCheck = !(gn->type & OP_IGNORE);
|
|---|
| 227 |
|
|---|
| 228 | cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
|
|---|
| 229 | cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
|
|---|
| 230 |
|
|---|
| 231 | /*
|
|---|
| 232 | * brk_string will return an argv with a NULL in av[0], thus causing
|
|---|
| 233 | * execvp to choke and die horribly. Besides, how can we execute a null
|
|---|
| 234 | * command? In any case, we warn the user that the command expanded to
|
|---|
| 235 | * nothing (is this the right thing to do?).
|
|---|
| 236 | */
|
|---|
| 237 |
|
|---|
| 238 | if (*cmdStart == '\0') {
|
|---|
| 239 | efree(cmdStart);
|
|---|
| 240 | Error("%s expands to empty string", cmd);
|
|---|
| 241 | return(0);
|
|---|
| 242 | } else {
|
|---|
| 243 | cmd = cmdStart;
|
|---|
| 244 | }
|
|---|
| 245 | Lst_Replace (cmdNode, (ClientData)cmdStart);
|
|---|
| 246 |
|
|---|
| 247 | if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
|
|---|
| 248 | (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
|
|---|
| 249 | return(0);
|
|---|
| 250 | } else if (strcmp(cmdStart, "...") == 0) {
|
|---|
| 251 | gn->type |= OP_SAVE_CMDS;
|
|---|
| 252 | return(0);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | while ((*cmd == '@') || (*cmd == '-')) {
|
|---|
| 256 | if (*cmd == '@') {
|
|---|
| 257 | silent = DEBUG(LOUD) ? FALSE : TRUE;
|
|---|
| 258 | } else {
|
|---|
| 259 | errCheck = FALSE;
|
|---|
| 260 | }
|
|---|
| 261 | cmd++;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | while (isspace((unsigned char)*cmd))
|
|---|
| 265 | cmd++;
|
|---|
| 266 |
|
|---|
| 267 | /*
|
|---|
| 268 | * Search for meta characters in the command. If there are no meta
|
|---|
| 269 | * characters, there's no need to execute a shell to execute the
|
|---|
| 270 | * command.
|
|---|
| 271 | */
|
|---|
| 272 | for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
|
|---|
| 273 | continue;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | /*
|
|---|
| 277 | * Print the command before echoing if we're not supposed to be quiet for
|
|---|
| 278 | * this one. We also print the command if -n given.
|
|---|
| 279 | */
|
|---|
| 280 | if (!silent || noExecute) {
|
|---|
| 281 | printf ("%s\n", cmd);
|
|---|
| 282 | fflush(stdout);
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | /*
|
|---|
| 286 | * If we're not supposed to execute any commands, this is as far as
|
|---|
| 287 | * we go...
|
|---|
| 288 | */
|
|---|
| 289 | if (noExecute) {
|
|---|
| 290 | return (0);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | if (*cp != '\0') {
|
|---|
| 294 | /*
|
|---|
| 295 | * If *cp isn't the null character, we hit a "meta" character and
|
|---|
| 296 | * need to pass the command off to the shell. We give the shell the
|
|---|
| 297 | * -e flag as well as -c if it's supposed to exit when it hits an
|
|---|
| 298 | * error.
|
|---|
| 299 | */
|
|---|
| 300 | static char *shargv[4] = { "/bin/sh" };
|
|---|
| 301 |
|
|---|
| 302 | shargv[1] = (errCheck ? "-ec" : "-c");
|
|---|
| 303 | shargv[2] = cmd;
|
|---|
| 304 | shargv[3] = (char *)NULL;
|
|---|
| 305 | av = shargv;
|
|---|
| 306 | argc = 0;
|
|---|
| 307 | } else if ((internal = shellneed(cmd))) {
|
|---|
| 308 | /*
|
|---|
| 309 | * This command must be passed by the shell for other reasons..
|
|---|
| 310 | * or.. possibly not at all.
|
|---|
| 311 | */
|
|---|
| 312 | static char *shargv[4] = { "/bin/sh" };
|
|---|
| 313 |
|
|---|
| 314 | if (internal == -1) {
|
|---|
| 315 | /* Command does not need to be executed */
|
|---|
| 316 | return (0);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | shargv[1] = (errCheck ? "-ec" : "-c");
|
|---|
| 320 | shargv[2] = cmd;
|
|---|
| 321 | shargv[3] = (char *)NULL;
|
|---|
| 322 | av = shargv;
|
|---|
| 323 | argc = 0;
|
|---|
| 324 | } else {
|
|---|
| 325 | /*
|
|---|
| 326 | * No meta-characters, so no need to exec a shell. Break the command
|
|---|
| 327 | * into words to form an argument vector we can execute.
|
|---|
| 328 | * brk_string sticks our name in av[0], so we have to
|
|---|
| 329 | * skip over it...
|
|---|
| 330 | */
|
|---|
| 331 | av = brk_string(cmd, &argc, TRUE);
|
|---|
| 332 | av += 1;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | local = TRUE;
|
|---|
| 336 |
|
|---|
| 337 | /*
|
|---|
| 338 | * Fork and execute the single command. If the fork fails, we abort.
|
|---|
| 339 | */
|
|---|
| 340 | #ifdef OS2 //@todo use klib later!
|
|---|
| 341 | cpid = _spawnvp(P_NOWAIT, av[0], av);
|
|---|
| 342 | #else
|
|---|
| 343 | cpid = vfork();
|
|---|
| 344 | if (cpid < 0) {
|
|---|
| 345 | Fatal("Could not fork");
|
|---|
| 346 | }
|
|---|
| 347 | if (cpid == 0) {
|
|---|
| 348 | if (local) {
|
|---|
| 349 | execvp(av[0], av);
|
|---|
| 350 | (void) write (2, av[0], strlen (av[0]));
|
|---|
| 351 | (void) write (2, ":", 1);
|
|---|
| 352 | (void) write (2, strerror(errno), strlen(strerror(errno)));
|
|---|
| 353 | (void) write (2, "\n", 1);
|
|---|
| 354 | } else {
|
|---|
| 355 | (void)execv(av[0], av);
|
|---|
| 356 | }
|
|---|
| 357 | exit(1);
|
|---|
| 358 | }
|
|---|
| 359 | #endif
|
|---|
| 360 |
|
|---|
| 361 | /*
|
|---|
| 362 | * we need to print out the command associated with this Gnode in
|
|---|
| 363 | * Targ_PrintCmd from Targ_PrintGraph when debugging at level g2,
|
|---|
| 364 | * in main(), Fatal() and DieHorribly(), therefore do not efree it
|
|---|
| 365 | * when debugging.
|
|---|
| 366 | */
|
|---|
| 367 | if (!DEBUG(GRAPH2)) {
|
|---|
| 368 | efree(cmdStart);
|
|---|
| 369 | Lst_Replace (cmdNode, cmdp);
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | /*
|
|---|
| 373 | * The child is off and running. Now all we can do is wait...
|
|---|
| 374 | */
|
|---|
| 375 | while (1) {
|
|---|
| 376 |
|
|---|
| 377 | while ((stat = wait(&reason)) != cpid) {
|
|---|
| 378 | if (stat == -1 && errno != EINTR) {
|
|---|
| 379 | break;
|
|---|
| 380 | }
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | if (stat > -1) {
|
|---|
| 384 | if (WIFSTOPPED(reason)) {
|
|---|
| 385 | status = WSTOPSIG(reason); /* stopped */
|
|---|
| 386 | } else if (WIFEXITED(reason)) {
|
|---|
| 387 | status = WEXITSTATUS(reason); /* exited */
|
|---|
| 388 | if (status != 0) {
|
|---|
| 389 | printf ("*** Error code %d", status);
|
|---|
| 390 | }
|
|---|
| 391 | } else {
|
|---|
| 392 | status = WTERMSIG(reason); /* signaled */
|
|---|
| 393 | printf ("*** Signal %d", status);
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 | if (!WIFEXITED(reason) || (status != 0)) {
|
|---|
| 398 | if (errCheck) {
|
|---|
| 399 | gn->made = ERROR;
|
|---|
| 400 | if (keepgoing) {
|
|---|
| 401 | /*
|
|---|
| 402 | * Abort the current target, but let others
|
|---|
| 403 | * continue.
|
|---|
| 404 | */
|
|---|
| 405 | printf (" (continuing)\n");
|
|---|
| 406 | }
|
|---|
| 407 | } else {
|
|---|
| 408 | /*
|
|---|
| 409 | * Continue executing commands for this target.
|
|---|
| 410 | * If we return 0, this will happen...
|
|---|
| 411 | */
|
|---|
| 412 | printf (" (ignored)\n");
|
|---|
| 413 | status = 0;
|
|---|
| 414 | }
|
|---|
| 415 | }
|
|---|
| 416 | break;
|
|---|
| 417 | } else {
|
|---|
| 418 | Fatal ("error in wait: %d", stat);
|
|---|
| 419 | /*NOTREACHED*/
|
|---|
| 420 | }
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | return (status);
|
|---|
| 424 | }
|
|---|
| 425 | |
|---|
| 426 |
|
|---|
| 427 | /*-
|
|---|
| 428 | *-----------------------------------------------------------------------
|
|---|
| 429 | * CompatMake --
|
|---|
| 430 | * Make a target.
|
|---|
| 431 | *
|
|---|
| 432 | * Results:
|
|---|
| 433 | * 0
|
|---|
| 434 | *
|
|---|
| 435 | * Side Effects:
|
|---|
| 436 | * If an error is detected and not being ignored, the process exits.
|
|---|
| 437 | *
|
|---|
| 438 | *-----------------------------------------------------------------------
|
|---|
| 439 | */
|
|---|
| 440 | static int
|
|---|
| 441 | CompatMake (gnp, pgnp)
|
|---|
| 442 | ClientData gnp; /* The node to make */
|
|---|
| 443 | ClientData pgnp; /* Parent to abort if necessary */
|
|---|
| 444 | {
|
|---|
| 445 | GNode *gn = (GNode *) gnp;
|
|---|
| 446 | GNode *pgn = (GNode *) pgnp;
|
|---|
| 447 | if (gn->type & OP_USE) {
|
|---|
| 448 | Make_HandleUse(gn, pgn);
|
|---|
| 449 | } else if (gn->made == UNMADE) {
|
|---|
| 450 | /*
|
|---|
| 451 | * First mark ourselves to be made, then apply whatever transformations
|
|---|
| 452 | * the suffix module thinks are necessary. Once that's done, we can
|
|---|
| 453 | * descend and make all our children. If any of them has an error
|
|---|
| 454 | * but the -k flag was given, our 'make' field will be set FALSE again.
|
|---|
| 455 | * This is our signal to not attempt to do anything but abort our
|
|---|
| 456 | * parent as well.
|
|---|
| 457 | */
|
|---|
| 458 | gn->make = TRUE;
|
|---|
| 459 | gn->made = BEINGMADE;
|
|---|
| 460 | Suff_FindDeps (gn);
|
|---|
| 461 | Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
|
|---|
| 462 | if (!gn->make) {
|
|---|
| 463 | gn->made = ABORTED;
|
|---|
| 464 | pgn->make = FALSE;
|
|---|
| 465 | return (0);
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
|
|---|
| 469 | char *p1;
|
|---|
| 470 | Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
|---|
| 471 | efree(p1);
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | /*
|
|---|
| 475 | * All the children were made ok. Now cmtime contains the modification
|
|---|
| 476 | * time of the newest child, we need to find out if we exist and when
|
|---|
| 477 | * we were modified last. The criteria for datedness are defined by the
|
|---|
| 478 | * Make_OODate function.
|
|---|
| 479 | */
|
|---|
| 480 | if (DEBUG(MAKE)) {
|
|---|
| 481 | printf("Examining %s...", gn->name);
|
|---|
| 482 | }
|
|---|
| 483 | if (! Make_OODate(gn)) {
|
|---|
| 484 | gn->made = UPTODATE;
|
|---|
| 485 | if (DEBUG(MAKE)) {
|
|---|
| 486 | printf("up-to-date.\n");
|
|---|
| 487 | }
|
|---|
| 488 | return (0);
|
|---|
| 489 | } else if (DEBUG(MAKE)) {
|
|---|
| 490 | printf("out-of-date.\n");
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| 493 | /*
|
|---|
| 494 | * If the user is just seeing if something is out-of-date, exit now
|
|---|
| 495 | * to tell him/her "yes".
|
|---|
| 496 | */
|
|---|
| 497 | if (queryFlag) {
|
|---|
| 498 | exit (-1);
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | /*
|
|---|
| 502 | * We need to be re-made. We also have to make sure we've got a $?
|
|---|
| 503 | * variable. To be nice, we also define the $> variable using
|
|---|
| 504 | * Make_DoAllVar().
|
|---|
| 505 | */
|
|---|
| 506 | Make_DoAllVar(gn);
|
|---|
| 507 |
|
|---|
| 508 | /*
|
|---|
| 509 | * Alter our type to tell if errors should be ignored or things
|
|---|
| 510 | * should not be printed so CompatRunCommand knows what to do.
|
|---|
| 511 | */
|
|---|
| 512 | if (Targ_Ignore (gn)) {
|
|---|
| 513 | gn->type |= OP_IGNORE;
|
|---|
| 514 | }
|
|---|
| 515 | if (Targ_Silent (gn)) {
|
|---|
| 516 | gn->type |= OP_SILENT;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | if (Job_CheckCommands (gn, Fatal)) {
|
|---|
| 520 | /*
|
|---|
| 521 | * Our commands are ok, but we still have to worry about the -t
|
|---|
| 522 | * flag...
|
|---|
| 523 | */
|
|---|
| 524 | if (!touchFlag) {
|
|---|
| 525 | curTarg = gn;
|
|---|
| 526 | Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
|
|---|
| 527 | curTarg = NILGNODE;
|
|---|
| 528 | } else {
|
|---|
| 529 | Job_Touch (gn, gn->type & OP_SILENT);
|
|---|
| 530 | }
|
|---|
| 531 | } else {
|
|---|
| 532 | gn->made = ERROR;
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | if (gn->made != ERROR) {
|
|---|
| 536 | /*
|
|---|
| 537 | * If the node was made successfully, mark it so, update
|
|---|
| 538 | * its modification time and timestamp all its parents. Note
|
|---|
| 539 | * that for .ZEROTIME targets, the timestamping isn't done.
|
|---|
| 540 | * This is to keep its state from affecting that of its parent.
|
|---|
| 541 | */
|
|---|
| 542 | gn->made = MADE;
|
|---|
| 543 | #ifndef RECHECK
|
|---|
| 544 | /*
|
|---|
| 545 | * We can't re-stat the thing, but we can at least take care of
|
|---|
| 546 | * rules where a target depends on a source that actually creates
|
|---|
| 547 | * the target, but only if it has changed, e.g.
|
|---|
| 548 | *
|
|---|
| 549 | * parse.h : parse.o
|
|---|
| 550 | *
|
|---|
| 551 | * parse.o : parse.y
|
|---|
| 552 | * yacc -d parse.y
|
|---|
| 553 | * cc -c y.tab.c
|
|---|
| 554 | * mv y.tab.o parse.o
|
|---|
| 555 | * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
|
|---|
| 556 | *
|
|---|
| 557 | * In this case, if the definitions produced by yacc haven't
|
|---|
| 558 | * changed from before, parse.h won't have been updated and
|
|---|
| 559 | * gn->mtime will reflect the current modification time for
|
|---|
| 560 | * parse.h. This is something of a kludge, I admit, but it's a
|
|---|
| 561 | * useful one..
|
|---|
| 562 | *
|
|---|
| 563 | * XXX: People like to use a rule like
|
|---|
| 564 | *
|
|---|
| 565 | * FRC:
|
|---|
| 566 | *
|
|---|
| 567 | * To force things that depend on FRC to be made, so we have to
|
|---|
| 568 | * check for gn->children being empty as well...
|
|---|
| 569 | */
|
|---|
| 570 | if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
|
|---|
| 571 | gn->mtime = now;
|
|---|
| 572 | }
|
|---|
| 573 | #else
|
|---|
| 574 | /*
|
|---|
| 575 | * This is what Make does and it's actually a good thing, as it
|
|---|
| 576 | * allows rules like
|
|---|
| 577 | *
|
|---|
| 578 | * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
|
|---|
| 579 | *
|
|---|
| 580 | * to function as intended. Unfortunately, thanks to the stateless
|
|---|
| 581 | * nature of NFS (and the speed of this program), there are times
|
|---|
| 582 | * when the modification time of a file created on a remote
|
|---|
| 583 | * machine will not be modified before the stat() implied by
|
|---|
| 584 | * the Dir_MTime occurs, thus leading us to believe that the file
|
|---|
| 585 | * is unchanged, wreaking havoc with files that depend on this one.
|
|---|
| 586 | *
|
|---|
| 587 | * I have decided it is better to make too much than to make too
|
|---|
| 588 | * little, so this stuff is commented out unless you're sure it's
|
|---|
| 589 | * ok.
|
|---|
| 590 | * -- ardeb 1/12/88
|
|---|
| 591 | */
|
|---|
| 592 | if (noExecute || Dir_MTime(gn) == 0) {
|
|---|
| 593 | gn->mtime = now;
|
|---|
| 594 | }
|
|---|
| 595 | if (gn->cmtime > gn->mtime)
|
|---|
| 596 | gn->mtime = gn->cmtime;
|
|---|
| 597 | if (DEBUG(MAKE)) {
|
|---|
| 598 | printf("update time: %s\n", Targ_FmtTime(gn->mtime));
|
|---|
| 599 | }
|
|---|
| 600 | #endif
|
|---|
| 601 | if (!(gn->type & OP_EXEC)) {
|
|---|
| 602 | pgn->childMade = TRUE;
|
|---|
| 603 | Make_TimeStamp(pgn, gn);
|
|---|
| 604 | }
|
|---|
| 605 | } else if (keepgoing) {
|
|---|
| 606 | pgn->make = FALSE;
|
|---|
| 607 | } else {
|
|---|
| 608 | char *p1;
|
|---|
| 609 |
|
|---|
| 610 | printf ("\n\nStop in %s.\n", Var_Value(".CURDIR", gn, &p1));
|
|---|
| 611 | efree(p1);
|
|---|
| 612 | exit (1);
|
|---|
| 613 | }
|
|---|
| 614 | } else if (gn->made == ERROR) {
|
|---|
| 615 | /*
|
|---|
| 616 | * Already had an error when making this beastie. Tell the parent
|
|---|
| 617 | * to abort.
|
|---|
| 618 | */
|
|---|
| 619 | pgn->make = FALSE;
|
|---|
| 620 | } else {
|
|---|
| 621 | if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
|
|---|
| 622 | char *p1;
|
|---|
| 623 | Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
|
|---|
| 624 | efree(p1);
|
|---|
| 625 | }
|
|---|
| 626 | switch(gn->made) {
|
|---|
| 627 | case BEINGMADE:
|
|---|
| 628 | Error("Graph cycles through %s\n", gn->name);
|
|---|
| 629 | gn->made = ERROR;
|
|---|
| 630 | pgn->make = FALSE;
|
|---|
| 631 | break;
|
|---|
| 632 | case MADE:
|
|---|
| 633 | if ((gn->type & OP_EXEC) == 0) {
|
|---|
| 634 | pgn->childMade = TRUE;
|
|---|
| 635 | Make_TimeStamp(pgn, gn);
|
|---|
| 636 | }
|
|---|
| 637 | break;
|
|---|
| 638 | case UPTODATE:
|
|---|
| 639 | if ((gn->type & OP_EXEC) == 0) {
|
|---|
| 640 | Make_TimeStamp(pgn, gn);
|
|---|
| 641 | }
|
|---|
| 642 | break;
|
|---|
| 643 | default:
|
|---|
| 644 | break;
|
|---|
| 645 | }
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 | return (0);
|
|---|
| 649 | }
|
|---|
| 650 | |
|---|
| 651 |
|
|---|
| 652 | /*-
|
|---|
| 653 | *-----------------------------------------------------------------------
|
|---|
| 654 | * Compat_Run --
|
|---|
| 655 | * Initialize this mode and start making.
|
|---|
| 656 | *
|
|---|
| 657 | * Results:
|
|---|
| 658 | * None.
|
|---|
| 659 | *
|
|---|
| 660 | * Side Effects:
|
|---|
| 661 | * Guess what?
|
|---|
| 662 | *
|
|---|
| 663 | *-----------------------------------------------------------------------
|
|---|
| 664 | */
|
|---|
| 665 | void
|
|---|
| 666 | Compat_Run(targs)
|
|---|
| 667 | Lst targs; /* List of target nodes to re-create */
|
|---|
| 668 | {
|
|---|
| 669 | char *cp; /* Pointer to string of shell meta-characters */
|
|---|
| 670 | GNode *gn = NULL;/* Current root target */
|
|---|
| 671 | int errors; /* Number of targets not remade due to errors */
|
|---|
| 672 |
|
|---|
| 673 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
|
|---|
| 674 | signal(SIGINT, CompatInterrupt);
|
|---|
| 675 | }
|
|---|
| 676 | if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
|
|---|
| 677 | signal(SIGTERM, CompatInterrupt);
|
|---|
| 678 | }
|
|---|
| 679 | #if !(defined(OS2) && defined(__IBMC__))
|
|---|
| 680 | if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
|---|
| 681 | signal(SIGHUP, CompatInterrupt);
|
|---|
| 682 | }
|
|---|
| 683 | #endif
|
|---|
| 684 | #if !(defined(OS2) && defined(__IBMC__))
|
|---|
| 685 | if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
|
|---|
| 686 | signal(SIGQUIT, CompatInterrupt);
|
|---|
| 687 | }
|
|---|
| 688 | #endif
|
|---|
| 689 |
|
|---|
| 690 | for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
|
|---|
| 691 | meta[(unsigned char) *cp] = 1;
|
|---|
| 692 | }
|
|---|
| 693 | /*
|
|---|
| 694 | * The null character serves as a sentinel in the string.
|
|---|
| 695 | */
|
|---|
| 696 | meta[0] = 1;
|
|---|
| 697 |
|
|---|
| 698 | ENDNode = Targ_FindNode(".END", TARG_CREATE);
|
|---|
| 699 | /*
|
|---|
| 700 | * If the user has defined a .BEGIN target, execute the commands attached
|
|---|
| 701 | * to it.
|
|---|
| 702 | */
|
|---|
| 703 | if (!queryFlag) {
|
|---|
| 704 | gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
|
|---|
| 705 | if (gn != NILGNODE) {
|
|---|
| 706 | Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
|
|---|
| 707 | if (gn->made == ERROR) {
|
|---|
| 708 | printf("\n\nStop.\n");
|
|---|
| 709 | exit(1);
|
|---|
| 710 | }
|
|---|
| 711 | }
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | /*
|
|---|
| 715 | * For each entry in the list of targets to create, call CompatMake on
|
|---|
| 716 | * it to create the thing. CompatMake will leave the 'made' field of gn
|
|---|
| 717 | * in one of several states:
|
|---|
| 718 | * UPTODATE gn was already up-to-date
|
|---|
| 719 | * MADE gn was recreated successfully
|
|---|
| 720 | * ERROR An error occurred while gn was being created
|
|---|
| 721 | * ABORTED gn was not remade because one of its inferiors
|
|---|
| 722 | * could not be made due to errors.
|
|---|
| 723 | */
|
|---|
| 724 | errors = 0;
|
|---|
| 725 | while (!Lst_IsEmpty (targs)) {
|
|---|
| 726 | gn = (GNode *) Lst_DeQueue (targs);
|
|---|
| 727 | CompatMake (gn, gn);
|
|---|
| 728 |
|
|---|
| 729 | if (gn->made == UPTODATE) {
|
|---|
| 730 | printf ("`%s' is up to date.\n", gn->name);
|
|---|
| 731 | } else if (gn->made == ABORTED) {
|
|---|
| 732 | printf ("`%s' not remade because of errors.\n", gn->name);
|
|---|
| 733 | errors += 1;
|
|---|
| 734 | }
|
|---|
| 735 | }
|
|---|
| 736 |
|
|---|
| 737 | /*
|
|---|
| 738 | * If the user has defined a .END target, run its commands.
|
|---|
| 739 | */
|
|---|
| 740 | if (errors == 0) {
|
|---|
| 741 | Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
|
|---|
| 742 | }
|
|---|
| 743 | }
|
|---|