Ignore:
Timestamp:
Jun 20, 2012, 12:44:52 AM (13 years ago)
Author:
bird
Message:

gnumake/current -> 3.82-cvs.

Location:
vendor/gnumake/current
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current

    • Property svn:ignore deleted
  • vendor/gnumake/current/main.c

    r1989 r2596  
    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, 2007 Free Software
    4 Foundation, Inc.
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
     42010 Free Software Foundation, Inc.
    55This file is part of GNU Make.
    66
     
    4545#endif
    4646
    47 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
    48 # define SET_STACK_SIZE
    49 #endif
    50 
    51 #ifdef SET_STACK_SIZE
    52 # include <sys/resource.h>
    53 #endif
    54 
    5547#ifdef _AMIGA
    5648int __stack = 20000; /* Make sure we have 20K of stack space */
     
    6557void print_dir_data_base (void);
    6658void print_rule_data_base (void);
    67 void print_file_data_base (void);
    6859void print_vpath_data_base (void);
    6960
     
    8980static void decode_switches (int argc, char **argv, int env);
    9081static void decode_env_switches (char *envar, unsigned int len);
    91 static void define_makeflags (int all, int makefile);
     82static const char *define_makeflags (int all, int makefile);
    9283static char *quote_for_env (char *out, const char *in);
    9384static void initialize_global_hash_tables (void);
     
    222213static struct stringlist *makefiles = 0;
    223214
     215/* Size of the stack when we started.  */
     216
     217#ifdef SET_STACK_SIZE
     218struct rlimit stack_limit;
     219#endif
     220
     221
    224222/* Number of job slots (commands that can be run at once).  */
    225223
     
    266264
    267265static struct stringlist *new_files = 0;
     266
     267/* List of strings to be eval'd.  */
     268static struct stringlist *eval_strings = 0;
    268269
    269270/* If nonzero, we should just print usage and exit.  */
     
    317318  -e, --environment-overrides\n\
    318319                              Environment variables override makefiles.\n"),
     320    N_("\
     321  --eval=STRING               Evaluate STRING as a makefile statement.\n"),
    319322    N_("\
    320323  -f FILE, --file=FILE, --makefile=FILE\n\
     
    423426    { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    424427      "warn-undefined-variables" },
     428    { CHAR_MAX+6, string, &eval_strings, 1, 0, 0, 0, 0, "eval" },
    425429    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    426430  };
     
    472476unsigned int makelevel;
    473477
    474 /* First file defined in the makefile whose name does not
    475    start with `.'.  This is the default to remake if the
    476    command line does not specify.  */
    477 
    478 struct file *default_goal_file;
    479 
    480 /* Pointer to the value of the .DEFAULT_GOAL special
    481    variable.  */
    482 char ** default_goal_name;
     478/* Pointer to the value of the .DEFAULT_GOAL special variable.
     479   The value will be the name of the goal to remake if the command line
     480   does not override it.  It can be set by the makefile, or else it's
     481   the first target defined in the makefile whose name does not start
     482   with '.'.  */
     483
     484struct variable * default_goal_var;
    483485
    484486/* Pointer to structure for the file .DEFAULT
     
    497499
    498500int second_expansion;
     501
     502/* Nonzero if we have seen the '.ONESHELL' target.
     503   This causes the entire recipe to be handed to SHELL
     504   as a single string, potentially containing newlines.  */
     505
     506int one_shell;
    499507
    500508/* Nonzero if we have seen the `.NOTPARALLEL' target.
     
    520528#endif
    521529
    522 #if !defined HAVE_BSD_SIGNAL && !defined bsd_signal
     530#if !HAVE_DECL_BSD_SIGNAL && !defined bsd_signal
    523531# if !defined HAVE_SIGACTION
    524532#  define bsd_signal signal
    525533# else
    526 typedef RETSIGTYPE (*bsd_signal_ret_t) ();
     534typedef RETSIGTYPE (*bsd_signal_ret_t) (int);
    527535
    528536static bsd_signal_ret_t
     
    684692    {
    685693      sprintf(errmsg,
    686               _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"),
    687               prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress);
     694              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%p)\n"),
     695              prg, exrec->ExceptionCode, exrec->ExceptionAddress);
    688696      fprintf(stderr, errmsg);
    689697      exit(255);
     
    691699
    692700  sprintf(errmsg,
    693           _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"),
     701          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = 0x%p\n"),
    694702          prg, exrec->ExceptionCode, exrec->ExceptionFlags,
    695           (DWORD)exrec->ExceptionAddress);
     703          exrec->ExceptionAddress);
    696704
    697705  if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
     
    699707    sprintf(&errmsg[strlen(errmsg)],
    700708            (exrec->ExceptionInformation[0]
    701              ? _("Access violation: write operation at address %lx\n")
    702              : _("Access violation: read operation at address %lx\n")),
    703             exrec->ExceptionInformation[1]);
     709             ? _("Access violation: write operation at address 0x%p\n")
     710             : _("Access violation: read operation at address 0x%p\n")),
     711            (PVOID)exrec->ExceptionInformation[1]);
    704712
    705713  /* turn this on if we want to put stuff in the event log too */
     
    775783    sprintf (sh_path, "%s", search_token);
    776784    default_shell = xstrdup (w32ify (sh_path, 0));
    777     DB (DB_VERBOSE,
    778         (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     785    DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
     786                    default_shell));
    779787    sh_found = 1;
    780788  } else if (!no_default_sh_exe &&
     
    786794    sprintf (sh_path, "%s", search_token);
    787795    default_shell = xstrdup (w32ify (sh_path, 0));
    788     DB (DB_VERBOSE,
    789         (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     796    DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
     797                    default_shell));
    790798    sh_found = 1;
    791799  } else {
     
    828836      if (sh_found)
    829837        DB (DB_VERBOSE,
    830             (_("find_and_set_shell path search set default_shell = %s\n"),
     838            (_("find_and_set_shell() path search set default_shell = %s\n"),
    831839             default_shell));
    832840    }
     
    935943
    936944    /* Set the stack limit huge so that alloca does not fail.  */
    937     if (getrlimit (RLIMIT_STACK, &rlim) == 0)
     945    if (getrlimit (RLIMIT_STACK, &rlim) == 0
     946        && rlim.rlim_cur > 0 && rlim.rlim_cur < rlim.rlim_max)
    938947      {
     948        stack_limit = rlim;
    939949        rlim.rlim_cur = rlim.rlim_max;
    940950        setrlimit (RLIMIT_STACK, &rlim);
    941951      }
     952    else
     953      stack_limit.rlim_cur = 0;
    942954  }
    943955#endif
     
    950962  initialize_main(&argc, &argv);
    951963
    952   default_goal_file = 0;
    953964  reading_file = 0;
    954965
     
    967978  /* Set up gettext/internationalization support.  */
    968979  setlocale (LC_ALL, "");
    969   bindtextdomain (PACKAGE, LOCALEDIR);
    970   textdomain (PACKAGE);
     980  /* The cast to void shuts up compiler warnings on systems that
     981     disable NLS.  */
     982  (void)bindtextdomain (PACKAGE, LOCALEDIR);
     983  (void)textdomain (PACKAGE);
    971984
    972985#ifdef  POSIX
     
    978991#define ADD_SIG(sig)    fatal_signal_mask |= sigmask (sig)
    979992#else
    980 #define ADD_SIG(sig)
     993#define ADD_SIG(sig)    (void)sig      /* Needed to avoid warnings in MSVC.  */
    981994#endif
    982995#endif
     
    11201133
    11211134  /* Initialize the special variables.  */
    1122   define_variable (".VARIABLES", 10, "", o_default, 0)->special = 1;
    1123   /* define_variable (".TARGETS", 8, "", o_default, 0)->special = 1; */
    1124   define_variable (".RECIPEPREFIX", 13, "", o_default, 0)->special = 1;
    1125 
    1126   /* Set up .FEATURES */
    1127   define_variable (".FEATURES", 9,
    1128                    "target-specific order-only second-expansion else-if",
    1129                    o_default, 0);
     1135  define_variable_cname (".VARIABLES", "", o_default, 0)->special = 1;
     1136  /* define_variable_cname (".TARGETS", "", o_default, 0)->special = 1; */
     1137  define_variable_cname (".RECIPEPREFIX", "", o_default, 0)->special = 1;
     1138  define_variable_cname (".SHELLFLAGS", "-c", o_default, 0);
     1139
     1140  /* Set up .FEATURES
     1141     We must do this in multiple calls because define_variable_cname() is
     1142     a macro and some compilers (MSVC) don't like conditionals in macros.  */
     1143  {
     1144    const char *features = "target-specific order-only second-expansion"
     1145                           " else-if shortest-stem undefine"
    11301146#ifndef NO_ARCHIVES
    1131   do_variable_definition (NILF, ".FEATURES", "archives",
    1132                           o_default, f_append, 0);
     1147                           " archives"
    11331148#endif
    11341149#ifdef MAKE_JOBSERVER
    1135   do_variable_definition (NILF, ".FEATURES", "jobserver",
    1136                           o_default, f_append, 0);
     1150                           " jobserver"
    11371151#endif
    11381152#ifdef MAKE_SYMLINKS
    1139   do_variable_definition (NILF, ".FEATURES", "check-symlink",
    1140                           o_default, f_append, 0);
    1141 #endif
     1153                           " check-symlink"
     1154#endif
     1155                           ;
     1156
     1157    define_variable_cname (".FEATURES", features, o_default, 0);
     1158  }
    11421159
    11431160  /* Read in variables from the environment.  It is important that this be
     
    11911208#endif
    11921209                shell_var.name = "SHELL";
     1210                shell_var.length = 5;
    11931211                shell_var.value = xstrdup (ep + 1);
    11941212              }
     
    12081226     */
    12091227    if (!unix_path)
    1210       define_variable("PATH", 4,
    1211                       windows32_path ? windows32_path : "",
    1212                       o_env, 1)->export = v_export;
     1228      define_variable_cname ("PATH", windows32_path ? windows32_path : "",
     1229                             o_env, 1)->export = v_export;
    12131230#endif
    12141231#else /* For Amiga, read the ENV: device, ignoring all dirs */
     
    12521269  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
    12531270#endif
     1271
    12541272  decode_switches (argc, argv, 0);
     1273
    12551274#ifdef WINDOWS32
    12561275  if (suspend_flag) {
     
    13161335# endif
    13171336      )
    1318     argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
     1337    argv[0] = xstrdup (concat (3, current_directory, "/", argv[0]));
    13191338#else  /* !__MSDOS__ */
    13201339  if (current_directory[0] != '\0'
     
    13251344#endif
    13261345      )
    1327     argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
     1346    argv[0] = xstrdup (concat (3, current_directory, "/", argv[0]));
    13281347#endif /* !__MSDOS__ */
    13291348#endif /* WINDOWS32 */
     
    13321351  /* The extra indirection through $(MAKE_COMMAND) is done
    13331352     for hysterical raisins.  */
    1334   (void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
    1335   (void) define_variable ("MAKE", 4, "$(MAKE_COMMAND)", o_default, 1);
     1353  define_variable_cname ("MAKE_COMMAND", argv[0], o_default, 0);
     1354  define_variable_cname ("MAKE", "$(MAKE_COMMAND)", o_default, 1);
    13361355
    13371356  if (command_variables != 0)
     
    13711390      /* Define an unchangeable variable with a name that no POSIX.2
    13721391         makefile could validly use for its own variable.  */
    1373       (void) define_variable ("-*-command-variables-*-", 23,
    1374                               value, o_automatic, 0);
     1392      define_variable_cname ("-*-command-variables-*-", value, o_automatic, 0);
    13751393
    13761394      /* Define the variable; this will not override any user definition.
     
    13801398         allow the user's setting of MAKEOVERRIDES to affect MAKEFLAGS, so
    13811399         a reference to this hidden variable is written instead. */
    1382       (void) define_variable ("MAKEOVERRIDES", 13,
    1383                               "${-*-command-variables-*-}", o_env, 1);
     1400      define_variable_cname ("MAKEOVERRIDES", "${-*-command-variables-*-}",
     1401                            o_env, 1);
    13841402    }
    13851403
     
    13951413             But allow -C/ just in case someone wants that.  */
    13961414          {
    1397             char *p = dir + strlen (dir) - 1;
     1415            char *p = (char *)dir + strlen (dir) - 1;
    13981416            while (p > dir && (p[0] == '/' || p[0] == '\\'))
    13991417              --p;
     
    14681486    }
    14691487
    1470   (void) define_variable ("CURDIR", 6, current_directory, o_file, 0);
     1488  define_variable_cname ("CURDIR", current_directory, o_file, 0);
    14711489
    14721490  /* Read any stdin makefiles into temporary files.  */
     
    16081626  default_file = enter_file (strcache_add (".DEFAULT"));
    16091627
    1610   {
    1611     struct variable *v = define_variable (".DEFAULT_GOAL", 13, "", o_file, 0);
    1612     default_goal_name = &v->value;
    1613   }
     1628  default_goal_var = define_variable_cname (".DEFAULT_GOAL", "", o_file, 0);
     1629
     1630  /* Evaluate all strings provided with --eval.
     1631     Also set up the $(-*-eval-flags-*-) variable.  */
     1632
     1633  if (eval_strings)
     1634    {
     1635      char *p, *value;
     1636      unsigned int i;
     1637      unsigned int len = sizeof ("--eval=") * eval_strings->idx;
     1638
     1639      for (i = 0; i < eval_strings->idx; ++i)
     1640        {
     1641          p = xstrdup (eval_strings->list[i]);
     1642          len += 2 * strlen (p);
     1643          eval_buffer (p);
     1644          free (p);
     1645        }
     1646
     1647      p = value = alloca (len);
     1648      for (i = 0; i < eval_strings->idx; ++i)
     1649        {
     1650          strcpy (p, "--eval=");
     1651          p += strlen (p);
     1652          p = quote_for_env (p, eval_strings->list[i]);
     1653          *(p++) = ' ';
     1654        }
     1655      p[-1] = '\0';
     1656
     1657      define_variable_cname ("-*-eval-flags-*-", value, o_automatic, 0);
     1658    }
    16141659
    16151660  /* Read all the makefiles.  */
     
    16701715
    16711716  if (jobserver_fds)
    1672   {
    1673     const char *cp;
    1674     unsigned int ui;
    1675 
    1676     for (ui=1; ui < jobserver_fds->idx; ++ui)
    1677       if (!streq (jobserver_fds->list[0], jobserver_fds->list[ui]))
    1678         fatal (NILF, _("internal error: multiple --jobserver-fds options"));
    1679 
    1680     /* Now parse the fds string and make sure it has the proper format.  */
    1681 
    1682     cp = jobserver_fds->list[0];
    1683 
    1684     if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2)
    1685       fatal (NILF,
    1686              _("internal error: invalid --jobserver-fds string `%s'"), cp);
    1687 
    1688     DB (DB_JOBS,
    1689         (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
    1690 
    1691     /* The combination of a pipe + !job_slots means we're using the
    1692        jobserver.  If !job_slots and we don't have a pipe, we can start
    1693        infinite jobs.  If we see both a pipe and job_slots >0 that means the
    1694        user set -j explicitly.  This is broken; in this case obey the user
    1695        (ignore the jobserver pipe for this make) but print a message.  */
    1696 
    1697     if (job_slots > 0)
    1698       error (NILF,
    1699              _("warning: -jN forced in submake: disabling jobserver mode."));
    1700 
    1701     /* Create a duplicate pipe, that will be closed in the SIGCHLD
    1702        handler.  If this fails with EBADF, the parent has closed the pipe
    1703        on us because it didn't think we were a submake.  If so, print a
    1704        warning then default to -j1.  */
    1705 
    1706     else if ((job_rfd = dup (job_fds[0])) < 0)
    1707       {
    1708         if (errno != EBADF)
    1709           pfatal_with_name (_("dup jobserver"));
    1710 
     1717    {
     1718      const char *cp;
     1719      unsigned int ui;
     1720
     1721      for (ui=1; ui < jobserver_fds->idx; ++ui)
     1722        if (!streq (jobserver_fds->list[0], jobserver_fds->list[ui]))
     1723          fatal (NILF, _("internal error: multiple --jobserver-fds options"));
     1724
     1725      /* Now parse the fds string and make sure it has the proper format.  */
     1726
     1727      cp = jobserver_fds->list[0];
     1728
     1729      if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2)
     1730        fatal (NILF,
     1731               _("internal error: invalid --jobserver-fds string `%s'"), cp);
     1732
     1733      DB (DB_JOBS,
     1734          (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
     1735
     1736      /* The combination of a pipe + !job_slots means we're using the
     1737         jobserver.  If !job_slots and we don't have a pipe, we can start
     1738         infinite jobs.  If we see both a pipe and job_slots >0 that means the
     1739         user set -j explicitly.  This is broken; in this case obey the user
     1740         (ignore the jobserver pipe for this make) but print a message.  */
     1741
     1742      if (job_slots > 0)
    17111743        error (NILF,
    1712                _("warning: jobserver unavailable: using -j1.  Add `+' to parent make rule."));
    1713         job_slots = 1;
    1714       }
    1715 
    1716     if (job_slots > 0)
    1717       {
    1718         close (job_fds[0]);
    1719         close (job_fds[1]);
    1720         job_fds[0] = job_fds[1] = -1;
    1721         free (jobserver_fds->list);
    1722         free (jobserver_fds);
    1723         jobserver_fds = 0;
    1724       }
    1725   }
     1744               _("warning: -jN forced in submake: disabling jobserver mode."));
     1745
     1746      /* Create a duplicate pipe, that will be closed in the SIGCHLD
     1747         handler.  If this fails with EBADF, the parent has closed the pipe
     1748         on us because it didn't think we were a submake.  If so, print a
     1749         warning then default to -j1.  */
     1750
     1751      else if ((job_rfd = dup (job_fds[0])) < 0)
     1752        {
     1753          if (errno != EBADF)
     1754            pfatal_with_name (_("dup jobserver"));
     1755
     1756          error (NILF,
     1757                 _("warning: jobserver unavailable: using -j1.  Add `+' to parent make rule."));
     1758          job_slots = 1;
     1759        }
     1760
     1761      if (job_slots > 0)
     1762        {
     1763          close (job_fds[0]);
     1764          close (job_fds[1]);
     1765          job_fds[0] = job_fds[1] = -1;
     1766          free (jobserver_fds->list);
     1767          free (jobserver_fds);
     1768          jobserver_fds = 0;
     1769        }
     1770    }
    17261771
    17271772  /* If we have >1 slot but no jobserver-fds, then we're a top-level make.
     
    18411886      FILE_TIMESTAMP *makefile_mtimes = 0;
    18421887      unsigned int mm_idx = 0;
    1843       char **nargv = argv;
    1844       int nargc = argc;
     1888      char **nargv;
     1889      int nargc;
    18451890      int orig_db_level = db_level;
    18461891      int status;
     
    20112056                if (strneq (argv[i], "-f", 2)) /* XXX */
    20122057                  {
    2013                     char *p = &argv[i][2];
    2014                     if (*p == '\0')
     2058                    if (argv[i][2] == '\0')
    20152059                      /* This cast is OK since we never modify argv.  */
    20162060                      argv[++i] = (char *) makefiles->list[j];
    20172061                    else
    2018                       argv[i] = xstrdup (concat ("-f", makefiles->list[j], ""));
     2062                      argv[i] = xstrdup (concat (2, "-f", makefiles->list[j]));
    20192063                    ++j;
    20202064                  }
     
    20222066
    20232067          /* Add -o option for the stdin temporary file, if necessary.  */
     2068          nargc = argc;
    20242069          if (stdin_nm)
    20252070            {
    20262071              nargv = xmalloc ((nargc + 2) * sizeof (char *));
    20272072              memcpy (nargv, argv, argc * sizeof (char *));
    2028               nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, ""));
     2073              nargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm));
    20292074              nargv[nargc] = 0;
    20302075            }
     2076          else
     2077            nargv = argv;
    20312078
    20322079          if (directories != 0 && directories->idx > 0)
     
    20452092
    20462093          ++restarts;
     2094
     2095          /* Reset makeflags in case they were changed.  */
     2096          {
     2097            const char *pv = define_makeflags (1, 1);
     2098            char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1);
     2099            sprintf (p, "MAKEFLAGS=%s", pv);
     2100            putenv (p);
     2101          }
    20472102
    20482103          if (ISDB (DB_BASIC))
     
    21642219    perror_with_name (_("unlink (temporary file): "), stdin_nm);
    21652220
     2221  /* If there were no command-line goals, use the default.  */
     2222  if (goals == 0)
     2223    {
     2224      char *p;
     2225
     2226      if (default_goal_var->recursive)
     2227        p = variable_expand (default_goal_var->value);
     2228      else
     2229        {
     2230          p = variable_buffer_output (variable_buffer, default_goal_var->value,
     2231                                      strlen (default_goal_var->value));
     2232          *p = '\0';
     2233          p = variable_buffer;
     2234        }
     2235
     2236      if (*p != '\0')
     2237        {
     2238          struct file *f = lookup_file (p);
     2239
     2240          /* If .DEFAULT_GOAL is a non-existent target, enter it into the
     2241             table and let the standard logic sort it out. */
     2242          if (f == 0)
     2243            {
     2244              struct nameseq *ns;
     2245
     2246              ns = PARSE_FILE_SEQ (&p, struct nameseq, '\0', NULL, 0);
     2247              if (ns)
     2248                {
     2249                  /* .DEFAULT_GOAL should contain one target. */
     2250                  if (ns->next != 0)
     2251                    fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
     2252
     2253                  f = enter_file (strcache_add (ns->name));
     2254
     2255                  ns->name = 0; /* It was reused by enter_file(). */
     2256                  free_ns_chain (ns);
     2257                }
     2258            }
     2259
     2260          if (f)
     2261            {
     2262              goals = alloc_dep ();
     2263              goals->file = f;
     2264            }
     2265        }
     2266    }
     2267  else
     2268    lastgoal->next = 0;
     2269
     2270
     2271  if (!goals)
     2272    {
     2273      if (read_makefiles == 0)
     2274        fatal (NILF, _("No targets specified and no makefile found"));
     2275
     2276      fatal (NILF, _("No targets"));
     2277    }
     2278
     2279  /* Update the goals.  */
     2280
     2281  DB (DB_BASIC, (_("Updating goal targets....\n")));
     2282
    21662283  {
    21672284    int status;
    2168 
    2169     /* If there were no command-line goals, use the default.  */
    2170     if (goals == 0)
    2171       {
    2172         if (**default_goal_name != '\0')
    2173           {
    2174             if (default_goal_file == 0 ||
    2175                 strcmp (*default_goal_name, default_goal_file->name) != 0)
    2176               {
    2177                 default_goal_file = lookup_file (*default_goal_name);
    2178 
    2179                 /* In case user set .DEFAULT_GOAL to a non-existent target
    2180                    name let's just enter this name into the table and let
    2181                    the standard logic sort it out. */
    2182                 if (default_goal_file == 0)
    2183                   {
    2184                     struct nameseq *ns;
    2185                     char *p = *default_goal_name;
    2186 
    2187                     ns = multi_glob (
    2188                       parse_file_seq (&p, '\0', sizeof (struct nameseq), 1),
    2189                       sizeof (struct nameseq));
    2190 
    2191                     /* .DEFAULT_GOAL should contain one target. */
    2192                     if (ns->next != 0)
    2193                       fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
    2194 
    2195                     default_goal_file = enter_file (strcache_add (ns->name));
    2196 
    2197                     ns->name = 0; /* It was reused by enter_file(). */
    2198                     free_ns_chain (ns);
    2199                   }
    2200               }
    2201 
    2202             goals = alloc_dep ();
    2203             goals->file = default_goal_file;
    2204           }
    2205       }
    2206     else
    2207       lastgoal->next = 0;
    2208 
    2209 
    2210     if (!goals)
    2211       {
    2212         if (read_makefiles == 0)
    2213           fatal (NILF, _("No targets specified and no makefile found"));
    2214 
    2215         fatal (NILF, _("No targets"));
    2216       }
    2217 
    2218     /* Update the goals.  */
    2219 
    2220     DB (DB_BASIC, (_("Updating goal targets....\n")));
    22212285
    22222286    switch (update_goal_chain (goals))
     
    23912455            value = vp;
    23922456          }
    2393         define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
     2457        define_variable_cname ("MAKECMDGOALS", value, o_default, 0);
    23942458      }
    23952459    }
     
    24932557                  else if (*optarg == '\0')
    24942558                    {
    2495                       error (NILF, _("the `-%c' option requires a non-empty string argument"),
    2496                              cs->c);
     2559                      char opt[2] = "c";
     2560                      const char *op = opt;
     2561
     2562                      if (short_option (cs->c))
     2563                        opt[0] = cs->c;
     2564                      else
     2565                        op = cs->long_name;
     2566
     2567                      error (NILF, _("the `%s%s' option requires a non-empty string argument"),
     2568                             short_option (cs->c) ? "-" : "--", op);
    24972569                      bad = 1;
    24982570                    }
     
    25112583                    {
    25122584                      sl->max += 5;
    2513                       sl->list = xrealloc (sl->list,
     2585                      /* MSVC erroneously warns without a cast here.  */
     2586                      sl->list = xrealloc ((void *)sl->list,
    25142587                                           sl->max * sizeof (char *));
    25152588                    }
     
    26582731       need permanent storage for this in case decode_switches saves
    26592732       pointers into the value.  */
    2660     argv[1] = xstrdup (concat ("-", argv[1], ""));
     2733    argv[1] = xstrdup (concat (2, "-", argv[1]));
    26612734
    26622735  /* Parse those words.  */
     
    26902763   Don't include options with the `no_makefile' flag set if MAKEFILE.  */
    26912764
    2692 static void
     2765static const char *
    26932766define_makeflags (int all, int makefile)
    26942767{
    2695   static const char ref[] = "$(MAKEOVERRIDES)";
    2696   static const char posixref[] = "$(-*-command-variables-*-)";
    2697   register const struct command_switch *cs;
     2768  const char ref[] = "$(MAKEOVERRIDES)";
     2769  const char posixref[] = "$(-*-command-variables-*-)";
     2770  const char evalref[] = "$(-*-eval-flags-*-)";
     2771  const struct command_switch *cs;
    26982772  char *flagstring;
    26992773  register char *p;
     
    27162790#define ADD_FLAG(ARG, LEN) \
    27172791  do {                                                                        \
    2718     struct flag *new = alloca (sizeof (struct flag));                         \
     2792    struct flag *new = alloca (sizeof (struct flag));                         \
    27192793    new->cs = cs;                                                             \
    27202794    new->arg = (ARG);                                                         \
     
    27242798      ++flagslen;               /* Just a single flag letter.  */             \
    27252799    else                                                                      \
    2726       flagslen += 1 + 1 + 1 + 1 + 3 * (LEN); /* " -x foo" */                  \
     2800      /* " -x foo", plus space to expand "foo".  */                           \
     2801      flagslen += 1 + 1 + 1 + 1 + (3 * (LEN));                                \
    27272802    if (!short_option (cs->c))                                                \
    27282803      /* This switch has no single-letter version, so we use the long.  */    \
     
    28112886        }
    28122887
    2813   flagslen += 4 + sizeof posixref; /* Four more for the possible " -- ".  */
     2888  /* Four more for the possible " -- ".  */
     2889  flagslen += 4 + sizeof (posixref) + sizeof (evalref);
    28142890
    28152891#undef  ADD_FLAG
     
    28832959  /* Since MFLAGS is not parsed for flags, there is no reason to
    28842960     override any makefile redefinition.  */
    2885   (void) define_variable ("MFLAGS", 6, flagstring, o_env, 1);
     2961  define_variable_cname ("MFLAGS", flagstring, o_env, 1);
     2962
     2963  /* Write a reference to -*-eval-flags-*-, which contains all the --eval
     2964     flag options.  */
     2965  if (eval_strings)
     2966    {
     2967      if (p == &flagstring[1])
     2968        /* No flags written, so elide the leading dash already written.  */
     2969        p = flagstring;
     2970      else
     2971        *p++ = ' ';
     2972      memcpy (p, evalref, sizeof (evalref) - 1);
     2973      p += sizeof (evalref) - 1;
     2974    }
    28862975
    28872976  if (all && command_variables != 0)
     
    29102999      if (posix_pedantic)
    29113000        {
    2912           memcpy (p, posixref, sizeof posixref - 1);
    2913           p += sizeof posixref - 1;
     3001          memcpy (p, posixref, sizeof (posixref) - 1);
     3002          p += sizeof (posixref) - 1;
    29143003        }
    29153004      else
    29163005        {
    2917           memcpy (p, ref, sizeof ref - 1);
    2918           p += sizeof ref - 1;
     3006          memcpy (p, ref, sizeof (ref) - 1);
     3007          p += sizeof (ref) - 1;
    29193008        }
    29203009    }
     
    29303019  *p = '\0';
    29313020
    2932   v = define_variable ("MAKEFLAGS", 9,
    2933                        /* If there are switches, omit the leading dash
    2934                           unless it is a single long option with two
    2935                           leading dashes.  */
    2936                        &flagstring[(flagstring[0] == '-'
    2937                                     && flagstring[1] != '-')
    2938                                    ? 1 : 0],
    2939                        /* This used to use o_env, but that lost when a
    2940                           makefile defined MAKEFLAGS.  Makefiles set
    2941                           MAKEFLAGS to add switches, but we still want
    2942                           to redefine its value with the full set of
    2943                           switches.  Of course, an override or command
    2944                           definition will still take precedence.  */
    2945                        o_file, 1);
     3021  /* If there are switches, omit the leading dash unless it is a single long
     3022     option with two leading dashes.  */
     3023  if (flagstring[0] == '-' && flagstring[1] != '-')
     3024    ++flagstring;
     3025
     3026  v = define_variable_cname ("MAKEFLAGS", flagstring,
     3027                             /* This used to use o_env, but that lost when a
     3028                                makefile defined MAKEFLAGS.  Makefiles set
     3029                                MAKEFLAGS to add switches, but we still want
     3030                                to redefine its value with the full set of
     3031                                switches.  Of course, an override or command
     3032                                definition will still take precedence.  */
     3033                             o_file, 1);
     3034
    29463035  if (! all)
    29473036    /* The first time we are called, set MAKEFLAGS to always be exported.
     
    29493038       after reading makefiles which might have done `unexport MAKEFLAGS'. */
    29503039    v->export = v_export;
     3040
     3041  return v->value;
    29513042}
    29523043
     
    29783069     word "Copyright", so it hardly seems worth it.  */
    29793070
    2980   printf ("%sCopyright (C) 2007  Free Software Foundation, Inc.\n", precede);
     3071  printf ("%sCopyright (C) 2010  Free Software Foundation, Inc.\n", precede);
    29813072
    29823073  printf (_("%sLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
     
    30603151
    30613152      close (job_fds[0]);
     3153
     3154      /* Clean out jobserver_fds so we don't pass this information to any
     3155         sub-makes.  Also reset job_slots since it will be put on the command
     3156         line, not in MAKEFLAGS.  */
     3157      job_slots = default_job_slots;
     3158      if (jobserver_fds)
     3159        {
     3160          /* MSVC erroneously warns without a cast here.  */
     3161          free ((void *)jobserver_fds->list);
     3162          free (jobserver_fds);
     3163          jobserver_fds = 0;
     3164        }
    30623165    }
    30633166}
     
    31043207         of relative pathnames fail.  */
    31053208      if (directory_before_chdir != 0)
    3106         chdir (directory_before_chdir);
     3209        {
     3210          /* If it fails we don't care: shut up GCC.  */
     3211          int _x;
     3212          _x = chdir (directory_before_chdir);
     3213        }
    31073214
    31083215      log_working_directory (0);
Note: See TracChangeset for help on using the changeset viewer.