Changeset 503 for trunk/src/gmake/main.c


Ignore:
Timestamp:
Sep 15, 2006, 7:09:38 AM (19 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

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

    r386 r503  
    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/* Negative if we have seen the `.NOTPARALLEL' target with empty dependency list.
     
    538543{
    539544  init_hash_global_variable_set ();
     545  strcache_init ();
    540546  init_hash_files ();
    541547  hash_init_directories ();
     
    671677    {
    672678      sprintf(errmsg,
    673               _("%s: Interrupt/Exception caught (code = 0x%x, addr = 0x%x)\n"),
    674               prg, exrec->ExceptionCode, exrec->ExceptionAddress);
     679              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"),
     680              prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress);
    675681      fprintf(stderr, errmsg);
    676682      exit(255);
     
    678684
    679685  sprintf(errmsg,
    680           _("\nUnhandled exception filter called from program %s\nExceptionCode = %x\nExceptionFlags = %x\nExceptionAddress = %x\n"),
     686          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"),
    681687          prg, exrec->ExceptionCode, exrec->ExceptionFlags,
    682           exrec->ExceptionAddress);
     688          (DWORD)exrec->ExceptionAddress);
    683689
    684690  if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
     
    686692    sprintf(&errmsg[strlen(errmsg)],
    687693            (exrec->ExceptionInformation[0]
    688              ? _("Access violation: write operation at address %x\n")
    689              : _("Access violation: read operation at address %x\n")),
     694             ? _("Access violation: write operation at address %lx\n")
     695             : _("Access violation: read operation at address %lx\n")),
    690696            exrec->ExceptionInformation[1]);
    691697
     
    760766    batch_mode_shell = 1;
    761767    unixy_shell = 0;
    762     sh_found = 0;
     768    sprintf (sh_path, "%s", search_token);
     769    default_shell = xstrdup (w32ify (sh_path, 0));
     770    DB (DB_VERBOSE,
     771        (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     772    sh_found = 1;
    763773  } else if (!no_default_sh_exe &&
    764774             (token == NULL || !strcmp (search_token, default_shell))) {
     
    774784  } else {
    775785    char *p;
    776     struct variable *v = lookup_variable ("PATH", 4);
     786    struct variable *v = lookup_variable (STRING_SIZE_TUPLE ("PATH"));
    777787
    778788    /* Search Path for shell */
     
    847857open_tmpfile(char **name, const char *template)
    848858{
     859#ifdef HAVE_FDOPEN
    849860  int fd;
     861#endif
    850862
    851863#if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
     
    899911  struct dep *read_makefiles;
    900912  PATH_VAR (current_directory);
     913  unsigned int restarts = 0;
    901914#ifdef WINDOWS32
    902915  char *unix_path = NULL;
     
    922935      }
    923936  }
     937#endif
     938
     939#ifdef HAVE_ATEXIT
     940  atexit (close_stdout);
    924941#endif
    925942
     
    10521069          /* Extract program from full path */
    10531070          int argv0_len;
    1054           char *p = strrchr (argv[0], '\\');
    1055           if (!p)
    1056             p = argv[0];
    1057           argv0_len = strlen(p);
    1058           if (argv0_len > 4
    1059               && streq (&p[argv0_len - 4], ".exe"))
     1071          program = strrchr (argv[0], '\\');
     1072          if (program)
    10601073            {
    1061               /* Remove .exe extension */
    1062               p[argv0_len - 4] = '\0';
    1063               /* Increment past the initial '\' */
    1064               program = p + 1;
     1074              argv0_len = strlen(program);
     1075              if (argv0_len > 4 && streq (&program[argv0_len - 4], ".exe"))
     1076                /* Remove .exe extension */
     1077                program[argv0_len - 4] = '\0';
    10651078            }
    10661079        }
     
    11061119  /* Set up .FEATURES */
    11071120  define_variable (".FEATURES", 9,
    1108                    "target-specific order-only second-expansion",
     1121                   "target-specific order-only second-expansion else-if",
    11091122                   o_default, 0);
     1123#ifndef NO_ARCHIVES
     1124  do_variable_definition (NILF, ".FEATURES", "archives",
     1125                          o_default, f_append, 0);
     1126#endif
    11101127#ifdef MAKE_JOBSERVER
    11111128  do_variable_definition (NILF, ".FEATURES", "jobserver",
     
    11551172
    11561173          /* Another wrinkle is that POSIX says the value of SHELL set in the
    1157              makefile should not change the value of SHELL given to
    1158              subprocesses, which seems silly to me but...  */
    1159           if (strncmp (envp[i], "SHELL=", 6) == 0)
     1174             makefile won't change the value of SHELL given to subprocesses  */
     1175          if (streq (v->name, "SHELL"))
    11601176            {
    11611177#ifndef __MSDOS__
     
    11641180              shell_var.name = "SHELL";
    11651181              shell_var.value = xstrdup (ep + 1);
     1182            }
     1183
     1184          /* If MAKE_RESTARTS is set, remember it but don't export it.  */
     1185          if (streq (v->name, "MAKE_RESTARTS"))
     1186            {
     1187              v->export = v_noexport;
     1188              restarts = (unsigned int) atoi (ep + 1);
    11661189            }
    11671190        }
     
    12091232  /* Decode the switches.  */
    12101233
    1211   decode_env_switches ("MAKEFLAGS", 9);
     1234  decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
    12121235#if 0
    12131236  /* People write things like:
    12141237        MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
    12151238     and we set the -p, -i and -e switches.  Doesn't seem quite right.  */
    1216   decode_env_switches ("MFLAGS", 6);
     1239  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
    12171240#endif
    12181241  decode_switches (argc, argv, 0);
    12191242#ifdef WINDOWS32
    12201243  if (suspend_flag) {
    1221         fprintf(stderr, "%s (pid = %d)\n", argv[0], GetCurrentProcessId());
     1244        fprintf(stderr, "%s (pid = %ld)\n", argv[0], GetCurrentProcessId());
    12221245        fprintf(stderr, _("%s is suspending for 30 seconds..."), argv[0]);
    12231246        Sleep(30 * 1000);
     
    12281251  decode_debug_flags ();
    12291252
     1253  /* Set always_make_flag if -B was given and we've not restarted already.  */
     1254  always_make_flag = always_make_set && (restarts == 0);
     1255
    12301256  /* Print version information.  */
    1231 
    12321257  if (print_version_flag || print_data_base_flag || db_level)
    1233     print_version ();
    1234 
    1235   /* `make --version' is supposed to just print the version and exit.  */
    1236   if (print_version_flag)
    1237     die (0);
     1258    {
     1259      print_version ();
     1260
     1261      /* `make --version' is supposed to just print the version and exit.  */
     1262      if (print_version_flag)
     1263        die (0);
     1264    }
    12381265
    12391266#ifndef VMS
     
    13821409  /* Figure out the level of recursion.  */
    13831410  {
    1384     struct variable *v = lookup_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH);
     1411    struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME));
    13851412    if (v != 0 && v->value[0] != '\0' && v->value[0] != '-')
    13861413      makelevel = (unsigned int) atoi (v->value);
     
    14291456    }
    14301457
    1431   (void) define_variable ("CURDIR", 6, current_directory, o_default, 0);
     1458  (void) define_variable ("CURDIR", 6, current_directory, o_file, 0);
    14321459
    14331460  /* Read any stdin makefiles into temporary files.  */
     
    15821609  if (no_default_sh_exe)
    15831610    no_default_sh_exe = !find_and_set_default_shell(NULL);
    1584 
    1585   if (no_default_sh_exe && job_slots != 1) {
    1586     error (NILF, _("Do not specify -j or --jobs if sh.exe is not available."));
    1587     error (NILF, _("Resetting make for single job mode."));
    1588     job_slots = 1;
    1589   }
    15901611#endif /* WINDOWS32 */
    15911612
     
    15941615  {
    15951616    extern int _is_unixy_shell (const char *_path);
    1596     struct variable *shv = lookup_variable ("SHELL", 5);
     1617    struct variable *shv = lookup_variable (STRING_SIZE_TUPLE ("SHELL"));
    15971618    extern int unixy_shell;
    15981619    extern char *default_shell;
     
    16131634
    16141635  /* Decode switches again, in case the variables were set by the makefile.  */
    1615   decode_env_switches ("MAKEFLAGS", 9);
     1636  decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
    16161637#if 0
    1617   decode_env_switches ("MFLAGS", 6);
     1638  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
    16181639#endif
    16191640
     
    17661787  build_vpath_lists ();
    17671788
    1768   /* Mark files given with -o flags as very old
    1769      and as having been updated already, and files given with -W flags as
    1770      brand new (time-stamp as far as possible into the future).  */
     1789  /* Mark files given with -o flags as very old and as having been updated
     1790     already, and files given with -W flags as brand new (time-stamp as far
     1791     as possible into the future).  If restarts is set we'll do -W later.  */
    17711792
    17721793  if (old_files != 0)
     
    17801801      }
    17811802
    1782   if (new_files != 0)
     1803  if (!restarts && new_files != 0)
    17831804    {
    17841805      for (p = new_files->list; *p != 0; ++p)
     
    18401861
    18411862                      /* Free the storage.  */
    1842                       free ((char *) d);
     1863                      free_dep (d);
    18431864
    18441865                      d = last == 0 ? read_makefiles : last->next;
     
    19591980          log_working_directory (0);
    19601981
     1982          clean_jobserver (0);
     1983
    19611984          if (makefiles != 0)
    19621985            {
     
    20032026            }
    20042027
    2005 #ifndef _AMIGA
    2006           for (p = environ; *p != 0; ++p)
    2007             if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
    2008                 && (*p)[MAKELEVEL_LENGTH] == '=')
    2009               {
    2010                 /* The SGI compiler apparently can't understand
    2011                    the concept of storing the result of a function
    2012                    in something other than a local variable.  */
    2013                 char *sgi_loses;
    2014                 sgi_loses = (char *) alloca (40);
    2015                 *p = sgi_loses;
    2016                 sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
    2017                 break;
    2018               }
    2019 #else /* AMIGA */
    2020           {
    2021             char buffer[256];
    2022             int len;
    2023 
    2024             len = GetVar (MAKELEVEL_NAME, buffer, sizeof (buffer), GVF_GLOBAL_ONLY);
    2025 
    2026             if (len != -1)
    2027             {
    2028             sprintf (buffer, "%u", makelevel);
    2029               SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY);
    2030             }
    2031           }
    2032 #endif
     2028          ++restarts;
    20332029
    20342030          if (ISDB (DB_BASIC))
    20352031            {
    20362032              char **p;
    2037               fputs (_("Re-executing:"), stdout);
     2033              printf (_("Re-executing[%u]:"), restarts);
    20382034              for (p = nargv; *p != 0; ++p)
    20392035                printf (" %s", *p);
    20402036              putchar ('\n');
    20412037            }
     2038
     2039#ifndef _AMIGA
     2040          for (p = environ; *p != 0; ++p)
     2041            {
     2042              if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
     2043                  && (*p)[MAKELEVEL_LENGTH] == '=')
     2044                {
     2045                  /* The SGI compiler apparently can't understand
     2046                     the concept of storing the result of a function
     2047                     in something other than a local variable.  */
     2048                  char *sgi_loses;
     2049                  sgi_loses = (char *) alloca (40);
     2050                  *p = sgi_loses;
     2051                  sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
     2052                }
     2053              if (strneq (*p, "MAKE_RESTARTS=", 14))
     2054                {
     2055                  char *sgi_loses;
     2056                  sgi_loses = (char *) alloca (40);
     2057                  *p = sgi_loses;
     2058                  sprintf (*p, "MAKE_RESTARTS=%u", restarts);
     2059                  restarts = 0;
     2060                }
     2061            }
     2062#else /* AMIGA */
     2063          {
     2064            char buffer[256];
     2065
     2066            sprintf (buffer, "%u", makelevel);
     2067            SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY);
     2068
     2069            sprintf (buffer, "%u", restarts);
     2070            SetVar ("MAKE_RESTARTS", buffer, -1, GVF_GLOBAL_ONLY);
     2071            restarts = 0;
     2072          }
     2073#endif
     2074
     2075          /* If we didn't set the restarts variable yet, add it.  */
     2076          if (restarts)
     2077            {
     2078              char *b = alloca (40);
     2079              sprintf (b, "MAKE_RESTARTS=%u", restarts);
     2080              putenv (b);
     2081            }
    20422082
    20432083          fflush (stdout);
     
    20912131  define_makeflags (1, 0);
    20922132
     2133  /* Set always_make_flag if -B was given.  */
     2134  always_make_flag = always_make_set;
     2135
     2136  /* If restarts is set we haven't set up -W files yet, so do that now.  */
     2137  if (restarts && new_files != 0)
     2138    {
     2139      for (p = new_files->list; *p != 0; ++p)
     2140        {
     2141          f = enter_command_line_file (*p);
     2142          f->last_mtime = f->mtime_before_update = NEW_MTIME;
     2143        }
     2144    }
     2145
    20932146  /* If there is a temp file from reading a makefile from stdin, get rid of
    20942147     it now.  */
     
    21322185              }
    21332186
    2134             goals = (struct dep *) xmalloc (sizeof (struct dep));
    2135             goals->next = 0;
    2136             goals->name = 0;
    2137             goals->ignore_mtime = 0;
    2138             goals->need_2nd_expansion = 0;
     2187            goals = alloc_dep ();
    21392188            goals->file = default_goal_file;
    21402189          }
     
    21862235  }
    21872236
     2237  /* NOTREACHED */
    21882238  return 0;
    21892239}
     
    22922342      if (goals == 0)
    22932343        {
    2294           goals = (struct dep *) xmalloc (sizeof (struct dep));
     2344          goals = alloc_dep ();
    22952345          lastgoal = goals;
    22962346        }
    22972347      else
    22982348        {
    2299           lastgoal->next = (struct dep *) xmalloc (sizeof (struct dep));
     2349          lastgoal->next = alloc_dep ();
    23002350          lastgoal = lastgoal->next;
    23012351        }
    2302       lastgoal->name = 0;
     2352
    23032353      lastgoal->file = f;
    2304       lastgoal->ignore_mtime = 0;
    2305       lastgoal->need_2nd_expansion = 0;
    23062354
    23072355      {
     
    23102358        char *value;
    23112359
    2312         v = lookup_variable ("MAKECMDGOALS", 12);
     2360        v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
    23132361        if (v == 0)
    23142362          value = f->name;
     
    29032951
    29042952  printf ("%sGNU Make %s\n\
    2905 %sCopyright (C) 2003  Free Software Foundation, Inc.\n",
     2953%sCopyright (C) 2006  Free Software Foundation, Inc.\n",
    29062954          precede, version_string, precede);
    29072955
     
    29272975
    29282976static void
    2929 print_data_base (void)
     2977print_data_base ()
    29302978{
    29312979  time_t when;
     
    29392987  print_file_data_base ();
    29402988  print_vpath_data_base ();
     2989  strcache_print_stats ("#");
    29412990
    29422991  when = time ((time_t *) 0);
    29432992  printf (_("\n# Finished Make data base on %s\n"), ctime (&when));
     2993}
     2994
     2995static void
     2996clean_jobserver (int status)
     2997{
     2998  char token = '+';
     2999
     3000  /* Sanity: have we written all our jobserver tokens back?  If our
     3001     exit status is 2 that means some kind of syntax error; we might not
     3002     have written all our tokens so do that now.  If tokens are left
     3003     after any other error code, that's bad.  */
     3004
     3005  if (job_fds[0] != -1 && jobserver_tokens)
     3006    {
     3007      if (status != 2)
     3008        error (NILF,
     3009               "INTERNAL: Exiting with %u jobserver tokens (should be 0)!",
     3010               jobserver_tokens);
     3011      else
     3012        while (jobserver_tokens--)
     3013          {
     3014            int r;
     3015
     3016            EINTRLOOP (r, write (job_fds[1], &token, 1));
     3017            if (r != 1)
     3018              perror_with_name ("write", "");
     3019          }
     3020    }
     3021
     3022
     3023  /* Sanity: If we're the master, were all the tokens written back?  */
     3024
     3025  if (master_job_slots)
     3026    {
     3027      /* We didn't write one for ourself, so start at 1.  */
     3028      unsigned int tcnt = 1;
     3029
     3030      /* Close the write side, so the read() won't hang.  */
     3031      close (job_fds[1]);
     3032
     3033      while (read (job_fds[0], &token, 1) == 1)
     3034        ++tcnt;
     3035
     3036      if (tcnt != master_job_slots)
     3037        error (NILF,
     3038               "INTERNAL: Exiting with %u jobserver tokens available; should be %u!",
     3039               tcnt, master_job_slots);
     3040
     3041      close (job_fds[0]);
     3042    }
    29443043}
    29453044
     
    29543053  if (!dying)
    29553054    {
    2956       char token = '+';
    29573055      int err;
    29583056
     
    29633061
    29643062      /* Wait for children to die.  */
    2965       for (err = (status != 0); job_slots_used > 0; err = 0)
     3063      err = (status != 0);
     3064      while (job_slots_used > 0)
    29663065        reap_children (1, err);
    29673066
     
    29753074        print_data_base ();
    29763075
    2977       /* Sanity: have we written all our jobserver tokens back?  If our
    2978          exit status is 2 that means some kind of syntax error; we might not
    2979          have written all our tokens so do that now.  If tokens are left
    2980          after any other error code, that's bad.  */
    2981 
    2982       if (job_fds[0] != -1 && jobserver_tokens)
    2983         {
    2984           if (status != 2)
    2985             error (NILF,
    2986                    "INTERNAL: Exiting with %u jobserver tokens (should be 0)!",
    2987                    jobserver_tokens);
    2988           else
    2989             while (jobserver_tokens--)
    2990               {
    2991                 int r;
    2992 
    2993                 EINTRLOOP (r, write (job_fds[1], &token, 1));
    2994                 if (r != 1)
    2995                   perror_with_name ("write", "");
    2996               }
    2997         }
    2998 
    2999 
    3000       /* Sanity: If we're the master, were all the tokens written back?  */
    3001 
    3002       if (master_job_slots)
    3003         {
    3004           /* We didn't write one for ourself, so start at 1.  */
    3005           unsigned int tcnt = 1;
    3006 
    3007           /* Close the write side, so the read() won't hang.  */
    3008           close (job_fds[1]);
    3009 
    3010           while ((err = read (job_fds[0], &token, 1)) == 1)
    3011             ++tcnt;
    3012 
    3013           if (tcnt != master_job_slots)
    3014             error (NILF,
    3015                    "INTERNAL: Exiting with %u jobserver tokens available; should be %u!",
    3016                    tcnt, master_job_slots);
    3017         }
     3076      clean_jobserver (status);
    30183077
    30193078      /* Try to move back to the original directory.  This is essential on
Note: See TracChangeset for help on using the changeset viewer.