Ignore:
Timestamp:
May 23, 2007, 7:31:19 AM (18 years ago)
Author:
bird
Message:

Merged with the 2007-05-23 CVS. Added rsort and fixed a couple of windows build issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/main.c

    r877 r903  
    11/* Argument parsing and main program of GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
    44Foundation, Inc.
    55This file is part of GNU Make.
     
    5757#endif
    5858
    59 extern void init_dir PARAMS ((void));
    60 extern void remote_setup PARAMS ((void));
    61 extern void remote_cleanup PARAMS ((void));
    62 extern RETSIGTYPE fatal_error_signal PARAMS ((int sig));
    63 
    64 extern void print_variable_data_base PARAMS ((void));
    65 extern void print_dir_data_base PARAMS ((void));
    66 extern void print_rule_data_base PARAMS ((void));
    67 extern void print_file_data_base PARAMS ((void));
    68 extern void print_vpath_data_base PARAMS ((void));
     59void init_dir (void);
     60void remote_setup (void);
     61void remote_cleanup (void);
     62RETSIGTYPE fatal_error_signal (int sig);
     63
     64void print_variable_data_base (void);
     65void print_dir_data_base (void);
     66void print_rule_data_base (void);
     67void print_file_data_base (void);
     68void print_vpath_data_base (void);
     69
     70void verify_file_data_base (void);
    6971
    7072#if defined HAVE_WAITPID || defined HAVE_WAIT3
     
    7274#endif
    7375
    74 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER)
    75 extern int chdir ();
     76#if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) /* bird */
     77int chdir ();
    7678#endif
    7779#ifndef STDC_HEADERS
    7880# ifndef sun                    /* Sun has an incorrect decl in a header.  */
    79 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
     81void exit (int) __attribute__ ((noreturn));
    8082# endif
    81 extern double atof ();
    82 #endif
    83 
    84 static void clean_jobserver PARAMS ((int status));
    85 static void print_data_base PARAMS ((void));
    86 static void print_version PARAMS ((void));
    87 static void decode_switches PARAMS ((int argc, char **argv, int env));
    88 static void decode_env_switches PARAMS ((char *envar, unsigned int len));
    89 static void define_makeflags PARAMS ((int all, int makefile));
    90 static char *quote_for_env PARAMS ((char *out, char *in));
    91 static void initialize_global_hash_tables PARAMS ((void));
     83double atof ();
     84#endif
     85
     86static void clean_jobserver (int status);
     87static void print_data_base (void);
     88static void print_version (void);
     89static void decode_switches (int argc, char **argv, int env);
     90static void decode_env_switches (char *envar, unsigned int len);
     91static void define_makeflags (int all, int makefile);
     92static char *quote_for_env (char *out, const char *in);
     93static void initialize_global_hash_tables (void);
    9294
    9395
     
    104106        flag_off,               /* Turn int flag off.  */
    105107        string,                 /* One string per switch.  */
     108        filename,               /* A string containing a file name.  */
    106109        positive_int,           /* A positive integer.  */
    107110        floating,               /* A floating-point number (double).  */
     
    109112      } type;
    110113
    111     char *value_ptr;    /* Pointer to the value-holding variable.  */
     114    void *value_ptr;    /* Pointer to the value-holding variable.  */
    112115
    113116    unsigned int env:1;         /* Can come from MAKEFLAGS.  */
     
    115118    unsigned int no_makefile:1; /* Don't propagate when remaking makefiles.  */
    116119
    117     char *noarg_value;  /* Pointer to value used if no argument is given.  */
    118     char *default_value;/* Pointer to default value.  */
     120    const void *noarg_value;    /* Pointer to value used if no arg given.  */
     121    const void *default_value;  /* Pointer to default value.  */
    119122
    120123    char *long_name;            /* Long option name.  */
     
    130133struct stringlist
    131134  {
    132     char **list;        /* Nil-terminated list of strings.  */
     135    const char **list;  /* Nil-terminated list of strings.  */
    133136    unsigned int idx;   /* Index into above.  */
    134137    unsigned int max;   /* Number of pointers allocated.  */
     
    164167
    165168int db_level = 0;
     169
     170/* Output level (--verbosity).  */
     171
     172static struct stringlist *verbosity_flags;
    166173
    167174#ifdef WINDOWS32
     
    288295
    289296struct variable shell_var;
     297
     298/* This character introduces a command: it's the first char on the line.  */
     299
     300char cmd_prefix = '\t';
    290301
    291302#ifdef KMK
     
    382393  {
    383394    { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 },
    384     { 'B', flag, (char *) &always_make_set, 1, 1, 0, 0, 0, "always-make" },
    385     { 'C', string, (char *) &directories, 0, 0, 0, 0, 0, "directory" },
    386     { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0, 0 },
    387     { CHAR_MAX+1, string, (char *) &db_flags, 1, 1, 0, "basic", 0, "debug" },
     395    { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" },
     396    { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" },
     397    { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 },
     398    { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" },
    388399#ifdef WINDOWS32
    389     { 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
    390 #endif
    391     { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
    392       "environment-overrides", },
    393     { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" },
    394     { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" },
    395     { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
    396       "ignore-errors" },
    397     { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
     400    { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
     401#endif
     402    { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", },
     403    { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" },
     404    { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" },
     405    { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" },
     406    { 'I', filename, &include_directories, 1, 1, 0, 0, 0,
    398407      "include-dir" },
    399     { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs,
    400       (char *) &default_job_slots, "jobs" },
    401     { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0,
    402       "jobserver-fds" },
    403     { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0,
    404       (char *) &default_keep_going_flag, "keep-going" },
     408    { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots,
     409      "jobs" },
     410    { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" },
     411    { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     412      "keep-going" },
    405413#ifndef NO_FLOAT
    406     { 'l', floating, (char *) &max_load_average, 1, 1, 0,
    407       (char *) &default_load_average, (char *) &default_load_average,
    408       "load-average" },
     414    { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average,
     415      &default_load_average, "load-average" },
    409416#else
    410     { 'l', positive_int, (char *) &max_load_average, 1, 1, 0,
    411       (char *) &default_load_average, (char *) &default_load_average,
    412       "load-average" },
    413 #endif
    414     { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0,
    415       "check-symlink-times" },
     417    { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average,
     418      &default_load_average, "load-average" },
     419#endif
     420    { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" },
    416421    { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 },
    417     { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
    418     { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" },
    419     { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
    420       "print-data-base" },
     422    { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
     423    { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },
     424    { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" },
    421425#ifdef CONFIG_PRETTY_COMMAND_PRINTING
    422426    { CHAR_MAX+6, flag, (char *) &pretty_command_printing, 1, 1, 1, 0, 0,
     
    427431      (char *) &process_priority, (char *) &process_priority, "priority" },
    428432#endif
    429     { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" },
    430     { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
    431       "no-builtin-rules" },
    432     { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0,
     433    { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" },
     434    { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, "no-builtin-rules" },
     435    { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0,
    433436      "no-builtin-variables" },
    434     { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" },
    435     { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0,
    436       (char *) &default_keep_going_flag, "no-keep-going" },
    437     { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0, "touch" },
    438     { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" },
    439     { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
    440       "print-directory" },
    441     { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
     437    { 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" },
     438    { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     439      "no-keep-going" },
     440    { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" },
     441    { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" },
     442    { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0,
     443      "verbosity" },
     444    { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" },
     445    { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
    442446      "no-print-directory" },
    443     { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" },
    444     { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
     447    { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" },
     448    { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    445449      "warn-undefined-variables" },
    446450    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
     
    588592}
    589593
    590 static struct file *
    591 enter_command_line_file (char *name)
     594static const char *
     595expand_command_line_file (char *name)
    592596{
     597  const char *cp;
     598  char *expanded = 0;
     599
    593600  if (name[0] == '\0')
    594601    fatal (NILF, _("empty string invalid as file name"));
     
    596603  if (name[0] == '~')
    597604    {
    598       char *expanded = tilde_expand (name);
     605      expanded = tilde_expand (name);
    599606      if (expanded != 0)
    600         name = expanded;        /* Memory leak; I don't care.  */
     607        name = expanded;
    601608    }
    602609
     
    622629    }
    623630
    624   return enter_file (xstrdup (name));
     631  cp = strcache_add (name);
     632
     633  if (expanded)
     634    free (expanded);
     635
     636  return cp;
    625637}
    626638
     
    638650decode_debug_flags (void)
    639651{
    640   char **pp;
     652  const char **pp;
    641653
    642654  if (debug_flag)
     
    814826
    815827int
    816 find_and_set_default_shell (char *token)
     828find_and_set_default_shell (const char *token)
    817829{
    818830  int sh_found = 0;
     831  char *atoken = 0;
    819832  char *search_token;
    820833  char *tokend;
     
    825838    search_token = default_shell;
    826839  else
    827     search_token = token;
    828 
     840    atoken = search_token = xstrdup (token);
    829841
    830842  /* If the user explicitly requests the DOS cmd shell, obey that request.
     
    836848        || (tokend > search_token
    837849            && (tokend[-1] == '/' || tokend[-1] == '\\')))
    838        && !strcmpi (tokend, "cmd"))
     850       && !strcasecmp (tokend, "cmd"))
    839851      || ((tokend - 4 == search_token
    840852           || (tokend - 4 > search_token
    841853               && (tokend[-5] == '/' || tokend[-5] == '\\')))
    842           && !strcmpi (tokend - 4, "cmd.exe"))) {
     854          && !strcasecmp (tokend - 4, "cmd.exe"))) {
    843855    batch_mode_shell = 1;
    844856    unixy_shell = 0;
     
    852864    /* no new information, path already set or known */
    853865    sh_found = 1;
    854   } else if (file_exists_p(search_token)) {
     866  } else if (file_exists_p (search_token)) {
    855867    /* search token path was found */
    856     sprintf(sh_path, "%s", search_token);
    857     default_shell = xstrdup(w32ify(sh_path,0));
     868    sprintf (sh_path, "%s", search_token);
     869    default_shell = xstrdup (w32ify (sh_path, 0));
    858870    DB (DB_VERBOSE,
    859871        (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     
    868880
    869881      p  = v->value;
    870       ep = strchr(p, PATH_SEPARATOR_CHAR);
     882      ep = strchr (p, PATH_SEPARATOR_CHAR);
    871883
    872884      while (ep && *ep) {
    873885        *ep = '\0';
    874886
    875         if (dir_file_exists_p(p, search_token)) {
    876           sprintf(sh_path, "%s/%s", p, search_token);
    877           default_shell = xstrdup(w32ify(sh_path,0));
     887        if (dir_file_exists_p (p, search_token)) {
     888          sprintf (sh_path, "%s/%s", p, search_token);
     889          default_shell = xstrdup (w32ify (sh_path, 0));
    878890          sh_found = 1;
    879891          *ep = PATH_SEPARATOR_CHAR;
    880892
    881893          /* terminate loop */
    882           p += strlen(p);
     894          p += strlen (p);
    883895        } else {
    884896          *ep = PATH_SEPARATOR_CHAR;
     
    886898        }
    887899
    888         ep = strchr(p, PATH_SEPARATOR_CHAR);
     900        ep = strchr (p, PATH_SEPARATOR_CHAR);
    889901      }
    890902
    891903      /* be sure to check last element of Path */
    892       if (p && *p && dir_file_exists_p(p, search_token)) {
    893           sprintf(sh_path, "%s/%s", p, search_token);
    894           default_shell = xstrdup(w32ify(sh_path,0));
     904      if (p && *p && dir_file_exists_p (p, search_token)) {
     905          sprintf (sh_path, "%s/%s", p, search_token);
     906          default_shell = xstrdup (w32ify (sh_path, 0));
    895907          sh_found = 1;
    896908      }
     
    916928  /* naive test */
    917929  if (!unixy_shell && sh_found &&
    918       (strstr(default_shell, "sh") || strstr(default_shell, "SH"))) {
     930      (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) {
    919931    unixy_shell = 1;
    920932    batch_mode_shell = 0;
     
    924936  batch_mode_shell = 1;
    925937#endif
     938
     939  if (atoken)
     940    free (atoken);
    926941
    927942  return (sh_found);
     
    9951010#endif  /* WINDOWS32 */
    9961011
    997 #ifdef  __MSDOS__
    998 
     1012#ifdef __MSDOS__
    9991013static void
    10001014msdos_return_to_initial_directory (void)
     
    10031017    chdir (directory_before_chdir);
    10041018}
    1005 #endif
    1006 
    1007 #ifndef _MSC_VER
    1008 extern char *mktemp PARAMS ((char *template));
    1009 #endif
    1010 extern int mkstemp PARAMS ((char *template));
     1019#endif  /* __MSDOS__ */
     1020
     1021#ifndef _MSC_VER /* bird */
     1022char *mktemp (char *template);
     1023#endif
     1024int mkstemp (char *template);
    10111025
    10121026FILE *
     
    10611075{
    10621076  static char *stdin_nm = 0;
    1063   struct file *f;
    1064   int i;
    10651077  int makefile_status = MAKE_SUCCESS;
    1066   char **p;
    10671078  struct dep *read_makefiles;
    10681079  PATH_VAR (current_directory);
     
    11931204# else  /* setvbuf not reversed.  */
    11941205  /* Some buggy systems lose if we pass 0 instead of allocating ourselves.  */
    1195   setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
     1206  setvbuf (stdout, 0, _IOLBF, BUFSIZ);
    11961207# endif /* setvbuf reversed.  */
    11971208#elif HAVE_SETLINEBUF
     
    13011312
    13021313#ifndef _AMIGA
    1303   for (i = 0; envp[i] != 0; ++i)
    1304     {
    1305       int do_not_define = 0;
    1306       char *ep = envp[i];
    1307 
    1308       while (*ep != '\0' && *ep != '=')
    1309         ++ep;
     1314  {
     1315    unsigned int i;
     1316
     1317    for (i = 0; envp[i] != 0; ++i)
     1318      {
     1319        int do_not_define = 0;
     1320        char *ep = envp[i];
     1321
     1322        while (*ep != '\0' && *ep != '=')
     1323          ++ep;
    13101324#ifdef WINDOWS32
    1311       if (!unix_path && strneq(envp[i], "PATH=", 5))
    1312         unix_path = ep+1;
    1313       else if (!strnicmp(envp[i], "Path=", 5)) {
    1314         do_not_define = 1; /* it gets defined after loop exits */
    1315         if (!windows32_path)
    1316           windows32_path = ep+1;
     1325        if (!unix_path && strneq(envp[i], "PATH=", 5))
     1326          unix_path = ep+1;
     1327        else if (!strnicmp(envp[i], "Path=", 5)) {
     1328          do_not_define = 1; /* it gets defined after loop exits */
     1329          if (!windows32_path)
     1330            windows32_path = ep+1;
     1331        }
     1332#endif
     1333        /* The result of pointer arithmetic is cast to unsigned int for
     1334           machines where ptrdiff_t is a different size that doesn't widen
     1335           the same.  */
     1336        if (!do_not_define)
     1337          {
     1338            struct variable *v;
     1339
     1340            v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
     1341                                 ep + 1, o_env, 1);
     1342            /* Force exportation of every variable culled from the
     1343               environment.  We used to rely on target_environment's
     1344               v_default code to do this.  But that does not work for the
     1345               case where an environment variable is redefined in a makefile
     1346               with `override'; it should then still be exported, because it
     1347               was originally in the environment.  */
     1348            v->export = v_export;
     1349
     1350            /* Another wrinkle is that POSIX says the value of SHELL set in
     1351               the makefile won't change the value of SHELL given to
     1352               subprocesses.  */
     1353            if (streq (v->name, "SHELL"))
     1354              {
     1355#ifndef __MSDOS__
     1356                v->export = v_noexport;
     1357#endif
     1358                shell_var.name = "SHELL";
     1359                shell_var.value = xstrdup (ep + 1);
     1360              }
     1361
     1362            /* If MAKE_RESTARTS is set, remember it but don't export it.  */
     1363            if (streq (v->name, "MAKE_RESTARTS"))
     1364              {
     1365                v->export = v_noexport;
     1366                restarts = (unsigned int) atoi (ep + 1);
     1367              }
     1368          }
    13171369      }
    1318 #endif
    1319       /* The result of pointer arithmetic is cast to unsigned int for
    1320          machines where ptrdiff_t is a different size that doesn't widen
    1321          the same.  */
    1322       if (!do_not_define)
    1323         {
    1324           struct variable *v;
    1325 
    1326           v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
    1327                                ep + 1, o_env, 1);
    1328           /* Force exportation of every variable culled from the environment.
    1329              We used to rely on target_environment's v_default code to do this.
    1330              But that does not work for the case where an environment variable
    1331              is redefined in a makefile with `override'; it should then still
    1332              be exported, because it was originally in the environment.  */
    1333           v->export = v_export;
    1334 
    1335           /* Another wrinkle is that POSIX says the value of SHELL set in the
    1336              makefile won't change the value of SHELL given to subprocesses  */
    1337           if (streq (v->name, "SHELL"))
    1338             {
    1339 #ifndef __MSDOS__
    1340               v->export = v_noexport;
    1341 #endif
    1342               shell_var.name = "SHELL";
    1343               shell_var.value = xstrdup (ep + 1);
    1344             }
    1345 
    1346           /* If MAKE_RESTARTS is set, remember it but don't export it.  */
    1347           if (streq (v->name, "MAKE_RESTARTS"))
    1348             {
    1349               v->export = v_noexport;
    1350               restarts = (unsigned int) atoi (ep + 1);
    1351             }
    1352         }
    1353     }
     1370  }
    13541371#ifdef WINDOWS32
    13551372    /* If we didn't find a correctly spelled PATH we define PATH as
     
    13971414#if 0
    13981415  /* People write things like:
    1399         MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
     1416        MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
    14001417     and we set the -p, -i and -e switches.  Doesn't seem quite right.  */
    14011418  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
     
    14641481      && argv[0] != 0
    14651482      && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':'))
    1466 #ifdef __EMX__
     1483# ifdef __EMX__
    14671484      /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */
    14681485      && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0)
    14691486# endif
    14701487      )
    1471     argv[0] = concat (current_directory, "/", argv[0]);
     1488    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    14721489#else  /* !__MSDOS__ */
    14731490  if (current_directory[0] != '\0'
    1474       && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0)
    1475     argv[0] = concat (current_directory, "/", argv[0]);
     1491      && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0
     1492#ifdef HAVE_DOS_PATHS
     1493      && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':'))
     1494      && strchr (argv[0], '\\') != 0
     1495#endif
     1496      )
     1497    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    14761498#endif /* !__MSDOS__ */
    14771499#endif /* WINDOWS32 */
     
    15071529
    15081530      /* Now allocate a buffer big enough and fill it.  */
    1509       p = value = (char *) alloca (len);
     1531      p = value = alloca (len);
    15101532      for (cv = command_variables; cv != 0; cv = cv->next)
    15111533        {
     
    15901612      }
    15911613    }
    1592 #endif
     1614#endif /* KMK */
    15931615
    15941616  /* If there were -C flags, move ourselves about.  */
    15951617  if (directories != 0)
    1596     for (i = 0; directories->list[i] != 0; ++i)
    1597       {
    1598         char *dir = directories->list[i];
    1599         char *expanded = 0;
    1600         if (dir[0] == '~')
    1601           {
    1602             expanded = tilde_expand (dir);
    1603             if (expanded != 0)
    1604               dir = expanded;
    1605           }
     1618    {
     1619      unsigned int i;
     1620      for (i = 0; directories->list[i] != 0; ++i)
     1621        {
     1622          const char *dir = directories->list[i];
    16061623#ifdef WINDOWS32
    1607         /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
    1608            But allow -C/ just in case someone wants that.  */
    1609         {
    1610           char *p = dir + strlen (dir) - 1;
    1611           while (p > dir && (p[0] == '/' || p[0] == '\\'))
    1612             --p;
    1613           p[1] = '\0';
     1624          /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
     1625             But allow -C/ just in case someone wants that.  */
     1626          {
     1627            char *p = (char *)dir + strlen (dir) - 1;
     1628            while (p > dir && (p[0] == '/' || p[0] == '\\'))
     1629              --p;
     1630            p[1] = '\0';
     1631          }
     1632#endif
     1633          if (chdir (dir) < 0)
     1634            pfatal_with_name (dir);
    16141635        }
    1615 #endif
    1616         if (chdir (dir) < 0)
    1617           pfatal_with_name (dir);
    1618         if (expanded)
    1619           free (expanded);
    1620       }
     1636    }
    16211637
    16221638#ifdef WINDOWS32
     
    16561672  /* Construct the list of include directories to search.  */
    16571673
    1658   construct_include_path (include_directories == 0 ? (char **) 0
    1659                           : include_directories->list);
     1674  construct_include_path (include_directories == 0
     1675                          ? 0 : include_directories->list);
    16601676
    16611677  /* Figure out where we are now, after chdir'ing.  */
     
    16881704  if (makefiles != 0)
    16891705    {
    1690       register unsigned int i;
     1706      unsigned int i;
    16911707      for (i = 0; i < makefiles->idx; ++i)
    16921708        if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
     
    17211737              tmpdir = DEFAULT_TMPDIR;
    17221738
    1723             template = (char *) alloca (strlen (tmpdir)
    1724                                         + sizeof (DEFAULT_TMPFILE) + 1);
     1739            template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);
    17251740            strcpy (template, tmpdir);
    17261741
     
    17461761                  pfatal_with_name (_("fwrite (temporary file)"));
    17471762              }
    1748             (void) fclose (outfile);
     1763            fclose (outfile);
    17491764
    17501765            /* Replace the name that read_all_makefiles will
    17511766               see with the name of the temporary file.  */
    1752             makefiles->list[i] = xstrdup (stdin_nm);
     1767            makefiles->list[i] = strcache_add (stdin_nm);
    17531768
    17541769            /* Make sure the temporary file will not be remade.  */
    1755             f = enter_file (stdin_nm);
    1756             f->updated = 1;
    1757             f->update_status = 0;
    1758             f->command_state = cs_finished;
    1759             /* Can't be intermediate, or it'll be removed too early for
    1760                make re-exec.  */
    1761             f->intermediate = 0;
    1762             f->dontcare = 0;
     1770            {
     1771              struct file *f = enter_file (strcache_add (stdin_nm));
     1772              f->updated = 1;
     1773              f->update_status = 0;
     1774              f->command_state = cs_finished;
     1775              /* Can't be intermediate, or it'll be removed too early for
     1776                 make re-exec.  */
     1777              f->intermediate = 0;
     1778              f->dontcare = 0;
     1779            }
    17631780          }
    17641781    }
    17651782
    1766 #if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX */
     1783#if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX (bird) */
    17671784#if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG)
    17681785  /* Set up to handle children dying.  This must be done before
     
    17791796     If none of these are true, we don't need a signal handler at all.  */
    17801797  {
    1781     extern RETSIGTYPE child_handler PARAMS ((int sig));
     1798    RETSIGTYPE child_handler (int sig);
    17821799# if defined SIGCHLD
    17831800    bsd_signal (SIGCHLD, child_handler);
     
    18191836  define_default_variables ();
    18201837
    1821   default_file = enter_file (".DEFAULT");
     1838  default_file = enter_file (strcache_add (".DEFAULT"));
    18221839
    18231840  {
     
    18291846
    18301847  read_makefiles
    1831     = read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
     1848    = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list);
    18321849
    18331850#ifdef WINDOWS32
     
    18841901  if (jobserver_fds)
    18851902  {
    1886     char *cp;
     1903    const char *cp;
    18871904    unsigned int ui;
    18881905
     
    18981915      fatal (NILF,
    18991916             _("internal error: invalid --jobserver-fds string `%s'"), cp);
     1917
     1918    DB (DB_JOBS,
     1919        (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
    19001920
    19011921    /* The combination of a pipe + !job_slots means we're using the
     
    19401960  if (job_slots > 1)
    19411961    {
     1962      char *cp;
    19421963      char c = '+';
    19431964
     
    19631984      /* Fill in the jobserver_fds struct for our children.  */
    19641985
     1986      cp = xmalloc ((sizeof ("1024")*2)+1);
     1987      sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
     1988
    19651989      jobserver_fds = (struct stringlist *)
    19661990                        xmalloc (sizeof (struct stringlist));
    1967       jobserver_fds->list = (char **) xmalloc (sizeof (char *));
    1968       jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1);
    1969 
    1970       sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]);
     1991      jobserver_fds->list = xmalloc (sizeof (char *));
     1992      jobserver_fds->list[0] = cp;
    19711993      jobserver_fds->idx = 1;
    19721994      jobserver_fds->max = 1;
     
    20182040
    20192041  if (old_files != 0)
    2020     for (p = old_files->list; *p != 0; ++p)
    2021       {
    2022         f = enter_command_line_file (*p);
    2023         f->last_mtime = f->mtime_before_update = OLD_MTIME;
    2024         f->updated = 1;
    2025         f->update_status = 0;
    2026         f->command_state = cs_finished;
    2027       }
     2042    {
     2043      const char **p;
     2044      for (p = old_files->list; *p != 0; ++p)
     2045        {
     2046          struct file *f = enter_file (*p);
     2047          f->last_mtime = f->mtime_before_update = OLD_MTIME;
     2048          f->updated = 1;
     2049          f->update_status = 0;
     2050          f->command_state = cs_finished;
     2051        }
     2052    }
    20282053
    20292054  if (!restarts && new_files != 0)
    20302055    {
     2056      const char **p;
    20312057      for (p = new_files->list; *p != 0; ++p)
    20322058        {
    2033           f = enter_command_line_file (*p);
     2059          struct file *f = enter_file (*p);
    20342060          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    20352061        }
     
    20632089        while (d != 0)
    20642090          {
    2065             register struct file *f = d->file;
     2091            struct file *f = d->file;
    20662092            if (f->double_colon)
    20672093              for (f = f->double_colon; f != NULL; f = f->prev)
     
    20962122            if (f == NULL || !f->double_colon)
    20972123              {
    2098                 makefile_mtimes = (FILE_TIMESTAMP *)
    2099                   xrealloc ((char *) makefile_mtimes,
    2100                             (mm_idx + 1) * sizeof (FILE_TIMESTAMP));
     2124                makefile_mtimes = xrealloc (makefile_mtimes,
     2125                                            (mm_idx+1)
     2126                                            * sizeof (FILE_TIMESTAMP));
    21012127                makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
    21022128                last = d;
     
    22172243                    char *p = &argv[i][2];
    22182244                    if (*p == '\0')
    2219                       argv[++i] = makefiles->list[j];
     2245                      /* This cast is OK since we never modify argv.  */
     2246                      argv[++i] = (char *) makefiles->list[j];
    22202247                    else
    2221                       argv[i] = concat ("-f", makefiles->list[j], "");
     2248                      argv[i] = xstrdup (concat ("-f", makefiles->list[j], ""));
    22222249                    ++j;
    22232250                  }
     
    22272254          if (stdin_nm)
    22282255            {
    2229               nargv = (char **) xmalloc ((nargc + 2) * sizeof (char *));
    2230               bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));
    2231               nargv[nargc++] = concat ("-o", stdin_nm, "");
     2256              nargv = xmalloc ((nargc + 2) * sizeof (char *));
     2257              memcpy (nargv, argv, argc * sizeof (char *));
     2258              nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, ""));
    22322259              nargv[nargc] = 0;
    22332260            }
     
    22352262          if (directories != 0 && directories->idx > 0)
    22362263            {
    2237               char bad;
     2264              int bad = 1;
    22382265              if (directory_before_chdir != 0)
    22392266                {
    22402267                  if (chdir (directory_before_chdir) < 0)
    2241                     {
    22422268                      perror_with_name ("chdir", "");
    2243                       bad = 1;
    2244                     }
    22452269                  else
    22462270                    bad = 0;
    22472271                }
    2248               else
    2249                 bad = 1;
    22502272              if (bad)
    22512273                fatal (NILF, _("Couldn't change back to original directory."));
     
    22642286
    22652287#ifndef _AMIGA
    2266           for (p = environ; *p != 0; ++p)
    2267             {
    2268               if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
    2269                   && (*p)[MAKELEVEL_LENGTH] == '=')
    2270                 {
    2271                   /* The SGI compiler apparently can't understand
    2272                      the concept of storing the result of a function
    2273                      in something other than a local variable.  */
    2274                   char *sgi_loses;
    2275                   sgi_loses = (char *) alloca (40);
    2276                   *p = sgi_loses;
    2277                   sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
    2278                 }
    2279               if (strneq (*p, "MAKE_RESTARTS=", 14))
    2280                 {
    2281                   char *sgi_loses;
    2282                   sgi_loses = (char *) alloca (40);
    2283                   *p = sgi_loses;
    2284                   sprintf (*p, "MAKE_RESTARTS=%u", restarts);
    2285                   restarts = 0;
    2286                 }
    2287             }
     2288          {
     2289            char **p;
     2290            for (p = environ; *p != 0; ++p)
     2291              {
     2292                if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
     2293                    && (*p)[MAKELEVEL_LENGTH] == '=')
     2294                  {
     2295                    *p = alloca (40);
     2296                    sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
     2297                  }
     2298                if (strneq (*p, "MAKE_RESTARTS=", 14))
     2299                  {
     2300                    *p = alloca (40);
     2301                    sprintf (*p, "MAKE_RESTARTS=%u", restarts);
     2302                    restarts = 0;
     2303                  }
     2304              }
     2305          }
    22882306#else /* AMIGA */
    22892307          {
     
    23512369      /* Free the makefile mtimes (if we allocated any).  */
    23522370      if (makefile_mtimes)
    2353         free ((char *) makefile_mtimes);
     2371        free (makefile_mtimes);
    23542372    }
    23552373
     
    23632381  if (restarts && new_files != 0)
    23642382    {
     2383      const char **p;
    23652384      for (p = new_files->list; *p != 0; ++p)
    23662385        {
    2367           f = enter_command_line_file (*p);
     2386          struct file *f = enter_file (*p);
    23682387          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    23692388        }
     
    24042423                      fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
    24052424
    2406                     default_goal_file = enter_file (ns->name);
     2425                    default_goal_file = enter_file (strcache_add (ns->name));
    24072426
    24082427                    ns->name = 0; /* It was reused by enter_file(). */
     
    25082527
    25092528        case string:
     2529        case filename:
    25102530        case positive_int:
    25112531        case floating:
     
    25522572
    25532573      if (! cv) {
    2554         cv = (struct command_variable *) xmalloc (sizeof (*cv));
     2574        cv = xmalloc (sizeof (*cv));
    25552575        cv->variable = v;
    25562576        cv->next = command_variables;
     
    25632583         target!  Enter it as a file and add it to the dep chain of
    25642584         goals.  */
    2565       struct file *f = enter_command_line_file (arg);
     2585      struct file *f = enter_file (strcache_add (expand_command_line_file (arg)));
    25662586      f->cmd_target = 1;
    25672587
     
    25812601      {
    25822602        /* Add this target name to the MAKECMDGOALS variable. */
    2583         struct variable *v;
    2584         char *value;
    2585 
    2586         v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
    2587         if (v == 0)
     2603        struct variable *gv;
     2604        const char *value;
     2605
     2606        gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
     2607        if (gv == 0)
    25882608          value = f->name;
    25892609        else
     
    25912611            /* Paste the old and new values together */
    25922612            unsigned int oldlen, newlen;
    2593 
    2594             oldlen = strlen (v->value);
     2613            char *vp;
     2614
     2615            oldlen = strlen (gv->value);
    25952616            newlen = strlen (f->name);
    2596             value = (char *) alloca (oldlen + 1 + newlen + 1);
    2597             bcopy (v->value, value, oldlen);
    2598             value[oldlen] = ' ';
    2599             bcopy (f->name, &value[oldlen + 1], newlen + 1);
     2617            vp = alloca (oldlen + 1 + newlen + 1);
     2618            memcpy (vp, gv->value, oldlen);
     2619            vp[oldlen] = ' ';
     2620            memcpy (&vp[oldlen + 1], f->name, newlen + 1);
     2621            value = vp;
    26002622          }
    26012623        define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
     
    26292651    printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"),
    26302652            BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
    2631 #else
     2653#else  /* !KMK */
    26322654  if (!remote_description || *remote_description == '\0')
    26332655    fprintf (usageto, _("\nThis program built for %s\n"), make_host);
     
    26352657    fprintf (usageto, _("\nThis program built for %s (%s)\n"),
    26362658             make_host, remote_description);
    2637 #endif
     2659#endif /* !KMK */
    26382660
    26392661  fprintf (usageto, _("Report bugs to <bug-make@gnu.org>\n"));
     
    27022724
    27032725                case string:
     2726                case filename:
    27042727                  if (!doit)
    27052728                    break;
    27062729
    27072730                  if (optarg == 0)
    2708                     optarg = cs->noarg_value;
     2731                    optarg = xstrdup (cs->noarg_value);
    27092732                  else if (*optarg == '\0')
    27102733                    {
     
    27212744                      sl->max = 5;
    27222745                      sl->idx = 0;
    2723                       sl->list = (char **) xmalloc (5 * sizeof (char *));
     2746                      sl->list = xmalloc (5 * sizeof (char *));
    27242747                      *(struct stringlist **) cs->value_ptr = sl;
    27252748                    }
     
    27272750                    {
    27282751                      sl->max += 5;
    2729                       sl->list = (char **)
    2730                         xrealloc ((char *) sl->list,
    2731                                   sl->max * sizeof (char *));
     2752                      sl->list = xrealloc (sl->list,
     2753                                           sl->max * sizeof (char *));
    27322754                    }
    2733                   sl->list[sl->idx++] = optarg;
     2755                  if (cs->type == filename)
     2756                    sl->list[sl->idx++] = expand_command_line_file (optarg);
     2757                  else
     2758                    sl->list[sl->idx++] = optarg;
    27342759                  sl->list[sl->idx] = 0;
    27352760                  break;
     
    28162841decode_env_switches (char *envar, unsigned int len)
    28172842{
    2818   char *varref = (char *) alloca (2 + len + 2);
     2843  char *varref = alloca (2 + len + 2);
    28192844  char *value, *p;
    28202845  int argc;
     
    28242849  varref[0] = '$';
    28252850  varref[1] = '(';
    2826   bcopy (envar, &varref[2], len);
     2851  memcpy (&varref[2], envar, len);
    28272852  varref[2 + len] = ')';
    28282853  varref[2 + len + 1] = '\0';
     
    28362861
    28372862  /* Allocate a vector that is definitely big enough.  */
    2838   argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
     2863  argv = alloca ((1 + len + 1) * sizeof (char *));
    28392864
    28402865  /* Allocate a buffer to copy the value into while we split it into words
    28412866     and unquote it.  We must use permanent storage for this because
    28422867     decode_switches may store pointers into the passed argument words.  */
    2843   p = (char *) xmalloc (2 * len);
     2868  p = xmalloc (2 * len);
    28442869
    28452870  /* getopt will look at the arguments starting at ARGV[1].
     
    28722897       need permanent storage for this in case decode_switches saves
    28732898       pointers into the value.  */
    2874     argv[1] = concat ("-", argv[1], "");
     2899    argv[1] = xstrdup (concat ("-", argv[1], ""));
    28752900
    28762901  /* Parse those words.  */
     
    28862911
    28872912static char *
    2888 quote_for_env (char *out, char *in)
     2913quote_for_env (char *out, const char *in)
    28892914{
    28902915  while (*in != '\0')
     
    29242949      struct flag *next;
    29252950      const struct command_switch *cs;
    2926       char *arg;
     2951      const char *arg;
    29272952    };
    29282953  struct flag *flags = 0;
     
    29302955#define ADD_FLAG(ARG, LEN) \
    29312956  do {                                                                        \
    2932     struct flag *new = (struct flag *) alloca (sizeof (struct flag));         \
     2957    struct flag *new = alloca (sizeof (struct flag));                         \
    29332958    new->cs = cs;                                                             \
    29342959    new->arg = (ARG);                                                         \
     
    29482973      switch (cs->type)
    29492974        {
    2950         default:
    2951           abort ();
    2952 
    29532975        case ignore:
    29542976          break;
     
    29803002              else
    29813003                {
    2982                   char *buf = (char *) alloca (30);
     3004                  char *buf = alloca (30);
    29833005                  sprintf (buf, "%u", *(unsigned int *) cs->value_ptr);
    29843006                  ADD_FLAG (buf, strlen (buf));
     
    30013023              else
    30023024                {
    3003                   char *buf = (char *) alloca (100);
     3025                  char *buf = alloca (100);
    30043026                  sprintf (buf, "%g", *(double *) cs->value_ptr);
    30053027                  ADD_FLAG (buf, strlen (buf));
     
    30093031#endif
    30103032
     3033        case filename:
    30113034        case string:
    30123035          if (all)
     
    30153038              if (sl != 0)
    30163039                {
    3017                   /* Add the elements in reverse order, because
    3018                      all the flags get reversed below; and the order
    3019                      matters for some switches (like -I).  */
    3020                   register unsigned int i = sl->idx;
     3040                  /* Add the elements in reverse order, because all the flags
     3041                     get reversed below; and the order matters for some
     3042                     switches (like -I).  */
     3043                  unsigned int i = sl->idx;
    30213044                  while (i-- > 0)
    30223045                    ADD_FLAG (sl->list[i], strlen (sl->list[i]));
     
    30243047            }
    30253048          break;
     3049
     3050        default:
     3051          abort ();
    30263052        }
    30273053
     
    30323058  /* Construct the value in FLAGSTRING.
    30333059     We allocate enough space for a preceding dash and trailing null.  */
    3034   flagstring = (char *) alloca (1 + flagslen + 1);
    3035   bzero (flagstring, 1 + flagslen + 1);
     3060  flagstring = alloca (1 + flagslen + 1);
     3061  memset (flagstring, '\0', 1 + flagslen + 1);
    30363062  p = flagstring;
    30373063  words = 1;
     
    31253151      if (posix_pedantic)
    31263152        {
    3127           bcopy (posixref, p, sizeof posixref - 1);
     3153          memcpy (p, posixref, sizeof posixref - 1);
    31283154          p += sizeof posixref - 1;
    31293155        }
    31303156      else
    31313157        {
    3132           bcopy (ref, p, sizeof ref - 1);
     3158          memcpy (p, ref, sizeof ref - 1);
    31333159          p += sizeof ref - 1;
    31343160        }
     
    33423368      if (print_data_base_flag)
    33433369        print_data_base ();
     3370
     3371      verify_file_data_base ();
    33443372
    33453373      clean_jobserver (status);
Note: See TracChangeset for help on using the changeset viewer.