Deleted Added
full compact
main.c (241146) main.c (246223)
1/* $NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $ */
1/* $NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $ */
2
3/*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 54 unchanged lines hidden (view full) ---

64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 */
70
71#ifndef MAKE_NATIVE
2
3/*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 54 unchanged lines hidden (view full) ---

64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 */
70
71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $";
72static char rcsid[] = "$NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $";
73#else
74#include <sys/cdefs.h>
75#ifndef lint
76__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
77 The Regents of the University of California. All rights reserved.");
78#endif /* not lint */
79
80#ifndef lint
81#if 0
82static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
83#else
73#else
74#include <sys/cdefs.h>
75#ifndef lint
76__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
77 The Regents of the University of California. All rights reserved.");
78#endif /* not lint */
79
80#ifndef lint
81#if 0
82static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
83#else
84__RCSID("$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $");
84__RCSID("$NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $");
85#endif
86#endif /* not lint */
87#endif
88
89/*-
90 * main.c --
91 * The main file for this entire program. Exit routines etc
92 * reside here.

--- 78 unchanged lines hidden (view full) ---

171Boolean checkEnvFirst; /* -e flag */
172Boolean parseWarnFatal; /* -W flag */
173Boolean jobServer; /* -J flag */
174static int jp_0 = -1, jp_1 = -1; /* ends of parent job pipe */
175Boolean varNoExportEnv; /* -X flag */
176Boolean doing_depend; /* Set while reading .depend */
177static Boolean jobsRunning; /* TRUE if the jobs might be running */
178static const char * tracefile;
85#endif
86#endif /* not lint */
87#endif
88
89/*-
90 * main.c --
91 * The main file for this entire program. Exit routines etc
92 * reside here.

--- 78 unchanged lines hidden (view full) ---

171Boolean checkEnvFirst; /* -e flag */
172Boolean parseWarnFatal; /* -W flag */
173Boolean jobServer; /* -J flag */
174static int jp_0 = -1, jp_1 = -1; /* ends of parent job pipe */
175Boolean varNoExportEnv; /* -X flag */
176Boolean doing_depend; /* Set while reading .depend */
177static Boolean jobsRunning; /* TRUE if the jobs might be running */
178static const char * tracefile;
179#ifndef NO_CHECK_MAKE_CHDIR
180static char * Check_Cwd_av(int, char **, int);
181#endif
182static void MainParseArgs(int, char **);
183static int ReadMakefile(const void *, const void *);
184static void usage(void) MAKE_ATTR_DEAD;
185
186static Boolean ignorePWD; /* if we use -C, PWD is meaningless */
187static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */
188char curdir[MAXPATHLEN + 1]; /* Startup directory */
189char *progname; /* the program name */

--- 1009 unchanged lines hidden (view full) ---

1199 if (!compatMake)
1200 Job_ServerStart(maxJobTokens, jp_0, jp_1);
1201 if (DEBUG(JOB))
1202 fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
1203 jp_0, jp_1, maxJobs, maxJobTokens, compatMake);
1204
1205 Main_ExportMAKEFLAGS(TRUE); /* initial export */
1206
179static void MainParseArgs(int, char **);
180static int ReadMakefile(const void *, const void *);
181static void usage(void) MAKE_ATTR_DEAD;
182
183static Boolean ignorePWD; /* if we use -C, PWD is meaningless */
184static char objdir[MAXPATHLEN + 1]; /* where we chdir'ed to */
185char curdir[MAXPATHLEN + 1]; /* Startup directory */
186char *progname; /* the program name */

--- 1009 unchanged lines hidden (view full) ---

1196 if (!compatMake)
1197 Job_ServerStart(maxJobTokens, jp_0, jp_1);
1198 if (DEBUG(JOB))
1199 fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
1200 jp_0, jp_1, maxJobs, maxJobTokens, compatMake);
1201
1202 Main_ExportMAKEFLAGS(TRUE); /* initial export */
1203
1207#ifndef NO_CHECK_MAKE_CHDIR
1208 Check_Cwd_av(0, NULL, 0); /* initialize it */
1209#endif
1210
1211 /*
1212 * For compatibility, look at the directories in the VPATH variable
1213 * and add them to the search path, if the variable is defined. The
1214 * variable's value is in the same format as the PATH envariable, i.e.
1215 * <directory>:<directory>:<directory>...
1216 */
1217 if (Var_Exists("VPATH", VAR_CMD)) {
1218 char *vpath, savec;

--- 199 unchanged lines hidden (view full) ---

1418 Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
1419 Parse_File(fname, fd);
1420 }
1421 free(path);
1422 return(0);
1423}
1424
1425
1204 /*
1205 * For compatibility, look at the directories in the VPATH variable
1206 * and add them to the search path, if the variable is defined. The
1207 * variable's value is in the same format as the PATH envariable, i.e.
1208 * <directory>:<directory>:<directory>...
1209 */
1210 if (Var_Exists("VPATH", VAR_CMD)) {
1211 char *vpath, savec;

--- 199 unchanged lines hidden (view full) ---

1411 Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
1412 Parse_File(fname, fd);
1413 }
1414 free(path);
1415 return(0);
1416}
1417
1418
1426/*
1427 * If MAKEOBJDIRPREFIX is in use, make ends up not in .CURDIR
1428 * in situations that would not arrise with ./obj (links or not).
1429 * This tends to break things like:
1430 *
1431 * build:
1432 * ${MAKE} includes
1433 *
1434 * This function spots when ${.MAKE:T} or ${.MAKE} is a command (as
1435 * opposed to an argument) in a command line and if so returns
1436 * ${.CURDIR} so caller can chdir() so that the assumptions made by
1437 * the Makefile hold true.
1438 *
1439 * If ${.MAKE} does not contain any '/', then ${.MAKE:T} is skipped.
1440 *
1441 * The chdir() only happens in the child process, and does nothing if
1442 * MAKEOBJDIRPREFIX and MAKEOBJDIR are not in the environment so it
1443 * should not break anything. Also if NOCHECKMAKECHDIR is set we
1444 * do nothing - to ensure historic semantics can be retained.
1445 */
1446#ifdef NO_CHECK_MAKE_CHDIR
1447char *
1448Check_Cwd_Cmd(cmd)
1449 char *cmd;
1450{
1451 return 0;
1452}
1453
1419
1454void
1455Check_Cwd(argv)
1456 char **argv;
1457{
1458 return;
1459}
1460
1461#else
1462
1463static int Check_Cwd_Off = 0;
1464
1465static char *
1466Check_Cwd_av(int ac, char **av, int copy)
1467{
1468 static char *make[4];
1469 static char *cur_dir = NULL;
1470 char **mp;
1471 char *cp;
1472 int is_cmd, next_cmd;
1473 int i;
1474 int n;
1475
1476 if (Check_Cwd_Off) {
1477 if (DEBUG(CWD))
1478 fprintf(debug_file, "check_cwd: check is off.\n");
1479 return NULL;
1480 }
1481
1482 if (make[0] == NULL) {
1483 if (Var_Exists("NOCHECKMAKECHDIR", VAR_GLOBAL)) {
1484 Check_Cwd_Off = 1;
1485 if (DEBUG(CWD))
1486 fprintf(debug_file, "check_cwd: turning check off.\n");
1487 return NULL;
1488 }
1489
1490 make[1] = Var_Value(".MAKE", VAR_GLOBAL, &cp);
1491 if ((make[0] = strrchr(make[1], '/')) == NULL) {
1492 make[0] = make[1];
1493 make[1] = NULL;
1494 } else
1495 ++make[0];
1496 make[2] = NULL;
1497 cur_dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
1498 }
1499 if (ac == 0 || av == NULL) {
1500 if (DEBUG(CWD))
1501 fprintf(debug_file, "check_cwd: empty command.\n");
1502 return NULL; /* initialization only */
1503 }
1504
1505 if (getenv("MAKEOBJDIR") == NULL &&
1506 getenv("MAKEOBJDIRPREFIX") == NULL) {
1507 if (DEBUG(CWD))
1508 fprintf(debug_file, "check_cwd: no obj dirs.\n");
1509 return NULL;
1510 }
1511
1512
1513 next_cmd = 1;
1514 for (i = 0; i < ac; ++i) {
1515 is_cmd = next_cmd;
1516
1517 n = strlen(av[i]);
1518 cp = &(av[i])[n - 1];
1519 if (strspn(av[i], "|&;") == (size_t)n) {
1520 next_cmd = 1;
1521 continue;
1522 } else if (*cp == ';' || *cp == '&' || *cp == '|' || *cp == ')') {
1523 next_cmd = 1;
1524 if (copy) {
1525 do {
1526 *cp-- = '\0';
1527 } while (*cp == ';' || *cp == '&' || *cp == '|' ||
1528 *cp == ')' || *cp == '}') ;
1529 } else {
1530 /*
1531 * XXX this should not happen.
1532 */
1533 fprintf(stderr, "%s: WARNING: raw arg ends in shell meta '%s'\n",
1534 progname, av[i]);
1535 }
1536 } else
1537 next_cmd = 0;
1538
1539 cp = av[i];
1540 if (*cp == ';' || *cp == '&' || *cp == '|')
1541 is_cmd = 1;
1542
1543 if (DEBUG(CWD))
1544 fprintf(debug_file, "av[%d] == %s '%s'",
1545 i, (is_cmd) ? "cmd" : "arg", av[i]);
1546 if (is_cmd != 0) {
1547 if (*cp == '(' || *cp == '{' ||
1548 *cp == ';' || *cp == '&' || *cp == '|') {
1549 do {
1550 ++cp;
1551 } while (*cp == '(' || *cp == '{' ||
1552 *cp == ';' || *cp == '&' || *cp == '|');
1553 if (*cp == '\0') {
1554 next_cmd = 1;
1555 continue;
1556 }
1557 }
1558 if (strcmp(cp, "cd") == 0 || strcmp(cp, "chdir") == 0) {
1559 if (DEBUG(CWD))
1560 fprintf(debug_file, " == cd, done.\n");
1561 return NULL;
1562 }
1563 for (mp = make; *mp != NULL; ++mp) {
1564 n = strlen(*mp);
1565 if (strcmp(cp, *mp) == 0) {
1566 if (DEBUG(CWD))
1567 fprintf(debug_file, " %s == '%s', chdir(%s)\n",
1568 cp, *mp, cur_dir);
1569 return cur_dir;
1570 }
1571 }
1572 }
1573 if (DEBUG(CWD))
1574 fprintf(debug_file, "\n");
1575 }
1576 return NULL;
1577}
1578
1579char *
1580Check_Cwd_Cmd(const char *cmd)
1581{
1582 char *cp, *bp;
1583 char **av;
1584 int ac;
1585
1586 if (Check_Cwd_Off)
1587 return NULL;
1588
1589 if (cmd) {
1590 av = brk_string(cmd, &ac, TRUE, &bp);
1591 if (DEBUG(CWD))
1592 fprintf(debug_file, "splitting: '%s' -> %d words\n",
1593 cmd, ac);
1594 } else {
1595 ac = 0;
1596 av = NULL;
1597 bp = NULL;
1598 }
1599 cp = Check_Cwd_av(ac, av, 1);
1600 if (bp)
1601 free(bp);
1602 if (av)
1603 free(av);
1604 return cp;
1605}
1606
1607void
1608Check_Cwd(const char **argv)
1609{
1610 char *cp;
1611 int ac;
1612
1613 if (Check_Cwd_Off)
1614 return;
1615
1616 for (ac = 0; argv[ac] != NULL; ++ac)
1617 /* NOTHING */;
1618 if (ac == 3 && *argv[1] == '-') {
1619 cp = Check_Cwd_Cmd(argv[2]);
1620 } else {
1621 cp = Check_Cwd_av(ac, UNCONST(argv), 0);
1622 }
1623 if (cp) {
1624 chdir(cp);
1625 }
1626}
1627#endif /* NO_CHECK_MAKE_CHDIR */
1628
1629/*-
1630 * Cmd_Exec --
1631 * Execute the command in cmd, and return the output of that command
1632 * in a string.
1633 *
1634 * Results:
1635 * A string containing the output of the command, or the empty string
1636 * If errnum is not NULL, it contains the reason for the command failure

--- 310 unchanged lines hidden (view full) ---

1947 IOADD(af);
1948 IOADD("(");
1949 IOADD(av);
1950 IOADD(") failed (");
1951 IOADD(strerror(errno));
1952 IOADD(")\n");
1953
1954#ifdef USE_IOVEC
1420/*-
1421 * Cmd_Exec --
1422 * Execute the command in cmd, and return the output of that command
1423 * in a string.
1424 *
1425 * Results:
1426 * A string containing the output of the command, or the empty string
1427 * If errnum is not NULL, it contains the reason for the command failure

--- 310 unchanged lines hidden (view full) ---

1738 IOADD(af);
1739 IOADD("(");
1740 IOADD(av);
1741 IOADD(") failed (");
1742 IOADD(strerror(errno));
1743 IOADD(")\n");
1744
1745#ifdef USE_IOVEC
1955 (void)writev(2, iov, 8);
1746 while (writev(2, iov, 8) == -1 && errno == EAGAIN)
1747 continue;
1956#endif
1957}
1958
1959/*
1960 * usage --
1961 * exit with usage message
1962 */
1963static void

--- 178 unchanged lines hidden ---
1748#endif
1749}
1750
1751/*
1752 * usage --
1753 * exit with usage message
1754 */
1755static void

--- 178 unchanged lines hidden ---