Print this page
make: be serial if 'make', parallel if 'dmake', and parallel if '-j' is specified either way

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/make/bin/main.cc
          +++ new/usr/src/cmd/make/bin/main.cc
↓ open down ↓ 32 lines elided ↑ open up ↑
  33   33   * Included files
  34   34   */
  35   35  #if defined(TEAMWARE_MAKE_CMN)
  36   36  #       include <avo/intl.h>
  37   37  #endif
  38   38  
  39   39  #include <bsd/bsd.h>            /* bsd_signal() */
  40   40  
  41   41  
  42   42  #include <locale.h>             /* setlocale() */
       43 +#include <libgen.h>
  43   44  #include <mk/defs.h>
  44   45  #include <mksdmsi18n/mksdmsi18n.h>      /* libmksdmsi18n_init() */
  45   46  #include <mksh/macro.h>         /* getvar() */
  46   47  #include <mksh/misc.h>          /* getmem(), setup_char_semantics() */
  47   48  
  48   49  #if defined(TEAMWARE_MAKE_CMN)
  49   50  #endif
  50   51  
  51   52  #include <pwd.h>                /* getpwnam() */
  52   53  #include <setjmp.h>
↓ open down ↓ 22 lines elided ↑ open up ↑
  75   76  
  76   77  
  77   78  /*
  78   79   * Defined macros
  79   80   */
  80   81  #define MAKE_PREFIX             NOCATGETS("/usr")
  81   82  #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT_32")
  82   83  #define LD_SUPPORT_ENV_VAR_32   NOCATGETS("SGS_SUPPORT_32")
  83   84  #define LD_SUPPORT_ENV_VAR_64   NOCATGETS("SGS_SUPPORT_64")
  84   85  #define LD_SUPPORT_MAKE_LIB     NOCATGETS("libmakestate.so.1")
  85      -#define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib")
  86      -#define LD_SUPPORT_MAKE_LIB_DIR_64      NOCATGETS("/64")
       86 +#ifdef __i386
       87 +#define LD_SUPPORT_MAKE_ARCH    NOCATGETS("i386")
       88 +#elif __sparc
       89 +#define LD_SUPPORT_MAKE_ARCH    NOCATGETS("sparc")
       90 +#else
       91 +#error "Unsupported architecture"
       92 +#endif
  87   93  
  88   94  /*
  89   95   * typedefs & structs
  90   96   */
  91   97  
  92   98  /*
  93   99   * Static variables
  94  100   */
  95  101  static  char            *argv_zero_string;
  96  102  static  Boolean         build_failed_ever_seen;
↓ open down ↓ 309 lines elided ↑ open up ↑
 406  412                  } else {
 407  413                          warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
 408  414                                dmake_value2->string_mb);
 409  415                  }
 410  416          }
 411  417          /*
 412  418           * Find the dmake_mode: parallel, or serial.
 413  419           */
 414  420      if ((!pmake_cap_r_specified) &&
 415  421          (!pmake_machinesfile_specified)) {
      422 +        char *s = strdup(argv[0]);    
      423 +            
 416  424          MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
 417  425          dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
 418  426          prop2 = get_prop(dmake_name2->prop, macro_prop);
 419      -        if (prop2 == NULL) {
 420      -                /* DMAKE_MODE not defined, default to parallel mode */
 421      -                dmake_mode_type = parallel_mode;
 422      -                no_parallel = false;
      427 +        // If we're invoked as 'make' run serially, regardless of DMAKE_MODE
      428 +        // If we're invoked as 'make' but passed -j, run parallel
      429 +        // If we're invoked as 'dmake', without DMAKE_MODE, default parallel
      430 +        // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it.
      431 +        if ((strcmp(basename(s), NOCATGETS("make")) == 0) &&
      432 +            !dmake_max_jobs_specified) {
      433 +                dmake_mode_type = serial_mode;
      434 +                no_parallel = true;
      435 +        } else if (prop2 == NULL) {
      436 +                /* DMAKE_MODE not defined, default based on our name */
      437 +                char *s = strdup(argv[0]);
      438 +
      439 +                if (strcmp(basename(s), NOCATGETS("dmake")) == 0) {
      440 +                        dmake_mode_type = parallel_mode;
      441 +                        no_parallel = false;
      442 +                }
 423  443          } else {
 424  444                  dmake_value2 = prop2->body.macro.value;
 425  445                  if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) {
 426  446                          dmake_mode_type = parallel_mode;
 427  447                          no_parallel = false;
 428  448                  } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("serial"))) {
 429  449                          dmake_mode_type = serial_mode;
 430  450                          no_parallel = true;
 431  451                  } else {
 432  452                          fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
 433  453                  }
 434  454          }
 435      -
      455 +        free(s);
 436  456      }
 437  457  
 438  458          parallel_flag = true;
 439  459          putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
 440  460  
 441  461  //
 442  462  // If dmake is running with -t option, set dmake_mode_type to serial.
 443  463  // This is done because doname() calls touch_command() that runs serially.
 444  464  // If we do not do that, maketool will have problems. 
 445  465  //
↓ open down ↓ 910 lines elided ↑ open up ↑
1356 1376                  if (invert_this) {
1357 1377                          ignore_errors_all = false;
1358 1378                  } else {
1359 1379                          ignore_errors_all = true;
1360 1380                  }
1361 1381                  return 0;
1362 1382          case 'j':                        /* Use alternative DMake max jobs */
1363 1383                  if (invert_this) {
1364 1384                          dmake_max_jobs_specified = false;
1365 1385                  } else {
     1386 +                        dmake_mode_type = parallel_mode;
     1387 +                        no_parallel = false;
1366 1388                          dmake_max_jobs_specified = true;
1367 1389                  }
1368 1390                  return 8;
1369 1391          case 'K':                        /* Read alternative .make.state */
1370 1392                  return 256;
1371 1393          case 'k':                        /* Keep making even after errors */
1372 1394                  if (invert_this) {
1373 1395                          continue_after_error = false;
1374 1396                  } else {
1375 1397                          continue_after_error = true;
↓ open down ↓ 216 lines elided ↑ open up ↑
1592 1614                                  done = 1;
1593 1615                          } else {
1594 1616                                  fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1595 1617                          }
1596 1618                      }
1597 1619                  }
1598 1620             }
1599 1621          }
1600 1622  }
1601 1623  
     1624 +char *
     1625 +make_install_prefix(void)
     1626 +{
     1627 +        int ret;
     1628 +        char origin[PATH_MAX];
     1629 +        char *dir;
     1630 +
     1631 +        if ((ret = readlink("/proc/self/path/a.out", origin,
     1632 +            PATH_MAX - 1)) < 0)
     1633 +                fatal("failed to read origin from /proc\n");
     1634 +
     1635 +        
     1636 +        origin[ret] = '\0';
     1637 +        return strdup(dirname(origin));
     1638 +}
     1639 +
     1640 +static char *
     1641 +add_to_env(const char *var, const char *value, const char *fallback)
     1642 +{
     1643 +        const char *oldpath;
     1644 +        char *newpath;
     1645 +
     1646 +        oldpath = getenv(var);
     1647 +        if (oldpath == NULL) {
     1648 +                if (value != NULL) {
     1649 +                        asprintf(&newpath, "%s=%s",
     1650 +                            var, value);
     1651 +                } else {
     1652 +                        asprintf(&newpath, "%s=%s",
     1653 +                            var, fallback);
     1654 +                }
     1655 +        } else {
     1656 +                if (value != NULL) {
     1657 +                        asprintf(&newpath, "%s=%s:%s",
     1658 +                            var, oldpath, value);
     1659 +                } else {
     1660 +                        asprintf(&newpath, "%s=%s:%s",
     1661 +                            var, oldpath, fallback);                    
     1662 +                }
     1663 +        }
     1664 +
     1665 +        return (newpath);
     1666 +}
     1667 +
1602 1668  /*
1603 1669   *      set_sgs_support()
1604 1670   *
1605 1671   *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1606 1672   *        if it's not already in there.
1607 1673   *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1608 1674   *        the linker ld to report .make.state info back to make.
1609 1675   *
1610 1676   * In the new world we always will set the 32-bit and 64-bit versions of this
1611 1677   * variable explicitly so that we can take into account the correct isa and our
1612 1678   * prefix. So say that the prefix was /opt/local. Then we would want to search
1613 1679   * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1614 1680   * the original location just as a safety measure.
1615 1681   */
1616 1682  static void
1617 1683  set_sgs_support()
1618 1684  {
1619 1685          int             len;
1620 1686          char            *newpath, *newpath64;
1621      -        char            *oldpath, *oldpath64;
     1687 +        char            *lib32, *lib64;
1622 1688          static char     *prev_path, *prev_path64;
     1689 +        char            *origin = make_install_prefix();
     1690 +        struct stat st;
1623 1691  
1624      -        oldpath = getenv(LD_SUPPORT_ENV_VAR_32);
1625      -        if (oldpath == NULL) {
1626      -                len = snprintf(NULL, 0, "%s=%s/%s/%s:%s",
1627      -                    LD_SUPPORT_ENV_VAR_32,
1628      -                    MAKE_PREFIX,
1629      -                    LD_SUPPORT_MAKE_LIB_DIR,
1630      -                    LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1631      -                newpath = (char *) malloc(len);
1632      -                sprintf(newpath, "%s=%s/%s/%s:%s",
1633      -                    LD_SUPPORT_ENV_VAR_32,
1634      -                    MAKE_PREFIX,
1635      -                    LD_SUPPORT_MAKE_LIB_DIR,
1636      -                    LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
1637      -        } else {
1638      -                len = snprintf(NULL, 0, "%s=%s:%s/%s/%s:%s",
1639      -                    LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1640      -                    LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1641      -                    LD_SUPPORT_MAKE_LIB) + 1;
1642      -                newpath = (char *) malloc(len);
1643      -                sprintf(newpath, "%s=%s:%s/%s/%s:%s",
1644      -                    LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1645      -                    LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1646      -                    LD_SUPPORT_MAKE_LIB);
1647      -        }
1648      -
1649      -        oldpath64 = getenv(LD_SUPPORT_ENV_VAR_64);
1650      -        if (oldpath64 == NULL) {
1651      -                len = snprintf(NULL, 0, "%s=%s/%s/%s/%s:%s",
1652      -                    LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1653      -                    LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1654      -                    LD_SUPPORT_MAKE_LIB) + 1;
1655      -                newpath64 = (char *) malloc(len);
1656      -                sprintf(newpath64, "%s=%s/%s/%s/%s:%s",
1657      -                    LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1658      -                    LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1659      -                    LD_SUPPORT_MAKE_LIB);
1660      -        } else {
1661      -                len = snprintf(NULL, 0, "%s=%s:%s/%s/%s/%s:%s",
1662      -                    LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1663      -                    LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1664      -                    LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1665      -                newpath64 = (char *) malloc(len);
1666      -                sprintf(newpath64, "%s=%s:%s/%s/%s/%s:%s",
1667      -                    LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1668      -                    LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1669      -                    LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
     1692 +        asprintf(&lib32, "%s/%s/%s", origin, "../lib",
     1693 +            LD_SUPPORT_MAKE_LIB);
     1694 +
     1695 +        if (stat(lib32, &st) != 0) {
     1696 +                free(lib32);
     1697 +                // Try the tools path
     1698 +                asprintf(&lib32, "%s/%s/%s/%s", origin, "../../lib/",
     1699 +                    LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB);
     1700 +
     1701 +                if (stat(lib32, &st) != 0) {
     1702 +                        free(lib32);
     1703 +                        lib32 = NULL;
     1704 +                }
     1705 +        }
     1706 +
     1707 +        asprintf(&lib64, "%s/%s/64/%s", origin, "../lib",
     1708 +            LD_SUPPORT_MAKE_LIB);
     1709 +
     1710 +        if (stat(lib64, &st) != 0) {
     1711 +                free(lib64);
     1712 +                // Try the tools path
     1713 +                asprintf(&lib64, "%s/%s/%s/64/%s", origin, "../../lib/",
     1714 +                    LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB);
     1715 +
     1716 +                if (stat(lib64, &st) != 0) {
     1717 +                        free(lib64);
     1718 +                        lib64 = NULL;
     1719 +                }
1670 1720          }
1671 1721  
     1722 +        newpath = add_to_env(LD_SUPPORT_ENV_VAR_32, lib32, LD_SUPPORT_MAKE_LIB);
     1723 +        newpath64 = add_to_env(LD_SUPPORT_ENV_VAR_64, lib64, LD_SUPPORT_MAKE_LIB);
     1724 +
1672 1725          putenv(newpath);
1673 1726          if (prev_path) {
1674 1727                  free(prev_path);
1675 1728          }
1676 1729          prev_path = newpath;
1677 1730  
1678 1731          putenv(newpath64);
1679 1732          if (prev_path64) {
1680 1733                  free(prev_path64);
1681 1734          }
1682 1735          prev_path64 = newpath64;
     1736 +        free(lib32);
     1737 +        free(lib64);
     1738 +        free(origin);
1683 1739  }
1684 1740  
1685 1741  /*
1686 1742   *      read_files_and_state(argc, argv)
1687 1743   *
1688 1744   *      Read the makefiles we care about and the environment
1689 1745   *      Also read the = style command line options
1690 1746   *
1691 1747   *      Parameters:
1692 1748   *              argc            You know what this is
↓ open down ↓ 1544 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX