Print this page
make: ship the Joyent patch to enable parallel make (originally from rm)


  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  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 #       include <avo/libcli.h>          /* libcli_init() */
  38 #       include <avo/cli_license.h>       /* avo_cli_get_license() */
  39 #       include <avo/find_dir.h>  /* avo_find_run_dir() */
  40 #       include <avo/version_string.h>
  41 #       include <avo/util.h>              /* avo_init() */
  42 #       include <avo/cleanup.h>
  43 #endif
  44 
  45 #include <bsd/bsd.h>              /* bsd_signal() */
  46 
  47 #ifdef DISTRIBUTED
  48 #       include <dm/Avo_AcknowledgeMsg.h>
  49 #       include <rw/xdrstrea.h>
  50 #       include <dmrc/dmrc.h> /* dmakerc file processing */
  51 #endif
  52 
  53 #include <locale.h>               /* setlocale() */
  54 #include <mk/defs.h>
  55 #include <mksdmsi18n/mksdmsi18n.h>        /* libmksdmsi18n_init() */
  56 #include <mksh/macro.h>           /* getvar() */
  57 #include <mksh/misc.h>            /* getmem(), setup_char_semantics() */
  58 
  59 #if defined(TEAMWARE_MAKE_CMN)
  60 #endif
  61 
  62 #include <pwd.h>          /* getpwnam() */


  73 #include <sys/wait.h>             /* wait() */
  74 #include <unistd.h>               /* execv(), unlink(), access() */
  75 #include <vroot/report.h> /* report_dependency(), get_report_file() */
  76 
  77 // From read2.cc
  78 extern  Name            normalize_name(register wchar_t *name_string, register int length);
  79 
  80 // From parallel.cc
  81 #if defined(TEAMWARE_MAKE_CMN)
  82 #define MAXJOBS_ADJUST_RFE4694000
  83 
  84 #ifdef MAXJOBS_ADJUST_RFE4694000
  85 extern void job_adjust_fini();
  86 #endif /* MAXJOBS_ADJUST_RFE4694000 */
  87 #endif /* TEAMWARE_MAKE_CMN */
  88 
  89 
  90 /*
  91  * Defined macros
  92  */
  93 #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT")



  94 #define LD_SUPPORT_MAKE_LIB     NOCATGETS("libmakestate.so.1")


  95 
  96 /*
  97  * typedefs & structs
  98  */
  99 
 100 /*
 101  * Static variables
 102  */
 103 static  char            *argv_zero_string;
 104 static  Boolean         build_failed_ever_seen;
 105 static  Boolean         continue_after_error_ever_seen; /* `-k' */
 106 static  Boolean         dmake_group_specified;          /* `-g' */
 107 static  Boolean         dmake_max_jobs_specified;       /* `-j' */
 108 static  Boolean         dmake_mode_specified;           /* `-m' */
 109 static  Boolean         dmake_add_mode_specified;       /* `-x' */
 110 static  Boolean         dmake_output_mode_specified;    /* `-x DMAKE_OUTPUT_MODE=' */
 111 static  Boolean         dmake_compat_mode_specified;    /* `-x SUN_MAKE_COMPAT_MODE=' */
 112 static  Boolean         dmake_odir_specified;           /* `-o' */
 113 static  Boolean         dmake_rcfile_specified;         /* `-c' */
 114 static  Boolean         env_wins;                       /* `-e' */
 115 static  Boolean         ignore_default_mk;              /* `-r' */
 116 static  Boolean         list_all_targets;               /* `-T' */
 117 static  int             mf_argc;
 118 static  char            **mf_argv;
 119 static  Dependency_rec  not_auto_depen_struct;
 120 static  Dependency      not_auto_depen = &not_auto_depen_struct;
 121 static  Boolean         pmake_cap_r_specified;          /* `-R' */
 122 static  Boolean         pmake_machinesfile_specified;   /* `-M' */
 123 static  Boolean         stop_after_error_ever_seen;     /* `-S' */
 124 static  Boolean         trace_status;                   /* `-p' */
 125 
 126 #ifdef DMAKE_STATISTICS
 127 static  Boolean         getname_stat = false;
 128 #endif
 129 
 130 #if defined(TEAMWARE_MAKE_CMN)
 131         static  time_t          start_time;
 132         static  int             g_argc;
 133         static  char            **g_argv;
 134         static  Avo_cleanup     *cleanup = NULL;
 135 #endif
 136 
 137 /*
 138  * File table of contents
 139  */
 140         extern "C" void         cleanup_after_exit(void);
 141 
 142 #ifdef TEAMWARE_MAKE_CMN
 143 extern "C" {
 144         extern  void            dmake_exit_callback(void);
 145         extern  void            dmake_message_callback(char *);
 146 }
 147 #endif
 148 
 149 extern  Name            normalize_name(register wchar_t *name_string, register int length);
 150 
 151 extern  int             main(int, char * []);
 152 
 153 static  void            append_makeflags_string(Name, String);
 154 static  void            doalarm(int);


 157 static  int             parse_command_option(char);
 158 static  void            read_command_options(int, char **);
 159 static  void            read_environment(Boolean);
 160 static  void            read_files_and_state(int, char **);
 161 static  Boolean         read_makefile(Name, Boolean, Boolean, Boolean);
 162 static  void            report_recursion(Name);
 163 static  void            set_sgs_support(void);
 164 static  void            setup_for_projectdir(void);
 165 static  void            setup_makeflags_argv(void);
 166 static  void            report_dir_enter_leave(Boolean entering);
 167 
 168 extern void expand_value(Name, register String , Boolean);
 169 
 170 #ifdef DISTRIBUTED
 171         extern  int             dmake_ofd;
 172         extern  FILE*           dmake_ofp;
 173         extern  int             rxmPid;
 174         extern  XDR             xdrs_out;
 175 #endif
 176 #ifdef TEAMWARE_MAKE_CMN
 177         extern  char            verstring[];
 178 #endif
 179 
 180 jmp_buf jmpbuffer;
 181 extern nl_catd catd;
 182 
 183 /*
 184  *      main(argc, argv)
 185  *
 186  *      Parameters:
 187  *              argc                    You know what this is
 188  *              argv                    You know what this is
 189  *
 190  *      Static variables used:
 191  *              list_all_targets        make -T seen
 192  *              trace_status            make -p seen
 193  *
 194  *      Global variables used:
 195  *              debug_level             Should we trace make actions?
 196  *              keep_state              Set if .KEEP_STATE seen
 197  *              makeflags               The Name "MAKEFLAGS", used to get macro


 212          */
 213         register char           *cp;
 214         char                    make_state_dir[MAXPATHLEN];
 215         Boolean                 parallel_flag = false;
 216         char                    *prognameptr;
 217         char                    *slash_ptr;
 218         mode_t                  um;
 219         int                     i;
 220 #ifdef TEAMWARE_MAKE_CMN
 221         struct itimerval        value;
 222         char                    def_dmakerc_path[MAXPATHLEN];
 223         Name                    dmake_name, dmake_name2;
 224         Name                    dmake_value, dmake_value2;
 225         Property                prop, prop2;
 226         struct stat             statbuf;
 227         int                     statval;
 228 #endif
 229 
 230         struct stat             out_stat, err_stat;
 231         hostid = gethostid();
 232 #ifdef TEAMWARE_MAKE_CMN
 233         avo_get_user(NULL, NULL); // Initialize user name
 234 #endif
 235         bsd_signals();
 236 
 237         (void) setlocale(LC_ALL, "");
 238 
 239 
 240 #ifdef DMAKE_STATISTICS
 241         if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
 242                 getname_stat = true;
 243         }
 244 #endif
 245 
 246 
 247         /*
 248          * avo_init() sets the umask to 0.  Save it here and restore
 249          * it after the avo_init() call.
 250          */
 251 #if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL)
 252         um = umask(0);
 253         avo_init(argv[0]);
 254         umask(um);
 255 
 256         cleanup = new Avo_cleanup(NOCATGETS("dmake"), argc, argv);
 257 #endif
 258 
 259 #if defined(TEAMWARE_MAKE_CMN)
 260         catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);
 261         libcli_init();
 262 #endif
 263 
 264 // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
 265 
 266 
 267 #if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL)
 268 /*
 269  * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
 270  * from avo_util library. 
 271  */
 272         libmksdmsi18n_init();
 273 #endif
 274 
 275 
 276 #ifndef TEAMWARE_MAKE_CMN
 277         textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
 278 #endif /* TEAMWARE_MAKE_CMN */
 279 
 280 #ifdef TEAMWARE_MAKE_CMN
 281         g_argc = argc;


 515                                         Avo_err         *err = rcfile->read(def_dmakerc_path, NULL, TRUE);
 516                                         if (err) {
 517                                                 fatal(err->str);
 518                                         }
 519                                         empty_dmakerc = rcfile->was_empty();
 520                                         delete rcfile;
 521                                 }
 522                         }
 523                         if (empty_dmakerc) {
 524                                 if (getenv(NOCATGETS("DMAKE_DEF_PRINTED")) == NULL) {
 525                                         putenv(NOCATGETS("DMAKE_DEF_PRINTED=TRUE"));
 526                                         (void) fprintf(stdout, catgets(catd, 1, 302, "dmake: defaulting to parallel mode.\n"));
 527                                         (void) fprintf(stdout, catgets(catd, 1, 303, "See the man page dmake(1) for more information on setting up the .dmakerc file.\n"));
 528                                 }
 529                                 dmake_mode_type = parallel_mode;
 530                                 no_parallel = false;
 531                         }
 532                 }
 533 #else
 534                 if(dmake_mode_type == distributed_mode) {
 535                         (void) fprintf(stdout, NOCATGETS("dmake: Distributed mode not implemented.\n"));
 536                         (void) fprintf(stdout, NOCATGETS("       Defaulting to parallel mode.\n"));
 537                         dmake_mode_type = parallel_mode;
 538                         no_parallel = false;
 539                 }
 540 #endif  /* DISTRIBUTED */
 541         }
 542     }
 543 #endif
 544 
 545 #ifdef TEAMWARE_MAKE_CMN
 546         parallel_flag = true;
 547         /* XXX - This is a major hack for DMake/Licensing. */
 548         if (getenv(NOCATGETS("DMAKE_CHILD")) == NULL) {
 549                 if (!avo_cli_search_license(argv[0], dmake_exit_callback, TRUE, dmake_message_callback)) {
 550                         /*
 551                          * If the user can not get a TeamWare license,
 552                          * default to serial mode.
 553                          */
 554                         dmake_mode_type = serial_mode;
 555                         no_parallel = true;
 556                 } else {
 557                         putenv(NOCATGETS("DMAKE_CHILD=TRUE"));
 558                 }
 559                 start_time = time(NULL);
 560                 /*
 561                  * XXX - Hack to disable SIGALRM's from licensing library's
 562                  *       setitimer().
 563                  */
 564                 value.it_interval.tv_sec = 0;
 565                 value.it_interval.tv_usec = 0;
 566                 value.it_value.tv_sec = 0;
 567                 value.it_value.tv_usec = 0;
 568                 (void) setitimer(ITIMER_REAL, &value, NULL);
 569         }
 570 
 571 //
 572 // If dmake is running with -t option, set dmake_mode_type to serial.
 573 // This is done because doname() calls touch_command() that runs serially.
 574 // If we do not do that, maketool will have problems. 
 575 //
 576         if(touch) {
 577                 dmake_mode_type = serial_mode;
 578                 no_parallel = true;
 579         }
 580 #else
 581         parallel_flag = false;
 582 #endif
 583 
 584 #if defined (TEAMWARE_MAKE_CMN)
 585         /*
 586          * Check whether stdout and stderr are physically same.
 587          * This is in order to decide whether we need to redirect
 588          * stderr separately from stdout.
 589          * This check is performed only if __DMAKE_SEPARATE_STDERR


 857                         (void) unlink(rp->stderr_file);
 858                         retmem_mb(rp->stderr_file);
 859                         rp->stderr_file = NULL;
 860                 }
 861                 command_changed = true;
 862 /*
 863                 line = get_prop(rp->target->prop, line_prop);
 864                 if (line != NULL) {
 865                         line->body.line.command_used = NULL;
 866                 }
 867  */
 868         }
 869         /* Remove the statefile lock file if the file has been locked */
 870         if ((make_state_lockfile != NULL) && (make_state_locked)) {
 871                 (void) unlink(make_state_lockfile);
 872                 make_state_lockfile = NULL;
 873                 make_state_locked = false;
 874         }
 875         /* Write .make.state */
 876         write_state_file(1, (Boolean) 1);
 877 
 878 #ifdef TEAMWARE_MAKE_CMN
 879         // Deleting the usage tracking object sends the usage mail 
 880         cleanup->set_exit_status(exit_status);
 881         delete cleanup;
 882 #endif
 883 
 884 /*
 885 #ifdef DISTRIBUTED
 886     }
 887 #endif
 888  */
 889 
 890 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 891         job_adjust_fini();
 892 #endif
 893 
 894 #ifdef TEAMWARE_MAKE_CMN
 895         catclose(catd);
 896 #endif
 897 #ifdef DISTRIBUTED
 898         if (rxmPid > 0) {
 899                 // Tell rxm to exit by sending it an Avo_AcknowledgeMsg
 900                 Avo_AcknowledgeMsg acknowledgeMsg;
 901                 RWCollectable *msg = (RWCollectable *)&acknowledgeMsg;
 902 
 903                 int xdrResult = xdr(&xdrs_out, msg);


1852                        (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1853                        if (access(path, F_OK) == 0) {
1854                                 sccs_dir_path = path;
1855                                 done = 1;
1856                         } else {
1857                                 fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1858                         }
1859                     }
1860                 }
1861            }
1862         }
1863 }
1864 
1865 /*
1866  *      set_sgs_support()
1867  *
1868  *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1869  *        if it's not already in there.
1870  *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1871  *        the linker ld to report .make.state info back to make.






1872  */
1873 static void
1874 set_sgs_support()
1875 {
1876         int             len;
1877         char            *newpath;
1878         char            *oldpath;
1879         static char     *prev_path;
1880 
1881         oldpath = getenv(LD_SUPPORT_ENV_VAR);
1882         if (oldpath == NULL) {
1883                 len = strlen(LD_SUPPORT_ENV_VAR) + 1 +
1884                         strlen(LD_SUPPORT_MAKE_LIB) + 1;



1885                 newpath = (char *) malloc(len);
1886                 sprintf(newpath, "%s=", LD_SUPPORT_ENV_VAR);
1887         } else {
1888                 len = strlen(LD_SUPPORT_ENV_VAR) + 1 + strlen(oldpath) + 1 +
1889                         strlen(LD_SUPPORT_MAKE_LIB) + 1;






1890                 newpath = (char *) malloc(len);
1891                 sprintf(newpath, "%s=%s", LD_SUPPORT_ENV_VAR, oldpath);


























1892         }
1893 
1894 #if defined(TEAMWARE_MAKE_CMN)
1895 
1896         /* function maybe_append_str_to_env_var() is defined in avo_util library
1897          * Serial make should not use this library !!!
1898          */
1899         maybe_append_str_to_env_var(newpath, LD_SUPPORT_MAKE_LIB);
1900 #else
1901         if (oldpath == NULL) {
1902                 sprintf(newpath, "%s%s", newpath, LD_SUPPORT_MAKE_LIB);
1903         } else {
1904                 sprintf(newpath, "%s:%s", newpath, LD_SUPPORT_MAKE_LIB);
1905         }
1906 #endif
1907         putenv(newpath);
1908         if (prev_path) {
1909                 free(prev_path);
1910         }
1911         prev_path = newpath;






1912 }
1913 
1914 /*
1915  *      read_files_and_state(argc, argv)
1916  *
1917  *      Read the makefiles we care about and the environment
1918  *      Also read the = style command line options
1919  *
1920  *      Parameters:
1921  *              argc            You know what this is
1922  *              argv            You know what this is
1923  *
1924  *      Static variables used:
1925  *              env_wins        make -e, determines if env vars are RO
1926  *              ignore_default_mk make -r, determines if make.rules is read
1927  *              not_auto_depen  dwight
1928  *
1929  *      Global variables used:
1930  *              default_target_to_build Set to first proper target from file
1931  *              do_not_exec_rule Set to false when makfile is made




  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  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 #ifdef DISTRIBUTED
  42 #       include <dm/Avo_AcknowledgeMsg.h>
  43 #       include <rw/xdrstrea.h>
  44 #       include <dmrc/dmrc.h> /* dmakerc file processing */
  45 #endif
  46 
  47 #include <locale.h>               /* setlocale() */
  48 #include <mk/defs.h>
  49 #include <mksdmsi18n/mksdmsi18n.h>        /* libmksdmsi18n_init() */
  50 #include <mksh/macro.h>           /* getvar() */
  51 #include <mksh/misc.h>            /* getmem(), setup_char_semantics() */
  52 
  53 #if defined(TEAMWARE_MAKE_CMN)
  54 #endif
  55 
  56 #include <pwd.h>          /* getpwnam() */


  67 #include <sys/wait.h>             /* wait() */
  68 #include <unistd.h>               /* execv(), unlink(), access() */
  69 #include <vroot/report.h> /* report_dependency(), get_report_file() */
  70 
  71 // From read2.cc
  72 extern  Name            normalize_name(register wchar_t *name_string, register int length);
  73 
  74 // From parallel.cc
  75 #if defined(TEAMWARE_MAKE_CMN)
  76 #define MAXJOBS_ADJUST_RFE4694000
  77 
  78 #ifdef MAXJOBS_ADJUST_RFE4694000
  79 extern void job_adjust_fini();
  80 #endif /* MAXJOBS_ADJUST_RFE4694000 */
  81 #endif /* TEAMWARE_MAKE_CMN */
  82 
  83 
  84 /*
  85  * Defined macros
  86  */
  87 #define MAKE_PREFIX             NOCATGETS("/usr")
  88 #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT_32")
  89 #define LD_SUPPORT_ENV_VAR_32   NOCATGETS("SGS_SUPPORT_32")
  90 #define LD_SUPPORT_ENV_VAR_64   NOCATGETS("SGS_SUPPORT_64")
  91 #define LD_SUPPORT_MAKE_LIB     NOCATGETS("libmakestate.so.1")
  92 #define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib")
  93 #define LD_SUPPORT_MAKE_LIB_DIR_64      NOCATGETS("/64")
  94 
  95 /*
  96  * typedefs & structs
  97  */
  98 
  99 /*
 100  * Static variables
 101  */
 102 static  char            *argv_zero_string;
 103 static  Boolean         build_failed_ever_seen;
 104 static  Boolean         continue_after_error_ever_seen; /* `-k' */
 105 static  Boolean         dmake_group_specified;          /* `-g' */
 106 static  Boolean         dmake_max_jobs_specified;       /* `-j' */
 107 static  Boolean         dmake_mode_specified;           /* `-m' */
 108 static  Boolean         dmake_add_mode_specified;       /* `-x' */
 109 static  Boolean         dmake_output_mode_specified;    /* `-x DMAKE_OUTPUT_MODE=' */
 110 static  Boolean         dmake_compat_mode_specified;    /* `-x SUN_MAKE_COMPAT_MODE=' */
 111 static  Boolean         dmake_odir_specified;           /* `-o' */
 112 static  Boolean         dmake_rcfile_specified;         /* `-c' */
 113 static  Boolean         env_wins;                       /* `-e' */
 114 static  Boolean         ignore_default_mk;              /* `-r' */
 115 static  Boolean         list_all_targets;               /* `-T' */
 116 static  int             mf_argc;
 117 static  char            **mf_argv;
 118 static  Dependency_rec  not_auto_depen_struct;
 119 static  Dependency      not_auto_depen = &not_auto_depen_struct;
 120 static  Boolean         pmake_cap_r_specified;          /* `-R' */
 121 static  Boolean         pmake_machinesfile_specified;   /* `-M' */
 122 static  Boolean         stop_after_error_ever_seen;     /* `-S' */
 123 static  Boolean         trace_status;                   /* `-p' */
 124 
 125 #ifdef DMAKE_STATISTICS
 126 static  Boolean         getname_stat = false;
 127 #endif
 128 
 129 #if defined(TEAMWARE_MAKE_CMN)
 130         static  time_t          start_time;
 131         static  int             g_argc;
 132         static  char            **g_argv;

 133 #endif
 134 
 135 /*
 136  * File table of contents
 137  */
 138         extern "C" void         cleanup_after_exit(void);
 139 
 140 #ifdef TEAMWARE_MAKE_CMN
 141 extern "C" {
 142         extern  void            dmake_exit_callback(void);
 143         extern  void            dmake_message_callback(char *);
 144 }
 145 #endif
 146 
 147 extern  Name            normalize_name(register wchar_t *name_string, register int length);
 148 
 149 extern  int             main(int, char * []);
 150 
 151 static  void            append_makeflags_string(Name, String);
 152 static  void            doalarm(int);


 155 static  int             parse_command_option(char);
 156 static  void            read_command_options(int, char **);
 157 static  void            read_environment(Boolean);
 158 static  void            read_files_and_state(int, char **);
 159 static  Boolean         read_makefile(Name, Boolean, Boolean, Boolean);
 160 static  void            report_recursion(Name);
 161 static  void            set_sgs_support(void);
 162 static  void            setup_for_projectdir(void);
 163 static  void            setup_makeflags_argv(void);
 164 static  void            report_dir_enter_leave(Boolean entering);
 165 
 166 extern void expand_value(Name, register String , Boolean);
 167 
 168 #ifdef DISTRIBUTED
 169         extern  int             dmake_ofd;
 170         extern  FILE*           dmake_ofp;
 171         extern  int             rxmPid;
 172         extern  XDR             xdrs_out;
 173 #endif
 174 #ifdef TEAMWARE_MAKE_CMN
 175         static const char       verstring[] = "illumos make";
 176 #endif
 177 
 178 jmp_buf jmpbuffer;
 179 extern nl_catd catd;
 180 
 181 /*
 182  *      main(argc, argv)
 183  *
 184  *      Parameters:
 185  *              argc                    You know what this is
 186  *              argv                    You know what this is
 187  *
 188  *      Static variables used:
 189  *              list_all_targets        make -T seen
 190  *              trace_status            make -p seen
 191  *
 192  *      Global variables used:
 193  *              debug_level             Should we trace make actions?
 194  *              keep_state              Set if .KEEP_STATE seen
 195  *              makeflags               The Name "MAKEFLAGS", used to get macro


 210          */
 211         register char           *cp;
 212         char                    make_state_dir[MAXPATHLEN];
 213         Boolean                 parallel_flag = false;
 214         char                    *prognameptr;
 215         char                    *slash_ptr;
 216         mode_t                  um;
 217         int                     i;
 218 #ifdef TEAMWARE_MAKE_CMN
 219         struct itimerval        value;
 220         char                    def_dmakerc_path[MAXPATHLEN];
 221         Name                    dmake_name, dmake_name2;
 222         Name                    dmake_value, dmake_value2;
 223         Property                prop, prop2;
 224         struct stat             statbuf;
 225         int                     statval;
 226 #endif
 227 
 228         struct stat             out_stat, err_stat;
 229         hostid = gethostid();



 230         bsd_signals();
 231 
 232         (void) setlocale(LC_ALL, "");
 233 
 234 
 235 #ifdef DMAKE_STATISTICS
 236         if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
 237                 getname_stat = true;
 238         }
 239 #endif
 240 













 241 #if defined(TEAMWARE_MAKE_CMN)
 242         catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);

 243 #endif
 244 
 245 // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
 246 
 247 
 248 #if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL)
 249 /*
 250  * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
 251  * from avo_util library. 
 252  */
 253         libmksdmsi18n_init();
 254 #endif
 255 
 256 
 257 #ifndef TEAMWARE_MAKE_CMN
 258         textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
 259 #endif /* TEAMWARE_MAKE_CMN */
 260 
 261 #ifdef TEAMWARE_MAKE_CMN
 262         g_argc = argc;


 496                                         Avo_err         *err = rcfile->read(def_dmakerc_path, NULL, TRUE);
 497                                         if (err) {
 498                                                 fatal(err->str);
 499                                         }
 500                                         empty_dmakerc = rcfile->was_empty();
 501                                         delete rcfile;
 502                                 }
 503                         }
 504                         if (empty_dmakerc) {
 505                                 if (getenv(NOCATGETS("DMAKE_DEF_PRINTED")) == NULL) {
 506                                         putenv(NOCATGETS("DMAKE_DEF_PRINTED=TRUE"));
 507                                         (void) fprintf(stdout, catgets(catd, 1, 302, "dmake: defaulting to parallel mode.\n"));
 508                                         (void) fprintf(stdout, catgets(catd, 1, 303, "See the man page dmake(1) for more information on setting up the .dmakerc file.\n"));
 509                                 }
 510                                 dmake_mode_type = parallel_mode;
 511                                 no_parallel = false;
 512                         }
 513                 }
 514 #else
 515                 if(dmake_mode_type == distributed_mode) {


 516                         dmake_mode_type = parallel_mode;
 517                         no_parallel = false;
 518                 }
 519 #endif  /* DISTRIBUTED */
 520         }
 521     }
 522 #endif
 523 
 524 #ifdef TEAMWARE_MAKE_CMN
 525         parallel_flag = true;
 526         putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));






















 527 
 528 //
 529 // If dmake is running with -t option, set dmake_mode_type to serial.
 530 // This is done because doname() calls touch_command() that runs serially.
 531 // If we do not do that, maketool will have problems. 
 532 //
 533         if(touch) {
 534                 dmake_mode_type = serial_mode;
 535                 no_parallel = true;
 536         }
 537 #else
 538         parallel_flag = false;
 539 #endif
 540 
 541 #if defined (TEAMWARE_MAKE_CMN)
 542         /*
 543          * Check whether stdout and stderr are physically same.
 544          * This is in order to decide whether we need to redirect
 545          * stderr separately from stdout.
 546          * This check is performed only if __DMAKE_SEPARATE_STDERR


 814                         (void) unlink(rp->stderr_file);
 815                         retmem_mb(rp->stderr_file);
 816                         rp->stderr_file = NULL;
 817                 }
 818                 command_changed = true;
 819 /*
 820                 line = get_prop(rp->target->prop, line_prop);
 821                 if (line != NULL) {
 822                         line->body.line.command_used = NULL;
 823                 }
 824  */
 825         }
 826         /* Remove the statefile lock file if the file has been locked */
 827         if ((make_state_lockfile != NULL) && (make_state_locked)) {
 828                 (void) unlink(make_state_lockfile);
 829                 make_state_lockfile = NULL;
 830                 make_state_locked = false;
 831         }
 832         /* Write .make.state */
 833         write_state_file(1, (Boolean) 1);







 834 /*
 835 #ifdef DISTRIBUTED
 836     }
 837 #endif
 838  */
 839 
 840 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 841         job_adjust_fini();
 842 #endif
 843 
 844 #ifdef TEAMWARE_MAKE_CMN
 845         catclose(catd);
 846 #endif
 847 #ifdef DISTRIBUTED
 848         if (rxmPid > 0) {
 849                 // Tell rxm to exit by sending it an Avo_AcknowledgeMsg
 850                 Avo_AcknowledgeMsg acknowledgeMsg;
 851                 RWCollectable *msg = (RWCollectable *)&acknowledgeMsg;
 852 
 853                 int xdrResult = xdr(&xdrs_out, msg);


1802                        (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1803                        if (access(path, F_OK) == 0) {
1804                                 sccs_dir_path = path;
1805                                 done = 1;
1806                         } else {
1807                                 fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1808                         }
1809                     }
1810                 }
1811            }
1812         }
1813 }
1814 
1815 /*
1816  *      set_sgs_support()
1817  *
1818  *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1819  *        if it's not already in there.
1820  *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1821  *        the linker ld to report .make.state info back to make.
1822  *
1823  * In the new world we always will set the 32-bit and 64-bit versions of this
1824  * variable explicitly so that we can take into account the correct isa and our
1825  * prefix. So say that the prefix was /opt/local. Then we would want to search
1826  * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1827  * the original location just as a safety measure.
1828  */
1829 static void
1830 set_sgs_support()
1831 {
1832         int             len;
1833         char            *newpath, *newpath64;
1834         char            *oldpath, *oldpath64;
1835         static char     *prev_path, *prev_path64;
1836 
1837         oldpath = getenv(LD_SUPPORT_ENV_VAR_32);
1838         if (oldpath == NULL) {
1839                 len = snprintf(NULL, 0, "%s=%s/%s/%s:%s",
1840                     LD_SUPPORT_ENV_VAR_32,
1841                     MAKE_PREFIX,
1842                     LD_SUPPORT_MAKE_LIB_DIR,
1843                     LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1844                 newpath = (char *) malloc(len);
1845                 sprintf(newpath, "%s=%s/%s/%s:%s",
1846                     LD_SUPPORT_ENV_VAR_32,
1847                     MAKE_PREFIX,
1848                     LD_SUPPORT_MAKE_LIB_DIR,
1849                     LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
1850         } else {
1851                 len = snprintf(NULL, 0, "%s=%s:%s/%s/%s:%s",
1852                     LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1853                     LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1854                     LD_SUPPORT_MAKE_LIB) + 1;
1855                 newpath = (char *) malloc(len);
1856                 sprintf(newpath, "%s=%s:%s/%s/%s:%s",
1857                     LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1858                     LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1859                     LD_SUPPORT_MAKE_LIB);
1860         }
1861 
1862         oldpath64 = getenv(LD_SUPPORT_ENV_VAR_64);
1863         if (oldpath64 == NULL) {
1864                 len = snprintf(NULL, 0, "%s=%s/%s/%s/%s:%s",
1865                     LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1866                     LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1867                     LD_SUPPORT_MAKE_LIB) + 1;
1868                 newpath64 = (char *) malloc(len);
1869                 sprintf(newpath64, "%s=%s/%s/%s/%s:%s",
1870                     LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1871                     LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1872                     LD_SUPPORT_MAKE_LIB);
1873         } else {
1874                 len = snprintf(NULL, 0, "%s=%s:%s/%s/%s/%s:%s",
1875                     LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1876                     LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1877                     LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1878                 newpath64 = (char *) malloc(len);
1879                 sprintf(newpath64, "%s=%s:%s/%s/%s/%s:%s",
1880                     LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1881                     LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1882                     LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
1883         }
1884 













1885         putenv(newpath);
1886         if (prev_path) {
1887                 free(prev_path);
1888         }
1889         prev_path = newpath;
1890 
1891         putenv(newpath64);
1892         if (prev_path64) {
1893                 free(prev_path64);
1894         }
1895         prev_path64 = newpath64;
1896 }
1897 
1898 /*
1899  *      read_files_and_state(argc, argv)
1900  *
1901  *      Read the makefiles we care about and the environment
1902  *      Also read the = style command line options
1903  *
1904  *      Parameters:
1905  *              argc            You know what this is
1906  *              argv            You know what this is
1907  *
1908  *      Static variables used:
1909  *              env_wins        make -e, determines if env vars are RO
1910  *              ignore_default_mk make -r, determines if make.rules is read
1911  *              not_auto_depen  dwight
1912  *
1913  *      Global variables used:
1914  *              default_target_to_build Set to first proper target from file
1915  *              do_not_exec_rule Set to false when makfile is made