Print this page
    
make: unifdef for TEAMWARE_MAKE_CMN (defined)
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/make/bin/main.cc
          +++ new/usr/src/cmd/make/bin/main.cc
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*
  27   27   *      main.cc
  28   28   *
  29   29   *      make program main routine plus some helper routines
  30   30   */
  31   31   
  32   32  /*
  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   43  #include <mk/defs.h>
  44   44  #include <mksdmsi18n/mksdmsi18n.h>      /* libmksdmsi18n_init() */
  45   45  #include <mksh/macro.h>         /* getvar() */
  46   46  #include <mksh/misc.h>          /* getmem(), setup_char_semantics() */
  47   47  
  48   48  #if defined(TEAMWARE_MAKE_CMN)
  49   49  #endif
  50   50  
  51   51  #include <pwd.h>                /* getpwnam() */
  52   52  #include <setjmp.h>
  53   53  #include <signal.h>
  54   54  #include <stdlib.h>
  55   55  #include <sys/errno.h>          /* ENOENT */
  56   56  #include <sys/stat.h>           /* fstat() */
  57   57  #include <fcntl.h>              /* open() */
  58   58  
  59   59  #       include <sys/systeminfo.h>      /* sysinfo() */
  
    | 
      ↓ open down ↓ | 
    59 lines elided | 
    
      ↑ open up ↑ | 
  
  60   60  
  61   61  #include <sys/types.h>          /* stat() */
  62   62  #include <sys/wait.h>           /* wait() */
  63   63  #include <unistd.h>             /* execv(), unlink(), access() */
  64   64  #include <vroot/report.h>       /* report_dependency(), get_report_file() */
  65   65  
  66   66  // From read2.cc
  67   67  extern  Name            normalize_name(register wchar_t *name_string, register int length);
  68   68  
  69   69  // From parallel.cc
  70      -#if defined(TEAMWARE_MAKE_CMN)
  71   70  #define MAXJOBS_ADJUST_RFE4694000
  72   71  
  73   72  #ifdef MAXJOBS_ADJUST_RFE4694000
  74   73  extern void job_adjust_fini();
  75   74  #endif /* MAXJOBS_ADJUST_RFE4694000 */
  76      -#endif /* TEAMWARE_MAKE_CMN */
  77   75  
  78   76  
  79   77  /*
  80   78   * Defined macros
  81   79   */
  82   80  #define MAKE_PREFIX             NOCATGETS("/usr")
  83   81  #define LD_SUPPORT_ENV_VAR      NOCATGETS("SGS_SUPPORT_32")
  84   82  #define LD_SUPPORT_ENV_VAR_32   NOCATGETS("SGS_SUPPORT_32")
  85   83  #define LD_SUPPORT_ENV_VAR_64   NOCATGETS("SGS_SUPPORT_64")
  86   84  #define LD_SUPPORT_MAKE_LIB     NOCATGETS("libmakestate.so.1")
  87   85  #define LD_SUPPORT_MAKE_LIB_DIR NOCATGETS("/lib")
  88   86  #define LD_SUPPORT_MAKE_LIB_DIR_64      NOCATGETS("/64")
  89   87  
  90   88  /*
  91   89   * typedefs & structs
  92   90   */
  93   91  
  94   92  /*
  95   93   * Static variables
  96   94   */
  97   95  static  char            *argv_zero_string;
  98   96  static  Boolean         build_failed_ever_seen;
  99   97  static  Boolean         continue_after_error_ever_seen; /* `-k' */
 100   98  static  Boolean         dmake_group_specified;          /* `-g' */
 101   99  static  Boolean         dmake_max_jobs_specified;       /* `-j' */
 102  100  static  Boolean         dmake_mode_specified;           /* `-m' */
 103  101  static  Boolean         dmake_add_mode_specified;       /* `-x' */
 104  102  static  Boolean         dmake_output_mode_specified;    /* `-x DMAKE_OUTPUT_MODE=' */
 105  103  static  Boolean         dmake_compat_mode_specified;    /* `-x SUN_MAKE_COMPAT_MODE=' */
 106  104  static  Boolean         dmake_odir_specified;           /* `-o' */
 107  105  static  Boolean         dmake_rcfile_specified;         /* `-c' */
 108  106  static  Boolean         env_wins;                       /* `-e' */
 109  107  static  Boolean         ignore_default_mk;              /* `-r' */
 110  108  static  Boolean         list_all_targets;               /* `-T' */
 111  109  static  int             mf_argc;
 112  110  static  char            **mf_argv;
 113  111  static  Dependency_rec  not_auto_depen_struct;
  
    | 
      ↓ open down ↓ | 
    27 lines elided | 
    
      ↑ open up ↑ | 
  
 114  112  static  Dependency      not_auto_depen = ¬_auto_depen_struct;
 115  113  static  Boolean         pmake_cap_r_specified;          /* `-R' */
 116  114  static  Boolean         pmake_machinesfile_specified;   /* `-M' */
 117  115  static  Boolean         stop_after_error_ever_seen;     /* `-S' */
 118  116  static  Boolean         trace_status;                   /* `-p' */
 119  117  
 120  118  #ifdef DMAKE_STATISTICS
 121  119  static  Boolean         getname_stat = false;
 122  120  #endif
 123  121  
 124      -#if defined(TEAMWARE_MAKE_CMN)
 125  122          static  time_t          start_time;
 126  123          static  int             g_argc;
 127  124          static  char            **g_argv;
 128      -#endif
 129  125  
 130  126  /*
 131  127   * File table of contents
 132  128   */
 133  129          extern "C" void         cleanup_after_exit(void);
 134  130  
 135      -#ifdef TEAMWARE_MAKE_CMN
 136  131  extern "C" {
 137  132          extern  void            dmake_exit_callback(void);
 138  133          extern  void            dmake_message_callback(char *);
 139  134  }
 140      -#endif
 141  135  
 142  136  extern  Name            normalize_name(register wchar_t *name_string, register int length);
 143  137  
 144  138  extern  int             main(int, char * []);
 145  139  
 146  140  static  void            append_makeflags_string(Name, String);
 147  141  static  void            doalarm(int);
 148  142  static  void            enter_argv_values(int , char **, ASCII_Dyn_Array *);
 149  143  static  void            make_targets(int, char **, Boolean);
 150  144  static  int             parse_command_option(char);
 151  145  static  void            read_command_options(int, char **);
 152  146  static  void            read_environment(Boolean);
  
    | 
      ↓ open down ↓ | 
    2 lines elided | 
    
      ↑ open up ↑ | 
  
 153  147  static  void            read_files_and_state(int, char **);
 154  148  static  Boolean         read_makefile(Name, Boolean, Boolean, Boolean);
 155  149  static  void            report_recursion(Name);
 156  150  static  void            set_sgs_support(void);
 157  151  static  void            setup_for_projectdir(void);
 158  152  static  void            setup_makeflags_argv(void);
 159  153  static  void            report_dir_enter_leave(Boolean entering);
 160  154  
 161  155  extern void expand_value(Name, register String , Boolean);
 162  156  
 163      -#ifdef TEAMWARE_MAKE_CMN
 164      -        static const char       verstring[] = "illumos make";
 165      -#endif
      157 +static const char       verstring[] = "illumos make";
 166  158  
 167  159  jmp_buf jmpbuffer;
 168  160  extern nl_catd catd;
 169  161  
 170  162  /*
 171  163   *      main(argc, argv)
 172  164   *
 173  165   *      Parameters:
 174  166   *              argc                    You know what this is
 175  167   *              argv                    You know what this is
 176  168   *
 177  169   *      Static variables used:
 178  170   *              list_all_targets        make -T seen
 179  171   *              trace_status            make -p seen
 180  172   *
 181  173   *      Global variables used:
 182  174   *              debug_level             Should we trace make actions?
 183  175   *              keep_state              Set if .KEEP_STATE seen
 184  176   *              makeflags               The Name "MAKEFLAGS", used to get macro
 185  177   *              remote_command_name     Name of remote invocation cmd ("on")
 186  178   *              running_list            List of parallel running processes
 187  179   *              stdout_stderr_same      true if stdout and stderr are the same
 188  180   *              auto_dependencies       The Name "SUNPRO_DEPENDENCIES"
 189  181   *              temp_file_directory     Set to the dir where we create tmp file
 190  182   *              trace_reader            Set to reflect tracing status
 191  183   *              working_on_targets      Set when building user targets
 192  184   */
 193  185  int
 194  186  main(int argc, char *argv[])
 195  187  {
 196  188          /*
  
    | 
      ↓ open down ↓ | 
    21 lines elided | 
    
      ↑ open up ↑ | 
  
 197  189           * cp is a -> to the value of the MAKEFLAGS env var,
 198  190           * which has to be regular chars.
 199  191           */
 200  192          register char           *cp;
 201  193          char                    make_state_dir[MAXPATHLEN];
 202  194          Boolean                 parallel_flag = false;
 203  195          char                    *prognameptr;
 204  196          char                    *slash_ptr;
 205  197          mode_t                  um;
 206  198          int                     i;
 207      -#ifdef TEAMWARE_MAKE_CMN
 208  199          struct itimerval        value;
 209  200          char                    def_dmakerc_path[MAXPATHLEN];
 210  201          Name                    dmake_name, dmake_name2;
 211  202          Name                    dmake_value, dmake_value2;
 212  203          Property                prop, prop2;
 213  204          struct stat             statbuf;
 214  205          int                     statval;
 215      -#endif
 216  206  
 217  207          struct stat             out_stat, err_stat;
 218  208          hostid = gethostid();
 219  209          bsd_signals();
 220  210  
 221  211          (void) setlocale(LC_ALL, "");
 222  212  
 223  213  
 224  214  #ifdef DMAKE_STATISTICS
 225  215          if (getenv(NOCATGETS("DMAKE_STATISTICS"))) {
 226  216                  getname_stat = true;
 227  217          }
 228  218  #endif
 229  219  
 230      -#if defined(TEAMWARE_MAKE_CMN)
 231  220          catd = catopen(AVO_DOMAIN_DMAKE, NL_CAT_LOCALE);
 232      -#endif
 233  221  
 234  222  // ---> fprintf(stderr, catgets(catd, 15, 666, "--- SUN make ---\n"));
 235  223  
 236  224  
 237      -#if defined(TEAMWARE_MAKE_CMN)
 238  225  /*
 239  226   * I put libmksdmsi18n_init() under #ifdef because it requires avo_i18n_init()
 240  227   * from avo_util library. 
 241  228   */
 242  229          libmksdmsi18n_init();
 243      -#endif
 244  230  
 245  231  
 246      -#ifndef TEAMWARE_MAKE_CMN
 247  232          textdomain(NOCATGETS("SUNW_SPRO_MAKE"));
 248      -#endif /* TEAMWARE_MAKE_CMN */
 249  233  
 250      -#ifdef TEAMWARE_MAKE_CMN
 251  234          g_argc = argc;
 252  235          g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
 253  236          for (i = 0; i < argc; i++) {
 254  237                  g_argv[i] = argv[i];
 255  238          }
 256  239          g_argv[i] = NULL;
 257      -#endif /* TEAMWARE_MAKE_CMN */
 258  240  
 259  241          /*
 260  242           * Set argv_zero_string to some form of argv[0] for
 261  243           * recursive MAKE builds.
 262  244           */
 263  245  
 264  246          if (*argv[0] == (int) slash_char) {
 265  247                  /* argv[0] starts with a slash */
 266  248                  argv_zero_string = strdup(argv[0]);
 267  249          } else if (strchr(argv[0], (int) slash_char) == NULL) {
 268  250                  /* argv[0] contains no slashes */
 269  251                  argv_zero_string = strdup(argv[0]);
 270  252          } else {
 271  253                  /*
 272  254                   * argv[0] contains at least one slash,
 273  255                   * but doesn't start with a slash
 274  256                   */
 275  257                  char    *tmp_current_path;
 276  258                  char    *tmp_string;
 277  259  
 278  260                  tmp_current_path = get_current_path();
 279  261                  tmp_string = getmem(strlen(tmp_current_path) + 1 +
 280  262                                      strlen(argv[0]) + 1);
 281  263                  (void) sprintf(tmp_string,
 282  264                                 "%s/%s",
 283  265                                 tmp_current_path,
 284  266                                 argv[0]);
 285  267                  argv_zero_string = strdup(tmp_string);
 286  268                  retmem_mb(tmp_string);
 287  269          }
 288  270  
 289  271          /* 
 290  272           * The following flags are reset if we don't have the 
 291  273           * (.nse_depinfo or .make.state) files locked and only set 
 292  274           * AFTER the file has been locked. This ensures that if the user
 293  275           * interrupts the program while file_lock() is waiting to lock
 294  276           * the file, the interrupt handler doesn't remove a lock 
 295  277           * that doesn't belong to us.
 296  278           */
 297  279          make_state_lockfile = NULL;
 298  280          make_state_locked = false;
 299  281  
 300  282  
 301  283          /*
 302  284           * look for last slash char in the path to look at the binary 
 303  285           * name. This is to resolve the hard link and invoke make
 304  286           * in svr4 mode.
 305  287           */
 306  288  
 307  289          /* Sun OS make standart */
 308  290          svr4 = false;  
 309  291          posix = false;
 310  292          if(!strcmp(argv_zero_string, NOCATGETS("/usr/xpg4/bin/make"))) {
 311  293                  svr4 = false;
 312  294                  posix = true;
 313  295          } else {
 314  296                  prognameptr = strrchr(argv[0], '/');
 315  297                  if(prognameptr) {
 316  298                          prognameptr++;
 317  299                  } else {
 318  300                          prognameptr = argv[0];
 319  301                  }
 320  302                  if(!strcmp(prognameptr, NOCATGETS("svr4.make"))) {
 321  303                          svr4 = true;
 322  304                          posix = false;
 323  305                  }
 324  306          }
 325  307          if (getenv(USE_SVR4_MAKE) || getenv(NOCATGETS("USE_SVID"))){
 326  308             svr4 = true;
 327  309             posix = false;
 328  310          }
 329  311  
 330  312          /*
 331  313           * Find the dmake_compat_mode: posix, sun, svr4, or gnu_style, .
 332  314           */
 333  315          char * dmake_compat_mode_var = getenv(NOCATGETS("SUN_MAKE_COMPAT_MODE"));
 334  316          if (dmake_compat_mode_var != NULL) {
 335  317                  if (0 == strcasecmp(dmake_compat_mode_var, NOCATGETS("GNU"))) {
 336  318                          gnu_style = true;
 337  319                  }
 338  320                  //svr4 = false;
 339  321                  //posix = false;
 340  322          }
 341  323  
 342  324          /*
 343  325           * Temporary directory set up.
 344  326           */
 345  327          char * tmpdir_var = getenv(NOCATGETS("TMPDIR"));
 346  328          if (tmpdir_var != NULL && *tmpdir_var == '/' && strlen(tmpdir_var) < MAXPATHLEN) {
 347  329                  strcpy(mbs_buffer, tmpdir_var);
 348  330                  for (tmpdir_var = mbs_buffer+strlen(mbs_buffer);
 349  331                          *(--tmpdir_var) == '/' && tmpdir_var > mbs_buffer;
 350  332                          *tmpdir_var = '\0');
 351  333                  if (strlen(mbs_buffer) + 32 < MAXPATHLEN) { /* 32 = strlen("/dmake.stdout.%d.%d.XXXXXX") */
 352  334                          sprintf(mbs_buffer2, NOCATGETS("%s/dmake.tst.%d.XXXXXX"),
 353  335                                  mbs_buffer, getpid());
 354  336                          int fd = mkstemp(mbs_buffer2);
 355  337                          if (fd >= 0) {
 356  338                                  close(fd);
 357  339                                  unlink(mbs_buffer2);
 358  340                                  tmpdir = strdup(mbs_buffer);
 359  341                          }
 360  342                  }
 361  343          }
 362  344  
 363  345          /* find out if stdout and stderr point to the same place */
 364  346          if (fstat(1, &out_stat) < 0) {
 365  347                  fatal(catgets(catd, 1, 165, "fstat of standard out failed: %s"), errmsg(errno));
 366  348          }
 367  349          if (fstat(2, &err_stat) < 0) {
 368  350                  fatal(catgets(catd, 1, 166, "fstat of standard error failed: %s"), errmsg(errno));
 369  351          }
 370  352          if ((out_stat.st_dev == err_stat.st_dev) &&
 371  353              (out_stat.st_ino == err_stat.st_ino)) {
 372  354                  stdout_stderr_same = true;
 373  355          } else {
 374  356                  stdout_stderr_same = false;
 375  357          }
 376  358          /* Make the vroot package scan the path using shell semantics */
 377  359          set_path_style(0);
 378  360  
 379  361          setup_char_semantics();
 380  362  
 381  363          setup_for_projectdir();
 382  364  
 383  365          /*
 384  366           * If running with .KEEP_STATE, curdir will be set with
 385  367           * the connected directory.
 386  368           */
 387  369          (void) atexit(cleanup_after_exit);
 388  370  
 389  371          load_cached_names();
 390  372  
 391  373  /*
 392  374   *      Set command line flags
 393  375   */
 394  376          setup_makeflags_argv();
 395  377          read_command_options(mf_argc, mf_argv);
  
    | 
      ↓ open down ↓ | 
    128 lines elided | 
    
      ↑ open up ↑ | 
  
 396  378          read_command_options(argc, argv);
 397  379          if (debug_level > 0) {
 398  380                  cp = getenv(makeflags->string_mb);
 399  381                  (void) printf(catgets(catd, 1, 167, "MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
 400  382          }
 401  383  
 402  384          setup_interrupt(handle_interrupt);
 403  385  
 404  386          read_files_and_state(argc, argv);
 405  387  
 406      -#ifdef TEAMWARE_MAKE_CMN
 407  388          /*
 408  389           * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
 409  390           */
 410  391          MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
 411  392          dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
 412  393          prop2 = get_prop(dmake_name2->prop, macro_prop);
 413  394          if (prop2 == NULL) {
 414  395                  /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
 415  396                  output_mode = txt1_mode;
 416  397          } else {
 417  398                  dmake_value2 = prop2->body.macro.value;
 418  399                  if ((dmake_value2 == NULL) ||
 419  400                      (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT1")))) {
 420  401                          output_mode = txt1_mode;
 421  402                  } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("TXT2"))) {
 422  403                          output_mode = txt2_mode;
 423  404                  } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("HTML1"))) {
 424  405                          output_mode = html1_mode;
 425  406                  } else {
 426  407                          warning(catgets(catd, 1, 352, "Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
 427  408                                dmake_value2->string_mb);
 428  409                  }
 429  410          }
 430  411          /*
 431  412           * Find the dmake_mode: distributed, parallel, or serial.
 432  413           */
 433  414      if ((!pmake_cap_r_specified) &&
 434  415          (!pmake_machinesfile_specified)) {
 435  416          MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
 436  417          dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
 437  418          prop2 = get_prop(dmake_name2->prop, macro_prop);
 438  419          if (prop2 == NULL) {
 439  420                  /* DMAKE_MODE not defined, default to distributed mode */
 440  421                  dmake_mode_type = distributed_mode;
 441  422                  no_parallel = false;
 442  423          } else {
 443  424                  dmake_value2 = prop2->body.macro.value;
 444  425                  if ((dmake_value2 == NULL) ||
 445  426                      (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("distributed")))) {
 446  427                          dmake_mode_type = distributed_mode;
 447  428                          no_parallel = false;
 448  429                  } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("parallel"))) {
 449  430                          dmake_mode_type = parallel_mode;
 450  431                          no_parallel = false;
 451  432                  } else if (IS_EQUAL(dmake_value2->string_mb, NOCATGETS("serial"))) {
 452  433                          dmake_mode_type = serial_mode;
 453  434                          no_parallel = true;
 454  435                  } else {
 455  436                          fatal(catgets(catd, 1, 307, "Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
 456  437                  }
 457  438          }
 458  439  
 459  440          if ((!list_all_targets) &&
 460  441              (report_dependencies_level == 0)) {
 461  442                  /*
 462  443                   * Check to see if either DMAKE_RCFILE or DMAKE_MODE is defined.
 463  444                   * They could be defined in the env, in the makefile, or on the
  
    | 
      ↓ open down ↓ | 
    47 lines elided | 
    
      ↑ open up ↑ | 
  
 464  445                   * command line.
 465  446                   * If neither is defined, and $(HOME)/.dmakerc does not exists,
 466  447                   * then print a message, and default to parallel mode.
 467  448                   */
 468  449                  if(dmake_mode_type == distributed_mode) {
 469  450                          dmake_mode_type = parallel_mode;
 470  451                          no_parallel = false;
 471  452                  }
 472  453          }
 473  454      }
 474      -#endif
 475  455  
 476      -#ifdef TEAMWARE_MAKE_CMN
 477  456          parallel_flag = true;
 478  457          putenv(strdup(NOCATGETS("DMAKE_CHILD=TRUE")));
 479  458  
 480  459  //
 481  460  // If dmake is running with -t option, set dmake_mode_type to serial.
 482  461  // This is done because doname() calls touch_command() that runs serially.
 483  462  // If we do not do that, maketool will have problems. 
 484  463  //
 485  464          if(touch) {
 486  465                  dmake_mode_type = serial_mode;
 487  466                  no_parallel = true;
 488  467          }
 489      -#else
 490      -        parallel_flag = false;
 491      -#endif
 492  468  
 493      -#if defined (TEAMWARE_MAKE_CMN)
 494  469          /*
 495  470           * Check whether stdout and stderr are physically same.
 496  471           * This is in order to decide whether we need to redirect
 497  472           * stderr separately from stdout.
 498  473           * This check is performed only if __DMAKE_SEPARATE_STDERR
 499  474           * is not set. This variable may be used in order to preserve
 500  475           * the 'old' behaviour.
 501  476           */
 502  477          out_err_same = true;
 503  478          char * dmake_sep_var = getenv(NOCATGETS("__DMAKE_SEPARATE_STDERR"));
 504  479          if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, NOCATGETS("NO")))) {
 505  480                  struct stat stdout_stat;
 506  481                  struct stat stderr_stat;
  
    | 
      ↓ open down ↓ | 
    3 lines elided | 
    
      ↑ open up ↑ | 
  
 507  482                  if( (fstat(1, &stdout_stat) == 0)
 508  483                   && (fstat(2, &stderr_stat) == 0) )
 509  484                  {
 510  485                          if( (stdout_stat.st_dev != stderr_stat.st_dev)
 511  486                           || (stdout_stat.st_ino != stderr_stat.st_ino) )
 512  487                          {
 513  488                                  out_err_same = false;
 514  489                          }
 515  490                  }
 516  491          }
 517      -#endif
 518  492  
 519  493                  
 520  494  /*
 521  495   *      Enable interrupt handler for alarms
 522  496   */
 523  497          (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
 524  498  
 525  499  /*
 526  500   *      Check if make should report
 527  501   */
 528  502          if (getenv(sunpro_dependencies->string_mb) != NULL) {
 529  503                  FILE    *report_file;
 530  504  
 531  505                  report_dependency("");
 532  506                  report_file = get_report_file();
 533  507                  if ((report_file != NULL) && (report_file != (FILE*)-1)) {
 534  508                          (void) fprintf(report_file, "\n");
 535  509                  }
 536  510          }
 537  511  
 538  512  /*
 539  513   *      Make sure SUNPRO_DEPENDENCIES is exported (or not) properly.
 540  514   */
 541  515          if (keep_state) {
 542  516                  maybe_append_prop(sunpro_dependencies, macro_prop)->
 543  517                    body.macro.exported = true;
 544  518          } else {
 545  519                  maybe_append_prop(sunpro_dependencies, macro_prop)->
 546  520                    body.macro.exported = false;
 547  521          }
 548  522  
 549  523          working_on_targets = true;
 550  524          if (trace_status) {
 551  525                  dump_make_state();
 552  526                  fclose(stdout);
 553  527                  fclose(stderr);
 554  528                  exit_status = 0;
 555  529                  exit(0);
 556  530          }
 557  531          if (list_all_targets) {
 558  532                  dump_target_list();
 559  533                  fclose(stdout);
 560  534                  fclose(stderr);
 561  535                  exit_status = 0;
 562  536                  exit(0);
 563  537          }
 564  538          trace_reader = false;
 565  539  
 566  540          /*
 567  541           * Set temp_file_directory to the directory the .make.state
 568  542           * file is written to.
 569  543           */
 570  544          if ((slash_ptr = strrchr(make_state->string_mb, (int) slash_char)) == NULL) {
 571  545                  temp_file_directory = strdup(get_current_path());
 572  546          } else {
 573  547                  *slash_ptr = (int) nul_char;
 574  548                  (void) strcpy(make_state_dir, make_state->string_mb);
 575  549                  *slash_ptr = (int) slash_char;
 576  550                     /* when there is only one slash and it's the first
 577  551                     ** character, make_state_dir should point to '/'.
 578  552                     */
 579  553                  if(make_state_dir[0] == '\0') {
 580  554                     make_state_dir[0] = '/';
 581  555                     make_state_dir[1] = '\0';
 582  556                  }
 583  557                  if (make_state_dir[0] == (int) slash_char) {
 584  558                          temp_file_directory = strdup(make_state_dir);
 585  559                  } else {
 586  560                          char    tmp_current_path2[MAXPATHLEN];
 587  561   
 588  562                          (void) sprintf(tmp_current_path2,
 589  563                                         "%s/%s",
 590  564                                         get_current_path(),
 591  565                                         make_state_dir);
 592  566                          temp_file_directory = strdup(tmp_current_path2);
 593  567                  }
 594  568          }
 595  569  
 596  570  
 597  571          report_dir_enter_leave(true);
 598  572  
 599  573          make_targets(argc, argv, parallel_flag);
 600  574  
 601  575          report_dir_enter_leave(false);
 602  576  
 603  577          if (build_failed_ever_seen) {
 604  578                  if (posix) {
 605  579                          exit_status = 1;
 606  580                  }
 607  581                  exit(1);
 608  582          }
 609  583          exit_status = 0;
 610  584          exit(0);
 611  585          /* NOTREACHED */
 612  586  }
 613  587  
 614  588  /*
 615  589   *      cleanup_after_exit()
 616  590   *
 617  591   *      Called from exit(), performs cleanup actions.
 618  592   *
 619  593   *      Parameters:
 620  594   *              status          The argument exit() was called with
 621  595   *              arg             Address of an argument vector to
 622  596   *                              cleanup_after_exit()
 623  597   *
 624  598   *      Global variables used:
 625  599   *              command_changed Set if we think .make.state should be rewritten
 626  600   *              current_line    Is set we set commands_changed
 627  601   *              do_not_exec_rule
 628  602   *                              True if -n flag on
 629  603   *              done            The Name ".DONE", rule we run
 630  604   *              keep_state      Set if .KEEP_STATE seen
 631  605   *              parallel        True if building in parallel
 632  606   *              quest           If -q is on we do not run .DONE
 633  607   *              report_dependencies
 634  608   *                              True if -P flag on
 635  609   *              running_list    List of parallel running processes
 636  610   *              temp_file_name  The temp file is removed, if any
 637  611   *              catd    the message catalog file
 638  612   */
 639  613  extern "C" void
 640  614  cleanup_after_exit(void)
 641  615  {
 642  616          Running         rp;
 643  617  
 644  618  extern long     getname_bytes_count;
 645  619  extern long     getname_names_count;
 646  620  extern long     getname_struct_count;
 647  621  extern long     freename_bytes_count;
 648  622  extern long     freename_names_count;
 649  623  extern long     freename_struct_count;
 650  624  extern long     other_alloc;
 651  625  
 652  626  extern long     env_alloc_num;
 653  627  extern long     env_alloc_bytes;
 654  628  
 655  629  
 656  630  #ifdef DMAKE_STATISTICS
 657  631  if(getname_stat) {
 658  632          printf(NOCATGETS(">>> Getname statistics:\n"));
 659  633          printf(NOCATGETS("  Allocated:\n"));
 660  634          printf(NOCATGETS("        Names: %ld\n"), getname_names_count);
 661  635          printf(NOCATGETS("      Strings: %ld Kb (%ld bytes)\n"), getname_bytes_count/1000, getname_bytes_count);
 662  636          printf(NOCATGETS("      Structs: %ld Kb (%ld bytes)\n"), getname_struct_count/1000, getname_struct_count);
 663  637          printf(NOCATGETS("  Total bytes: %ld Kb (%ld bytes)\n"), getname_struct_count/1000 + getname_bytes_count/1000, getname_struct_count + getname_bytes_count);
 664  638  
 665  639          printf(NOCATGETS("\n  Unallocated: %ld\n"), freename_names_count);
 666  640          printf(NOCATGETS("        Names: %ld\n"), freename_names_count);
 667  641          printf(NOCATGETS("      Strings: %ld Kb (%ld bytes)\n"), freename_bytes_count/1000, freename_bytes_count);
 668  642          printf(NOCATGETS("      Structs: %ld Kb (%ld bytes)\n"), freename_struct_count/1000, freename_struct_count);
 669  643          printf(NOCATGETS("  Total bytes: %ld Kb (%ld bytes)\n"), freename_struct_count/1000 + freename_bytes_count/1000, freename_struct_count + freename_bytes_count);
 670  644  
 671  645          printf(NOCATGETS("\n  Total used: %ld Kb (%ld bytes)\n"), (getname_struct_count/1000 + getname_bytes_count/1000) - (freename_struct_count/1000 + freename_bytes_count/1000), (getname_struct_count + getname_bytes_count) - (freename_struct_count + freename_bytes_count));
 672  646  
 673  647          printf(NOCATGETS("\n>>> Other:\n"));
 674  648          printf(
 675  649                  NOCATGETS("       Env (%ld): %ld Kb (%ld bytes)\n"),
 676  650                  env_alloc_num,
 677  651                  env_alloc_bytes/1000,
 678  652                  env_alloc_bytes
 679  653          );
 680  654  
 681  655  }
 682  656  #endif
 683  657  
  
    | 
      ↓ open down ↓ | 
    156 lines elided | 
    
      ↑ open up ↑ | 
  
 684  658          parallel = false;
 685  659          /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
 686  660          if (!getenv(USE_SVR4_MAKE)){
 687  661              /* Build the target .DONE or .FAILED if we caught an error */
 688  662              if (!quest && !list_all_targets) {
 689  663                  Name            failed_name;
 690  664  
 691  665                  MBSTOWCS(wcs_buffer, NOCATGETS(".FAILED"));
 692  666                  failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
 693  667                  if ((exit_status != 0) && (failed_name->prop != NULL)) {
 694      -#ifdef TEAMWARE_MAKE_CMN
 695  668                          /*
 696  669                           * [tolik] switch DMake to serial mode
 697  670                           */
 698  671                          dmake_mode_type = serial_mode;
 699  672                          no_parallel = true;
 700      -#endif
 701  673                          (void) doname(failed_name, false, true);
 702  674                  } else {
 703  675                      if (!trace_status) {
 704      -#ifdef TEAMWARE_MAKE_CMN
 705  676                          /*
 706  677                           * Switch DMake to serial mode
 707  678                           */
 708  679                          dmake_mode_type = serial_mode;
 709  680                          no_parallel = true;
 710      -#endif
 711  681                          (void) doname(done, false, true);
 712  682                      }
 713  683                  }
 714  684              }
 715  685          }
 716  686          /*
 717  687           * Remove the temp file utilities report dependencies thru if it
 718  688           * is still around
 719  689           */
 720  690          if (temp_file_name != NULL) {
 721  691                  (void) unlink(temp_file_name->string_mb);
 722  692          }
 723  693          /*
 724  694           * Do not save the current command in .make.state if make
 725  695           * was interrupted.
 726  696           */
 727  697          if (current_line != NULL) {
 728  698                  command_changed = true;
 729  699                  current_line->body.line.command_used = NULL;
 730  700          }
 731  701          /*
 732  702           * For each parallel build process running, remove the temp files
 733  703           * and zap the command line so it won't be put in .make.state
 734  704           */
 735  705          for (rp = running_list; rp != NULL; rp = rp->next) {
 736  706                  if (rp->temp_file != NULL) {
 737  707                          (void) unlink(rp->temp_file->string_mb);
 738  708                  }
 739  709                  if (rp->stdout_file != NULL) {
 740  710                          (void) unlink(rp->stdout_file);
 741  711                          retmem_mb(rp->stdout_file);
 742  712                          rp->stdout_file = NULL;
 743  713                  }
 744  714                  if (rp->stderr_file != NULL) {
 745  715                          (void) unlink(rp->stderr_file);
 746  716                          retmem_mb(rp->stderr_file);
 747  717                          rp->stderr_file = NULL;
 748  718                  }
 749  719                  command_changed = true;
 750  720  /*
 751  721                  line = get_prop(rp->target->prop, line_prop);
 752  722                  if (line != NULL) {
 753  723                          line->body.line.command_used = NULL;
 754  724                  }
 755  725   */
 756  726          }
 757  727          /* Remove the statefile lock file if the file has been locked */
 758  728          if ((make_state_lockfile != NULL) && (make_state_locked)) {
 759  729                  (void) unlink(make_state_lockfile);
 760  730                  make_state_lockfile = NULL;
 761  731                  make_state_locked = false;
 762  732          }
 763  733          /* Write .make.state */
 764  734          write_state_file(1, (Boolean) 1);
 765  735  
 766  736  #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
 767  737          job_adjust_fini();
 768  738  #endif
 769  739  
 770  740  #ifdef TEAMWARE_MAKE_CMN
 771  741          catclose(catd);
 772  742  #endif
 773  743  }
 774  744  
 775  745  /*
 776  746   *      handle_interrupt()
 777  747   *
 778  748   *      This is where C-C traps are caught.
 779  749   *
 780  750   *      Parameters:
 781  751   *
 782  752   *      Global variables used (except DMake 1.0):
 783  753   *              current_target          Sometimes the current target is removed
 784  754   *              do_not_exec_rule        But not if -n is on
 785  755   *              quest                   or -q
 786  756   *              running_list            List of parallel running processes
 787  757   *              touch                   Current target is not removed if -t on
 788  758   */
 789  759  void
 790  760  handle_interrupt(int)
 791  761  {
 792  762          Property                member;
 793  763          Running                 rp;
 794  764  
 795  765          (void) fflush(stdout);
 796  766          if (childPid > 0) {
 797  767                  kill(childPid, SIGTERM);
 798  768                  childPid = -1;
 799  769          }
 800  770          for (rp = running_list; rp != NULL; rp = rp->next) {
 801  771                  if (rp->state != build_running) {
 802  772                          continue;
  
    | 
      ↓ open down ↓ | 
    82 lines elided | 
    
      ↑ open up ↑ | 
  
 803  773                  }
 804  774                  if (rp->pid > 0) {
 805  775                          kill(rp->pid, SIGTERM);
 806  776                          rp->pid = -1;
 807  777                  }
 808  778          }
 809  779          if (getpid() == getpgrp()) {
 810  780                  bsd_signal(SIGTERM, SIG_IGN);
 811  781                  kill (-getpid(), SIGTERM);
 812  782          }
 813      -#ifdef TEAMWARE_MAKE_CMN
 814  783          /* Clean up all parallel/distributed children already finished */
 815  784          finish_children(false);
 816      -#endif
 817  785  
 818  786          /* Make sure the processes running under us terminate first */
 819  787  
 820  788          while (wait((int *) NULL) != -1);
 821  789          /* Delete the current targets unless they are precious */
 822  790          if ((current_target != NULL) &&
 823  791              current_target->is_member &&
 824  792              ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
 825  793                  current_target = member->body.member.library;
 826  794          }
 827  795          if (!do_not_exec_rule &&
 828  796              !touch &&
 829  797              !quest &&
 830  798              (current_target != NULL) &&
 831  799              !(current_target->stat.is_precious || all_precious)) {
 832  800  
 833  801  /* BID_1030811 */
 834  802  /* azv 16 Oct 95 */
 835  803                  current_target->stat.time = file_no_time; 
 836  804  
 837  805                  if (exists(current_target) != file_doesnt_exist) {
 838  806                          (void) fprintf(stderr,
 839  807                                         "\n*** %s ",
 840  808                                         current_target->string_mb);
 841  809                          if (current_target->stat.is_dir) {
 842  810                                  (void) fprintf(stderr,
 843  811                                                 catgets(catd, 1, 168, "not removed.\n"),
 844  812                                                 current_target->string_mb);
 845  813                          } else if (unlink(current_target->string_mb) == 0) {
 846  814                                  (void) fprintf(stderr,
 847  815                                                 catgets(catd, 1, 169, "removed.\n"),
 848  816                                                 current_target->string_mb);
 849  817                          } else {
 850  818                                  (void) fprintf(stderr,
 851  819                                                 catgets(catd, 1, 170, "could not be removed: %s.\n"),
 852  820                                                 current_target->string_mb,
 853  821                                                 errmsg(errno));
 854  822                          }
 855  823                  }
 856  824          }
 857  825          for (rp = running_list; rp != NULL; rp = rp->next) {
 858  826                  if (rp->state != build_running) {
 859  827                          continue;
 860  828                  }
 861  829                  if (rp->target->is_member &&
 862  830                      ((member = get_prop(rp->target->prop, member_prop)) !=
 863  831                       NULL)) {
 864  832                          rp->target = member->body.member.library;
 865  833                  }
 866  834                  if (!do_not_exec_rule &&
 867  835                      !touch &&
 868  836                      !quest &&
 869  837                      !(rp->target->stat.is_precious || all_precious)) {
 870  838  
 871  839                          rp->target->stat.time = file_no_time; 
 872  840                          if (exists(rp->target) != file_doesnt_exist) {
 873  841                                  (void) fprintf(stderr,
 874  842                                                 "\n*** %s ",
 875  843                                                 rp->target->string_mb);
 876  844                                  if (rp->target->stat.is_dir) {
 877  845                                          (void) fprintf(stderr,
 878  846                                                         catgets(catd, 1, 171, "not removed.\n"),
 879  847                                                         rp->target->string_mb);
 880  848                                  } else if (unlink(rp->target->string_mb) == 0) {
 881  849                                          (void) fprintf(stderr,
 882  850                                                         catgets(catd, 1, 172, "removed.\n"),
 883  851                                                         rp->target->string_mb);
 884  852                                  } else {
 885  853                                          (void) fprintf(stderr,
 886  854                                                         catgets(catd, 1, 173, "could not be removed: %s.\n"),
 887  855                                                         rp->target->string_mb,
 888  856                                                         errmsg(errno));
 889  857                                  }
 890  858                          }
 891  859                  }
 892  860          }
 893  861  
 894  862  
 895  863          /* Have we locked .make.state or .nse_depinfo? */
 896  864          if ((make_state_lockfile != NULL) && (make_state_locked)) {
 897  865                  unlink(make_state_lockfile);
 898  866                  make_state_lockfile = NULL;
 899  867                  make_state_locked = false;
 900  868          }
 901  869          /*
 902  870           * Re-read .make.state file (it might be changed by recursive make)
 903  871           */
 904  872          check_state(NULL);
 905  873  
 906  874          report_dir_enter_leave(false);
 907  875  
 908  876          exit_status = 2;
 909  877          exit(2);
 910  878  }
 911  879  
 912  880  /*
 913  881   *      doalarm(sig, ...)
 914  882   *
 915  883   *      Handle the alarm interrupt but do nothing.  Side effect is to
 916  884   *      cause return from wait3.
 917  885   *
 918  886   *      Parameters:
 919  887   *              sig
 920  888   *
 921  889   *      Global variables used:
 922  890   */
 923  891  /*ARGSUSED*/
 924  892  static void
 925  893  doalarm(int)
 926  894  {
 927  895          return;
 928  896  }
 929  897  
 930  898  
 931  899  /*
 932  900   *      read_command_options(argc, argv)
 933  901   *
 934  902   *      Scan the cmd line options and process the ones that start with "-"
 935  903   *
 936  904   *      Return value:
 937  905   *                              -M argument, if any
 938  906   *
 939  907   *      Parameters:
 940  908   *              argc            You know what this is
 941  909   *              argv            You know what this is
 942  910   *
 943  911   *      Global variables used:
 944  912   */
 945  913  static void
 946  914  read_command_options(register int argc, register char **argv)
 947  915  {
 948  916          register int            ch;
 949  917          int                     current_optind = 1;
 950  918          int                     last_optind_with_double_hyphen = 0;
 951  919          int                     last_optind;
 952  920          int                     last_current_optind;
 953  921          register int            i;
 954  922          register int            j;
 955  923          register int            k;
 956  924          register int            makefile_next = 0; /*
 957  925                                                      * flag to note options:
  
    | 
      ↓ open down ↓ | 
    131 lines elided | 
    
      ↑ open up ↑ | 
  
 958  926                                                      * -c, f, g, j, m, o
 959  927                                                      */
 960  928          const char              *tptr;
 961  929          const char              *CMD_OPTS;
 962  930  
 963  931          extern char             *optarg;
 964  932          extern int              optind, opterr, optopt;
 965  933  
 966  934  #define SUNPRO_CMD_OPTS "-~Bbc:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
 967  935  
 968      -#ifdef TEAMWARE_MAKE_CMN
 969  936  #       define SVR4_CMD_OPTS   "-c:ef:g:ij:km:nO:o:pqrsTtVv"
 970      -#else
 971      -#       define SVR4_CMD_OPTS   "-ef:iknpqrstV"
 972      -#endif
 973  937  
 974  938          /*
 975  939           * Added V in SVR4_CMD_OPTS also, which is going to be a hidden
 976  940           * option, just to make sure that the getopt doesn't fail when some
 977  941           * users leave their USE_SVR4_MAKE set and try to use the makefiles
 978  942           * that are designed to issue commands like $(MAKE) -V. Anyway it
 979  943           * sets the same flag but ensures that getopt doesn't fail.
 980  944           */
 981  945  
 982  946          opterr = 0;
 983  947          optind = 1;
 984  948          while (1) {
 985  949                  last_optind=optind;                     /* Save optind and current_optind values */
 986  950                  last_current_optind=current_optind;     /* in case we have to repeat this round. */
 987  951                  if (svr4) {
 988  952                          CMD_OPTS=SVR4_CMD_OPTS;
 989  953                          ch = getopt(argc, argv, SVR4_CMD_OPTS);
 990  954                  } else {
 991  955                          CMD_OPTS=SUNPRO_CMD_OPTS;
 992  956                          ch = getopt(argc, argv, SUNPRO_CMD_OPTS);
 993  957                  }
 994  958                  if (ch == EOF) {
 995  959                          if(optind < argc) {
 996  960                                  /*
 997  961                                   * Fixing bug 4102537:
 998  962                                   *    Strange behaviour of command make using -- option.
 999  963                                   * Not all argv have been processed
1000  964                                   * Skip non-flag argv and continue processing.
1001  965                                   */
1002  966                                  optind++;
1003  967                                  current_optind++;
1004  968                                  continue;
1005  969                          } else {
1006  970                                  break;
1007  971                          }
1008  972  
1009  973                  }
1010  974                  if (ch == '?') {
1011  975                          if (optopt == '-') {
1012  976                                  /* Bug 5060758: getopt() changed behavior (s10_60),
1013  977                                   * and now we have to deal with cases when options
1014  978                                   * with double hyphen appear here, from -$(MAKEFLAGS)
1015  979                                   */
1016  980                                  i = current_optind;
1017  981                                  if (argv[i][0] == '-') {
1018  982                                    if (argv[i][1] == '-') {
1019  983                                      if (argv[i][2] != '\0') {
1020  984                                        /* Check if this option is allowed */
1021  985                                        tptr = strchr(CMD_OPTS, argv[i][2]);
1022  986                                        if (tptr) {
1023  987                                          if (last_optind_with_double_hyphen != current_optind) {
1024  988                                            /* This is first time we are trying to fix "--"
1025  989                                             * problem with this option. If we come here second 
1026  990                                             * time, we will go to fatal error.
1027  991                                             */
1028  992                                            last_optind_with_double_hyphen = current_optind;
1029  993                                            
1030  994                                            /* Eliminate first hyphen character */
1031  995                                            for (j=0; argv[i][j] != '\0'; j++) {
1032  996                                              argv[i][j] = argv[i][j+1];
1033  997                                            }
1034  998                                            
1035  999                                            /* Repeat the processing of this argument */
1036 1000                                            optind=last_optind;
1037 1001                                            current_optind=last_current_optind;
1038 1002                                            continue;
  
    | 
      ↓ open down ↓ | 
    56 lines elided | 
    
      ↑ open up ↑ | 
  
1039 1003                                          }
1040 1004                                        }
1041 1005                                      }
1042 1006                                    }
1043 1007                                  }
1044 1008                          }
1045 1009                  }
1046 1010  
1047 1011                  if (ch == '?') {
1048 1012                          if (svr4) {
1049      -#ifdef TEAMWARE_MAKE_CMN
1050 1013                                  fprintf(stderr,
1051 1014                                          catgets(catd, 1, 267, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1052 1015                                  fprintf(stderr,
1053 1016                                          catgets(catd, 1, 268, "              [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
1054 1017                                  fprintf(stderr,
1055 1018                                          catgets(catd, 1, 269, "              [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
1056      -#else
1057      -                                fprintf(stderr,
1058      -                                        catgets(catd, 1, 270, "Usage : make [ -f makefile ]... [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ]\n"));
1059      -                                fprintf(stderr,
1060      -                                        catgets(catd, 1, 271, "             [ -s ][ -t ]\n"));
1061      -#endif
1062 1019                                  tptr = strchr(SVR4_CMD_OPTS, optopt);
1063 1020                          } else {
1064      -#ifdef TEAMWARE_MAKE_CMN
1065 1021                                  fprintf(stderr,
1066 1022                                          catgets(catd, 1, 272, "Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1067 1023                                  fprintf(stderr,
1068 1024                                          catgets(catd, 1, 273, "              [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1069 1025                                  fprintf(stderr,
1070 1026                                          catgets(catd, 1, 274, "              [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1071 1027                                  fprintf(stderr,
1072 1028                                          catgets(catd, 1, 275, "              [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1073      -#else
1074      -                                fprintf(stderr,
1075      -                                        catgets(catd, 1, 276, "Usage : make [ -f makefile ][ -K statefile ]... [ -d ][ -dd ][ -D ][ -DD ]\n"));
1076      -                                fprintf(stderr,
1077      -                                        catgets(catd, 1, 277, "             [ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -q ][ -r ][ -s ][ -S ][ -t ]\n"));
1078      -                                fprintf(stderr,
1079      -                                        catgets(catd, 1, 278, "             [ -u ][ -w ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1080      -#endif
1081 1029                                  tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1082 1030                          }
1083 1031                          if (!tptr) {
1084 1032                                  fatal(catgets(catd, 1, 279, "Unknown option `-%c'"), optopt);
1085 1033                          } else {
1086 1034                                  fatal(catgets(catd, 1, 280, "Missing argument after `-%c'"), optopt);
1087 1035                          }
1088 1036                  }
1089 1037  
1090 1038  
1091 1039  
1092 1040                  makefile_next |= parse_command_option(ch);
1093 1041                  /*
1094 1042                   * If we're done processing all of the options of
1095 1043                   * ONE argument string...
1096 1044                   */
1097 1045                  if (current_optind < optind) {
1098 1046                          i = current_optind;
1099 1047                          k = 0;
1100 1048                          /* If there's an argument for an option... */
1101 1049                          if ((optind - current_optind) > 1) {
1102 1050                                  k = i + 1;
1103 1051                          }
1104 1052                          switch (makefile_next) {
1105 1053                          case 0:
1106 1054                                  argv[i] = NULL;
  
    | 
      ↓ open down ↓ | 
    16 lines elided | 
    
      ↑ open up ↑ | 
  
1107 1055                                  /* This shouldn't happen */
1108 1056                                  if (k) {
1109 1057                                          argv[k] = NULL;
1110 1058                                  }
1111 1059                                  break;
1112 1060                          case 1: /* -f seen */
1113 1061                                  argv[i] = (char *)NOCATGETS("-f");
1114 1062                                  break;
1115 1063                          case 2: /* -c seen */
1116 1064                                  argv[i] = (char *)NOCATGETS("-c");
1117      -#ifndef TEAMWARE_MAKE_CMN
1118      -                                warning(catgets(catd, 1, 281, "Ignoring DistributedMake -c option"));
1119      -#endif
1120 1065                                  break;
1121 1066                          case 4: /* -g seen */
1122 1067                                  argv[i] = (char *)NOCATGETS("-g");
1123      -#ifndef TEAMWARE_MAKE_CMN
1124      -                                warning(catgets(catd, 1, 282, "Ignoring DistributedMake -g option"));
1125      -#endif
1126 1068                                  break;
1127 1069                          case 8: /* -j seen */
1128 1070                                  argv[i] = (char *)NOCATGETS("-j");
1129      -#ifndef TEAMWARE_MAKE_CMN
1130      -                                warning(catgets(catd, 1, 283, "Ignoring DistributedMake -j option"));
1131      -#endif
1132 1071                                  break;
1133 1072                          case 16: /* -M seen */
1134 1073                                  argv[i] = (char *)NOCATGETS("-M");
1135      -#ifndef TEAMWARE_MAKE_CMN
1136      -                                warning(catgets(catd, 1, 284, "Ignoring ParallelMake -M option"));
1137      -#endif
1138 1074                                  break;
1139 1075                          case 32: /* -m seen */
1140 1076                                  argv[i] = (char *)NOCATGETS("-m");
1141      -#ifndef TEAMWARE_MAKE_CMN
1142      -                                warning(catgets(catd, 1, 285, "Ignoring DistributedMake -m option"));
1143      -#endif
1144 1077                                  break;
1145 1078                          case 128: /* -O seen */
1146 1079                                  argv[i] = (char *)NOCATGETS("-O");
1147 1080                                  break;
1148 1081                          case 256: /* -K seen */
1149 1082                                  argv[i] = (char *)NOCATGETS("-K");
1150 1083                                  break;
1151 1084                          case 512:       /* -o seen */
1152 1085                                  argv[i] = (char *)NOCATGETS("-o");
1153      -#ifndef TEAMWARE_MAKE_CMN
1154      -                                warning(catgets(catd, 1, 311, "Ignoring DistributedMake -o option"));
1155      -#endif
1156 1086                                  break;
1157 1087                          case 1024: /* -x seen */
1158 1088                                  argv[i] = (char *)NOCATGETS("-x");
1159      -#ifndef TEAMWARE_MAKE_CMN
1160      -                                warning(catgets(catd, 1, 353, "Ignoring DistributedMake -x option"));
1161      -#endif
1162 1089                                  break;
1163 1090                          default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1164 1091                                  fatal(catgets(catd, 1, 286, "Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1165 1092                          }
1166 1093  
1167 1094                          makefile_next = 0;
1168 1095                          current_optind = optind;
1169 1096                  }
1170 1097          }
1171 1098  }
1172 1099  
1173 1100  static void
1174 1101  quote_str(char *str, char *qstr)
1175 1102  {
1176 1103          char            *to;
1177 1104          char            *from;
1178 1105  
1179 1106          to = qstr;
1180 1107          for (from = str; *from; from++) {
1181 1108                  switch (*from) {
1182 1109                  case ';':       /* End of command */
1183 1110                  case '(':       /* Start group */
1184 1111                  case ')':       /* End group */
1185 1112                  case '{':       /* Start group */
1186 1113                  case '}':       /* End group */
1187 1114                  case '[':       /* Reg expr - any of a set of chars */
1188 1115                  case ']':       /* End of set of chars */
1189 1116                  case '|':       /* Pipe or logical-or */
1190 1117                  case '^':       /* Old-fashioned pipe */
1191 1118                  case '&':       /* Background or logical-and */
1192 1119                  case '<':       /* Redirect stdin */
1193 1120                  case '>':       /* Redirect stdout */
1194 1121                  case '*':       /* Reg expr - any sequence of chars */
1195 1122                  case '?':       /* Reg expr - any single char */
1196 1123                  case '$':       /* Variable substitution */
1197 1124                  case '\'':      /* Singe quote - turn off all magic */
1198 1125                  case '"':       /* Double quote - span whitespace */
1199 1126                  case '`':       /* Backquote - run a command */
1200 1127                  case '#':       /* Comment */
1201 1128                  case ' ':       /* Space (for MACRO=value1 value2  */
1202 1129                  case '\\':      /* Escape char - turn off magic of next char */
1203 1130                          *to++ = '\\';
1204 1131                          break;
1205 1132  
1206 1133                  default:
1207 1134                          break;
1208 1135                  }
1209 1136                  *to++ = *from;
1210 1137          }
1211 1138          *to = '\0';
1212 1139  }
1213 1140  
1214 1141  static void
1215 1142  unquote_str(char *str, char *qstr)
1216 1143  {
1217 1144          char            *to;
1218 1145          char            *from;
1219 1146  
1220 1147          to = qstr;
1221 1148          for (from = str; *from; from++) {
1222 1149                  if (*from == '\\') {
1223 1150                          from++;
1224 1151                  }
1225 1152                  *to++ = *from;
1226 1153          }
1227 1154          *to = '\0';
1228 1155  }
1229 1156  
1230 1157  /*
1231 1158   * Convert the MAKEFLAGS string value into a vector of char *, similar
1232 1159   * to argv.
1233 1160   */
1234 1161  static void
1235 1162  setup_makeflags_argv()
1236 1163  {
1237 1164          char            *cp;
1238 1165          char            *cp1;
1239 1166          char            *cp2;
1240 1167          char            *cp3;
1241 1168          char            *cp_orig;
1242 1169          Boolean         add_hyphen;
1243 1170          int             i;
1244 1171          char            tmp_char;
1245 1172  
1246 1173          mf_argc = 1;
1247 1174          cp = getenv(makeflags->string_mb);
1248 1175          cp_orig = cp;
1249 1176  
1250 1177          if (cp) {
1251 1178                  /*
1252 1179                   * If new MAKEFLAGS format, no need to add hyphen.
1253 1180                   * If old MAKEFLAGS format, add hyphen before flags.
1254 1181                   */
1255 1182  
1256 1183                  if ((strchr(cp, (int) hyphen_char) != NULL) ||
1257 1184                      (strchr(cp, (int) equal_char) != NULL)) {
1258 1185  
1259 1186                          /* New MAKEFLAGS format */
1260 1187  
1261 1188                          add_hyphen = false;
1262 1189  #ifdef ADDFIX5060758                    
1263 1190                          /* Check if MAKEFLAGS value begins with multiple
1264 1191                           * hyphen characters, and remove all duplicates.
1265 1192                           * Usually it happens when the next command is
1266 1193                           * used: $(MAKE) -$(MAKEFLAGS)
1267 1194                           * This is a workaround for BugID 5060758.
1268 1195                           */
1269 1196                          while (*cp) {
1270 1197                                  if (*cp != (int) hyphen_char) {
1271 1198                                          break;
1272 1199                                  }
1273 1200                                  cp++;
1274 1201                                  if (*cp == (int) hyphen_char) {
1275 1202                                          /* There are two hyphens. Skip one */
1276 1203                                          cp_orig = cp;
1277 1204                                          cp++;
1278 1205                                  }
1279 1206                                  if (!(*cp)) {
1280 1207                                          /* There are hyphens only. Skip all */
1281 1208                                          cp_orig = cp;
1282 1209                                          break;
1283 1210                                  }
1284 1211                          }
1285 1212  #endif
1286 1213                  } else {
1287 1214  
1288 1215                          /* Old MAKEFLAGS format */
1289 1216  
1290 1217                          add_hyphen = true;
1291 1218                  }
1292 1219          }
1293 1220  
1294 1221          /* Find the number of arguments in MAKEFLAGS */
1295 1222          while (cp && *cp) {
1296 1223                  /* Skip white spaces */
1297 1224                  while (cp && *cp && isspace(*cp)) {
1298 1225                          cp++;
1299 1226                  }
1300 1227                  if (cp && *cp) {
1301 1228                          /* Increment arg count */
1302 1229                          mf_argc++;
1303 1230                          /* Go to next white space */
1304 1231                          while (cp && *cp && !isspace(*cp)) {
1305 1232                                  if(*cp == (int) backslash_char) {
1306 1233                                          cp++;
1307 1234                                  }
1308 1235                                  cp++;
1309 1236                          }
1310 1237                  }
1311 1238          }
1312 1239          /* Allocate memory for the new MAKEFLAGS argv */
1313 1240          mf_argv = (char **) malloc((mf_argc + 1) * sizeof(char *));
1314 1241          mf_argv[0] = (char *)NOCATGETS("MAKEFLAGS");
1315 1242          /*
1316 1243           * Convert the MAKEFLAGS string value into a vector of char *,
1317 1244           * similar to argv.
1318 1245           */
1319 1246          cp = cp_orig;
1320 1247          for (i = 1; i < mf_argc; i++) {
1321 1248                  /* Skip white spaces */
1322 1249                  while (cp && *cp && isspace(*cp)) {
1323 1250                          cp++;
1324 1251                  }
1325 1252                  if (cp && *cp) {
1326 1253                          cp_orig = cp;
1327 1254                          /* Go to next white space */
1328 1255                          while (cp && *cp && !isspace(*cp)) {
1329 1256                                  if(*cp == (int) backslash_char) {
1330 1257                                          cp++;
1331 1258                                  }
1332 1259                                  cp++;
1333 1260                          }
1334 1261                          tmp_char = *cp;
1335 1262                          *cp = (int) nul_char;
1336 1263                          if (add_hyphen) {
1337 1264                                  mf_argv[i] = getmem(2 + strlen(cp_orig));
1338 1265                                  mf_argv[i][0] = '\0';
1339 1266                                  (void) strcat(mf_argv[i], "-");
1340 1267                                  // (void) strcat(mf_argv[i], cp_orig);
1341 1268                                  unquote_str(cp_orig, mf_argv[i]+1);
1342 1269                          } else {
1343 1270                                  mf_argv[i] = getmem(2 + strlen(cp_orig));
1344 1271                                  //mf_argv[i] = strdup(cp_orig);
1345 1272                                  unquote_str(cp_orig, mf_argv[i]);
1346 1273                          }
1347 1274                          *cp = tmp_char;
1348 1275                  }
1349 1276          }
1350 1277          mf_argv[i] = NULL;
1351 1278  }
1352 1279  
1353 1280  /*
1354 1281   *      parse_command_option(ch)
1355 1282   *
1356 1283   *      Parse make command line options.
1357 1284   *
1358 1285   *      Return value:
1359 1286   *                              Indicates if any -f -c or -M were seen
1360 1287   *
1361 1288   *      Parameters:
1362 1289   *              ch              The character to parse
1363 1290   *
1364 1291   *      Static variables used:
1365 1292   *              dmake_group_specified   Set for make -g
1366 1293   *              dmake_max_jobs_specified        Set for make -j
1367 1294   *              dmake_mode_specified    Set for make -m
1368 1295   *              dmake_add_mode_specified        Set for make -x
1369 1296   *              dmake_compat_mode_specified     Set for make -x SUN_MAKE_COMPAT_MODE=
1370 1297   *              dmake_output_mode_specified     Set for make -x DMAKE_OUTPUT_MODE=
1371 1298   *              dmake_odir_specified    Set for make -o
1372 1299   *              dmake_rcfile_specified  Set for make -c
1373 1300   *              env_wins                Set for make -e
1374 1301   *              ignore_default_mk       Set for make -r
1375 1302   *              trace_status            Set for make -p
1376 1303   *
1377 1304   *      Global variables used:
1378 1305   *              .make.state path & name set for make -K
1379 1306   *              continue_after_error    Set for make -k
1380 1307   *              debug_level             Set for make -d
1381 1308   *              do_not_exec_rule        Set for make -n
1382 1309   *              filter_stderr           Set for make -X
1383 1310   *              ignore_errors_all       Set for make -i
1384 1311   *              no_parallel             Set for make -R
1385 1312   *              quest                   Set for make -q
1386 1313   *              read_trace_level        Set for make -D
1387 1314   *              report_dependencies     Set for make -P
1388 1315   *              send_mtool_msgs         Set for make -K
1389 1316   *              silent_all              Set for make -s
1390 1317   *              touch                   Set for make -t
1391 1318   */
1392 1319  static int
1393 1320  parse_command_option(register char ch)
1394 1321  {
1395 1322          static int              invert_next = 0;
1396 1323          int                     invert_this = invert_next;
1397 1324  
1398 1325          invert_next = 0;
1399 1326          switch (ch) {
1400 1327          case '-':                        /* Ignore "--" */
1401 1328                  return 0;
1402 1329          case '~':                        /* Invert next option */
1403 1330                  invert_next = 1;
1404 1331                  return 0;
1405 1332          case 'B':                        /* Obsolete */
1406 1333                  return 0;
1407 1334          case 'b':                        /* Obsolete */
1408 1335                  return 0;
1409 1336          case 'c':                        /* Read alternative dmakerc file */
1410 1337                  if (invert_this) {
1411 1338                          dmake_rcfile_specified = false;
1412 1339                  } else {
1413 1340                          dmake_rcfile_specified = true;
1414 1341                  }
1415 1342                  return 2;
1416 1343          case 'D':                        /* Show lines read */
1417 1344                  if (invert_this) {
1418 1345                          read_trace_level--;
1419 1346                  } else {
1420 1347                          read_trace_level++;
1421 1348                  }
1422 1349                  return 0;
1423 1350          case 'd':                        /* Debug flag */
1424 1351                  if (invert_this) {
1425 1352                          debug_level--;
1426 1353                  } else {
1427 1354                          debug_level++;
1428 1355                  }
1429 1356                  return 0;
1430 1357          case 'e':                        /* Environment override flag */
1431 1358                  if (invert_this) {
1432 1359                          env_wins = false;
1433 1360                  } else {
1434 1361                          env_wins = true;
1435 1362                  }
1436 1363                  return 0;
1437 1364          case 'f':                        /* Read alternative makefile(s) */
1438 1365                  return 1;
1439 1366          case 'g':                        /* Use alternative DMake group */
1440 1367                  if (invert_this) {
1441 1368                          dmake_group_specified = false;
1442 1369                  } else {
1443 1370                          dmake_group_specified = true;
1444 1371                  }
1445 1372                  return 4;
1446 1373          case 'i':                        /* Ignore errors */
1447 1374                  if (invert_this) {
1448 1375                          ignore_errors_all = false;
1449 1376                  } else {
1450 1377                          ignore_errors_all = true;
1451 1378                  }
1452 1379                  return 0;
1453 1380          case 'j':                        /* Use alternative DMake max jobs */
1454 1381                  if (invert_this) {
1455 1382                          dmake_max_jobs_specified = false;
1456 1383                  } else {
1457 1384                          dmake_max_jobs_specified = true;
1458 1385                  }
1459 1386                  return 8;
1460 1387          case 'K':                        /* Read alternative .make.state */
1461 1388                  return 256;
1462 1389          case 'k':                        /* Keep making even after errors */
1463 1390                  if (invert_this) {
1464 1391                          continue_after_error = false;
1465 1392                  } else {
1466 1393                          continue_after_error = true;
1467 1394                          continue_after_error_ever_seen = true;
1468 1395                  }
1469 1396                  return 0;
1470 1397          case 'M':                        /* Read alternative make.machines file */
1471 1398                  if (invert_this) {
1472 1399                          pmake_machinesfile_specified = false;
1473 1400                  } else {
1474 1401                          pmake_machinesfile_specified = true;
1475 1402                          dmake_mode_type = parallel_mode;
1476 1403                          no_parallel = false;
1477 1404                  }
1478 1405                  return 16;
1479 1406          case 'm':                        /* Use alternative DMake build mode */
1480 1407                  if (invert_this) {
1481 1408                          dmake_mode_specified = false;
1482 1409                  } else {
1483 1410                          dmake_mode_specified = true;
1484 1411                  }
1485 1412                  return 32;
1486 1413          case 'x':                        /* Use alternative DMake mode */
1487 1414                  if (invert_this) {
1488 1415                          dmake_add_mode_specified = false;
1489 1416                  } else {
1490 1417                          dmake_add_mode_specified = true;
1491 1418                  }
1492 1419                  return 1024;
1493 1420          case 'N':                        /* Reverse -n */
1494 1421                  if (invert_this) {
1495 1422                          do_not_exec_rule = true;
1496 1423                  } else {
1497 1424                          do_not_exec_rule = false;
1498 1425                  }
1499 1426                  return 0;
1500 1427          case 'n':                        /* Print, not exec commands */
1501 1428                  if (invert_this) {
1502 1429                          do_not_exec_rule = false;
1503 1430                  } else {
1504 1431                          do_not_exec_rule = true;
1505 1432                  }
1506 1433                  return 0;
1507 1434          case 'O':                        /* Send job start & result msgs */
1508 1435                  if (invert_this) {
1509 1436                          send_mtool_msgs = false;
1510 1437                  } else {
1511 1438                  }
1512 1439                  return 128;
1513 1440          case 'o':                        /* Use alternative dmake output dir */
1514 1441                  if (invert_this) {
1515 1442                          dmake_odir_specified = false;
1516 1443                  } else {
1517 1444                          dmake_odir_specified = true;
1518 1445                  }
1519 1446                  return 512;
1520 1447          case 'P':                        /* Print for selected targets */
1521 1448                  if (invert_this) {
1522 1449                          report_dependencies_level--;
1523 1450                  } else {
1524 1451                          report_dependencies_level++;
1525 1452                  }
1526 1453                  return 0;
1527 1454          case 'p':                        /* Print description */
1528 1455                  if (invert_this) {
1529 1456                          trace_status = false;
1530 1457                          do_not_exec_rule = false;
1531 1458                  } else {
1532 1459                          trace_status = true;
1533 1460                          do_not_exec_rule = true;
  
    | 
      ↓ open down ↓ | 
    362 lines elided | 
    
      ↑ open up ↑ | 
  
1534 1461                  }
1535 1462                  return 0;
1536 1463          case 'q':                        /* Question flag */
1537 1464                  if (invert_this) {
1538 1465                          quest = false;
1539 1466                  } else {
1540 1467                          quest = true;
1541 1468                  }
1542 1469                  return 0;
1543 1470          case 'R':                        /* Don't run in parallel */
1544      -#ifdef TEAMWARE_MAKE_CMN
1545 1471                  if (invert_this) {
1546 1472                          pmake_cap_r_specified = false;
1547 1473                          no_parallel = false;
1548 1474                  } else {
1549 1475                          pmake_cap_r_specified = true;
1550 1476                          dmake_mode_type = serial_mode;
1551 1477                          no_parallel = true;
1552 1478                  }
1553      -#else
1554      -                warning(catgets(catd, 1, 182, "Ignoring ParallelMake -R option"));
1555      -#endif
1556 1479                  return 0;
1557 1480          case 'r':                        /* Turn off internal rules */
1558 1481                  if (invert_this) {
1559 1482                          ignore_default_mk = false;
1560 1483                  } else {
1561 1484                          ignore_default_mk = true;
1562 1485                  }
1563 1486                  return 0;
1564 1487          case 'S':                        /* Reverse -k */
1565 1488                  if (invert_this) {
1566 1489                          continue_after_error = true;
1567 1490                  } else {
1568 1491                          continue_after_error = false;
1569 1492                          stop_after_error_ever_seen = true;
1570 1493                  }
1571 1494                  return 0;
1572 1495          case 's':                        /* Silent flag */
1573 1496                  if (invert_this) {
1574 1497                          silent_all = false;
1575 1498                  } else {
1576 1499                          silent_all = true;
1577 1500                  }
1578 1501                  return 0;
1579 1502          case 'T':                        /* Print target list */
1580 1503                  if (invert_this) {
1581 1504                          list_all_targets = false;
1582 1505                          do_not_exec_rule = false;
1583 1506                  } else {
1584 1507                          list_all_targets = true;
1585 1508                          do_not_exec_rule = true;
1586 1509                  }
1587 1510                  return 0;
1588 1511          case 't':                        /* Touch flag */
1589 1512                  if (invert_this) {
1590 1513                          touch = false;
1591 1514                  } else {
1592 1515                          touch = true;
1593 1516                  }
1594 1517                  return 0;
1595 1518          case 'u':                        /* Unconditional flag */
1596 1519                  if (invert_this) {
1597 1520                          build_unconditional = false;
  
    | 
      ↓ open down ↓ | 
    32 lines elided | 
    
      ↑ open up ↑ | 
  
1598 1521                  } else {
1599 1522                          build_unconditional = true;
1600 1523                  }
1601 1524                  return 0;
1602 1525          case 'V':                       /* SVR4 mode */
1603 1526                  svr4 = true;
1604 1527                  return 0;
1605 1528          case 'v':                       /* Version flag */
1606 1529                  if (invert_this) {
1607 1530                  } else {
1608      -#ifdef TEAMWARE_MAKE_CMN
1609 1531                          fprintf(stdout, NOCATGETS("dmake: %s\n"), verstring);
1610 1532                          exit_status = 0;
1611 1533                          exit(0);
1612      -#else
1613      -                        warning(catgets(catd, 1, 324, "Ignoring DistributedMake -v option"));
1614      -#endif
1615 1534                  }
1616 1535                  return 0;
1617 1536          case 'w':                        /* Unconditional flag */
1618 1537                  if (invert_this) {
1619 1538                          report_cwd = false;
1620 1539                  } else {
1621 1540                          report_cwd = true;
1622 1541                  }
1623 1542                  return 0;
1624 1543  #if 0
1625 1544          case 'X':                       /* Filter stdout */
1626 1545                  if (invert_this) {
1627 1546                          filter_stderr = false;
1628 1547                  } else {
1629 1548                          filter_stderr = true;
1630 1549                  }
1631 1550                  return 0;
1632 1551  #endif
1633 1552          default:
1634 1553                  break;
1635 1554          }
1636 1555          return 0;
1637 1556  }
1638 1557  
1639 1558  /*
1640 1559   *      setup_for_projectdir()
1641 1560   *
1642 1561   *      Read the PROJECTDIR variable, if defined, and set the sccs path
1643 1562   *
1644 1563   *      Parameters:
1645 1564   *
1646 1565   *      Global variables used:
1647 1566   *              sccs_dir_path   Set to point to SCCS dir to use
1648 1567   */
1649 1568  static void
1650 1569  setup_for_projectdir(void)
1651 1570  {
1652 1571  static char     path[MAXPATHLEN];
1653 1572  char            cwdpath[MAXPATHLEN];
1654 1573  uid_t uid;
1655 1574  int   done=0;
1656 1575  
1657 1576          /* Check if we should use PROJECTDIR when reading the SCCS dir. */
1658 1577          sccs_dir_path = getenv(NOCATGETS("PROJECTDIR"));
1659 1578          if ((sccs_dir_path != NULL) &&
1660 1579              (sccs_dir_path[0] != (int) slash_char)) {
1661 1580                  struct passwd *pwent;
1662 1581  
1663 1582               {
1664 1583                  uid = getuid();
1665 1584                  pwent = getpwuid(uid);
1666 1585                  if (pwent == NULL) {
1667 1586                     fatal(catgets(catd, 1, 188, "Bogus USERID "));
1668 1587                  }
1669 1588                  if ((pwent = getpwnam(sccs_dir_path)) == NULL) {
1670 1589                          /*empty block : it'll go & check cwd  */
1671 1590                  }
1672 1591                  else {
1673 1592                    (void) sprintf(path, NOCATGETS("%s/src"), pwent->pw_dir);
1674 1593                    if (access(path, F_OK) == 0) {
1675 1594                          sccs_dir_path = path;
1676 1595                          done = 1;
1677 1596                    } else {
1678 1597                          (void) sprintf(path, NOCATGETS("%s/source"), pwent->pw_dir);
1679 1598                          if (access(path, F_OK) == 0) {
1680 1599                                  sccs_dir_path = path;
1681 1600                                  done = 1;
1682 1601                          }
1683 1602                       }
1684 1603                  }
1685 1604                  if (!done) {
1686 1605                      if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1687 1606  
1688 1607                         (void) sprintf(path, NOCATGETS("%s/%s"), cwdpath,sccs_dir_path);
1689 1608                         if (access(path, F_OK) == 0) {
1690 1609                                  sccs_dir_path = path;
1691 1610                                  done = 1;
1692 1611                          } else {
1693 1612                                  fatal(catgets(catd, 1, 189, "Bogus PROJECTDIR '%s'"), sccs_dir_path);
1694 1613                          }
1695 1614                      }
1696 1615                  }
1697 1616             }
1698 1617          }
1699 1618  }
1700 1619  
1701 1620  /*
1702 1621   *      set_sgs_support()
1703 1622   *
1704 1623   *      Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1705 1624   *        if it's not already in there.
1706 1625   *      The SGS_SUPPORT env var and libmakestate.so.1 is used by
1707 1626   *        the linker ld to report .make.state info back to make.
1708 1627   *
1709 1628   * In the new world we always will set the 32-bit and 64-bit versions of this
1710 1629   * variable explicitly so that we can take into account the correct isa and our
1711 1630   * prefix. So say that the prefix was /opt/local. Then we would want to search
1712 1631   * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1713 1632   * the original location just as a safety measure.
1714 1633   */
1715 1634  static void
1716 1635  set_sgs_support()
1717 1636  {
1718 1637          int             len;
1719 1638          char            *newpath, *newpath64;
1720 1639          char            *oldpath, *oldpath64;
1721 1640          static char     *prev_path, *prev_path64;
1722 1641  
1723 1642          oldpath = getenv(LD_SUPPORT_ENV_VAR_32);
1724 1643          if (oldpath == NULL) {
1725 1644                  len = snprintf(NULL, 0, "%s=%s/%s/%s:%s",
1726 1645                      LD_SUPPORT_ENV_VAR_32,
1727 1646                      MAKE_PREFIX,
1728 1647                      LD_SUPPORT_MAKE_LIB_DIR,
1729 1648                      LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1730 1649                  newpath = (char *) malloc(len);
1731 1650                  sprintf(newpath, "%s=%s/%s/%s:%s",
1732 1651                      LD_SUPPORT_ENV_VAR_32,
1733 1652                      MAKE_PREFIX,
1734 1653                      LD_SUPPORT_MAKE_LIB_DIR,
1735 1654                      LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
1736 1655          } else {
1737 1656                  len = snprintf(NULL, 0, "%s=%s:%s/%s/%s:%s",
1738 1657                      LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1739 1658                      LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1740 1659                      LD_SUPPORT_MAKE_LIB) + 1;
1741 1660                  newpath = (char *) malloc(len);
1742 1661                  sprintf(newpath, "%s=%s:%s/%s/%s:%s",
1743 1662                      LD_SUPPORT_ENV_VAR_32, oldpath, MAKE_PREFIX,
1744 1663                      LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB,
1745 1664                      LD_SUPPORT_MAKE_LIB);
1746 1665          }
1747 1666  
1748 1667          oldpath64 = getenv(LD_SUPPORT_ENV_VAR_64);
1749 1668          if (oldpath64 == NULL) {
1750 1669                  len = snprintf(NULL, 0, "%s=%s/%s/%s/%s:%s",
1751 1670                      LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1752 1671                      LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1753 1672                      LD_SUPPORT_MAKE_LIB) + 1;
1754 1673                  newpath64 = (char *) malloc(len);
1755 1674                  sprintf(newpath64, "%s=%s/%s/%s/%s:%s",
1756 1675                      LD_SUPPORT_ENV_VAR_64, MAKE_PREFIX, LD_SUPPORT_MAKE_LIB_DIR,
1757 1676                      LD_SUPPORT_MAKE_LIB_DIR_64, LD_SUPPORT_MAKE_LIB,
1758 1677                      LD_SUPPORT_MAKE_LIB);
1759 1678          } else {
1760 1679                  len = snprintf(NULL, 0, "%s=%s:%s/%s/%s/%s:%s",
1761 1680                      LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1762 1681                      LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1763 1682                      LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB) + 1;
1764 1683                  newpath64 = (char *) malloc(len);
1765 1684                  sprintf(newpath64, "%s=%s:%s/%s/%s/%s:%s",
1766 1685                      LD_SUPPORT_ENV_VAR_64, oldpath64, MAKE_PREFIX,
1767 1686                      LD_SUPPORT_MAKE_LIB_DIR, LD_SUPPORT_MAKE_LIB_DIR_64,
1768 1687                      LD_SUPPORT_MAKE_LIB, LD_SUPPORT_MAKE_LIB);
1769 1688          }
1770 1689  
1771 1690          putenv(newpath);
1772 1691          if (prev_path) {
1773 1692                  free(prev_path);
1774 1693          }
1775 1694          prev_path = newpath;
1776 1695  
1777 1696          putenv(newpath64);
1778 1697          if (prev_path64) {
1779 1698                  free(prev_path64);
1780 1699          }
1781 1700          prev_path64 = newpath64;
1782 1701  }
1783 1702  
1784 1703  /*
1785 1704   *      read_files_and_state(argc, argv)
1786 1705   *
1787 1706   *      Read the makefiles we care about and the environment
1788 1707   *      Also read the = style command line options
1789 1708   *
1790 1709   *      Parameters:
1791 1710   *              argc            You know what this is
1792 1711   *              argv            You know what this is
1793 1712   *
1794 1713   *      Static variables used:
1795 1714   *              env_wins        make -e, determines if env vars are RO
1796 1715   *              ignore_default_mk make -r, determines if make.rules is read
1797 1716   *              not_auto_depen  dwight
1798 1717   *
1799 1718   *      Global variables used:
1800 1719   *              default_target_to_build Set to first proper target from file
1801 1720   *              do_not_exec_rule Set to false when makfile is made
1802 1721   *              dot             The Name ".", used to read current dir
1803 1722   *              empty_name      The Name "", use as macro value
1804 1723   *              keep_state      Set if KEEP_STATE is in environment
1805 1724   *              make_state      The Name ".make.state", used to read file
1806 1725   *              makefile_type   Set to type of file being read
1807 1726   *              makeflags       The Name "MAKEFLAGS", used to set macro value
1808 1727   *              not_auto        dwight
1809 1728   *              read_trace_level Checked to se if the reader should trace
1810 1729   *              report_dependencies If -P is on we do not read .make.state
1811 1730   *              trace_reader    Set if reader should trace
1812 1731   *              virtual_root    The Name "VIRTUAL_ROOT", used to check value
1813 1732   */
1814 1733  static void
1815 1734  read_files_and_state(int argc, char **argv)
1816 1735  {
1817 1736          wchar_t                 buffer[1000];
1818 1737          wchar_t                 buffer_posix[1000];
1819 1738          register char           ch;
1820 1739          register char           *cp;
1821 1740          Property                def_make_macro = NULL;
1822 1741          Name                    def_make_name;
1823 1742          Name                    default_makefile;
1824 1743          String_rec              dest;
1825 1744          wchar_t                 destbuffer[STRING_BUFFER_LENGTH];
1826 1745          register int            i;
1827 1746          register int            j;
1828 1747          Name                    keep_state_name;
1829 1748          int                     length;
1830 1749          Name                    Makefile;
1831 1750          register Property       macro;
1832 1751          struct stat             make_state_stat;
1833 1752          Name                    makefile_name;
1834 1753          register int            makefile_next = 0;
1835 1754          register Boolean        makefile_read = false;
1836 1755          String_rec              makeflags_string;
1837 1756          String_rec              makeflags_string_posix;
1838 1757          String_rec *            makeflags_string_current;
1839 1758          Name                    makeflags_value_saved;
1840 1759          register Name           name;
1841 1760          Name                    new_make_value;
1842 1761          Boolean                 save_do_not_exec_rule;
1843 1762          Name                    sdotMakefile;
1844 1763          Name                    sdotmakefile_name;
1845 1764          static wchar_t          state_file_str;
1846 1765          static char             state_file_str_mb[MAXPATHLEN];
1847 1766          static struct _Name     state_filename;
1848 1767          Boolean                 temp;
1849 1768          char                    tmp_char;
1850 1769          wchar_t                 *tmp_wcs_buffer;
1851 1770          register Name           value;
1852 1771          ASCII_Dyn_Array         makeflags_and_macro;
1853 1772          Boolean                 is_xpg4;
1854 1773  
1855 1774  /*
1856 1775   *      Remember current mode. It may be changed after reading makefile
1857 1776   *      and we will have to correct MAKEFLAGS variable.
1858 1777   */
1859 1778          is_xpg4 = posix;
1860 1779  
1861 1780          MBSTOWCS(wcs_buffer, NOCATGETS("KEEP_STATE"));
1862 1781          keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
1863 1782          MBSTOWCS(wcs_buffer, NOCATGETS("Makefile"));
1864 1783          Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1865 1784          MBSTOWCS(wcs_buffer, NOCATGETS("makefile"));
1866 1785          makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1867 1786          MBSTOWCS(wcs_buffer, NOCATGETS("s.makefile"));
1868 1787          sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1869 1788          MBSTOWCS(wcs_buffer, NOCATGETS("s.Makefile"));
1870 1789          sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
1871 1790  
1872 1791  /*
1873 1792   *      Set flag if NSE is active
1874 1793   */
1875 1794  
1876 1795  /*
1877 1796   *      initialize global dependency entry for .NOT_AUTO
1878 1797   */
1879 1798          not_auto_depen->next = NULL;
1880 1799          not_auto_depen->name = not_auto;
1881 1800          not_auto_depen->automatic = not_auto_depen->stale = false;
1882 1801  
1883 1802  /*
1884 1803   *      Read internal definitions and rules.
1885 1804   */
1886 1805          if (read_trace_level > 1) {
1887 1806                  trace_reader = true;
1888 1807          }
1889 1808          if (!ignore_default_mk) {
1890 1809                  if (svr4) {
1891 1810                          MBSTOWCS(wcs_buffer, NOCATGETS("svr4.make.rules"));
1892 1811                          default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1893 1812                  } else {
1894 1813                          MBSTOWCS(wcs_buffer, NOCATGETS("make.rules"));
1895 1814                          default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1896 1815                  }
1897 1816                  default_makefile->stat.is_file = true;
1898 1817  
1899 1818                  (void) read_makefile(default_makefile,
1900 1819                                       true,
1901 1820                                       false,
1902 1821                                       true);
1903 1822          }
1904 1823  
1905 1824          /*
1906 1825           * If the user did not redefine the MAKE macro in the
1907 1826           * default makefile (make.rules), then we'd like to
1908 1827           * change the macro value of MAKE to be some form
1909 1828           * of argv[0] for recursive MAKE builds.
1910 1829           */
1911 1830          MBSTOWCS(wcs_buffer, NOCATGETS("MAKE"));
1912 1831          def_make_name = GETNAME(wcs_buffer, wslen(wcs_buffer));
1913 1832          def_make_macro = get_prop(def_make_name->prop, macro_prop);
1914 1833          if ((def_make_macro != NULL) &&
1915 1834              (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1916 1835                        NOCATGETS("make")))) {
1917 1836                  MBSTOWCS(wcs_buffer, argv_zero_string);
1918 1837                  new_make_value = GETNAME(wcs_buffer, wslen(wcs_buffer));
1919 1838                  (void) SETVAR(def_make_name,
1920 1839                                new_make_value,
1921 1840                                false);
1922 1841          }
1923 1842  
1924 1843          default_target_to_build = NULL;
1925 1844          trace_reader = false;
1926 1845  
1927 1846  /*
1928 1847   *      Read environment args. Let file args which follow override unless
1929 1848   *      -e option seen. If -e option is not mentioned.
1930 1849   */
1931 1850          read_environment(env_wins);
1932 1851          if (getvar(virtual_root)->hash.length == 0) {
1933 1852                  maybe_append_prop(virtual_root, macro_prop)
1934 1853                    ->body.macro.exported = true;
1935 1854                  MBSTOWCS(wcs_buffer, "/");
1936 1855                  (void) SETVAR(virtual_root,
1937 1856                                GETNAME(wcs_buffer, FIND_LENGTH),
1938 1857                                false);
1939 1858          }
1940 1859  
1941 1860  /*
1942 1861   * We now scan mf_argv and argv to see if we need to set
1943 1862   * any of the DMake-added options/variables in MAKEFLAGS.
1944 1863   */
1945 1864  
1946 1865          makeflags_and_macro.start = 0;
1947 1866          makeflags_and_macro.size = 0;
1948 1867          enter_argv_values(mf_argc, mf_argv, &makeflags_and_macro);
1949 1868          enter_argv_values(argc, argv, &makeflags_and_macro);
1950 1869  
1951 1870  /*
1952 1871   *      Set MFLAGS and MAKEFLAGS
1953 1872   *      
1954 1873   *      Before reading makefile we do not know exactly which mode
1955 1874   *      (posix or not) is used. So prepare two MAKEFLAGS strings
1956 1875   *      for both posix and solaris modes because they are different.
1957 1876   */
1958 1877          INIT_STRING_FROM_STACK(makeflags_string, buffer);
1959 1878          INIT_STRING_FROM_STACK(makeflags_string_posix, buffer_posix);
1960 1879          append_char((int) hyphen_char, &makeflags_string);
1961 1880          append_char((int) hyphen_char, &makeflags_string_posix);
1962 1881  
1963 1882          switch (read_trace_level) {
1964 1883          case 2:
1965 1884                  append_char('D', &makeflags_string);
1966 1885                  append_char('D', &makeflags_string_posix);
1967 1886          case 1:
1968 1887                  append_char('D', &makeflags_string);
1969 1888                  append_char('D', &makeflags_string_posix);
1970 1889          }
1971 1890          switch (debug_level) {
1972 1891          case 2:
1973 1892                  append_char('d', &makeflags_string);
1974 1893                  append_char('d', &makeflags_string_posix);
1975 1894          case 1:
1976 1895                  append_char('d', &makeflags_string);
1977 1896                  append_char('d', &makeflags_string_posix);
1978 1897          }
1979 1898          if (env_wins) {
1980 1899                  append_char('e', &makeflags_string);
1981 1900                  append_char('e', &makeflags_string_posix);
1982 1901          }
1983 1902          if (ignore_errors_all) {
1984 1903                  append_char('i', &makeflags_string);
1985 1904                  append_char('i', &makeflags_string_posix);
1986 1905          }
1987 1906          if (continue_after_error) {
1988 1907                  if (stop_after_error_ever_seen) {
1989 1908                          append_char('S', &makeflags_string_posix);
1990 1909                          append_char((int) space_char, &makeflags_string_posix);
1991 1910                          append_char((int) hyphen_char, &makeflags_string_posix);
1992 1911                  }
1993 1912                  append_char('k', &makeflags_string);
1994 1913                  append_char('k', &makeflags_string_posix);
1995 1914          } else {
1996 1915                  if (stop_after_error_ever_seen 
1997 1916                      && continue_after_error_ever_seen) {
1998 1917                          append_char('k', &makeflags_string_posix);
1999 1918                          append_char((int) space_char, &makeflags_string_posix);
2000 1919                          append_char((int) hyphen_char, &makeflags_string_posix);
2001 1920                          append_char('S', &makeflags_string_posix);
2002 1921                  }
2003 1922          }
2004 1923          if (do_not_exec_rule) {
2005 1924                  append_char('n', &makeflags_string);
2006 1925                  append_char('n', &makeflags_string_posix);
2007 1926          }
2008 1927          switch (report_dependencies_level) {
2009 1928          case 4:
2010 1929                  append_char('P', &makeflags_string);
2011 1930                  append_char('P', &makeflags_string_posix);
2012 1931          case 3:
2013 1932                  append_char('P', &makeflags_string);
2014 1933                  append_char('P', &makeflags_string_posix);
2015 1934          case 2:
2016 1935                  append_char('P', &makeflags_string);
2017 1936                  append_char('P', &makeflags_string_posix);
2018 1937          case 1:
2019 1938                  append_char('P', &makeflags_string);
2020 1939                  append_char('P', &makeflags_string_posix);
2021 1940          }
2022 1941          if (trace_status) {
2023 1942                  append_char('p', &makeflags_string);
2024 1943                  append_char('p', &makeflags_string_posix);
2025 1944          }
2026 1945          if (quest) {
2027 1946                  append_char('q', &makeflags_string);
2028 1947                  append_char('q', &makeflags_string_posix);
2029 1948          }
2030 1949          if (silent_all) {
2031 1950                  append_char('s', &makeflags_string);
2032 1951                  append_char('s', &makeflags_string_posix);
2033 1952          }
2034 1953          if (touch) {
2035 1954                  append_char('t', &makeflags_string);
2036 1955                  append_char('t', &makeflags_string_posix);
2037 1956          }
2038 1957          if (build_unconditional) {
2039 1958                  append_char('u', &makeflags_string);
2040 1959                  append_char('u', &makeflags_string_posix);
2041 1960          }
2042 1961          if (report_cwd) {
2043 1962                  append_char('w', &makeflags_string);
2044 1963                  append_char('w', &makeflags_string_posix);
2045 1964          }
2046 1965          /* -c dmake_rcfile */
2047 1966          if (dmake_rcfile_specified) {
2048 1967                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_RCFILE"));
2049 1968                  dmake_rcfile = GETNAME(wcs_buffer, FIND_LENGTH);
2050 1969                  append_makeflags_string(dmake_rcfile, &makeflags_string);
2051 1970                  append_makeflags_string(dmake_rcfile, &makeflags_string_posix);
2052 1971          }
2053 1972          /* -g dmake_group */
2054 1973          if (dmake_group_specified) {
2055 1974                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_GROUP"));
2056 1975                  dmake_group = GETNAME(wcs_buffer, FIND_LENGTH);
2057 1976                  append_makeflags_string(dmake_group, &makeflags_string);
2058 1977                  append_makeflags_string(dmake_group, &makeflags_string_posix);
2059 1978          }
2060 1979          /* -j dmake_max_jobs */
2061 1980          if (dmake_max_jobs_specified) {
2062 1981                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
2063 1982                  dmake_max_jobs = GETNAME(wcs_buffer, FIND_LENGTH);
2064 1983                  append_makeflags_string(dmake_max_jobs, &makeflags_string);
2065 1984                  append_makeflags_string(dmake_max_jobs, &makeflags_string_posix);
2066 1985          }
2067 1986          /* -m dmake_mode */
2068 1987          if (dmake_mode_specified) {
2069 1988                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
2070 1989                  dmake_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2071 1990                  append_makeflags_string(dmake_mode, &makeflags_string);
2072 1991                  append_makeflags_string(dmake_mode, &makeflags_string_posix);
2073 1992          }
2074 1993          /* -x dmake_compat_mode */
2075 1994  //      if (dmake_compat_mode_specified) {
2076 1995  //              MBSTOWCS(wcs_buffer, NOCATGETS("SUN_MAKE_COMPAT_MODE"));
2077 1996  //              dmake_compat_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2078 1997  //              append_makeflags_string(dmake_compat_mode, &makeflags_string);
2079 1998  //              append_makeflags_string(dmake_compat_mode, &makeflags_string_posix);
2080 1999  //      }
2081 2000          /* -x dmake_output_mode */
2082 2001          if (dmake_output_mode_specified) {
2083 2002                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
2084 2003                  dmake_output_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2085 2004                  append_makeflags_string(dmake_output_mode, &makeflags_string);
2086 2005                  append_makeflags_string(dmake_output_mode, &makeflags_string_posix);
2087 2006          }
2088 2007          /* -o dmake_odir */
2089 2008          if (dmake_odir_specified) {
2090 2009                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_ODIR"));
2091 2010                  dmake_odir = GETNAME(wcs_buffer, FIND_LENGTH);
2092 2011                  append_makeflags_string(dmake_odir, &makeflags_string);
2093 2012                  append_makeflags_string(dmake_odir, &makeflags_string_posix);
2094 2013          }
2095 2014          /* -M pmake_machinesfile */
2096 2015          if (pmake_machinesfile_specified) {
2097 2016                  MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
2098 2017                  pmake_machinesfile = GETNAME(wcs_buffer, FIND_LENGTH);
2099 2018                  append_makeflags_string(pmake_machinesfile, &makeflags_string);
2100 2019                  append_makeflags_string(pmake_machinesfile, &makeflags_string_posix);
2101 2020          }
2102 2021          /* -R */
2103 2022          if (pmake_cap_r_specified) {
2104 2023                  append_char((int) space_char, &makeflags_string);
2105 2024                  append_char((int) hyphen_char, &makeflags_string);
2106 2025                  append_char('R', &makeflags_string);
2107 2026                  append_char((int) space_char, &makeflags_string_posix);
2108 2027                  append_char((int) hyphen_char, &makeflags_string_posix);
2109 2028                  append_char('R', &makeflags_string_posix);
2110 2029          }
2111 2030  
2112 2031  /*
2113 2032   *      Make sure MAKEFLAGS is exported
2114 2033   */
2115 2034          maybe_append_prop(makeflags, macro_prop)->
2116 2035            body.macro.exported = true;
2117 2036  
2118 2037          if (makeflags_string.buffer.start[1] != (int) nul_char) {
2119 2038                  if (makeflags_string.buffer.start[1] != (int) space_char) {
2120 2039                          MBSTOWCS(wcs_buffer, NOCATGETS("MFLAGS"));
2121 2040                          (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2122 2041                                        GETNAME(makeflags_string.buffer.start,
2123 2042                                                FIND_LENGTH),
2124 2043                                        false);
2125 2044                  } else {
2126 2045                          MBSTOWCS(wcs_buffer, NOCATGETS("MFLAGS"));
2127 2046                          (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2128 2047                                        GETNAME(makeflags_string.buffer.start + 2,
2129 2048                                                FIND_LENGTH),
2130 2049                                        false);
2131 2050                  }
2132 2051          }
2133 2052  
2134 2053  /* 
2135 2054   *      Add command line macro to POSIX makeflags_string  
2136 2055   */
2137 2056          if (makeflags_and_macro.start) {
2138 2057                  tmp_char = (char) space_char;
2139 2058                  cp = makeflags_and_macro.start;
2140 2059                  do {
2141 2060                          append_char(tmp_char, &makeflags_string_posix);
2142 2061                  } while ( tmp_char = *cp++ ); 
2143 2062                  retmem_mb(makeflags_and_macro.start);
2144 2063          }
2145 2064  
2146 2065  /*
2147 2066   *      Now set the value of MAKEFLAGS macro in accordance
2148 2067   *      with current mode.
2149 2068   */
2150 2069          macro = maybe_append_prop(makeflags, macro_prop);
2151 2070          temp = (Boolean) macro->body.macro.read_only;
2152 2071          macro->body.macro.read_only = false;
2153 2072          if(posix || gnu_style) {
2154 2073                  makeflags_string_current = &makeflags_string_posix;
2155 2074          } else {
2156 2075                  makeflags_string_current = &makeflags_string;
2157 2076          }
2158 2077          if (makeflags_string_current->buffer.start[1] == (int) nul_char) {
2159 2078                  makeflags_value_saved =
2160 2079                          GETNAME( makeflags_string_current->buffer.start + 1
2161 2080                                 , FIND_LENGTH
2162 2081                                 );
2163 2082          } else {
2164 2083                  if (makeflags_string_current->buffer.start[1] != (int) space_char) {
2165 2084                          makeflags_value_saved =
2166 2085                                  GETNAME( makeflags_string_current->buffer.start
2167 2086                                         , FIND_LENGTH
2168 2087                                         );
2169 2088                  } else {
2170 2089                          makeflags_value_saved =
2171 2090                                  GETNAME( makeflags_string_current->buffer.start + 2
2172 2091                                         , FIND_LENGTH
2173 2092                                         );
2174 2093                  }
2175 2094          }
2176 2095          (void) SETVAR( makeflags
2177 2096                       , makeflags_value_saved
2178 2097                       , false
2179 2098                       );
2180 2099          macro->body.macro.read_only = temp;
2181 2100  
2182 2101  /*
2183 2102   *      Read command line "-f" arguments and ignore -c, g, j, K, M, m, O and o args.
2184 2103   */
2185 2104          save_do_not_exec_rule = do_not_exec_rule;
2186 2105          do_not_exec_rule = false;
2187 2106          if (read_trace_level > 0) {
2188 2107                  trace_reader = true;
2189 2108          }
2190 2109  
2191 2110          for (i = 1; i < argc; i++) {
2192 2111                  if (argv[i] &&
2193 2112                      (argv[i][0] == (int) hyphen_char) &&
2194 2113                      (argv[i][1] == 'f') &&
2195 2114                      (argv[i][2] == (int) nul_char)) {
2196 2115                          argv[i] = NULL;         /* Remove -f */
2197 2116                          if (i >= argc - 1) {
2198 2117                                  fatal(catgets(catd, 1, 190, "No filename argument after -f flag"));
2199 2118                          }
2200 2119                          MBSTOWCS(wcs_buffer, argv[++i]);
2201 2120                          primary_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2202 2121                          (void) read_makefile(primary_makefile, true, true, true);
2203 2122                          argv[i] = NULL;         /* Remove filename */
2204 2123                          makefile_read = true;
2205 2124                  } else if (argv[i] &&
2206 2125                             (argv[i][0] == (int) hyphen_char) &&
2207 2126                             (argv[i][1] == 'c' ||
2208 2127                              argv[i][1] == 'g' ||
2209 2128                              argv[i][1] == 'j' ||
2210 2129                              argv[i][1] == 'K' ||
2211 2130                              argv[i][1] == 'M' ||
2212 2131                              argv[i][1] == 'm' ||
2213 2132                              argv[i][1] == 'O' ||
2214 2133                              argv[i][1] == 'o') &&
2215 2134                             (argv[i][2] == (int) nul_char)) {
2216 2135                          argv[i] = NULL;
2217 2136                          argv[++i] = NULL;
2218 2137                  }
2219 2138          }
2220 2139  
2221 2140  /*
2222 2141   *      If no command line "-f" args then look for "makefile", and then for
2223 2142   *      "Makefile" if "makefile" isn't found.
2224 2143   */
2225 2144          if (!makefile_read) {
2226 2145                  (void) read_dir(dot,
2227 2146                                  (wchar_t *) NULL,
2228 2147                                  (Property) NULL,
2229 2148                                  (wchar_t *) NULL);
2230 2149              if (!posix) {
2231 2150                  if (makefile_name->stat.is_file) {
2232 2151                          if (Makefile->stat.is_file) {
2233 2152                                  warning(catgets(catd, 1, 310, "Both `makefile' and `Makefile' exist"));
2234 2153                          }
2235 2154                          primary_makefile = makefile_name;
2236 2155                          makefile_read = read_makefile(makefile_name,
2237 2156                                                        false,
2238 2157                                                        false,
2239 2158                                                        true);
2240 2159                  }
2241 2160                  if (!makefile_read &&
2242 2161                      Makefile->stat.is_file) {
2243 2162                          primary_makefile = Makefile;
2244 2163                          makefile_read = read_makefile(Makefile,
2245 2164                                                        false,
2246 2165                                                        false,
2247 2166                                                        true);
2248 2167                  }
2249 2168              } else {
2250 2169  
2251 2170                  enum sccs_stat save_m_has_sccs = NO_SCCS;
2252 2171                  enum sccs_stat save_M_has_sccs = NO_SCCS;
2253 2172  
2254 2173                  if (makefile_name->stat.is_file) {
2255 2174                          if (Makefile->stat.is_file) {
2256 2175                                  warning(catgets(catd, 1, 191, "Both `makefile' and `Makefile' exist"));
2257 2176                          }
2258 2177                  }
2259 2178                  if (makefile_name->stat.is_file) {
2260 2179                          if (makefile_name->stat.has_sccs == NO_SCCS) {
2261 2180                             primary_makefile = makefile_name;
2262 2181                             makefile_read = read_makefile(makefile_name,
2263 2182                                                        false,
2264 2183                                                        false,
2265 2184                                                        true);
2266 2185                          } else {
2267 2186                            save_m_has_sccs = makefile_name->stat.has_sccs;
2268 2187                            makefile_name->stat.has_sccs = NO_SCCS;
2269 2188                            primary_makefile = makefile_name;
2270 2189                            makefile_read = read_makefile(makefile_name,
2271 2190                                                        false,
2272 2191                                                        false,
2273 2192                                                        true);
2274 2193                          }
2275 2194                  }
2276 2195                  if (!makefile_read &&
2277 2196                      Makefile->stat.is_file) {
2278 2197                          if (Makefile->stat.has_sccs == NO_SCCS) {
2279 2198                             primary_makefile = Makefile;
2280 2199                             makefile_read = read_makefile(Makefile,
2281 2200                                                        false,
2282 2201                                                        false,
2283 2202                                                        true);
2284 2203                          } else {
2285 2204                            save_M_has_sccs = Makefile->stat.has_sccs;
2286 2205                            Makefile->stat.has_sccs = NO_SCCS;
2287 2206                            primary_makefile = Makefile;
2288 2207                            makefile_read = read_makefile(Makefile,
2289 2208                                                        false,
2290 2209                                                        false,
2291 2210                                                        true);
2292 2211                          }
2293 2212                  }
2294 2213                  if (!makefile_read &&
2295 2214                          makefile_name->stat.is_file) {
2296 2215                             makefile_name->stat.has_sccs = save_m_has_sccs;
2297 2216                             primary_makefile = makefile_name;
2298 2217                             makefile_read = read_makefile(makefile_name,
2299 2218                                                        false,
2300 2219                                                        false,
2301 2220                                                        true);
2302 2221                  }
2303 2222                  if (!makefile_read &&
2304 2223                      Makefile->stat.is_file) {
2305 2224                             Makefile->stat.has_sccs = save_M_has_sccs;
2306 2225                             primary_makefile = Makefile;
2307 2226                             makefile_read = read_makefile(Makefile,
2308 2227                                                        false,
2309 2228                                                        false,
2310 2229                                                        true);
2311 2230                  }
2312 2231              }
2313 2232          }
2314 2233          do_not_exec_rule = save_do_not_exec_rule;
2315 2234          allrules_read = makefile_read;
2316 2235          trace_reader = false;
2317 2236  
2318 2237  /*
2319 2238   *      Now get current value of MAKEFLAGS and compare it with
2320 2239   *      the saved value we set before reading makefile.
2321 2240   *      If they are different then MAKEFLAGS is subsequently set by
2322 2241   *      makefile, just leave it there. Otherwise, if make mode
2323 2242   *      is changed by using .POSIX target in makefile we need
2324 2243   *      to correct MAKEFLAGS value.
2325 2244   */
2326 2245          Name mf_val = getvar(makeflags);
2327 2246          if( (posix != is_xpg4)
2328 2247           && (!strcmp(mf_val->string_mb, makeflags_value_saved->string_mb)))
2329 2248          {
2330 2249                  if (makeflags_string_posix.buffer.start[1] == (int) nul_char) {
2331 2250                          (void) SETVAR(makeflags,
2332 2251                                        GETNAME(makeflags_string_posix.buffer.start + 1,
2333 2252                                                FIND_LENGTH),
2334 2253                                        false);
2335 2254                  } else {
2336 2255                          if (makeflags_string_posix.buffer.start[1] != (int) space_char) {
2337 2256                                  (void) SETVAR(makeflags,
2338 2257                                                GETNAME(makeflags_string_posix.buffer.start,
2339 2258                                                        FIND_LENGTH),
2340 2259                                                false);
2341 2260                          } else {
2342 2261                                  (void) SETVAR(makeflags,
2343 2262                                                GETNAME(makeflags_string_posix.buffer.start + 2,
2344 2263                                                        FIND_LENGTH),
2345 2264                                                false);
2346 2265                          }
2347 2266                  }
2348 2267          }
2349 2268  
2350 2269          if (makeflags_string.free_after_use) {
2351 2270                  retmem(makeflags_string.buffer.start);
2352 2271          }
2353 2272          if (makeflags_string_posix.free_after_use) {
2354 2273                  retmem(makeflags_string_posix.buffer.start);
2355 2274          }
2356 2275          makeflags_string.buffer.start = NULL;
2357 2276          makeflags_string_posix.buffer.start = NULL;
2358 2277  
2359 2278          if (posix) {
2360 2279                  /*
2361 2280                   * If the user did not redefine the ARFLAGS macro in the
2362 2281                   * default makefile (make.rules), then we'd like to
2363 2282                   * change the macro value of ARFLAGS to be in accordance
2364 2283                   * with "POSIX" requirements.
2365 2284                   */
2366 2285                  MBSTOWCS(wcs_buffer, NOCATGETS("ARFLAGS"));
2367 2286                  name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2368 2287                  macro = get_prop(name->prop, macro_prop);
2369 2288                  if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2370 2289                      (IS_EQUAL(macro->body.macro.value->string_mb,
2371 2290                                NOCATGETS("rv")))) {
2372 2291                          MBSTOWCS(wcs_buffer, NOCATGETS("-rv"));
2373 2292                          value = GETNAME(wcs_buffer, wslen(wcs_buffer));
2374 2293                          (void) SETVAR(name,
2375 2294                                        value,
2376 2295                                        false);
2377 2296                  }
2378 2297          }
2379 2298  
2380 2299          if (!posix && !svr4) {
2381 2300                  set_sgs_support();
2382 2301          }
2383 2302  
2384 2303  
2385 2304  /*
2386 2305   *      Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2387 2306   */
2388 2307          macro = get_prop(keep_state_name->prop, macro_prop);
2389 2308          if ((macro != NULL) &&
2390 2309              macro->body.macro.exported) {
2391 2310                  keep_state = true;
2392 2311          }
2393 2312          if (keep_state) {
2394 2313                  if (macro == NULL) {
2395 2314                          macro = maybe_append_prop(keep_state_name,
2396 2315                                                    macro_prop);
2397 2316                  }
2398 2317                  macro->body.macro.exported = true;
2399 2318                  (void) SETVAR(keep_state_name,
2400 2319                                empty_name,
2401 2320                                false);
2402 2321  
2403 2322                  /*
2404 2323                   *      Read state file
2405 2324                   */
2406 2325  
2407 2326                  /* Before we read state, let's make sure we have
2408 2327                  ** right state file.
2409 2328                  */
2410 2329                  /* just in case macro references are used in make_state file
2411 2330                  ** name, we better expand them at this stage using expand_value.
2412 2331                  */
2413 2332                  INIT_STRING_FROM_STACK(dest, destbuffer);
2414 2333                  expand_value(make_state, &dest, false);
2415 2334  
2416 2335                  make_state = GETNAME(dest.buffer.start, FIND_LENGTH);
2417 2336  
2418 2337                  if(!stat(make_state->string_mb, &make_state_stat)) {
2419 2338                     if(!(make_state_stat.st_mode & S_IFREG) ) {
2420 2339                          /* copy the make_state structure to the other
2421 2340                          ** and then let make_state point to the new
2422 2341                          ** one.
2423 2342                          */
2424 2343                        memcpy(&state_filename, make_state,sizeof(state_filename));
2425 2344                        state_filename.string_mb = state_file_str_mb;
2426 2345                  /* Just a kludge to avoid two slashes back to back */                   
2427 2346                        if((make_state->hash.length == 1)&&
2428 2347                                  (make_state->string_mb[0] == '/')) {
2429 2348                           make_state->hash.length = 0;
2430 2349                           make_state->string_mb[0] = '\0';
2431 2350                        }
2432 2351                        sprintf(state_file_str_mb,NOCATGETS("%s%s"),
2433 2352                         make_state->string_mb,NOCATGETS("/.make.state"));
2434 2353                        make_state = &state_filename;
2435 2354                          /* adjust the length to reflect the appended string */
2436 2355                        make_state->hash.length += 12;
2437 2356                     }
2438 2357                  } else { /* the file doesn't exist or no permission */
2439 2358                     char tmp_path[MAXPATHLEN];
2440 2359                     char *slashp;
2441 2360  
2442 2361                     if (slashp = strrchr(make_state->string_mb, '/')) {
2443 2362                        strncpy(tmp_path, make_state->string_mb, 
2444 2363                                  (slashp - make_state->string_mb));
2445 2364                          tmp_path[slashp - make_state->string_mb]=0;
2446 2365                        if(strlen(tmp_path)) {
2447 2366                          if(stat(tmp_path, &make_state_stat)) {
2448 2367                            warning(catgets(catd, 1, 192, "directory %s for .KEEP_STATE_FILE does not exist"),tmp_path);
2449 2368                          }
2450 2369                          if (access(tmp_path, F_OK) != 0) {
2451 2370                            warning(catgets(catd, 1, 193, "can't access dir %s"),tmp_path);
2452 2371                          }
2453 2372                        }
2454 2373                     }
2455 2374                  }
2456 2375                  if (report_dependencies_level != 1) {
2457 2376                          Makefile_type   makefile_type_temp = makefile_type;
2458 2377                          makefile_type = reading_statefile;
2459 2378                          if (read_trace_level > 1) {
2460 2379                                  trace_reader = true;
2461 2380                          }
2462 2381                          (void) read_simple_file(make_state,
2463 2382                                                  false,
2464 2383                                                  false,
2465 2384                                                  false,
2466 2385                                                  false,
2467 2386                                                  false,
2468 2387                                                  true);
2469 2388                          trace_reader = false;
2470 2389                          makefile_type = makefile_type_temp;
2471 2390                  }
2472 2391          }
2473 2392  }
2474 2393  
2475 2394  /*
2476 2395   * Scan the argv for options and "=" type args and make them readonly.
2477 2396   */
2478 2397  static void
2479 2398  enter_argv_values(int argc, char *argv[], ASCII_Dyn_Array *makeflags_and_macro)
2480 2399  {
2481 2400          register char           *cp;
2482 2401          register int            i;
2483 2402          int                     length;
2484 2403          register Name           name;
2485 2404          int                     opt_separator = argc; 
2486 2405          char                    tmp_char;
2487 2406          wchar_t                 *tmp_wcs_buffer;
2488 2407          register Name           value;
2489 2408          Boolean                 append = false;
2490 2409          Property                macro;
2491 2410          struct stat             statbuf;
2492 2411  
2493 2412  
2494 2413          /* Read argv options and "=" type args and make them readonly. */
2495 2414          makefile_type = reading_nothing;
2496 2415          for (i = 1; i < argc; ++i) {
2497 2416                  append = false;
2498 2417                  if (argv[i] == NULL) {
2499 2418                          continue;
2500 2419                  } else if (((argv[i][0] == '-') && (argv[i][1] == '-')) ||
2501 2420                             ((argv[i][0] == (int) ' ') &&
2502 2421                              (argv[i][1] == (int) '-') &&
2503 2422                              (argv[i][2] == (int) ' ') &&
2504 2423                              (argv[i][3] == (int) '-'))) {
2505 2424                          argv[i] = NULL;
2506 2425                          opt_separator = i;
2507 2426                          continue;
2508 2427                  } else if ((i < opt_separator) && (argv[i][0] == (int) hyphen_char)) {
2509 2428                          switch (parse_command_option(argv[i][1])) {
2510 2429                          case 1: /* -f seen */
2511 2430                                  ++i;
2512 2431                                  continue;
2513 2432                          case 2: /* -c seen */
2514 2433                                  if (argv[i+1] == NULL) {
2515 2434                                          fatal(catgets(catd, 1, 194, "No dmake rcfile argument after -c flag"));
2516 2435                                  }
2517 2436                                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_RCFILE"));
2518 2437                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2519 2438                                  break;
2520 2439                          case 4: /* -g seen */
2521 2440                                  if (argv[i+1] == NULL) {
2522 2441                                          fatal(catgets(catd, 1, 195, "No dmake group argument after -g flag"));
2523 2442                                  }
2524 2443                                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_GROUP"));
2525 2444                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2526 2445                                  break;
2527 2446                          case 8: /* -j seen */
2528 2447                                  if (argv[i+1] == NULL) {
2529 2448                                          fatal(catgets(catd, 1, 196, "No dmake max jobs argument after -j flag"));
2530 2449                                  }
2531 2450                                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
2532 2451                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2533 2452                                  break;
2534 2453                          case 16: /* -M seen */
2535 2454                                  if (argv[i+1] == NULL) {
2536 2455                                          fatal(catgets(catd, 1, 323, "No pmake machinesfile argument after -M flag"));
2537 2456                                  }
2538 2457                                  MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
2539 2458                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2540 2459                                  break;
2541 2460                          case 32: /* -m seen */
2542 2461                                  if (argv[i+1] == NULL) {
2543 2462                                          fatal(catgets(catd, 1, 197, "No dmake mode argument after -m flag"));
2544 2463                                  }
2545 2464                                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MODE"));
2546 2465                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2547 2466                                  break;
2548 2467                          case 128: /* -O seen */
2549 2468                                  if (argv[i+1] == NULL) {
2550 2469                                          fatal(catgets(catd, 1, 287, "No file descriptor argument after -O flag"));
2551 2470                                  }
2552 2471                                  mtool_msgs_fd = atoi(argv[i+1]);
2553 2472                                  /* find out if mtool_msgs_fd is a valid file descriptor */
2554 2473                                  if (fstat(mtool_msgs_fd, &statbuf) < 0) {
2555 2474                                          fatal(catgets(catd, 1, 355, "Invalid file descriptor %d after -O flag"), mtool_msgs_fd);
2556 2475                                  }
2557 2476                                  argv[i] = NULL;
2558 2477                                  argv[i+1] = NULL;
2559 2478                                  continue;
2560 2479                          case 256: /* -K seen */
2561 2480                                  if (argv[i+1] == NULL) {
2562 2481                                          fatal(catgets(catd, 1, 288, "No makestate filename argument after -K flag"));
2563 2482                                  }
2564 2483                                  MBSTOWCS(wcs_buffer, argv[i+1]);
2565 2484                                  make_state = GETNAME(wcs_buffer, FIND_LENGTH);
2566 2485                                  keep_state = true;
2567 2486                                  argv[i] = NULL;
2568 2487                                  argv[i+1] = NULL;
2569 2488                                  continue;
2570 2489                          case 512:       /* -o seen */
2571 2490                                  if (argv[i+1] == NULL) {
2572 2491                                          fatal(catgets(catd, 1, 312, "No dmake output dir argument after -o flag"));
2573 2492                                  }
2574 2493                                  MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_ODIR"));
2575 2494                                  name = GETNAME(wcs_buffer, FIND_LENGTH);
2576 2495                                  break;
2577 2496                          case 1024: /* -x seen */
2578 2497                                  if (argv[i+1] == NULL) {
2579 2498                                          fatal(catgets(catd, 1, 351, "No argument after -x flag"));
2580 2499                                  }
2581 2500                                  length = strlen( NOCATGETS("SUN_MAKE_COMPAT_MODE="));
2582 2501                                  if (strncmp(argv[i+1], NOCATGETS("SUN_MAKE_COMPAT_MODE="), length) == 0) {
2583 2502                                          argv[i+1] = &argv[i+1][length];
2584 2503                                          MBSTOWCS(wcs_buffer, NOCATGETS("SUN_MAKE_COMPAT_MODE"));
2585 2504                                          name = GETNAME(wcs_buffer, FIND_LENGTH);
2586 2505                                          dmake_compat_mode_specified = dmake_add_mode_specified;
2587 2506                                          break;
2588 2507                                  }
2589 2508                                  length = strlen( NOCATGETS("DMAKE_OUTPUT_MODE="));
2590 2509                                  if (strncmp(argv[i+1], NOCATGETS("DMAKE_OUTPUT_MODE="), length) == 0) {
2591 2510                                          argv[i+1] = &argv[i+1][length];
2592 2511                                          MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_OUTPUT_MODE"));
2593 2512                                          name = GETNAME(wcs_buffer, FIND_LENGTH);
2594 2513                                          dmake_output_mode_specified = dmake_add_mode_specified;
2595 2514                                  } else {
2596 2515                                          warning(catgets(catd, 1, 354, "Unknown argument `%s' after -x flag (ignored)"),
2597 2516                                                argv[i+1]);
2598 2517                                          argv[i] = argv[i + 1] = NULL;
2599 2518                                          continue;
2600 2519                                  }
2601 2520                                  break;
2602 2521                          default: /* Shouldn't reach here */
2603 2522                                  argv[i] = NULL;
2604 2523                                  continue;
2605 2524                          }
2606 2525                          argv[i] = NULL;
2607 2526                          if (i == (argc - 1)) {
2608 2527                                  break;
2609 2528                          }
2610 2529                          if ((length = strlen(argv[i+1])) >= MAXPATHLEN) {
2611 2530                                  tmp_wcs_buffer = ALLOC_WC(length + 1);
2612 2531                                  (void) mbstowcs(tmp_wcs_buffer, argv[i+1], length + 1);
2613 2532                                  value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2614 2533                                  retmem(tmp_wcs_buffer);
2615 2534                          } else {
2616 2535                                  MBSTOWCS(wcs_buffer, argv[i+1]);
2617 2536                                  value = GETNAME(wcs_buffer, FIND_LENGTH);
2618 2537                          }
2619 2538                          argv[i+1] = NULL;
2620 2539                  } else if ((cp = strchr(argv[i], (int) equal_char)) != NULL) {
2621 2540  /* 
2622 2541   * Combine all macro in dynamic array
2623 2542   */
2624 2543                          if(*(cp-1) == (int) plus_char)
2625 2544                          {
2626 2545                                  if(isspace(*(cp-2))) {
2627 2546                                          append = true;
2628 2547                                          cp--;
2629 2548                                  }
2630 2549                          }
2631 2550                          if(!append)
2632 2551                                  append_or_replace_macro_in_dyn_array(makeflags_and_macro, argv[i]);
2633 2552  
2634 2553                          while (isspace(*(cp-1))) {
2635 2554                                  cp--;
2636 2555                          }
2637 2556                          tmp_char = *cp;
2638 2557                          *cp = (int) nul_char;
2639 2558                          MBSTOWCS(wcs_buffer, argv[i]);
2640 2559                          *cp = tmp_char;
2641 2560                          name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2642 2561                          while (*cp != (int) equal_char) {
2643 2562                                  cp++;
2644 2563                          }
2645 2564                          cp++;
2646 2565                          while (isspace(*cp) && (*cp != (int) nul_char)) {
2647 2566                                  cp++;
2648 2567                          }
2649 2568                          if ((length = strlen(cp)) >= MAXPATHLEN) {
2650 2569                                  tmp_wcs_buffer = ALLOC_WC(length + 1);
2651 2570                                  (void) mbstowcs(tmp_wcs_buffer, cp, length + 1);
2652 2571                                  value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2653 2572                                  retmem(tmp_wcs_buffer);
2654 2573                          } else {
2655 2574                                  MBSTOWCS(wcs_buffer, cp);
2656 2575                                  value = GETNAME(wcs_buffer, FIND_LENGTH);
2657 2576                          }
2658 2577                          argv[i] = NULL;
2659 2578                  } else {
2660 2579                          /* Illegal MAKEFLAGS argument */
2661 2580                          continue;
2662 2581                  }
2663 2582                  if(append) {
2664 2583                          setvar_append(name, value);
2665 2584                          append = false;
2666 2585                  } else {
2667 2586                          macro = maybe_append_prop(name, macro_prop);
2668 2587                          macro->body.macro.exported = true;
2669 2588                          SETVAR(name, value, false)->body.macro.read_only = true;
2670 2589                  }
2671 2590          }
2672 2591  }
2673 2592  
2674 2593  /*
2675 2594   * Append the DMake option and value to the MAKEFLAGS string.
2676 2595   */
2677 2596  static void
2678 2597  append_makeflags_string(Name name, register String makeflags_string)
2679 2598  {
2680 2599          const char      *option;
2681 2600  
2682 2601          if (strcmp(name->string_mb, NOCATGETS("DMAKE_GROUP")) == 0) {
2683 2602                  option = NOCATGETS(" -g ");
2684 2603          } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_MAX_JOBS")) == 0) {
2685 2604                  option = NOCATGETS(" -j ");
2686 2605          } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_MODE")) == 0) {
2687 2606                  option = NOCATGETS(" -m ");
2688 2607          } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_ODIR")) == 0) {
2689 2608                  option = NOCATGETS(" -o ");
2690 2609          } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_RCFILE")) == 0) {
2691 2610                  option = NOCATGETS(" -c ");
2692 2611          } else if (strcmp(name->string_mb, NOCATGETS("PMAKE_MACHINESFILE")) == 0) {
2693 2612                  option = NOCATGETS(" -M ");
2694 2613          } else if (strcmp(name->string_mb, NOCATGETS("DMAKE_OUTPUT_MODE")) == 0) {
2695 2614                  option = NOCATGETS(" -x DMAKE_OUTPUT_MODE=");
2696 2615          } else if (strcmp(name->string_mb, NOCATGETS("SUN_MAKE_COMPAT_MODE")) == 0) {
2697 2616                  option = NOCATGETS(" -x SUN_MAKE_COMPAT_MODE=");
2698 2617          } else {
2699 2618                  fatal(catgets(catd, 1, 289, "Internal error: name not recognized in append_makeflags_string()"));
2700 2619          }
2701 2620          Property prop = maybe_append_prop(name, macro_prop);
2702 2621          if( prop == 0 || prop->body.macro.value == 0 ||
2703 2622              prop->body.macro.value->string_mb == 0 ) {
2704 2623                  return;
2705 2624          }
2706 2625          char mbs_value[MAXPATHLEN + 100];
2707 2626          strcpy(mbs_value, option);
2708 2627          strcat(mbs_value, prop->body.macro.value->string_mb);
2709 2628          MBSTOWCS(wcs_buffer, mbs_value);
2710 2629          append_string(wcs_buffer, makeflags_string, FIND_LENGTH);
2711 2630  }
2712 2631  
2713 2632  /*
2714 2633   *      read_environment(read_only)
2715 2634   *
2716 2635   *      This routine reads the process environment when make starts and enters
2717 2636   *      it as make macros. The environment variable SHELL is ignored.
2718 2637   *
2719 2638   *      Parameters:
2720 2639   *              read_only       Should we make env vars read only?
2721 2640   *
2722 2641   *      Global variables used:
2723 2642   *              report_pwd      Set if this make was started by other make
2724 2643   */
2725 2644  static void
2726 2645  read_environment(Boolean read_only)
2727 2646  {
2728 2647          register char           **environment;
2729 2648          int                     length;
2730 2649          wchar_t                 *tmp_wcs_buffer;
2731 2650          Boolean                 alloced_tmp_wcs_buffer = false;
2732 2651          register wchar_t        *name;
2733 2652          register wchar_t        *value;
2734 2653          register Name           macro;
2735 2654          Property                val;
2736 2655          Boolean                 read_only_saved;
2737 2656  
2738 2657          reading_environment = true;
2739 2658          environment = environ;
2740 2659          for (; *environment; environment++) {
2741 2660                  read_only_saved = read_only;
2742 2661                  if ((length = strlen(*environment)) >= MAXPATHLEN) {
2743 2662                          tmp_wcs_buffer = ALLOC_WC(length + 1);
2744 2663                          alloced_tmp_wcs_buffer = true;
2745 2664                          (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2746 2665                          name = tmp_wcs_buffer;
2747 2666                  } else {
2748 2667                          MBSTOWCS(wcs_buffer, *environment);
2749 2668                          name = wcs_buffer;
2750 2669                  }
2751 2670                  value = (wchar_t *) wschr(name, (int) equal_char);
2752 2671  
2753 2672                  /*
2754 2673                   * Looks like there's a bug in the system, but sometimes
2755 2674                   * you can get blank lines in *environment.
2756 2675                   */
2757 2676                  if (!value) {
2758 2677                          continue;
2759 2678                  }
2760 2679                  MBSTOWCS(wcs_buffer2, NOCATGETS("SHELL="));
2761 2680                  if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2762 2681                          continue;
2763 2682                  }
2764 2683                  MBSTOWCS(wcs_buffer2, NOCATGETS("MAKEFLAGS="));
2765 2684                  if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2766 2685                          report_pwd = true;
2767 2686                          /*
2768 2687                           * In POSIX mode we do not want MAKEFLAGS to be readonly.
2769 2688                           * If the MAKEFLAGS macro is subsequently set by the makefile,
2770 2689                           * it replaces the MAKEFLAGS variable currently found in the
2771 2690                           * environment.
2772 2691                           * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2773 2692                           */
2774 2693                          if(posix) {
2775 2694                                  read_only_saved = false;
2776 2695                          }
2777 2696                  }
2778 2697  
2779 2698                  /*
2780 2699                   * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2781 2700                   * set by make and read by cpp which then writes info to
2782 2701                   * .make.dependency.xxx.  When make is invoked by another make
2783 2702                   * (recursive make), we don't want to read this because then
2784 2703                   * the child make will end up writing to the parent
2785 2704                   * directory's .make.state and clobbering them.
2786 2705                   */
2787 2706                  MBSTOWCS(wcs_buffer2, NOCATGETS("SUNPRO_DEPENDENCIES"));
2788 2707                  if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2789 2708                          continue;
2790 2709                  }
2791 2710  
2792 2711                  macro = GETNAME(name, value - name);
2793 2712                  maybe_append_prop(macro, macro_prop)->body.macro.exported =
2794 2713                    true;
2795 2714                  if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2796 2715                          val = setvar_daemon(macro,
2797 2716                                              (Name) NULL,
2798 2717                                              false, no_daemon, false, debug_level);
2799 2718                  } else {
2800 2719                          val = setvar_daemon(macro,
2801 2720                                              GETNAME(value + 1, FIND_LENGTH),
2802 2721                                              false, no_daemon, false, debug_level);
2803 2722                  }
2804 2723                  val->body.macro.read_only = read_only_saved;
2805 2724                  if (alloced_tmp_wcs_buffer) {
2806 2725                          retmem(tmp_wcs_buffer);
2807 2726                          alloced_tmp_wcs_buffer = false;
2808 2727                  }
2809 2728          }
2810 2729          reading_environment = false;
2811 2730  }
2812 2731  
2813 2732  /*
2814 2733   *      read_makefile(makefile, complain, must_exist, report_file)
2815 2734   *
2816 2735   *      Read one makefile and check the result
2817 2736   *
2818 2737   *      Return value:
2819 2738   *                              false is the read failed
2820 2739   *
2821 2740   *      Parameters:
2822 2741   *              makefile        The file to read
2823 2742   *              complain        Passed thru to read_simple_file()
2824 2743   *              must_exist      Passed thru to read_simple_file()
2825 2744   *              report_file     Passed thru to read_simple_file()
2826 2745   *
2827 2746   *      Global variables used:
2828 2747   *              makefile_type   Set to indicate we are reading main file
2829 2748   *              recursion_level Initialized
2830 2749   */
2831 2750  static Boolean
2832 2751  read_makefile(register Name makefile, Boolean complain, Boolean must_exist, Boolean report_file)
2833 2752  {
2834 2753          Boolean                 b;
2835 2754          
2836 2755          makefile_type = reading_makefile;
2837 2756          recursion_level = 0;
2838 2757          reading_dependencies = true;
2839 2758          b = read_simple_file(makefile, true, true, complain,
2840 2759                               must_exist, report_file, false);
2841 2760          reading_dependencies = false;
2842 2761          return b;
2843 2762  }
2844 2763  
2845 2764  /*
2846 2765   *      make_targets(argc, argv, parallel_flag)
2847 2766   *
2848 2767   *      Call doname on the specified targets
2849 2768   *
2850 2769   *      Parameters:
2851 2770   *              argc            You know what this is
2852 2771   *              argv            You know what this is
2853 2772   *              parallel_flag   True if building in parallel
2854 2773   *
2855 2774   *      Global variables used:
2856 2775   *              build_failed_seen Used to generated message after failed -k
2857 2776   *              commands_done   Used to generate message "Up to date"
2858 2777   *              default_target_to_build First proper target in makefile
2859 2778   *              init            The Name ".INIT", use to run command
2860 2779   *              parallel        Global parallel building flag
2861 2780   *              quest           make -q, suppresses messages
2862 2781   *              recursion_level Initialized, used for tracing
2863 2782   *              report_dependencies make -P, regroves whole process
2864 2783   */
2865 2784  static void
2866 2785  make_targets(int argc, char **argv, Boolean parallel_flag)
2867 2786  {
2868 2787          int                     i;
  
    | 
      ↓ open down ↓ | 
    1244 lines elided | 
    
      ↑ open up ↑ | 
  
2869 2788          char                    *cp;
2870 2789          Doname                  result;
2871 2790          register Boolean        target_to_make_found = false;
2872 2791  
2873 2792          (void) doname(init, true, true);
2874 2793          recursion_level = 1;
2875 2794          parallel = parallel_flag;
2876 2795  /*
2877 2796   *      make remaining args
2878 2797   */
2879      -#ifdef TEAMWARE_MAKE_CMN
2880 2798  /*
2881 2799          if ((report_dependencies_level == 0) && parallel) {
2882 2800   */
2883 2801          if (parallel) {
2884 2802                  /*
2885 2803                   * If building targets in parallel, start all of the
2886 2804                   * remaining args to build in parallel.
2887 2805                   */
2888 2806                  for (i = 1; i < argc; i++) {
2889 2807                          if ((cp = argv[i]) != NULL) {
2890 2808                                  commands_done = false;
2891 2809                                  if ((cp[0] == (int) period_char) &&
2892 2810                                      (cp[1] == (int) slash_char)) {
2893 2811                                          cp += 2;
2894 2812                                  }
2895 2813                                   if((cp[0] == (int) ' ') &&
2896 2814                                      (cp[1] == (int) '-') &&
2897 2815                                      (cp[2] == (int) ' ') &&
2898 2816                                      (cp[3] == (int) '-')) {
2899 2817                                      argv[i] = NULL;
2900 2818                                          continue;
2901 2819                                  }
2902 2820                                  MBSTOWCS(wcs_buffer, cp);
2903 2821                                  //default_target_to_build = GETNAME(wcs_buffer,
2904 2822                                  //                                FIND_LENGTH);
2905 2823                                  default_target_to_build = normalize_name(wcs_buffer,
2906 2824                                                                    wslen(wcs_buffer));
2907 2825                                  if (default_target_to_build == wait_name) {
2908 2826                                          if (parallel_process_cnt > 0) {
2909 2827                                                  finish_running();
2910 2828                                          }
2911 2829                                          continue;
2912 2830                                  }
2913 2831                                  top_level_target = get_wstring(default_target_to_build->string_mb);
2914 2832                                  /*
2915 2833                                   * If we can't execute the current target in
2916 2834                                   * parallel, hold off the target processing
2917 2835                                   * to preserve the order of the targets as they appeared
2918 2836                                   * in command line.
2919 2837                                   */
2920 2838                                  if (!parallel_ok(default_target_to_build, false)
2921 2839                                                  && parallel_process_cnt > 0) {
2922 2840                                          finish_running();
2923 2841                                  }
2924 2842                                  result = doname_check(default_target_to_build,
2925 2843                                                        true,
2926 2844                                                        false,
2927 2845                                                        false);
2928 2846                                  gather_recursive_deps();
2929 2847                                  if (/* !commands_done && */
2930 2848                                      (result == build_ok) &&
2931 2849                                      !quest &&
2932 2850                                      (report_dependencies_level == 0) /*  &&
2933 2851                                      (exists(default_target_to_build) > file_doesnt_exist)  */) {
2934 2852                                          if (posix) {
2935 2853                                                  if (!commands_done) {
2936 2854                                                          (void) printf(catgets(catd, 1, 293, "`%s' is updated.\n"),
2937 2855                                                                        default_target_to_build->string_mb);
2938 2856                                                  } else {
2939 2857                                                          if (no_action_was_taken) {
2940 2858                                                                  (void) printf(catgets(catd, 1, 294, "`%s': no action was taken.\n"),
2941 2859                                                                                default_target_to_build->string_mb);
2942 2860                                                          }
2943 2861                                                  }
2944 2862                                          } else {
2945 2863                                                  default_target_to_build->stat.time = file_no_time;
2946 2864                                                  if (!commands_done &&
2947 2865                                                      (exists(default_target_to_build) > file_doesnt_exist)) {
2948 2866                                                          (void) printf(catgets(catd, 1, 295, "`%s' is up to date.\n"),
2949 2867                                                                        default_target_to_build->string_mb);
  
    | 
      ↓ open down ↓ | 
    60 lines elided | 
    
      ↑ open up ↑ | 
  
2950 2868                                                  }
2951 2869                                          }
2952 2870                                  }
2953 2871                          }
2954 2872                  }
2955 2873                  /* Now wait for all of the targets to finish running */
2956 2874                  finish_running();
2957 2875                  //              setjmp(jmpbuffer);
2958 2876                  
2959 2877          }
2960      -#endif
2961 2878          for (i = 1; i < argc; i++) {
2962 2879                  if ((cp = argv[i]) != NULL) {
2963 2880                          target_to_make_found = true;
2964 2881                          if ((cp[0] == (int) period_char) &&
2965 2882                              (cp[1] == (int) slash_char)) {
2966 2883                                  cp += 2;
2967 2884                          }
2968 2885                                   if((cp[0] == (int) ' ') &&
2969 2886                                      (cp[1] == (int) '-') &&
2970 2887                                      (cp[2] == (int) ' ') &&
2971 2888                                      (cp[3] == (int) '-')) {
2972 2889                                      argv[i] = NULL;
2973 2890                                          continue;
2974 2891                                  }
2975 2892                          MBSTOWCS(wcs_buffer, cp);
2976 2893                          default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2977 2894                          top_level_target = get_wstring(default_target_to_build->string_mb);
2978 2895                          report_recursion(default_target_to_build);
2979 2896                          commands_done = false;
2980 2897                          if (parallel) {
2981 2898                                  result = (Doname) default_target_to_build->state;
2982 2899                          } else {
2983 2900                                  result = doname_check(default_target_to_build,
2984 2901                                                        true,
2985 2902                                                        false,
2986 2903                                                        false);
2987 2904                          }
2988 2905                          gather_recursive_deps();
2989 2906                          if (build_failed_seen) {
2990 2907                                  build_failed_ever_seen = true;
2991 2908                                  warning(catgets(catd, 1, 200, "Target `%s' not remade because of errors"),
2992 2909                                          default_target_to_build->string_mb);
2993 2910                          }
2994 2911                          build_failed_seen = false;
2995 2912                          if (report_dependencies_level > 0) {
2996 2913                                  print_dependencies(default_target_to_build,
2997 2914                                                     get_prop(default_target_to_build->prop,
2998 2915                                                              line_prop));
2999 2916                          }
3000 2917                          default_target_to_build->stat.time =
3001 2918                            file_no_time;
3002 2919                          if (default_target_to_build->colon_splits > 0) {
3003 2920                                  default_target_to_build->state =
3004 2921                                    build_dont_know;
3005 2922                          }
3006 2923                          if (!parallel &&
3007 2924                              /* !commands_done && */
3008 2925                              (result == build_ok) &&
3009 2926                              !quest &&
3010 2927                              (report_dependencies_level == 0) /*  &&
3011 2928                              (exists(default_target_to_build) > file_doesnt_exist)  */) {
3012 2929                                  if (posix) {
3013 2930                                          if (!commands_done) {
3014 2931                                                  (void) printf(catgets(catd, 1, 296, "`%s' is updated.\n"),
3015 2932                                                                default_target_to_build->string_mb);
3016 2933                                          } else {
3017 2934                                                  if (no_action_was_taken) {
3018 2935                                                          (void) printf(catgets(catd, 1, 297, "`%s': no action was taken.\n"),
3019 2936                                                                        default_target_to_build->string_mb);
3020 2937                                                  }
3021 2938                                          }
3022 2939                                  } else {
3023 2940                                          if (!commands_done &&
3024 2941                                              (exists(default_target_to_build) > file_doesnt_exist)) {
3025 2942                                                  (void) printf(catgets(catd, 1, 298, "`%s' is up to date.\n"),
3026 2943                                                                default_target_to_build->string_mb);
3027 2944                                          }
3028 2945                                  }
3029 2946                          }
3030 2947                  }
3031 2948          }
3032 2949  
3033 2950  /*
3034 2951   *      If no file arguments have been encountered,
3035 2952   *      make the first name encountered that doesnt start with a dot
3036 2953   */
3037 2954          if (!target_to_make_found) {
3038 2955                  if (default_target_to_build == NULL) {
3039 2956                          fatal(catgets(catd, 1, 202, "No arguments to build"));
3040 2957                  }
3041 2958                  commands_done = false;
  
    | 
      ↓ open down ↓ | 
    71 lines elided | 
    
      ↑ open up ↑ | 
  
3042 2959                  top_level_target = get_wstring(default_target_to_build->string_mb);
3043 2960                  report_recursion(default_target_to_build);
3044 2961  
3045 2962  
3046 2963                  if (getenv(NOCATGETS("SPRO_EXPAND_ERRORS"))){
3047 2964                          (void) printf(NOCATGETS("::(%s)\n"),
3048 2965                                        default_target_to_build->string_mb);
3049 2966                  }
3050 2967  
3051 2968  
3052      -#ifdef TEAMWARE_MAKE_CMN
3053 2969                  result = doname_parallel(default_target_to_build, true, false);
3054      -#else
3055      -                result = doname_check(default_target_to_build, true,
3056      -                                      false, false);
3057      -#endif
3058 2970                  gather_recursive_deps();
3059 2971                  if (build_failed_seen) {
3060 2972                          build_failed_ever_seen = true;
3061 2973                          warning(catgets(catd, 1, 203, "Target `%s' not remade because of errors"),
3062 2974                                  default_target_to_build->string_mb);
3063 2975                  }
3064 2976                  build_failed_seen = false;
3065 2977                  if (report_dependencies_level > 0) {
3066 2978                          print_dependencies(default_target_to_build,
3067 2979                                             get_prop(default_target_to_build->
3068 2980                                                      prop,
3069 2981                                                      line_prop));
3070 2982                  }
3071 2983                  default_target_to_build->stat.time = file_no_time;
3072 2984                  if (default_target_to_build->colon_splits > 0) {
3073 2985                          default_target_to_build->state = build_dont_know;
3074 2986                  }
3075 2987                  if (/* !commands_done && */
3076 2988                      (result == build_ok) &&
3077 2989                      !quest &&
3078 2990                      (report_dependencies_level == 0) /*  &&
3079 2991                      (exists(default_target_to_build) > file_doesnt_exist)  */) {
3080 2992                          if (posix) {
3081 2993                                  if (!commands_done) {
3082 2994                                          (void) printf(catgets(catd, 1, 299, "`%s' is updated.\n"),
3083 2995                                                        default_target_to_build->string_mb);
3084 2996                                  } else {
3085 2997                                          if (no_action_was_taken) {
3086 2998                                                  (void) printf(catgets(catd, 1, 300, "`%s': no action was taken.\n"),
3087 2999                                                                default_target_to_build->string_mb);
3088 3000                                          }
3089 3001                                  }
3090 3002                          } else {
3091 3003                                  if (!commands_done &&
3092 3004                                      (exists(default_target_to_build) > file_doesnt_exist)) {
3093 3005                                          (void) printf(catgets(catd, 1, 301, "`%s' is up to date.\n"),
3094 3006                                                        default_target_to_build->string_mb);
3095 3007                                  }
3096 3008                          }
3097 3009                  }
3098 3010          }
3099 3011  }
3100 3012  
3101 3013  /*
3102 3014   *      report_recursion(target)
3103 3015   *
3104 3016   *      If this is a recursive make and the parent make has KEEP_STATE on
3105 3017   *      this routine reports the dependency to the parent make
3106 3018   *
3107 3019   *      Parameters:
3108 3020   *              target          Target to report
3109 3021   *
3110 3022   *      Global variables used:
3111 3023   *              makefiles_used          List of makefiles read
3112 3024   *              recursive_name          The Name ".RECURSIVE", printed
3113 3025   *              report_dependency       dwight
3114 3026   */
3115 3027  static void
3116 3028  report_recursion(register Name target)
3117 3029  {
3118 3030          register FILE           *report_file = get_report_file();
3119 3031  
3120 3032          if ((report_file == NULL) || (report_file == (FILE*)-1)) {
3121 3033                  return;
3122 3034          }
3123 3035          if (primary_makefile == NULL) {
3124 3036                  /*
3125 3037                   * This can happen when there is no makefile and
3126 3038                   * only implicit rules are being used.
3127 3039                   */
3128 3040                  return;
3129 3041          }
3130 3042          (void) fprintf(report_file,
3131 3043                         "%s: %s ",
3132 3044                         get_target_being_reported_for(),
3133 3045                         recursive_name->string_mb);
3134 3046          report_dependency(get_current_path());
3135 3047          report_dependency(target->string_mb);
3136 3048          report_dependency(primary_makefile->string_mb);
3137 3049          (void) fprintf(report_file, "\n");
3138 3050  }
3139 3051  
3140 3052  /* Next function "append_or_replace_macro_in_dyn_array" must be in "misc.cc". */
3141 3053  /* NIKMOL */
3142 3054  extern void
3143 3055  append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro)
3144 3056  {
3145 3057          register char   *cp0;   /* work pointer in macro */
3146 3058          register char   *cp1;   /* work pointer in array */
3147 3059          register char   *cp2;   /* work pointer in array */
3148 3060          register char   *cp3;   /* work pointer in array */
3149 3061          register char   *name;  /* macro name */
3150 3062          register char   *value; /* macro value */
3151 3063          register int    len_array;
3152 3064          register int    len_macro;
3153 3065  
3154 3066          char * esc_value = NULL;
3155 3067          int esc_len;
3156 3068  
3157 3069          if (!(len_macro = strlen(macro))) return;
3158 3070          name = macro;
3159 3071          while (isspace(*(name))) {
3160 3072                  name++;
3161 3073          }
3162 3074          if (!(value = strchr(name, (int) equal_char))) {
3163 3075                  /* no '=' in macro */
3164 3076                  goto ERROR_MACRO;
3165 3077          }
3166 3078          cp0 = value;
3167 3079          value++;
3168 3080          while (isspace(*(value))) {
3169 3081                  value++;
3170 3082          }
3171 3083          while (isspace(*(cp0-1))) {
3172 3084                  cp0--;
3173 3085          }
3174 3086          if (cp0 <= name) goto ERROR_MACRO; /* no name */
3175 3087          if (!(Ar->size)) goto ALLOC_ARRAY;
3176 3088          cp1 = Ar->start;
3177 3089  
3178 3090  LOOK_FOR_NAME:
3179 3091          if (!(cp1 = strchr(cp1, name[0]))) goto APPEND_MACRO;
3180 3092          if (!(cp2 = strchr(cp1, (int) equal_char))) goto APPEND_MACRO;
3181 3093          if (strncmp(cp1, name, (size_t)(cp0-name))) {
3182 3094                  /* another name */
3183 3095                  cp1++;
3184 3096                  goto LOOK_FOR_NAME;
3185 3097          }
3186 3098          if (cp1 != Ar->start) {
3187 3099                  if (!isspace(*(cp1-1))) {
3188 3100                          /* another name */
3189 3101                          cp1++;
3190 3102                          goto LOOK_FOR_NAME;
3191 3103                  }
3192 3104          }
3193 3105          for (cp3 = cp1 + (cp0-name); cp3 < cp2; cp3++) {
3194 3106                  if (isspace(*cp3)) continue;
3195 3107                  /* else: another name */
3196 3108                  cp1++;
3197 3109                  goto LOOK_FOR_NAME;
3198 3110          }
3199 3111          /* Look for the next macro name in array */
3200 3112          cp3 = cp2+1;
3201 3113          if (*cp3 != (int) doublequote_char) {
3202 3114                  /* internal error */
3203 3115                  goto ERROR_MACRO;
3204 3116          }
3205 3117          if (!(cp3 = strchr(cp3+1, (int) doublequote_char))) {
3206 3118                  /* internal error */
3207 3119                  goto ERROR_MACRO;
3208 3120          }
3209 3121          cp3++;
3210 3122          while (isspace(*cp3)) {
3211 3123                  cp3++;
3212 3124          }
3213 3125          
3214 3126          cp2 = cp1;  /* remove old macro */
3215 3127          if ((*cp3) && (cp3 < Ar->start + Ar->size)) {
3216 3128                  for (; cp3 < Ar->start + Ar->size; cp3++) {
3217 3129                          *cp2++ = *cp3;
3218 3130                  }
3219 3131          } 
3220 3132          for (; cp2 < Ar->start + Ar->size; cp2++) {
3221 3133                  *cp2 = 0;
3222 3134          }
3223 3135          if (*cp1) {
3224 3136                  /* check next name */
3225 3137                  goto LOOK_FOR_NAME;
3226 3138          }
3227 3139          goto APPEND_MACRO;
3228 3140  
3229 3141  ALLOC_ARRAY:
3230 3142          if (Ar->size) {
3231 3143                  cp1 = Ar->start;
3232 3144          } else {
3233 3145                  cp1 = 0;
3234 3146          }
3235 3147          Ar->size += 128;
3236 3148          Ar->start = getmem(Ar->size);
3237 3149          for (len_array=0; len_array < Ar->size; len_array++) {
3238 3150                  Ar->start[len_array] = 0;
3239 3151          }
3240 3152          if (cp1) {
3241 3153                  strcpy(Ar->start, cp1);
3242 3154                  retmem((wchar_t *) cp1);
3243 3155          }
3244 3156  
3245 3157  APPEND_MACRO:
3246 3158          len_array = strlen(Ar->start);
3247 3159          esc_value = (char*)malloc(strlen(value)*2 + 1);
3248 3160          quote_str(value, esc_value);
3249 3161          esc_len = strlen(esc_value) - strlen(value);
3250 3162          if (len_array + len_macro + esc_len + 5 >= Ar->size) goto  ALLOC_ARRAY;
3251 3163          strcat(Ar->start, " ");
3252 3164          strncat(Ar->start, name, cp0-name);
3253 3165          strcat(Ar->start, "=");
3254 3166          strncat(Ar->start, esc_value, strlen(esc_value));
3255 3167          free(esc_value);
3256 3168          return;
3257 3169  ERROR_MACRO:    
3258 3170          /* Macro without '=' or with invalid left/right part */
3259 3171          return;
3260 3172  }
3261 3173  
3262 3174  #ifdef TEAMWARE_MAKE_CMN
3263 3175  /*
3264 3176   * This function, if registered w/ avo_cli_get_license(), will be called
3265 3177   * if the application is about to exit because:
3266 3178   *   1) there has been certain unrecoverable error(s) that cause the
3267 3179   *      application to exit immediately.
3268 3180   *   2) the user has lost a license while the application is running.
3269 3181   */
3270 3182  extern "C" void
3271 3183  dmake_exit_callback(void)
3272 3184  {
3273 3185          fatal(catgets(catd, 1, 306, "can not get a license, exiting..."));
3274 3186          exit(1);
3275 3187  }
3276 3188  
3277 3189  /*
3278 3190   * This function, if registered w/ avo_cli_get_license(), will be called
3279 3191   * if the application can not get a license.
3280 3192   */
3281 3193  extern "C" void
3282 3194  dmake_message_callback(char *err_msg)
3283 3195  {
3284 3196          static Boolean  first = true;
3285 3197  
3286 3198          if (!first) {
3287 3199                  return;
3288 3200          }
3289 3201          first = false;
3290 3202          if ((!list_all_targets) &&
3291 3203              (report_dependencies_level == 0) &&
3292 3204              (dmake_mode_type != serial_mode)) {
3293 3205                  warning(catgets(catd, 1, 313, "can not get a TeamWare license, defaulting to serial mode..."));
3294 3206          }
3295 3207  }
3296 3208  #endif
3297 3209  
3298 3210  
3299 3211  static void
3300 3212  report_dir_enter_leave(Boolean entering)
3301 3213  {
3302 3214          char    rcwd[MAXPATHLEN];
3303 3215  static  char *  mlev = NULL;
3304 3216          char *  make_level_str = NULL;
3305 3217          int     make_level_val = 0;
3306 3218  
3307 3219          make_level_str = getenv(NOCATGETS("MAKELEVEL"));
3308 3220          if(make_level_str) {
3309 3221                  make_level_val = atoi(make_level_str);
3310 3222          }
3311 3223          if(mlev == NULL) {
3312 3224                  mlev = (char*) malloc(MAXPATHLEN);
3313 3225          }
3314 3226          if(entering) {
  
    | 
      ↓ open down ↓ | 
    247 lines elided | 
    
      ↑ open up ↑ | 
  
3315 3227                  sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val + 1);
3316 3228          } else {
3317 3229                  make_level_val--;
3318 3230                  sprintf(mlev, NOCATGETS("MAKELEVEL=%d"), make_level_val);
3319 3231          }
3320 3232          putenv(mlev);
3321 3233  
3322 3234          if(report_cwd) {
3323 3235                  if(make_level_val <= 0) {
3324 3236                          if(entering) {
3325      -#ifdef TEAMWARE_MAKE_CMN
3326 3237                                  sprintf( rcwd
3327 3238                                         , catgets(catd, 1, 329, "dmake: Entering directory `%s'\n")
3328 3239                                         , get_current_path());
3329      -#else
3330      -                                sprintf( rcwd
3331      -                                       , catgets(catd, 1, 330, "make: Entering directory `%s'\n")
3332      -                                       , get_current_path());
3333      -#endif
3334 3240                          } else {
3335      -#ifdef TEAMWARE_MAKE_CMN
3336 3241                                  sprintf( rcwd
3337 3242                                         , catgets(catd, 1, 331, "dmake: Leaving directory `%s'\n")
3338 3243                                         , get_current_path());
3339      -#else
3340      -                                sprintf( rcwd
3341      -                                       , catgets(catd, 1, 332, "make: Leaving directory `%s'\n")
3342      -                                       , get_current_path());
3343      -#endif
3344 3244                          }
3345 3245                  } else {
3346 3246                          if(entering) {
3347      -#ifdef TEAMWARE_MAKE_CMN
3348 3247                                  sprintf( rcwd
3349 3248                                         , catgets(catd, 1, 333, "dmake[%d]: Entering directory `%s'\n")
3350 3249                                         , make_level_val, get_current_path());
3351      -#else
3352      -                                sprintf( rcwd
3353      -                                       , catgets(catd, 1, 334, "make[%d]: Entering directory `%s'\n")
3354      -                                       , make_level_val, get_current_path());
3355      -#endif
3356 3250                          } else {
3357      -#ifdef TEAMWARE_MAKE_CMN
3358 3251                                  sprintf( rcwd
3359 3252                                         , catgets(catd, 1, 335, "dmake[%d]: Leaving directory `%s'\n")
3360 3253                                         , make_level_val, get_current_path());
3361      -#else
3362      -                                sprintf( rcwd
3363      -                                       , catgets(catd, 1, 336, "make[%d]: Leaving directory `%s'\n")
3364      -                                       , make_level_val, get_current_path());
3365      -#endif
3366 3254                          }
3367 3255                  }
3368 3256                  printf(NOCATGETS("%s"), rcwd);
3369 3257          }
3370 3258  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX