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


  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  *      main.cc
  28  *
  29  *      make program main routine plus some helper routines
  30  */
  31  
  32 /*
  33  * Included files
  34  */
  35 #if defined(TEAMWARE_MAKE_CMN)
  36 #       include <avo/intl.h>
  37 #endif
  38 
  39 #include <bsd/bsd.h>              /* bsd_signal() */
  40 
  41 
  42 #include <locale.h>               /* setlocale() */

  43 #include <mk/defs.h>
  44 #include <mksdmsi18n/mksdmsi18n.h>        /* libmksdmsi18n_init() */
  45 #include <mksh/macro.h>           /* getvar() */
  46 #include <mksh/misc.h>            /* getmem(), setup_char_semantics() */
  47 
  48 #if defined(TEAMWARE_MAKE_CMN)
  49 #endif
  50 
  51 #include <pwd.h>          /* getpwnam() */
  52 #include <setjmp.h>
  53 #include <signal.h>
  54 #include <stdlib.h>
  55 #include <sys/errno.h>            /* ENOENT */
  56 #include <sys/stat.h>             /* fstat() */
  57 #include <fcntl.h>                /* open() */
  58 
  59 #       include <sys/systeminfo.h>        /* sysinfo() */
  60 
  61 #include <sys/types.h>            /* stat() */
  62 #include <sys/wait.h>             /* wait() */


  65 
  66 // From read2.cc
  67 extern  Name            normalize_name(register wchar_t *name_string, register int length);
  68 
  69 // From parallel.cc
  70 #define MAXJOBS_ADJUST_RFE4694000
  71 
  72 #ifdef MAXJOBS_ADJUST_RFE4694000
  73 extern void job_adjust_fini();
  74 #endif /* MAXJOBS_ADJUST_RFE4694000 */
  75 
  76 
  77 /*
  78  * Defined macros
  79  */
  80 #define MAKE_PREFIX             NOCATGETS("/usr")
  81 #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT_32")
  82 #define LD_SUPPORT_ENV_VAR_32   NOCATGETS("SGS_SUPPORT_32")
  83 #define LD_SUPPORT_ENV_VAR_64   NOCATGETS("SGS_SUPPORT_64")
  84 #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")





  87 
  88 /*
  89  * typedefs & structs
  90  */
  91 
  92 /*
  93  * Static variables
  94  */
  95 static  char            *argv_zero_string;
  96 static  Boolean         build_failed_ever_seen;
  97 static  Boolean         continue_after_error_ever_seen; /* `-k' */
  98 static  Boolean         dmake_group_specified;          /* `-g' */
  99 static  Boolean         dmake_max_jobs_specified;       /* `-j' */
 100 static  Boolean         dmake_mode_specified;           /* `-m' */
 101 static  Boolean         dmake_add_mode_specified;       /* `-x' */
 102 static  Boolean         dmake_output_mode_specified;    /* `-x DMAKE_OUTPUT_MODE=' */
 103 static  Boolean         dmake_compat_mode_specified;    /* `-x SUN_MAKE_COMPAT_MODE=' */
 104 static  Boolean         dmake_odir_specified;           /* `-o' */
 105 static  Boolean         dmake_rcfile_specified;         /* `-c' */
 106 static  Boolean         env_wins;                       /* `-e' */


 396                 output_mode = txt1_mode;
 397         } else {
 398                 dmake_value2 = prop2->body.macro.value;
 399                 if ((dmake_value2 == NULL) ||
 400                     (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
 401                         output_mode = txt1_mode;
 402                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
 403                         output_mode = txt2_mode;
 404                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
 405                         output_mode = html1_mode;
 406                 } else {
 407                         warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
 408                               dmake_value2->string_mb);
 409                 }
 410         }
 411         /*
 412          * Find the dmake_mode: parallel, or serial.
 413          */
 414     if ((!pmake_cap_r_specified) &&
 415         (!pmake_machinesfile_specified)) {


 416         MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
 417         dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
 418         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;

 423         } else {
 424                 dmake_value2 = prop2->body.macro.value;
 425                 if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) {
 426                         dmake_mode_type = parallel_mode;
 427                         no_parallel = false;
 428                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("serial"))) {
 429                         dmake_mode_type = serial_mode;
 430                         no_parallel = true;
 431                 } else {
 432                         fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
 433                 }
 434         }
 435 
 436     }
 437 
 438         parallel_flag = true;
 439         putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
 440 
 441 //
 442 // If dmake is running with -t option, set dmake_mode_type to serial.
 443 // This is done because doname() calls touch_command() that runs serially.
 444 // If we do not do that, maketool will have problems. 
 445 //
 446         if(touch) {
 447                 dmake_mode_type = serial_mode;
 448                 no_parallel = true;
 449         }
 450 
 451         /*
 452          * Check whether stdout and stderr are physically same.
 453          * This is in order to decide whether we need to redirect
 454          * stderr separately from stdout.
 455          * This check is performed only if __DMAKE_SEPARATE_STDERR


1346         case 'f':                        /* Read alternative makefile(s) */
1347                 return 1;
1348         case 'g':                        /* Use alternative DMake group */
1349                 if (invert_this) {
1350                         dmake_group_specified = false;
1351                 } else {
1352                         dmake_group_specified = true;
1353                 }
1354                 return 4;
1355         case 'i':                        /* Ignore errors */
1356                 if (invert_this) {
1357                         ignore_errors_all = false;
1358                 } else {
1359                         ignore_errors_all = true;
1360                 }
1361                 return 0;
1362         case 'j':                        /* Use alternative DMake max jobs */
1363                 if (invert_this) {
1364                         dmake_max_jobs_specified = false;
1365                 } else {


1366                         dmake_max_jobs_specified = true;
1367                 }
1368                 return 8;
1369         case 'K':                        /* Read alternative .make.state */
1370                 return 256;
1371         case 'k':                        /* Keep making even after errors */
1372                 if (invert_this) {
1373                         continue_after_error = false;
1374                 } else {
1375                         continue_after_error = true;
1376                         continue_after_error_ever_seen = true;
1377                 }
1378                 return 0;
1379         case 'M':                        /* Read alternative make.machines file */
1380                 if (invert_this) {
1381                         pmake_machinesfile_specified = false;
1382                 } else {
1383                         pmake_machinesfile_specified = true;
1384                         dmake_mode_type = parallel_mode;
1385                         no_parallel = false;


1582                                 done = 1;
1583                         }
1584                      }
1585                 }
1586                 if (!done) {
1587                     if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1588 
1589                        (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1590                        if (access(path, F_OK) == 0) {
1591                                 sccs_dir_path = path;
1592                                 done = 1;
1593                         } else {
1594                                 fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1595                         }
1596                     }
1597                 }
1598            }
1599         }
1600 }
1601 












































1602 /*
1603  *      set_sgs_support()
1604  *
1605  *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1606  *        if it's not already in there.
1607  *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1608  *        the linker ld to report .make.state info back to make.
1609  *
1610  * In the new world we always will set the 32-bit and 64-bit versions of this
1611  * variable explicitly so that we can take into account the correct isa and our
1612  * prefix. So say that the prefix was /opt/local. Then we would want to search
1613  * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1614  * the original location just as a safety measure.
1615  */
1616 static void
1617 set_sgs_support()
1618 {
1619         int             len;
1620         char            *newpath, *newpath64;
1621         char            *oldpath, *oldpath64;
1622         static char     *prev_path, *prev_path64;


1623 
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);
1670         }




1671 
1672         putenv(newpath);
1673         if (prev_path) {
1674                 free(prev_path);
1675         }
1676         prev_path = newpath;
1677 
1678         putenv(newpath64);
1679         if (prev_path64) {
1680                 free(prev_path64);
1681         }
1682         prev_path64 = newpath64;



1683 }
1684 
1685 /*
1686  *      read_files_and_state(argc, argv)
1687  *
1688  *      Read the makefiles we care about and the environment
1689  *      Also read the = style command line options
1690  *
1691  *      Parameters:
1692  *              argc            You know what this is
1693  *              argv            You know what this is
1694  *
1695  *      Static variables used:
1696  *              env_wins        make -e, determines if env vars are RO
1697  *              ignore_default_mk make -r, determines if make.rules is read
1698  *              not_auto_depen  dwight
1699  *
1700  *      Global variables used:
1701  *              default_target_to_build Set to first proper target from file
1702  *              do_not_exec_rule Set to false when makfile is made




  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  *      main.cc
  28  *
  29  *      make program main routine plus some helper routines
  30  */
  31  
  32 /*
  33  * Included files
  34  */
  35 #if defined(TEAMWARE_MAKE_CMN)
  36 #       include <avo/intl.h>
  37 #endif
  38 
  39 #include <bsd/bsd.h>              /* bsd_signal() */
  40 
  41 
  42 #include <locale.h>               /* setlocale() */
  43 #include <libgen.h>
  44 #include <mk/defs.h>
  45 #include <mksdmsi18n/mksdmsi18n.h>        /* libmksdmsi18n_init() */
  46 #include <mksh/macro.h>           /* getvar() */
  47 #include <mksh/misc.h>            /* getmem(), setup_char_semantics() */
  48 
  49 #if defined(TEAMWARE_MAKE_CMN)
  50 #endif
  51 
  52 #include <pwd.h>          /* getpwnam() */
  53 #include <setjmp.h>
  54 #include <signal.h>
  55 #include <stdlib.h>
  56 #include <sys/errno.h>            /* ENOENT */
  57 #include <sys/stat.h>             /* fstat() */
  58 #include <fcntl.h>                /* open() */
  59 
  60 #       include <sys/systeminfo.h>        /* sysinfo() */
  61 
  62 #include <sys/types.h>            /* stat() */
  63 #include <sys/wait.h>             /* wait() */


  66 
  67 // From read2.cc
  68 extern  Name            normalize_name(register wchar_t *name_string, register int length);
  69 
  70 // From parallel.cc
  71 #define MAXJOBS_ADJUST_RFE4694000
  72 
  73 #ifdef MAXJOBS_ADJUST_RFE4694000
  74 extern void job_adjust_fini();
  75 #endif /* MAXJOBS_ADJUST_RFE4694000 */
  76 
  77 
  78 /*
  79  * Defined macros
  80  */
  81 #define MAKE_PREFIX             NOCATGETS("/usr")
  82 #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT_32")
  83 #define LD_SUPPORT_ENV_VAR_32   NOCATGETS("SGS_SUPPORT_32")
  84 #define LD_SUPPORT_ENV_VAR_64   NOCATGETS("SGS_SUPPORT_64")
  85 #define LD_SUPPORT_MAKE_LIB     NOCATGETS("libmakestate.so.1")
  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
  93 
  94 /*
  95  * typedefs & structs
  96  */
  97 
  98 /*
  99  * Static variables
 100  */
 101 static  char            *argv_zero_string;
 102 static  Boolean         build_failed_ever_seen;
 103 static  Boolean         continue_after_error_ever_seen; /* `-k' */
 104 static  Boolean         dmake_group_specified;          /* `-g' */
 105 static  Boolean         dmake_max_jobs_specified;       /* `-j' */
 106 static  Boolean         dmake_mode_specified;           /* `-m' */
 107 static  Boolean         dmake_add_mode_specified;       /* `-x' */
 108 static  Boolean         dmake_output_mode_specified;    /* `-x DMAKE_OUTPUT_MODE=' */
 109 static  Boolean         dmake_compat_mode_specified;    /* `-x SUN_MAKE_COMPAT_MODE=' */
 110 static  Boolean         dmake_odir_specified;           /* `-o' */
 111 static  Boolean         dmake_rcfile_specified;         /* `-c' */
 112 static  Boolean         env_wins;                       /* `-e' */


 402                 output_mode = txt1_mode;
 403         } else {
 404                 dmake_value2 = prop2->body.macro.value;
 405                 if ((dmake_value2 == NULL) ||
 406                     (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
 407                         output_mode = txt1_mode;
 408                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
 409                         output_mode = txt2_mode;
 410                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
 411                         output_mode = html1_mode;
 412                 } else {
 413                         warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
 414                               dmake_value2->string_mb);
 415                 }
 416         }
 417         /*
 418          * Find the dmake_mode: parallel, or serial.
 419          */
 420     if ((!pmake_cap_r_specified) &&
 421         (!pmake_machinesfile_specified)) {
 422         char *s = strdup(argv[0]);    
 423             
 424         MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
 425         dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
 426         prop2 = get_prop(dmake_name2->prop, macro_prop);
 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                 }
 443         } else {
 444                 dmake_value2 = prop2->body.macro.value;
 445                 if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) {
 446                         dmake_mode_type = parallel_mode;
 447                         no_parallel = false;
 448                 } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("serial"))) {
 449                         dmake_mode_type = serial_mode;
 450                         no_parallel = true;
 451                 } else {
 452                         fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
 453                 }
 454         }
 455         free(s);
 456     }
 457 
 458         parallel_flag = true;
 459         putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
 460 
 461 //
 462 // If dmake is running with -t option, set dmake_mode_type to serial.
 463 // This is done because doname() calls touch_command() that runs serially.
 464 // If we do not do that, maketool will have problems. 
 465 //
 466         if(touch) {
 467                 dmake_mode_type = serial_mode;
 468                 no_parallel = true;
 469         }
 470 
 471         /*
 472          * Check whether stdout and stderr are physically same.
 473          * This is in order to decide whether we need to redirect
 474          * stderr separately from stdout.
 475          * This check is performed only if __DMAKE_SEPARATE_STDERR


1366         case 'f':                        /* Read alternative makefile(s) */
1367                 return 1;
1368         case 'g':                        /* Use alternative DMake group */
1369                 if (invert_this) {
1370                         dmake_group_specified = false;
1371                 } else {
1372                         dmake_group_specified = true;
1373                 }
1374                 return 4;
1375         case 'i':                        /* Ignore errors */
1376                 if (invert_this) {
1377                         ignore_errors_all = false;
1378                 } else {
1379                         ignore_errors_all = true;
1380                 }
1381                 return 0;
1382         case 'j':                        /* Use alternative DMake max jobs */
1383                 if (invert_this) {
1384                         dmake_max_jobs_specified = false;
1385                 } else {
1386                         dmake_mode_type = parallel_mode;
1387                         no_parallel = false;
1388                         dmake_max_jobs_specified = true;
1389                 }
1390                 return 8;
1391         case 'K':                        /* Read alternative .make.state */
1392                 return 256;
1393         case 'k':                        /* Keep making even after errors */
1394                 if (invert_this) {
1395                         continue_after_error = false;
1396                 } else {
1397                         continue_after_error = true;
1398                         continue_after_error_ever_seen = true;
1399                 }
1400                 return 0;
1401         case 'M':                        /* Read alternative make.machines file */
1402                 if (invert_this) {
1403                         pmake_machinesfile_specified = false;
1404                 } else {
1405                         pmake_machinesfile_specified = true;
1406                         dmake_mode_type = parallel_mode;
1407                         no_parallel = false;


1604                                 done = 1;
1605                         }
1606                      }
1607                 }
1608                 if (!done) {
1609                     if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1610 
1611                        (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1612                        if (access(path, F_OK) == 0) {
1613                                 sccs_dir_path = path;
1614                                 done = 1;
1615                         } else {
1616                                 fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1617                         }
1618                     }
1619                 }
1620            }
1621         }
1622 }
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 
1668 /*
1669  *      set_sgs_support()
1670  *
1671  *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1672  *        if it's not already in there.
1673  *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1674  *        the linker ld to report .make.state info back to make.
1675  *
1676  * In the new world we always will set the 32-bit and 64-bit versions of this
1677  * variable explicitly so that we can take into account the correct isa and our
1678  * prefix. So say that the prefix was /opt/local. Then we would want to search
1679  * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1680  * the original location just as a safety measure.
1681  */
1682 static void
1683 set_sgs_support()
1684 {
1685         int             len;
1686         char            *newpath, *newpath64;
1687         char            *lib32, *lib64;
1688         static char     *prev_path, *prev_path64;
1689         char            *origin = make_install_prefix();
1690         struct stat st;
1691 
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                 }
1720         }
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 
1725         putenv(newpath);
1726         if (prev_path) {
1727                 free(prev_path);
1728         }
1729         prev_path = newpath;
1730 
1731         putenv(newpath64);
1732         if (prev_path64) {
1733                 free(prev_path64);
1734         }
1735         prev_path64 = newpath64;
1736         free(lib32);
1737         free(lib64);
1738         free(origin);
1739 }
1740 
1741 /*
1742  *      read_files_and_state(argc, argv)
1743  *
1744  *      Read the makefiles we care about and the environment
1745  *      Also read the = style command line options
1746  *
1747  *      Parameters:
1748  *              argc            You know what this is
1749  *              argv            You know what this is
1750  *
1751  *      Static variables used:
1752  *              env_wins        make -e, determines if env vars are RO
1753  *              ignore_default_mk make -r, determines if make.rules is read
1754  *              not_auto_depen  dwight
1755  *
1756  *      Global variables used:
1757  *              default_target_to_build Set to first proper target from file
1758  *              do_not_exec_rule Set to false when makfile is made