Ignore:
Timestamp:
May 23, 2007, 5:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/main.c

    r501 r900  
    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
     
    7375
    7476#ifndef HAVE_UNISTD_H
    75 extern int chdir ();
     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.  */
     
    158161
    159162int db_level = 0;
     163
     164/* Output level (--verbosity).  */
     165
     166static struct stringlist *verbosity_flags;
    160167
    161168#ifdef WINDOWS32
     
    282289
    283290struct variable shell_var;
     291
     292/* This character introduces a command: it's the first char on the line.  */
     293
     294char cmd_prefix = '\t';
    284295
    285296
     
    365376  {
    366377    { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 },
    367     { 'B', flag, (char *) &always_make_set, 1, 1, 0, 0, 0, "always-make" },
    368     { 'C', string, (char *) &directories, 0, 0, 0, 0, 0, "directory" },
    369     { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0, 0 },
    370     { CHAR_MAX+1, string, (char *) &db_flags, 1, 1, 0, "basic", 0, "debug" },
     378    { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" },
     379    { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" },
     380    { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 },
     381    { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" },
    371382#ifdef WINDOWS32
    372     { 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
    373 #endif
    374     { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
    375       "environment-overrides", },
    376     { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" },
    377     { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" },
    378     { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
    379       "ignore-errors" },
    380     { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
     383    { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
     384#endif
     385    { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", },
     386    { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" },
     387    { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" },
     388    { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" },
     389    { 'I', filename, &include_directories, 1, 1, 0, 0, 0,
    381390      "include-dir" },
    382     { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs,
    383       (char *) &default_job_slots, "jobs" },
    384     { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0,
    385       "jobserver-fds" },
    386     { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0,
    387       (char *) &default_keep_going_flag, "keep-going" },
     391    { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots,
     392      "jobs" },
     393    { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" },
     394    { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     395      "keep-going" },
    388396#ifndef NO_FLOAT
    389     { 'l', floating, (char *) &max_load_average, 1, 1, 0,
    390       (char *) &default_load_average, (char *) &default_load_average,
    391       "load-average" },
     397    { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average,
     398      &default_load_average, "load-average" },
    392399#else
    393     { 'l', positive_int, (char *) &max_load_average, 1, 1, 0,
    394       (char *) &default_load_average, (char *) &default_load_average,
    395       "load-average" },
    396 #endif
    397     { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0,
    398       "check-symlink-times" },
     400    { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average,
     401      &default_load_average, "load-average" },
     402#endif
     403    { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" },
    399404    { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 },
    400     { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
    401     { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" },
    402     { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
    403       "print-data-base" },
    404     { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" },
    405     { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
    406       "no-builtin-rules" },
    407     { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0,
     405    { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
     406    { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },
     407    { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" },
     408    { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" },
     409    { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, "no-builtin-rules" },
     410    { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0,
    408411      "no-builtin-variables" },
    409     { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" },
    410     { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0,
    411       (char *) &default_keep_going_flag, "no-keep-going" },
    412     { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0, "touch" },
    413     { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" },
    414     { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
    415       "print-directory" },
    416     { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
     412    { 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" },
     413    { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     414      "no-keep-going" },
     415    { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" },
     416    { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" },
     417    { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0,
     418      "verbosity" },
     419    { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" },
     420    { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
    417421      "no-print-directory" },
    418     { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" },
    419     { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
     422    { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" },
     423    { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    420424      "warn-undefined-variables" },
    421425    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
     
    547551}
    548552
    549 static struct file *
    550 enter_command_line_file (char *name)
     553static const char *
     554expand_command_line_file (char *name)
    551555{
     556  const char *cp;
     557  char *expanded = 0;
     558
    552559  if (name[0] == '\0')
    553560    fatal (NILF, _("empty string invalid as file name"));
     
    555562  if (name[0] == '~')
    556563    {
    557       char *expanded = tilde_expand (name);
     564      expanded = tilde_expand (name);
    558565      if (expanded != 0)
    559         name = expanded;        /* Memory leak; I don't care.  */
     566        name = expanded;
    560567    }
    561568
     
    581588    }
    582589
    583   return enter_file (xstrdup (name));
     590  cp = strcache_add (name);
     591
     592  if (expanded)
     593    free (expanded);
     594
     595  return cp;
    584596}
    585597
     
    597609decode_debug_flags (void)
    598610{
    599   char **pp;
     611  const char **pp;
    600612
    601613  if (debug_flag)
     
    732744
    733745int
    734 find_and_set_default_shell (char *token)
     746find_and_set_default_shell (const char *token)
    735747{
    736748  int sh_found = 0;
     749  char *atoken = 0;
    737750  char *search_token;
    738751  char *tokend;
     
    743756    search_token = default_shell;
    744757  else
    745     search_token = token;
    746 
     758    atoken = search_token = xstrdup (token);
    747759
    748760  /* If the user explicitly requests the DOS cmd shell, obey that request.
     
    754766        || (tokend > search_token
    755767            && (tokend[-1] == '/' || tokend[-1] == '\\')))
    756        && !strcmpi (tokend, "cmd"))
     768       && !strcasecmp (tokend, "cmd"))
    757769      || ((tokend - 4 == search_token
    758770           || (tokend - 4 > search_token
    759771               && (tokend[-5] == '/' || tokend[-5] == '\\')))
    760           && !strcmpi (tokend - 4, "cmd.exe"))) {
     772          && !strcasecmp (tokend - 4, "cmd.exe"))) {
    761773    batch_mode_shell = 1;
    762774    unixy_shell = 0;
     
    770782    /* no new information, path already set or known */
    771783    sh_found = 1;
    772   } else if (file_exists_p(search_token)) {
     784  } else if (file_exists_p (search_token)) {
    773785    /* search token path was found */
    774     sprintf(sh_path, "%s", search_token);
    775     default_shell = xstrdup(w32ify(sh_path,0));
     786    sprintf (sh_path, "%s", search_token);
     787    default_shell = xstrdup (w32ify (sh_path, 0));
    776788    DB (DB_VERBOSE,
    777789        (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     
    786798
    787799      p  = v->value;
    788       ep = strchr(p, PATH_SEPARATOR_CHAR);
     800      ep = strchr (p, PATH_SEPARATOR_CHAR);
    789801
    790802      while (ep && *ep) {
    791803        *ep = '\0';
    792804
    793         if (dir_file_exists_p(p, search_token)) {
    794           sprintf(sh_path, "%s/%s", p, search_token);
    795           default_shell = xstrdup(w32ify(sh_path,0));
     805        if (dir_file_exists_p (p, search_token)) {
     806          sprintf (sh_path, "%s/%s", p, search_token);
     807          default_shell = xstrdup (w32ify (sh_path, 0));
    796808          sh_found = 1;
    797809          *ep = PATH_SEPARATOR_CHAR;
    798810
    799811          /* terminate loop */
    800           p += strlen(p);
     812          p += strlen (p);
    801813        } else {
    802814          *ep = PATH_SEPARATOR_CHAR;
     
    804816        }
    805817
    806         ep = strchr(p, PATH_SEPARATOR_CHAR);
     818        ep = strchr (p, PATH_SEPARATOR_CHAR);
    807819      }
    808820
    809821      /* be sure to check last element of Path */
    810       if (p && *p && dir_file_exists_p(p, search_token)) {
    811           sprintf(sh_path, "%s/%s", p, search_token);
    812           default_shell = xstrdup(w32ify(sh_path,0));
     822      if (p && *p && dir_file_exists_p (p, search_token)) {
     823          sprintf (sh_path, "%s/%s", p, search_token);
     824          default_shell = xstrdup (w32ify (sh_path, 0));
    813825          sh_found = 1;
    814826      }
     
    823835  /* naive test */
    824836  if (!unixy_shell && sh_found &&
    825       (strstr(default_shell, "sh") || strstr(default_shell, "SH"))) {
     837      (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) {
    826838    unixy_shell = 1;
    827839    batch_mode_shell = 0;
     
    832844#endif
    833845
     846  if (atoken)
     847    free (atoken);
     848
    834849  return (sh_found);
    835850}
    836851#endif  /* WINDOWS32 */
    837852
    838 #ifdef  __MSDOS__
    839 
     853#ifdef __MSDOS__
    840854static void
    841855msdos_return_to_initial_directory (void)
     
    844858    chdir (directory_before_chdir);
    845859}
    846 #endif
    847 
    848 extern char *mktemp PARAMS ((char *template));
    849 extern int mkstemp PARAMS ((char *template));
     860#endif  /* __MSDOS__ */
     861
     862char *mktemp (char *template);
     863int mkstemp (char *template);
    850864
    851865FILE *
     
    900914{
    901915  static char *stdin_nm = 0;
    902   struct file *f;
    903   int i;
    904916  int makefile_status = MAKE_SUCCESS;
    905   char **p;
    906917  struct dep *read_makefiles;
    907918  PATH_VAR (current_directory);
     
    10261037# else  /* setvbuf not reversed.  */
    10271038  /* Some buggy systems lose if we pass 0 instead of allocating ourselves.  */
    1028   setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
     1039  setvbuf (stdout, 0, _IOLBF, BUFSIZ);
    10291040# endif /* setvbuf reversed.  */
    10301041#elif HAVE_SETLINEBUF
     
    11341145
    11351146#ifndef _AMIGA
    1136   for (i = 0; envp[i] != 0; ++i)
    1137     {
    1138       int do_not_define = 0;
    1139       char *ep = envp[i];
    1140 
    1141       while (*ep != '\0' && *ep != '=')
    1142         ++ep;
     1147  {
     1148    unsigned int i;
     1149
     1150    for (i = 0; envp[i] != 0; ++i)
     1151      {
     1152        int do_not_define = 0;
     1153        char *ep = envp[i];
     1154
     1155        while (*ep != '\0' && *ep != '=')
     1156          ++ep;
    11431157#ifdef WINDOWS32
    1144       if (!unix_path && strneq(envp[i], "PATH=", 5))
    1145         unix_path = ep+1;
    1146       else if (!strnicmp(envp[i], "Path=", 5)) {
    1147         do_not_define = 1; /* it gets defined after loop exits */
    1148         if (!windows32_path)
    1149           windows32_path = ep+1;
     1158        if (!unix_path && strneq(envp[i], "PATH=", 5))
     1159          unix_path = ep+1;
     1160        else if (!strnicmp(envp[i], "Path=", 5)) {
     1161          do_not_define = 1; /* it gets defined after loop exits */
     1162          if (!windows32_path)
     1163            windows32_path = ep+1;
     1164        }
     1165#endif
     1166        /* The result of pointer arithmetic is cast to unsigned int for
     1167           machines where ptrdiff_t is a different size that doesn't widen
     1168           the same.  */
     1169        if (!do_not_define)
     1170          {
     1171            struct variable *v;
     1172
     1173            v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
     1174                                 ep + 1, o_env, 1);
     1175            /* Force exportation of every variable culled from the
     1176               environment.  We used to rely on target_environment's
     1177               v_default code to do this.  But that does not work for the
     1178               case where an environment variable is redefined in a makefile
     1179               with `override'; it should then still be exported, because it
     1180               was originally in the environment.  */
     1181            v->export = v_export;
     1182
     1183            /* Another wrinkle is that POSIX says the value of SHELL set in
     1184               the makefile won't change the value of SHELL given to
     1185               subprocesses.  */
     1186            if (streq (v->name, "SHELL"))
     1187              {
     1188#ifndef __MSDOS__
     1189                v->export = v_noexport;
     1190#endif
     1191                shell_var.name = "SHELL";
     1192                shell_var.value = xstrdup (ep + 1);
     1193              }
     1194
     1195            /* If MAKE_RESTARTS is set, remember it but don't export it.  */
     1196            if (streq (v->name, "MAKE_RESTARTS"))
     1197              {
     1198                v->export = v_noexport;
     1199                restarts = (unsigned int) atoi (ep + 1);
     1200              }
     1201          }
    11501202      }
    1151 #endif
    1152       /* The result of pointer arithmetic is cast to unsigned int for
    1153          machines where ptrdiff_t is a different size that doesn't widen
    1154          the same.  */
    1155       if (!do_not_define)
    1156         {
    1157           struct variable *v;
    1158 
    1159           v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
    1160                                ep + 1, o_env, 1);
    1161           /* Force exportation of every variable culled from the environment.
    1162              We used to rely on target_environment's v_default code to do this.
    1163              But that does not work for the case where an environment variable
    1164              is redefined in a makefile with `override'; it should then still
    1165              be exported, because it was originally in the environment.  */
    1166           v->export = v_export;
    1167 
    1168           /* Another wrinkle is that POSIX says the value of SHELL set in the
    1169              makefile won't change the value of SHELL given to subprocesses  */
    1170           if (streq (v->name, "SHELL"))
    1171             {
    1172 #ifndef __MSDOS__
    1173               v->export = v_noexport;
    1174 #endif
    1175               shell_var.name = "SHELL";
    1176               shell_var.value = xstrdup (ep + 1);
    1177             }
    1178 
    1179           /* If MAKE_RESTARTS is set, remember it but don't export it.  */
    1180           if (streq (v->name, "MAKE_RESTARTS"))
    1181             {
    1182               v->export = v_noexport;
    1183               restarts = (unsigned int) atoi (ep + 1);
    1184             }
    1185         }
    1186     }
     1203  }
    11871204#ifdef WINDOWS32
    11881205    /* If we didn't find a correctly spelled PATH we define PATH as
     
    12301247#if 0
    12311248  /* People write things like:
    1232         MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
     1249        MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
    12331250     and we set the -p, -i and -e switches.  Doesn't seem quite right.  */
    12341251  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
     
    12931310      && argv[0] != 0
    12941311      && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':'))
    1295 #ifdef __EMX__
     1312# ifdef __EMX__
    12961313      /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */
    12971314      && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0)
    12981315# endif
    12991316      )
    1300     argv[0] = concat (current_directory, "/", argv[0]);
     1317    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    13011318#else  /* !__MSDOS__ */
    13021319  if (current_directory[0] != '\0'
    1303       && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0)
    1304     argv[0] = concat (current_directory, "/", argv[0]);
     1320      && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0
     1321#ifdef HAVE_DOS_PATHS
     1322      && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':'))
     1323      && strchr (argv[0], '\\') != 0
     1324#endif
     1325      )
     1326    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    13051327#endif /* !__MSDOS__ */
    13061328#endif /* WINDOWS32 */
     
    13331355
    13341356      /* Now allocate a buffer big enough and fill it.  */
    1335       p = value = (char *) alloca (len);
     1357      p = value = alloca (len);
    13361358      for (cv = command_variables; cv != 0; cv = cv->next)
    13371359        {
     
    13631385  /* If there were -C flags, move ourselves about.  */
    13641386  if (directories != 0)
    1365     for (i = 0; directories->list[i] != 0; ++i)
    1366       {
    1367         char *dir = directories->list[i];
    1368         char *expanded = 0;
    1369         if (dir[0] == '~')
    1370           {
    1371             expanded = tilde_expand (dir);
    1372             if (expanded != 0)
    1373               dir = expanded;
    1374           }
     1387    {
     1388      unsigned int i;
     1389      for (i = 0; directories->list[i] != 0; ++i)
     1390        {
     1391          const char *dir = directories->list[i];
    13751392#ifdef WINDOWS32
    1376         /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
    1377            But allow -C/ just in case someone wants that.  */
    1378         {
    1379           char *p = dir + strlen (dir) - 1;
    1380           while (p > dir && (p[0] == '/' || p[0] == '\\'))
    1381             --p;
    1382           p[1] = '\0';
     1393          /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
     1394             But allow -C/ just in case someone wants that.  */
     1395          {
     1396            char *p = dir + strlen (dir) - 1;
     1397            while (p > dir && (p[0] == '/' || p[0] == '\\'))
     1398              --p;
     1399            p[1] = '\0';
     1400          }
     1401#endif
     1402          if (chdir (dir) < 0)
     1403            pfatal_with_name (dir);
    13831404        }
    1384 #endif
    1385         if (chdir (dir) < 0)
    1386           pfatal_with_name (dir);
    1387         if (expanded)
    1388           free (expanded);
    1389       }
     1405    }
    13901406
    13911407#ifdef WINDOWS32
     
    14251441  /* Construct the list of include directories to search.  */
    14261442
    1427   construct_include_path (include_directories == 0 ? (char **) 0
    1428                           : include_directories->list);
     1443  construct_include_path (include_directories == 0
     1444                          ? 0 : include_directories->list);
    14291445
    14301446  /* Figure out where we are now, after chdir'ing.  */
     
    14571473  if (makefiles != 0)
    14581474    {
    1459       register unsigned int i;
     1475      unsigned int i;
    14601476      for (i = 0; i < makefiles->idx; ++i)
    14611477        if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
     
    14901506              tmpdir = DEFAULT_TMPDIR;
    14911507
    1492             template = (char *) alloca (strlen (tmpdir)
    1493                                         + sizeof (DEFAULT_TMPFILE) + 1);
     1508            template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);
    14941509            strcpy (template, tmpdir);
    14951510
     
    15151530                  pfatal_with_name (_("fwrite (temporary file)"));
    15161531              }
    1517             (void) fclose (outfile);
     1532            fclose (outfile);
    15181533
    15191534            /* Replace the name that read_all_makefiles will
    15201535               see with the name of the temporary file.  */
    1521             makefiles->list[i] = xstrdup (stdin_nm);
     1536            makefiles->list[i] = strcache_add (stdin_nm);
    15221537
    15231538            /* Make sure the temporary file will not be remade.  */
    1524             f = enter_file (stdin_nm);
    1525             f->updated = 1;
    1526             f->update_status = 0;
    1527             f->command_state = cs_finished;
    1528             /* Can't be intermediate, or it'll be removed too early for
    1529                make re-exec.  */
    1530             f->intermediate = 0;
    1531             f->dontcare = 0;
     1539            {
     1540              struct file *f = enter_file (strcache_add (stdin_nm));
     1541              f->updated = 1;
     1542              f->update_status = 0;
     1543              f->command_state = cs_finished;
     1544              /* Can't be intermediate, or it'll be removed too early for
     1545                 make re-exec.  */
     1546              f->intermediate = 0;
     1547              f->dontcare = 0;
     1548            }
    15321549          }
    15331550    }
     
    15481565     If none of these are true, we don't need a signal handler at all.  */
    15491566  {
    1550     extern RETSIGTYPE child_handler PARAMS ((int sig));
     1567    RETSIGTYPE child_handler (int sig);
    15511568# if defined SIGCHLD
    15521569    bsd_signal (SIGCHLD, child_handler);
     
    15881605  define_default_variables ();
    15891606
    1590   default_file = enter_file (".DEFAULT");
     1607  default_file = enter_file (strcache_add (".DEFAULT"));
    15911608
    15921609  {
     
    15981615
    15991616  read_makefiles
    1600     = read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
     1617    = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list);
    16011618
    16021619#ifdef WINDOWS32
     
    16531670  if (jobserver_fds)
    16541671  {
    1655     char *cp;
     1672    const char *cp;
    16561673    unsigned int ui;
    16571674
     
    16671684      fatal (NILF,
    16681685             _("internal error: invalid --jobserver-fds string `%s'"), cp);
     1686
     1687    DB (DB_JOBS,
     1688        (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
    16691689
    16701690    /* The combination of a pipe + !job_slots means we're using the
     
    17091729  if (job_slots > 1)
    17101730    {
     1731      char *cp;
    17111732      char c = '+';
    17121733
     
    17321753      /* Fill in the jobserver_fds struct for our children.  */
    17331754
     1755      cp = xmalloc ((sizeof ("1024")*2)+1);
     1756      sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
     1757
    17341758      jobserver_fds = (struct stringlist *)
    17351759                        xmalloc (sizeof (struct stringlist));
    1736       jobserver_fds->list = (char **) xmalloc (sizeof (char *));
    1737       jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1);
    1738 
    1739       sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]);
     1760      jobserver_fds->list = xmalloc (sizeof (char *));
     1761      jobserver_fds->list[0] = cp;
    17401762      jobserver_fds->idx = 1;
    17411763      jobserver_fds->max = 1;
     
    17871809
    17881810  if (old_files != 0)
    1789     for (p = old_files->list; *p != 0; ++p)
    1790       {
    1791         f = enter_command_line_file (*p);
    1792         f->last_mtime = f->mtime_before_update = OLD_MTIME;
    1793         f->updated = 1;
    1794         f->update_status = 0;
    1795         f->command_state = cs_finished;
    1796       }
     1811    {
     1812      const char **p;
     1813      for (p = old_files->list; *p != 0; ++p)
     1814        {
     1815          struct file *f = enter_file (*p);
     1816          f->last_mtime = f->mtime_before_update = OLD_MTIME;
     1817          f->updated = 1;
     1818          f->update_status = 0;
     1819          f->command_state = cs_finished;
     1820        }
     1821    }
    17971822
    17981823  if (!restarts && new_files != 0)
    17991824    {
     1825      const char **p;
    18001826      for (p = new_files->list; *p != 0; ++p)
    18011827        {
    1802           f = enter_command_line_file (*p);
     1828          struct file *f = enter_file (*p);
    18031829          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    18041830        }
     
    18321858        while (d != 0)
    18331859          {
    1834             register struct file *f = d->file;
     1860            struct file *f = d->file;
    18351861            if (f->double_colon)
    18361862              for (f = f->double_colon; f != NULL; f = f->prev)
     
    18651891            if (f == NULL || !f->double_colon)
    18661892              {
    1867                 makefile_mtimes = (FILE_TIMESTAMP *)
    1868                   xrealloc ((char *) makefile_mtimes,
    1869                             (mm_idx + 1) * sizeof (FILE_TIMESTAMP));
     1893                makefile_mtimes = xrealloc (makefile_mtimes,
     1894                                            (mm_idx+1)
     1895                                            * sizeof (FILE_TIMESTAMP));
    18701896                makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
    18711897                last = d;
     
    19862012                    char *p = &argv[i][2];
    19872013                    if (*p == '\0')
    1988                       argv[++i] = makefiles->list[j];
     2014                      /* This cast is OK since we never modify argv.  */
     2015                      argv[++i] = (char *) makefiles->list[j];
    19892016                    else
    1990                       argv[i] = concat ("-f", makefiles->list[j], "");
     2017                      argv[i] = xstrdup (concat ("-f", makefiles->list[j], ""));
    19912018                    ++j;
    19922019                  }
     
    19962023          if (stdin_nm)
    19972024            {
    1998               nargv = (char **) xmalloc ((nargc + 2) * sizeof (char *));
    1999               bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));
    2000               nargv[nargc++] = concat ("-o", stdin_nm, "");
     2025              nargv = xmalloc ((nargc + 2) * sizeof (char *));
     2026              memcpy (nargv, argv, argc * sizeof (char *));
     2027              nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, ""));
    20012028              nargv[nargc] = 0;
    20022029            }
     
    20042031          if (directories != 0 && directories->idx > 0)
    20052032            {
    2006               char bad;
     2033              int bad = 1;
    20072034              if (directory_before_chdir != 0)
    20082035                {
    20092036                  if (chdir (directory_before_chdir) < 0)
    2010                     {
    20112037                      perror_with_name ("chdir", "");
    2012                       bad = 1;
    2013                     }
    20142038                  else
    20152039                    bad = 0;
    20162040                }
    2017               else
    2018                 bad = 1;
    20192041              if (bad)
    20202042                fatal (NILF, _("Couldn't change back to original directory."));
     
    20332055
    20342056#ifndef _AMIGA
    2035           for (p = environ; *p != 0; ++p)
    2036             {
    2037               if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
    2038                   && (*p)[MAKELEVEL_LENGTH] == '=')
    2039                 {
    2040                   /* The SGI compiler apparently can't understand
    2041                      the concept of storing the result of a function
    2042                      in something other than a local variable.  */
    2043                   char *sgi_loses;
    2044                   sgi_loses = (char *) alloca (40);
    2045                   *p = sgi_loses;
    2046                   sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
    2047                 }
    2048               if (strneq (*p, "MAKE_RESTARTS=", 14))
    2049                 {
    2050                   char *sgi_loses;
    2051                   sgi_loses = (char *) alloca (40);
    2052                   *p = sgi_loses;
    2053                   sprintf (*p, "MAKE_RESTARTS=%u", restarts);
    2054                   restarts = 0;
    2055                 }
    2056             }
     2057          {
     2058            char **p;
     2059            for (p = environ; *p != 0; ++p)
     2060              {
     2061                if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
     2062                    && (*p)[MAKELEVEL_LENGTH] == '=')
     2063                  {
     2064                    *p = alloca (40);
     2065                    sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
     2066                  }
     2067                if (strneq (*p, "MAKE_RESTARTS=", 14))
     2068                  {
     2069                    *p = alloca (40);
     2070                    sprintf (*p, "MAKE_RESTARTS=%u", restarts);
     2071                    restarts = 0;
     2072                  }
     2073              }
     2074          }
    20572075#else /* AMIGA */
    20582076          {
     
    21202138      /* Free the makefile mtimes (if we allocated any).  */
    21212139      if (makefile_mtimes)
    2122         free ((char *) makefile_mtimes);
     2140        free (makefile_mtimes);
    21232141    }
    21242142
     
    21322150  if (restarts && new_files != 0)
    21332151    {
     2152      const char **p;
    21342153      for (p = new_files->list; *p != 0; ++p)
    21352154        {
    2136           f = enter_command_line_file (*p);
     2155          struct file *f = enter_file (*p);
    21372156          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    21382157        }
     
    21732192                      fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
    21742193
    2175                     default_goal_file = enter_file (ns->name);
     2194                    default_goal_file = enter_file (strcache_add (ns->name));
    21762195
    21772196                    ns->name = 0; /* It was reused by enter_file(). */
     
    22772296
    22782297        case string:
     2298        case filename:
    22792299        case positive_int:
    22802300        case floating:
     
    23212341
    23222342      if (! cv) {
    2323         cv = (struct command_variable *) xmalloc (sizeof (*cv));
     2343        cv = xmalloc (sizeof (*cv));
    23242344        cv->variable = v;
    23252345        cv->next = command_variables;
     
    23322352         target!  Enter it as a file and add it to the dep chain of
    23332353         goals.  */
    2334       struct file *f = enter_command_line_file (arg);
     2354      struct file *f = enter_file (strcache_add (expand_command_line_file (arg)));
    23352355      f->cmd_target = 1;
    23362356
     
    23502370      {
    23512371        /* Add this target name to the MAKECMDGOALS variable. */
    2352         struct variable *v;
    2353         char *value;
    2354 
    2355         v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
    2356         if (v == 0)
     2372        struct variable *gv;
     2373        const char *value;
     2374
     2375        gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
     2376        if (gv == 0)
    23572377          value = f->name;
    23582378        else
     
    23602380            /* Paste the old and new values together */
    23612381            unsigned int oldlen, newlen;
    2362 
    2363             oldlen = strlen (v->value);
     2382            char *vp;
     2383
     2384            oldlen = strlen (gv->value);
    23642385            newlen = strlen (f->name);
    2365             value = (char *) alloca (oldlen + 1 + newlen + 1);
    2366             bcopy (v->value, value, oldlen);
    2367             value[oldlen] = ' ';
    2368             bcopy (f->name, &value[oldlen + 1], newlen + 1);
     2386            vp = alloca (oldlen + 1 + newlen + 1);
     2387            memcpy (vp, gv->value, oldlen);
     2388            vp[oldlen] = ' ';
     2389            memcpy (&vp[oldlen + 1], f->name, newlen + 1);
     2390            value = vp;
    23692391          }
    23702392        define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
     
    24622484
    24632485                case string:
     2486                case filename:
    24642487                  if (!doit)
    24652488                    break;
    24662489
    24672490                  if (optarg == 0)
    2468                     optarg = cs->noarg_value;
     2491                    optarg = xstrdup (cs->noarg_value);
    24692492                  else if (*optarg == '\0')
    24702493                    {
     
    24812504                      sl->max = 5;
    24822505                      sl->idx = 0;
    2483                       sl->list = (char **) xmalloc (5 * sizeof (char *));
     2506                      sl->list = xmalloc (5 * sizeof (char *));
    24842507                      *(struct stringlist **) cs->value_ptr = sl;
    24852508                    }
     
    24872510                    {
    24882511                      sl->max += 5;
    2489                       sl->list = (char **)
    2490                         xrealloc ((char *) sl->list,
    2491                                   sl->max * sizeof (char *));
     2512                      sl->list = xrealloc (sl->list,
     2513                                           sl->max * sizeof (char *));
    24922514                    }
    2493                   sl->list[sl->idx++] = optarg;
     2515                  if (cs->type == filename)
     2516                    sl->list[sl->idx++] = expand_command_line_file (optarg);
     2517                  else
     2518                    sl->list[sl->idx++] = optarg;
    24942519                  sl->list[sl->idx] = 0;
    24952520                  break;
     
    25762601decode_env_switches (char *envar, unsigned int len)
    25772602{
    2578   char *varref = (char *) alloca (2 + len + 2);
     2603  char *varref = alloca (2 + len + 2);
    25792604  char *value, *p;
    25802605  int argc;
     
    25842609  varref[0] = '$';
    25852610  varref[1] = '(';
    2586   bcopy (envar, &varref[2], len);
     2611  memcpy (&varref[2], envar, len);
    25872612  varref[2 + len] = ')';
    25882613  varref[2 + len + 1] = '\0';
     
    25962621
    25972622  /* Allocate a vector that is definitely big enough.  */
    2598   argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
     2623  argv = alloca ((1 + len + 1) * sizeof (char *));
    25992624
    26002625  /* Allocate a buffer to copy the value into while we split it into words
    26012626     and unquote it.  We must use permanent storage for this because
    26022627     decode_switches may store pointers into the passed argument words.  */
    2603   p = (char *) xmalloc (2 * len);
     2628  p = xmalloc (2 * len);
    26042629
    26052630  /* getopt will look at the arguments starting at ARGV[1].
     
    26322657       need permanent storage for this in case decode_switches saves
    26332658       pointers into the value.  */
    2634     argv[1] = concat ("-", argv[1], "");
     2659    argv[1] = xstrdup (concat ("-", argv[1], ""));
    26352660
    26362661  /* Parse those words.  */
     
    26462671
    26472672static char *
    2648 quote_for_env (char *out, char *in)
     2673quote_for_env (char *out, const char *in)
    26492674{
    26502675  while (*in != '\0')
     
    26842709      struct flag *next;
    26852710      const struct command_switch *cs;
    2686       char *arg;
     2711      const char *arg;
    26872712    };
    26882713  struct flag *flags = 0;
     
    26902715#define ADD_FLAG(ARG, LEN) \
    26912716  do {                                                                        \
    2692     struct flag *new = (struct flag *) alloca (sizeof (struct flag));         \
     2717    struct flag *new = alloca (sizeof (struct flag));                         \
    26932718    new->cs = cs;                                                             \
    26942719    new->arg = (ARG);                                                         \
     
    27082733      switch (cs->type)
    27092734        {
    2710         default:
    2711           abort ();
    2712 
    27132735        case ignore:
    27142736          break;
     
    27382760              else
    27392761                {
    2740                   char *buf = (char *) alloca (30);
     2762                  char *buf = alloca (30);
    27412763                  sprintf (buf, "%u", *(unsigned int *) cs->value_ptr);
    27422764                  ADD_FLAG (buf, strlen (buf));
     
    27592781              else
    27602782                {
    2761                   char *buf = (char *) alloca (100);
     2783                  char *buf = alloca (100);
    27622784                  sprintf (buf, "%g", *(double *) cs->value_ptr);
    27632785                  ADD_FLAG (buf, strlen (buf));
     
    27672789#endif
    27682790
     2791        case filename:
    27692792        case string:
    27702793          if (all)
     
    27732796              if (sl != 0)
    27742797                {
    2775                   /* Add the elements in reverse order, because
    2776                      all the flags get reversed below; and the order
    2777                      matters for some switches (like -I).  */
    2778                   register unsigned int i = sl->idx;
     2798                  /* Add the elements in reverse order, because all the flags
     2799                     get reversed below; and the order matters for some
     2800                     switches (like -I).  */
     2801                  unsigned int i = sl->idx;
    27792802                  while (i-- > 0)
    27802803                    ADD_FLAG (sl->list[i], strlen (sl->list[i]));
     
    27822805            }
    27832806          break;
     2807
     2808        default:
     2809          abort ();
    27842810        }
    27852811
     
    27902816  /* Construct the value in FLAGSTRING.
    27912817     We allocate enough space for a preceding dash and trailing null.  */
    2792   flagstring = (char *) alloca (1 + flagslen + 1);
    2793   bzero (flagstring, 1 + flagslen + 1);
     2818  flagstring = alloca (1 + flagslen + 1);
     2819  memset (flagstring, '\0', 1 + flagslen + 1);
    27942820  p = flagstring;
    27952821  words = 1;
     
    28832909      if (posix_pedantic)
    28842910        {
    2885           bcopy (posixref, p, sizeof posixref - 1);
     2911          memcpy (p, posixref, sizeof posixref - 1);
    28862912          p += sizeof posixref - 1;
    28872913        }
    28882914      else
    28892915        {
    2890           bcopy (ref, p, sizeof ref - 1);
     2916          memcpy (p, ref, sizeof ref - 1);
    28912917          p += sizeof ref - 1;
    28922918        }
     
    30663092      if (print_data_base_flag)
    30673093        print_data_base ();
     3094
     3095      verify_file_data_base ();
    30683096
    30693097      clean_jobserver (status);
Note: See TracChangeset for help on using the changeset viewer.