Ignore:
Timestamp:
Sep 15, 2006, 4:30:32 AM (19 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

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

    r280 r501  
    11/* Argument parsing and main program of GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
    3 2002, 2003, 2005 Free Software Foundation, Inc.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    45This file is part of GNU Make.
    56
    6 GNU Make is free software; you can redistribute it and/or modify
    7 it under the terms of the GNU General Public License as published by
    8 the Free Software Foundation; either version 2, or (at your option)
    9 any later version.
    10 
    11 GNU Make is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Make; see the file COPYING.  If not, write to
    18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
    19 MA 02111-1307, USA.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    2018
    2119#include "make.h"
     
    8482#endif
    8583
     84static void clean_jobserver PARAMS ((int status));
    8685static void print_data_base PARAMS ((void));
    8786static void print_version PARAMS ((void));
     
    273272   they appear out of date or not.  */
    274273
     274static int always_make_set = 0;
    275275int always_make_flag = 0;
    276276
     
    365365  {
    366366    { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 },
    367     { 'B', flag, (char *) &always_make_flag, 1, 1, 0, 0, 0, "always-make" },
     367    { 'B', flag, (char *) &always_make_set, 1, 1, 0, 0, 0, "always-make" },
    368368    { 'C', string, (char *) &directories, 0, 0, 0, 0, 0, "directory" },
    369369    { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0, 0 },
     
    419419    { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    420420      "warn-undefined-variables" },
    421     { 0 }
     421    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    422422  };
    423423
     
    488488
    489489int posix_pedantic;
     490
     491/* Nonzero if we have seen the '.SECONDEXPANSION' target.
     492   This turns on secondary expansion of prerequisites.  */
     493
     494int second_expansion;
    490495
    491496/* Nonzero if we have seen the `.NOTPARALLEL' target.
     
    536541{
    537542  init_hash_global_variable_set ();
     543  strcache_init ();
    538544  init_hash_files ();
    539545  hash_init_directories ();
     
    666672    {
    667673      sprintf(errmsg,
    668               _("%s: Interrupt/Exception caught (code = 0x%x, addr = 0x%x)\n"),
    669               prg, exrec->ExceptionCode, exrec->ExceptionAddress);
     674              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"),
     675              prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress);
    670676      fprintf(stderr, errmsg);
    671677      exit(255);
     
    673679
    674680  sprintf(errmsg,
    675           _("\nUnhandled exception filter called from program %s\nExceptionCode = %x\nExceptionFlags = %x\nExceptionAddress = %x\n"),
     681          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"),
    676682          prg, exrec->ExceptionCode, exrec->ExceptionFlags,
    677           exrec->ExceptionAddress);
     683          (DWORD)exrec->ExceptionAddress);
    678684
    679685  if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
     
    681687    sprintf(&errmsg[strlen(errmsg)],
    682688            (exrec->ExceptionInformation[0]
    683              ? _("Access violation: write operation at address %x\n")
    684              : _("Access violation: read operation at address %x\n")),
     689             ? _("Access violation: write operation at address %lx\n")
     690             : _("Access violation: read operation at address %lx\n")),
    685691            exrec->ExceptionInformation[1]);
    686692
     
    755761    batch_mode_shell = 1;
    756762    unixy_shell = 0;
    757     sh_found = 0;
     763    sprintf (sh_path, "%s", search_token);
     764    default_shell = xstrdup (w32ify (sh_path, 0));
     765    DB (DB_VERBOSE,
     766        (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     767    sh_found = 1;
    758768  } else if (!no_default_sh_exe &&
    759769             (token == NULL || !strcmp (search_token, default_shell))) {
     
    769779  } else {
    770780    char *p;
    771     struct variable *v = lookup_variable ("PATH", 4);
     781    struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH"));
    772782
    773783    /* Search Path for shell */
     
    842852open_tmpfile(char **name, const char *template)
    843853{
     854#ifdef HAVE_FDOPEN
    844855  int fd;
     856#endif
    845857
    846858#if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
     
    894906  struct dep *read_makefiles;
    895907  PATH_VAR (current_directory);
     908  unsigned int restarts = 0;
    896909#ifdef WINDOWS32
    897910  char *unix_path = NULL;
     
    917930      }
    918931  }
     932#endif
     933
     934#ifdef HAVE_ATEXIT
     935  atexit (close_stdout);
    919936#endif
    920937
     
    10471064          /* Extract program from full path */
    10481065          int argv0_len;
    1049           char *p = strrchr (argv[0], '\\');
    1050           if (!p)
    1051             p = argv[0];
    1052           argv0_len = strlen(p);
    1053           if (argv0_len > 4
    1054               && streq (&p[argv0_len - 4], ".exe"))
     1066          program = strrchr (argv[0], '\\');
     1067          if (program)
    10551068            {
    1056               /* Remove .exe extension */
    1057               p[argv0_len - 4] = '\0';
    1058               /* Increment past the initial '\' */
    1059               program = p + 1;
     1069              argv0_len = strlen(program);
     1070              if (argv0_len > 4 && streq (&program[argv0_len - 4], ".exe"))
     1071                /* Remove .exe extension */
     1072                program[argv0_len - 4] = '\0';
    10601073            }
    10611074        }
     
    11011114  /* Set up .FEATURES */
    11021115  define_variable (".FEATURES", 9,
    1103                    "target-specific order-only second-expansion",
     1116                   "target-specific order-only second-expansion else-if",
    11041117                   o_default, 0);
     1118#ifndef NO_ARCHIVES
     1119  do_variable_definition (NILF, ".FEATURES", "archives",
     1120                          o_default, f_append, 0);
     1121#endif
    11051122#ifdef MAKE_JOBSERVER
    11061123  do_variable_definition (NILF, ".FEATURES", "jobserver",
     
    11501167
    11511168          /* Another wrinkle is that POSIX says the value of SHELL set in the
    1152              makefile should not change the value of SHELL given to
    1153              subprocesses, which seems silly to me but...  */
    1154           if (strncmp (envp[i], "SHELL=", 6) == 0)
     1169             makefile won't change the value of SHELL given to subprocesses  */
     1170          if (streq (v->name, "SHELL"))
    11551171            {
    11561172#ifndef __MSDOS__
     
    11591175              shell_var.name = "SHELL";
    11601176              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);
    11611184            }
    11621185        }
     
    12041227  /* Decode the switches.  */
    12051228
    1206   decode_env_switches ("MAKEFLAGS", 9);
     1229  decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
    12071230#if 0
    12081231  /* People write things like:
    12091232        MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
    12101233     and we set the -p, -i and -e switches.  Doesn't seem quite right.  */
    1211   decode_env_switches ("MFLAGS", 6);
     1234  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
    12121235#endif
    12131236  decode_switches (argc, argv, 0);
    12141237#ifdef WINDOWS32
    12151238  if (suspend_flag) {
    1216         fprintf(stderr, "%s (pid = %d)\n", argv[0], GetCurrentProcessId());
     1239        fprintf(stderr, "%s (pid = %ld)\n", argv[0], GetCurrentProcessId());
    12171240        fprintf(stderr, _("%s is suspending for 30 seconds..."), argv[0]);
    12181241        Sleep(30 * 1000);
     
    12231246  decode_debug_flags ();
    12241247
     1248  /* Set always_make_flag if -B was given and we've not restarted already.  */
     1249  always_make_flag = always_make_set && (restarts == 0);
     1250
    12251251  /* Print version information.  */
    1226 
    12271252  if (print_version_flag || print_data_base_flag || db_level)
    1228     print_version ();
    1229 
    1230   /* `make --version' is supposed to just print the version and exit.  */
    1231   if (print_version_flag)
    1232     die (0);
     1253    {
     1254      print_version ();
     1255
     1256      /* `make --version' is supposed to just print the version and exit.  */
     1257      if (print_version_flag)
     1258        die (0);
     1259    }
    12331260
    12341261#ifndef VMS
     
    13771404  /* Figure out the level of recursion.  */
    13781405  {
    1379     struct variable *v = lookup_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH);
     1406    struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME));
    13801407    if (v != 0 && v->value[0] != '\0' && v->value[0] != '-')
    13811408      makelevel = (unsigned int) atoi (v->value);
     
    14241451    }
    14251452
    1426   (void) define_variable ("CURDIR", 6, current_directory, o_default, 0);
     1453  (void) define_variable ("CURDIR", 6, current_directory, o_file, 0);
    14271454
    14281455  /* Read any stdin makefiles into temporary files.  */
     
    15771604  if (no_default_sh_exe)
    15781605    no_default_sh_exe = !find_and_set_default_shell(NULL);
    1579 
    1580   if (no_default_sh_exe && job_slots != 1) {
    1581     error (NILF, _("Do not specify -j or --jobs if sh.exe is not available."));
    1582     error (NILF, _("Resetting make for single job mode."));
    1583     job_slots = 1;
    1584   }
    15851606#endif /* WINDOWS32 */
    15861607
     
    15891610  {
    15901611    extern int _is_unixy_shell (const char *_path);
    1591     struct variable *shv = lookup_variable ("SHELL", 5);
     1612    struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL"));
    15921613    extern int unixy_shell;
    15931614    extern char *default_shell;
     
    16081629
    16091630  /* Decode switches again, in case the variables were set by the makefile.  */
    1610   decode_env_switches ("MAKEFLAGS", 9);
     1631  decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
    16111632#if 0
    1612   decode_env_switches ("MFLAGS", 6);
     1633  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
    16131634#endif
    16141635
     
    17611782  build_vpath_lists ();
    17621783
    1763   /* Mark files given with -o flags as very old
    1764      and as having been updated already, and files given with -W flags as
    1765      brand new (time-stamp as far as possible into the future).  */
     1784  /* Mark files given with -o flags as very old and as having been updated
     1785     already, and files given with -W flags as brand new (time-stamp as far
     1786     as possible into the future).  If restarts is set we'll do -W later.  */
    17661787
    17671788  if (old_files != 0)
     
    17751796      }
    17761797
    1777   if (new_files != 0)
     1798  if (!restarts && new_files != 0)
    17781799    {
    17791800      for (p = new_files->list; *p != 0; ++p)
     
    18351856
    18361857                      /* Free the storage.  */
    1837                       free ((char *) d);
     1858                      free_dep (d);
    18381859
    18391860                      d = last == 0 ? read_makefiles : last->next;
     
    19541975          log_working_directory (0);
    19551976
     1977          clean_jobserver (0);
     1978
    19561979          if (makefiles != 0)
    19571980            {
     
    19982021            }
    19992022
    2000 #ifndef _AMIGA
    2001           for (p = environ; *p != 0; ++p)
    2002             if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
    2003                 && (*p)[MAKELEVEL_LENGTH] == '=')
    2004               {
    2005                 /* The SGI compiler apparently can't understand
    2006                    the concept of storing the result of a function
    2007                    in something other than a local variable.  */
    2008                 char *sgi_loses;
    2009                 sgi_loses = (char *) alloca (40);
    2010                 *p = sgi_loses;
    2011                 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
    2012                 break;
    2013               }
    2014 #else /* AMIGA */
    2015           {
    2016             char buffer[256];
    2017             int len;
    2018 
    2019             len = GetVar (MAKELEVEL_NAME, buffer, sizeof (buffer), GVF_GLOBAL_ONLY);
    2020 
    2021             if (len != -1)
    2022             {
    2023             sprintf (buffer, "%u", makelevel);
    2024               SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY);
    2025             }
    2026           }
    2027 #endif
     2023          ++restarts;
    20282024
    20292025          if (ISDB (DB_BASIC))
    20302026            {
    20312027              char **p;
    2032               fputs (_("Re-executing:"), stdout);
     2028              printf (_("Re-executing[%u]:"), restarts);
    20332029              for (p = nargv; *p != 0; ++p)
    20342030                printf (" %s", *p);
    20352031              putchar ('\n');
    20362032            }
     2033
     2034#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#else /* AMIGA */
     2058          {
     2059            char buffer[256];
     2060
     2061            sprintf (buffer, "%u", makelevel);
     2062            SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY);
     2063
     2064            sprintf (buffer, "%u", restarts);
     2065            SetVar ("MAKE_RESTARTS", buffer, -1, GVF_GLOBAL_ONLY);
     2066            restarts = 0;
     2067          }
     2068#endif
     2069
     2070          /* If we didn't set the restarts variable yet, add it.  */
     2071          if (restarts)
     2072            {
     2073              char *b = alloca (40);
     2074              sprintf (b, "MAKE_RESTARTS=%u", restarts);
     2075              putenv (b);
     2076            }
    20372077
    20382078          fflush (stdout);
     
    20862126  define_makeflags (1, 0);
    20872127
     2128  /* Set always_make_flag if -B was given.  */
     2129  always_make_flag = always_make_set;
     2130
     2131  /* If restarts is set we haven't set up -W files yet, so do that now.  */
     2132  if (restarts && new_files != 0)
     2133    {
     2134      for (p = new_files->list; *p != 0; ++p)
     2135        {
     2136          f = enter_command_line_file (*p);
     2137          f->last_mtime = f->mtime_before_update = NEW_MTIME;
     2138        }
     2139    }
     2140
    20882141  /* If there is a temp file from reading a makefile from stdin, get rid of
    20892142     it now.  */
     
    21272180              }
    21282181
    2129             goals = (struct dep *) xmalloc (sizeof (struct dep));
    2130             goals->next = 0;
    2131             goals->name = 0;
    2132             goals->ignore_mtime = 0;
    2133             goals->need_2nd_expansion = 0;
     2182            goals = alloc_dep ();
    21342183            goals->file = default_goal_file;
    21352184          }
     
    21812230  }
    21822231
     2232  /* NOTREACHED */
    21832233  return 0;
    21842234}
     
    22872337      if (goals == 0)
    22882338        {
    2289           goals = (struct dep *) xmalloc (sizeof (struct dep));
     2339          goals = alloc_dep ();
    22902340          lastgoal = goals;
    22912341        }
    22922342      else
    22932343        {
    2294           lastgoal->next = (struct dep *) xmalloc (sizeof (struct dep));
     2344          lastgoal->next = alloc_dep ();
    22952345          lastgoal = lastgoal->next;
    22962346        }
    2297       lastgoal->name = 0;
     2347
    22982348      lastgoal->file = f;
    2299       lastgoal->ignore_mtime = 0;
    2300       lastgoal->need_2nd_expansion = 0;
    23012349
    23022350      {
     
    23052353        char *value;
    23062354
    2307         v = lookup_variable ("MAKECMDGOALS", 12);
     2355        v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
    23082356        if (v == 0)
    23092357          value = f->name;
     
    28962944
    28972945  printf ("%sGNU Make %s\n\
    2898 %sCopyright (C) 2003  Free Software Foundation, Inc.\n",
     2946%sCopyright (C) 2006  Free Software Foundation, Inc.\n",
    28992947          precede, version_string, precede);
    29002948
     
    29202968
    29212969static void
    2922 print_data_base (void)
     2970print_data_base ()
    29232971{
    29242972  time_t when;
     
    29322980  print_file_data_base ();
    29332981  print_vpath_data_base ();
     2982  strcache_print_stats ("#");
    29342983
    29352984  when = time ((time_t *) 0);
    29362985  printf (_("\n# Finished Make data base on %s\n"), ctime (&when));
     2986}
     2987
     2988static void
     2989clean_jobserver (int status)
     2990{
     2991  char token = '+';
     2992
     2993  /* Sanity: have we written all our jobserver tokens back?  If our
     2994     exit status is 2 that means some kind of syntax error; we might not
     2995     have written all our tokens so do that now.  If tokens are left
     2996     after any other error code, that's bad.  */
     2997
     2998  if (job_fds[0] != -1 && jobserver_tokens)
     2999    {
     3000      if (status != 2)
     3001        error (NILF,
     3002               "INTERNAL: Exiting with %u jobserver tokens (should be 0)!",
     3003               jobserver_tokens);
     3004      else
     3005        while (jobserver_tokens--)
     3006          {
     3007            int r;
     3008
     3009            EINTRLOOP (r, write (job_fds[1], &token, 1));
     3010            if (r != 1)
     3011              perror_with_name ("write", "");
     3012          }
     3013    }
     3014
     3015
     3016  /* Sanity: If we're the master, were all the tokens written back?  */
     3017
     3018  if (master_job_slots)
     3019    {
     3020      /* We didn't write one for ourself, so start at 1.  */
     3021      unsigned int tcnt = 1;
     3022
     3023      /* Close the write side, so the read() won't hang.  */
     3024      close (job_fds[1]);
     3025
     3026      while (read (job_fds[0], &token, 1) == 1)
     3027        ++tcnt;
     3028
     3029      if (tcnt != master_job_slots)
     3030        error (NILF,
     3031               "INTERNAL: Exiting with %u jobserver tokens available; should be %u!",
     3032               tcnt, master_job_slots);
     3033
     3034      close (job_fds[0]);
     3035    }
    29373036}
    29383037
     
    29473046  if (!dying)
    29483047    {
    2949       char token = '+';
    29503048      int err;
    29513049
     
    29563054
    29573055      /* Wait for children to die.  */
    2958       for (err = (status != 0); job_slots_used > 0; err = 0)
     3056      err = (status != 0);
     3057      while (job_slots_used > 0)
    29593058        reap_children (1, err);
    29603059
     
    29683067        print_data_base ();
    29693068
    2970       /* Sanity: have we written all our jobserver tokens back?  If our
    2971          exit status is 2 that means some kind of syntax error; we might not
    2972          have written all our tokens so do that now.  If tokens are left
    2973          after any other error code, that's bad.  */
    2974 
    2975       if (job_fds[0] != -1 && jobserver_tokens)
    2976         {
    2977           if (status != 2)
    2978             error (NILF,
    2979                    "INTERNAL: Exiting with %u jobserver tokens (should be 0)!",
    2980                    jobserver_tokens);
    2981           else
    2982             while (jobserver_tokens--)
    2983               {
    2984                 int r;
    2985 
    2986                 EINTRLOOP (r, write (job_fds[1], &token, 1));
    2987                 if (r != 1)
    2988                   perror_with_name ("write", "");
    2989               }
    2990         }
    2991 
    2992 
    2993       /* Sanity: If we're the master, were all the tokens written back?  */
    2994 
    2995       if (master_job_slots)
    2996         {
    2997           /* We didn't write one for ourself, so start at 1.  */
    2998           unsigned int tcnt = 1;
    2999 
    3000           /* Close the write side, so the read() won't hang.  */
    3001           close (job_fds[1]);
    3002 
    3003           while ((err = read (job_fds[0], &token, 1)) == 1)
    3004             ++tcnt;
    3005 
    3006           if (tcnt != master_job_slots)
    3007             error (NILF,
    3008                    "INTERNAL: Exiting with %u jobserver tokens available; should be %u!",
    3009                    tcnt, master_job_slots);
    3010         }
     3069      clean_jobserver (status);
    30113070
    30123071      /* Try to move back to the original directory.  This is essential on
Note: See TracChangeset for help on using the changeset viewer.