Changeset 2591 for trunk/src/kmk/main.c


Ignore:
Timestamp:
Jun 17, 2012, 10:45:31 PM (13 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

    • Property svn:ignore
      •  

        old new  
        1313stamp-*
        1414makebook*
         15
        1516.*gdbinit
         17.gdb_history
         18
        1619*.dep
        1720*.dvi
         
        3134*.pg
        3235*.pgs
         36
        3337README
        3438README.DOS
        3539README.W32
         40README.OS2
        3641aclocal.m4
        3742autom4te.cache
         
        5257config.h.W32
        5358config.h-vms
         59
        5460loadavg
        5561loadavg.c
        5662make
         63
        5764.deps
        5865.dep_segment
         66ID
         67TAGS
         68
        5969_*
        6070sun4
         
        7282sol2
        7383i486-linux
         84
        7485customs
         86
        7587install-sh
        7688mkinstalldirs
         89
         90.directive.asc
  • trunk/src/kmk/main.c

    r2549 r2591  
    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
     
    8181void print_dir_data_base (void);
    8282void print_rule_data_base (void);
    83 void print_file_data_base (void);
    8483void print_vpath_data_base (void);
    8584
     
    110109static void decode_switches (int argc, char **argv, int env);
    111110static void decode_env_switches (char *envar, unsigned int len);
    112 static void define_makeflags (int all, int makefile);
     111static const char *define_makeflags (int all, int makefile);
    113112static char *quote_for_env (char *out, const char *in);
    114113static void initialize_global_hash_tables (void);
     
    265264static struct stringlist *makefiles = 0;
    266265
     266/* Size of the stack when we started.  */
     267
     268#ifdef SET_STACK_SIZE
     269struct rlimit stack_limit;
     270#endif
     271
     272
    267273/* Number of job slots (commands that can be run at once).  */
    268274
     
    309315
    310316static struct stringlist *new_files = 0;
     317
     318/* List of strings to be eval'd.  */
     319static struct stringlist *eval_strings = 0;
    311320
    312321/* If nonzero, we should just print usage and exit.  */
     
    382391  -e, --environment-overrides\n\
    383392                              Environment variables override makefiles.\n"),
     393    N_("\
     394  --eval=STRING               Evaluate STRING as a makefile statement.\n"),
    384395    N_("\
    385396  -f FILE, --file=FILE, --makefile=FILE\n\
     
    544555    { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    545556      "warn-undefined-variables" },
     557    { CHAR_MAX+6, string, &eval_strings, 1, 0, 0, 0, 0, "eval" },
    546558    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    547559  };
     
    596608unsigned int makelevel;
    597609
    598 /* First file defined in the makefile whose name does not
    599    start with `.'.  This is the default to remake if the
    600    command line does not specify.  */
    601 
    602 struct file *default_goal_file;
    603 
    604 /* Pointer to the value of the .DEFAULT_GOAL special
    605    variable.  */
    606 char ** default_goal_name;
     610/* Pointer to the value of the .DEFAULT_GOAL special variable.
     611   The value will be the name of the goal to remake if the command line
     612   does not override it.  It can be set by the makefile, or else it's
     613   the first target defined in the makefile whose name does not start
     614   with '.'.  */
     615
     616struct variable * default_goal_var;
    607617
    608618/* Pointer to structure for the file .DEFAULT
     
    622632int second_expansion;
    623633
     634/* Nonzero if we have seen the '.ONESHELL' target.
     635   This causes the entire recipe to be handed to SHELL
     636   as a single string, potentially containing newlines.  */
     637
     638int one_shell;
     639
    624640#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
    625641/* Nonzero if we have seen the '.SECONDTARGETEXPANSION' target.
     
    630646
    631647#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
     648
    632649/* Nonzero if we have seen the `.NOTPARALLEL' target.
    633650   This turns off parallel builds for this invocation of make.  */
     
    667684#endif
    668685
    669 #if !defined HAVE_BSD_SIGNAL && !defined bsd_signal
     686#if !HAVE_DECL_BSD_SIGNAL && !defined bsd_signal
    670687# if !defined HAVE_SIGACTION
    671688#  define bsd_signal signal
    672689# else
    673 typedef RETSIGTYPE (*bsd_signal_ret_t) ();
     690typedef RETSIGTYPE (*bsd_signal_ret_t) (int);
    674691
    675692static bsd_signal_ret_t
     
    924941    {
    925942      sprintf(errmsg,
    926               _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%lx)\n"),
    927               prg, exrec->ExceptionCode, (DWORD)exrec->ExceptionAddress);
     943              _("%s: Interrupt/Exception caught (code = 0x%lx, addr = 0x%p)\n"),
     944              prg, exrec->ExceptionCode, exrec->ExceptionAddress);
    928945      fprintf(stderr, errmsg);
    929946      exit(255);
     
    931948
    932949  sprintf(errmsg,
    933           _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = %lx\n"),
     950          _("\nUnhandled exception filter called from program %s\nExceptionCode = %lx\nExceptionFlags = %lx\nExceptionAddress = 0x%p\n"),
    934951          prg, exrec->ExceptionCode, exrec->ExceptionFlags,
    935           (DWORD)exrec->ExceptionAddress);
     952          exrec->ExceptionAddress);
    936953
    937954  if (exrec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION
     
    939956    sprintf(&errmsg[strlen(errmsg)],
    940957            (exrec->ExceptionInformation[0]
    941              ? _("Access violation: write operation at address %lx\n")
    942              : _("Access violation: read operation at address %lx\n")),
    943             exrec->ExceptionInformation[1]);
     958             ? _("Access violation: write operation at address 0x%p\n")
     959             : _("Access violation: read operation at address 0x%p\n")),
     960            (PVOID)exrec->ExceptionInformation[1]);
    944961
    945962  /* turn this on if we want to put stuff in the event log too */
     
    10151032    sprintf (sh_path, "%s", search_token);
    10161033    default_shell = xstrdup (w32ify (sh_path, 0));
    1017     DB (DB_VERBOSE,
    1018         (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     1034    DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
     1035                    default_shell));
    10191036    sh_found = 1;
    10201037  } else if (!no_default_sh_exe &&
     
    10261043    sprintf (sh_path, "%s", search_token);
    10271044    default_shell = xstrdup (w32ify (sh_path, 0));
    1028     DB (DB_VERBOSE,
    1029         (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     1045    DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
     1046                    default_shell));
    10301047    sh_found = 1;
    10311048  } else {
     
    10681085      if (sh_found)
    10691086        DB (DB_VERBOSE,
    1070             (_("find_and_set_shell path search set default_shell = %s\n"),
     1087            (_("find_and_set_shell() path search set default_shell = %s\n"),
    10711088             default_shell));
    10721089    }
     
    13831400
    13841401    /* Set the stack limit huge so that alloca does not fail.  */
    1385     if (getrlimit (RLIMIT_STACK, &rlim) == 0)
     1402    if (getrlimit (RLIMIT_STACK, &rlim) == 0
     1403        && rlim.rlim_cur > 0 && rlim.rlim_cur < rlim.rlim_max)
    13861404      {
     1405        stack_limit = rlim;
    13871406        rlim.rlim_cur = rlim.rlim_max;
    13881407        setrlimit (RLIMIT_STACK, &rlim);
    13891408      }
     1409    else
     1410      stack_limit.rlim_cur = 0;
    13901411  }
    13911412#endif
     
    14021423#endif
    14031424
    1404   default_goal_file = 0;
    14051425  reading_file = 0;
    14061426
     
    14191439  /* Set up gettext/internationalization support.  */
    14201440  setlocale (LC_ALL, "");
     1441  /* The cast to void shuts up compiler warnings on systems that
     1442     disable NLS.  */
    14211443#ifdef LOCALEDIR /* bird */
    1422   bindtextdomain (PACKAGE, LOCALEDIR);
    1423   textdomain (PACKAGE);
     1444  (void)bindtextdomain (PACKAGE, LOCALEDIR);
     1445  (void)textdomain (PACKAGE);
    14241446#endif
    14251447
     
    14321454#define ADD_SIG(sig)    fatal_signal_mask |= sigmask (sig)
    14331455#else
    1434 #define ADD_SIG(sig)
     1456#define ADD_SIG(sig)    (void)sig      /* Needed to avoid warnings in MSVC.  */
    14351457#endif
    14361458#endif
     
    15871609
    15881610  /* Initialize the special variables.  */
    1589   define_variable (".VARIABLES", 10, "", o_default, 0)->special = 1;
    1590   /* define_variable (".TARGETS", 8, "", o_default, 0)->special = 1; */
    1591   define_variable (".RECIPEPREFIX", 13, "", o_default, 0)->special = 1;
    1592 
    1593   /* Set up .FEATURES */
    1594   define_variable (".FEATURES", 9,
    1595                    "target-specific order-only second-expansion else-if",
    1596                    o_default, 0);
     1611  define_variable_cname (".VARIABLES", "", o_default, 0)->special = 1;
     1612  /* define_variable_cname (".TARGETS", "", o_default, 0)->special = 1; */
     1613  define_variable_cname (".RECIPEPREFIX", "", o_default, 0)->special = 1;
     1614  define_variable_cname (".SHELLFLAGS", "-c", o_default, 0);
     1615
     1616  /* Set up .FEATURES
     1617     We must do this in multiple calls because define_variable_cname() is
     1618     a macro and some compilers (MSVC) don't like conditionals in macros.  */
     1619  {
     1620    const char *features = "target-specific order-only second-expansion"
     1621                           " else-if shortest-stem undefine"
    15971622#ifndef NO_ARCHIVES
    1598   do_variable_definition (NILF, ".FEATURES", "archives",
    1599                           o_default, f_append, 0);
     1623                           " archives"
    16001624#endif
    16011625#ifdef MAKE_JOBSERVER
    1602   do_variable_definition (NILF, ".FEATURES", "jobserver",
    1603                           o_default, f_append, 0);
     1626                           " jobserver"
    16041627#endif
    16051628#ifdef MAKE_SYMLINKS
    1606   do_variable_definition (NILF, ".FEATURES", "check-symlink",
    1607                           o_default, f_append, 0);
     1629                           " check-symlink"
    16081630#endif
    16091631#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    1610   do_variable_definition (NILF, ".FEATURES", "explicit-multitarget",
    1611                           o_default, f_append, 0);
     1632                           " explicit-multitarget"
    16121633#endif
    16131634#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    1614   do_variable_definition (NILF, ".FEATURES", "prepend-assignment",
    1615                           o_default, f_append, 0);
    1616 #endif
     1635                           " prepend-assignment"
     1636#endif
     1637                           ;
     1638
     1639    define_variable_cname (".FEATURES", features, o_default, 0);
     1640  }
    16171641
    16181642#ifdef KMK
     
    16751699                shell_var.name = v->name;
    16761700#endif
    1677                 shell_var.length = 5; /* bird - gotta set the length too! */
     1701                shell_var.length = 5;
    16781702#ifndef CONFIG_WITH_VALUE_LENGTH
    16791703                shell_var.value = xstrdup (ep + 1);
    16801704#else
    1681                 shell_var.value = savestring (v->value, v->value_length);
     1705                shell_var.value = xstrndup (v->value, v->value_length);
    16821706                shell_var.value_length = v->value_length;
    16831707#endif
    1684 
    16851708              }
    16861709
     
    16991722     */
    17001723    if (!unix_path)
    1701       define_variable("PATH", 4,
    1702                       windows32_path ? windows32_path : "",
    1703                       o_env, 1)->export = v_export;
     1724      define_variable_cname ("PATH", windows32_path ? windows32_path : "",
     1725                             o_env, 1)->export = v_export;
    17041726#endif
    17051727#else /* For Amiga, read the ENV: device, ignoring all dirs */
     
    17471769#endif
    17481770#endif /* !KMK */
     1771
    17491772  decode_switches (argc, argv, 0);
     1773
    17501774#ifdef WINDOWS32
    17511775  if (suspend_flag) {
     
    18151839# endif
    18161840      )
    1817     argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
     1841    argv[0] = xstrdup (concat (3, current_directory, "/", argv[0]));
    18181842#else  /* !__MSDOS__ */
    18191843  if (current_directory[0] != '\0'
     
    18241848#endif
    18251849      )
    1826     argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
     1850    argv[0] = xstrdup (concat (3, current_directory, "/", argv[0]));
    18271851#endif /* !__MSDOS__ */
    18281852#endif /* WINDOWS32 */
     
    18311855  /* The extra indirection through $(MAKE_COMMAND) is done
    18321856     for hysterical raisins.  */
    1833   (void) define_variable ("MAKE_COMMAND", 12, argv[0], o_default, 0);
    1834   (void) define_variable ("MAKE", 4, "$(MAKE_COMMAND)", o_default, 1);
     1857  define_variable_cname ("MAKE_COMMAND", argv[0], o_default, 0);
     1858  define_variable_cname ("MAKE", "$(MAKE_COMMAND)", o_default, 1);
    18351859#ifdef KMK
    18361860  (void) define_variable ("KMK", 3, argv[0], o_default, 1);
     
    18731897      /* Define an unchangeable variable with a name that no POSIX.2
    18741898         makefile could validly use for its own variable.  */
    1875       (void) define_variable ("-*-command-variables-*-", 23,
    1876                               value, o_automatic, 0);
     1899      define_variable_cname ("-*-command-variables-*-", value, o_automatic, 0);
    18771900
    18781901      /* Define the variable; this will not override any user definition.
     
    18831906         a reference to this hidden variable is written instead. */
    18841907#ifdef KMK
    1885       (void) define_variable ("KMK_OVERRIDES", 13,
    1886                               "${-*-command-variables-*-}", o_env, 1);
     1908      define_variable_cname ("KMK_OVERRIDES", "${-*-command-variables-*-}",
     1909                            o_env, 1);
    18871910#else
    1888       (void) define_variable ("MAKEOVERRIDES", 13,
    1889                               "${-*-command-variables-*-}", o_env, 1);
     1911      define_variable_cname ("MAKEOVERRIDES", "${-*-command-variables-*-}",
     1912                            o_env, 1);
    18901913#endif
    18911914    }
     
    20582081    }
    20592082
    2060   (void) define_variable ("CURDIR", 6, current_directory, o_file, 0);
     2083  define_variable_cname ("CURDIR", current_directory, o_file, 0);
    20612084
    20622085  /* Read any stdin makefiles into temporary files.  */
     
    21982221  default_file = enter_file (strcache_add (".DEFAULT"));
    21992222
    2200   {
    2201     struct variable *v = define_variable (".DEFAULT_GOAL", 13, "", o_file, 0);
    2202     default_goal_name = &v->value;
    2203   }
     2223  default_goal_var = define_variable_cname (".DEFAULT_GOAL", "", o_file, 0);
     2224
     2225  /* Evaluate all strings provided with --eval.
     2226     Also set up the $(-*-eval-flags-*-) variable.  */
     2227
     2228  if (eval_strings)
     2229    {
     2230      char *p, *value;
     2231      unsigned int i;
     2232      unsigned int len = sizeof ("--eval=") * eval_strings->idx;
     2233
     2234      for (i = 0; i < eval_strings->idx; ++i)
     2235        {
     2236#ifndef CONFIG_WITH_VALUE_LENGTH
     2237          p = xstrdup (eval_strings->list[i]);
     2238          len += 2 * strlen (p);
     2239          eval_buffer (p);
     2240#else
     2241          unsigned int sub_len = strlen(eval_strings->list[i]);
     2242          p = xstrndup (eval_strings->list[i], sub_len);
     2243          len += 2 * sub_len;
     2244          eval_buffer (p, p + sub_len);
     2245#endif
     2246          free (p);
     2247        }
     2248
     2249      p = value = alloca (len);
     2250      for (i = 0; i < eval_strings->idx; ++i)
     2251        {
     2252          strcpy (p, "--eval=");
     2253          p += strlen (p);
     2254          p = quote_for_env (p, eval_strings->list[i]);
     2255          *(p++) = ' ';
     2256        }
     2257      p[-1] = '\0';
     2258
     2259      define_variable_cname ("-*-eval-flags-*-", value, o_automatic, 0);
     2260    }
    22042261
    22052262  /* Read all the makefiles.  */
     
    22642321
    22652322  if (jobserver_fds)
    2266   {
    2267     const char *cp;
    2268     unsigned int ui;
    2269 
    2270     for (ui=1; ui < jobserver_fds->idx; ++ui)
    2271       if (!streq (jobserver_fds->list[0], jobserver_fds->list[ui]))
    2272         fatal (NILF, _("internal error: multiple --jobserver-fds options"));
    2273 
    2274     /* Now parse the fds string and make sure it has the proper format.  */
    2275 
    2276     cp = jobserver_fds->list[0];
    2277 
    2278     if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2)
    2279       fatal (NILF,
    2280              _("internal error: invalid --jobserver-fds string `%s'"), cp);
    2281 
    2282     DB (DB_JOBS,
    2283         (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
    2284 
    2285     /* The combination of a pipe + !job_slots means we're using the
    2286        jobserver.  If !job_slots and we don't have a pipe, we can start
    2287        infinite jobs.  If we see both a pipe and job_slots >0 that means the
    2288        user set -j explicitly.  This is broken; in this case obey the user
    2289        (ignore the jobserver pipe for this make) but print a message.  */
    2290 
    2291     if (job_slots > 0)
    2292       error (NILF,
    2293              _("warning: -jN forced in submake: disabling jobserver mode."));
    2294 
    2295     /* Create a duplicate pipe, that will be closed in the SIGCHLD
    2296        handler.  If this fails with EBADF, the parent has closed the pipe
    2297        on us because it didn't think we were a submake.  If so, print a
    2298        warning then default to -j1.  */
    2299 
    2300     else if ((job_rfd = dup (job_fds[0])) < 0)
    2301       {
    2302         if (errno != EBADF)
    2303           pfatal_with_name (_("dup jobserver"));
    2304 
     2323    {
     2324      const char *cp;
     2325      unsigned int ui;
     2326
     2327      for (ui=1; ui < jobserver_fds->idx; ++ui)
     2328        if (!streq (jobserver_fds->list[0], jobserver_fds->list[ui]))
     2329          fatal (NILF, _("internal error: multiple --jobserver-fds options"));
     2330
     2331      /* Now parse the fds string and make sure it has the proper format.  */
     2332
     2333      cp = jobserver_fds->list[0];
     2334
     2335      if (sscanf (cp, "%d,%d", &job_fds[0], &job_fds[1]) != 2)
     2336        fatal (NILF,
     2337               _("internal error: invalid --jobserver-fds string `%s'"), cp);
     2338
     2339      DB (DB_JOBS,
     2340          (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
     2341
     2342      /* The combination of a pipe + !job_slots means we're using the
     2343         jobserver.  If !job_slots and we don't have a pipe, we can start
     2344         infinite jobs.  If we see both a pipe and job_slots >0 that means the
     2345         user set -j explicitly.  This is broken; in this case obey the user
     2346         (ignore the jobserver pipe for this make) but print a message.  */
     2347
     2348      if (job_slots > 0)
    23052349        error (NILF,
    2306                _("warning: jobserver unavailable: using -j1.  Add `+' to parent make rule."));
    2307         job_slots = 1;
    2308       }
    2309 
    2310     if (job_slots > 0)
    2311       {
    2312         close (job_fds[0]);
    2313         close (job_fds[1]);
    2314         job_fds[0] = job_fds[1] = -1;
    2315         free (jobserver_fds->list);
    2316         free (jobserver_fds);
    2317         jobserver_fds = 0;
    2318       }
    2319   }
     2350               _("warning: -jN forced in submake: disabling jobserver mode."));
     2351
     2352      /* Create a duplicate pipe, that will be closed in the SIGCHLD
     2353         handler.  If this fails with EBADF, the parent has closed the pipe
     2354         on us because it didn't think we were a submake.  If so, print a
     2355         warning then default to -j1.  */
     2356
     2357      else if ((job_rfd = dup (job_fds[0])) < 0)
     2358        {
     2359          if (errno != EBADF)
     2360            pfatal_with_name (_("dup jobserver"));
     2361
     2362          error (NILF,
     2363                 _("warning: jobserver unavailable: using -j1.  Add `+' to parent make rule."));
     2364          job_slots = 1;
     2365        }
     2366
     2367      if (job_slots > 0)
     2368        {
     2369          close (job_fds[0]);
     2370          close (job_fds[1]);
     2371          job_fds[0] = job_fds[1] = -1;
     2372          free (jobserver_fds->list);
     2373          free (jobserver_fds);
     2374          jobserver_fds = 0;
     2375        }
     2376    }
    23202377
    23212378  /* If we have >1 slot but no jobserver-fds, then we're a top-level make.
     
    24352492      FILE_TIMESTAMP *makefile_mtimes = 0;
    24362493      unsigned int mm_idx = 0;
    2437       char **nargv = argv;
    2438       int nargc = argc;
     2494      char **nargv;
     2495      int nargc;
    24392496      int orig_db_level = db_level;
    24402497      int status;
     
    26052662                if (strneq (argv[i], "-f", 2)) /* XXX */
    26062663                  {
    2607                     char *p = &argv[i][2];
    2608                     if (*p == '\0')
     2664                    if (argv[i][2] == '\0')
    26092665                      /* This cast is OK since we never modify argv.  */
    26102666                      argv[++i] = (char *) makefiles->list[j];
    26112667                    else
    2612                       argv[i] = xstrdup (concat ("-f", makefiles->list[j], ""));
     2668                      argv[i] = xstrdup (concat (2, "-f", makefiles->list[j]));
    26132669                    ++j;
    26142670                  }
     
    26162672
    26172673          /* Add -o option for the stdin temporary file, if necessary.  */
     2674          nargc = argc;
    26182675          if (stdin_nm)
    26192676            {
    26202677              nargv = xmalloc ((nargc + 2) * sizeof (char *));
    26212678              memcpy (nargv, argv, argc * sizeof (char *));
    2622               nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, ""));
     2679              nargv[nargc++] = xstrdup (concat (2, "-o", stdin_nm));
    26232680              nargv[nargc] = 0;
    26242681            }
     2682          else
     2683            nargv = argv;
    26252684
    26262685          if (directories != 0 && directories->idx > 0)
     
    26392698
    26402699          ++restarts;
     2700
     2701          /* Reset makeflags in case they were changed.  */
     2702          {
     2703            const char *pv = define_makeflags (1, 1);
     2704            char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1);
     2705            sprintf (p, "MAKEFLAGS=%s", pv);
     2706            putenv (p);
     2707          }
    26412708
    26422709          if (ISDB (DB_BASIC))
     
    27582825    perror_with_name (_("unlink (temporary file): "), stdin_nm);
    27592826
     2827  /* If there were no command-line goals, use the default.  */
     2828  if (goals == 0)
     2829    {
     2830      char *p;
     2831
     2832      if (default_goal_var->recursive)
     2833        p = variable_expand (default_goal_var->value);
     2834      else
     2835        {
     2836          p = variable_buffer_output (variable_buffer, default_goal_var->value,
     2837                                      strlen (default_goal_var->value));
     2838          *p = '\0';
     2839          p = variable_buffer;
     2840        }
     2841
     2842      if (*p != '\0')
     2843        {
     2844          struct file *f = lookup_file (p);
     2845
     2846          /* If .DEFAULT_GOAL is a non-existent target, enter it into the
     2847             table and let the standard logic sort it out. */
     2848          if (f == 0)
     2849            {
     2850              struct nameseq *ns;
     2851              ns = PARSE_FILE_SEQ (&p, struct nameseq, '\0', NULL, 0);
     2852              if (ns)
     2853                {
     2854                  /* .DEFAULT_GOAL should contain one target. */
     2855                  if (ns->next != 0)
     2856                    fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
     2857
     2858#ifndef CONFIG_WITH_VALUE_LENGTH
     2859                  f = enter_file (strcache_add (ns->name));
     2860#else
     2861                  f = enter_file (ns->name);
     2862#endif
     2863
     2864                  ns->name = 0; /* It was reused by enter_file(). */
     2865                  free_ns_chain (ns);
     2866                }
     2867            }
     2868
     2869          if (f)
     2870            {
     2871              goals = alloc_dep ();
     2872              goals->file = f;
     2873            }
     2874        }
     2875    }
     2876  else
     2877    lastgoal->next = 0;
     2878
     2879
     2880  if (!goals)
     2881    {
     2882      if (read_makefiles == 0)
     2883        fatal (NILF, _("No targets specified and no makefile found"));
     2884
     2885      fatal (NILF, _("No targets"));
     2886    }
     2887
     2888  /* Update the goals.  */
     2889
     2890  DB (DB_BASIC, (_("Updating goal targets....\n")));
     2891
    27602892  {
    27612893    int status;
    2762 
    2763     /* If there were no command-line goals, use the default.  */
    2764     if (goals == 0)
    2765       {
    2766         if (**default_goal_name != '\0')
    2767           {
    2768             if (default_goal_file == 0 ||
    2769                 strcmp (*default_goal_name, default_goal_file->name) != 0)
    2770               {
    2771                 default_goal_file = lookup_file (*default_goal_name);
    2772 
    2773                 /* In case user set .DEFAULT_GOAL to a non-existent target
    2774                    name let's just enter this name into the table and let
    2775                    the standard logic sort it out. */
    2776                 if (default_goal_file == 0)
    2777                   {
    2778                     struct nameseq *ns;
    2779                     char *p = *default_goal_name;
    2780 
    2781 #ifndef CONFIG_WITH_ALLOC_CACHES
    2782                     ns = multi_glob (
    2783                       parse_file_seq (&p, '\0', sizeof (struct nameseq), 1),
    2784                       sizeof (struct nameseq));
    2785 #else
    2786                     ns = multi_glob (
    2787                       parse_file_seq (&p, '\0', &nameseq_cache, 1),
    2788                       &nameseq_cache);
    2789 #endif
    2790 
    2791                     /* .DEFAULT_GOAL should contain one target. */
    2792                     if (ns->next != 0)
    2793                       fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
    2794 
    2795 #ifndef CONFIG_WITH_VALUE_LENGTH
    2796                     default_goal_file = enter_file (strcache_add (ns->name));
    2797 #else
    2798                     default_goal_file = enter_file (ns->name);
    2799 #endif
    2800 
    2801                     ns->name = 0; /* It was reused by enter_file(). */
    2802                     free_ns_chain (ns);
    2803                   }
    2804               }
    2805 
    2806             goals = alloc_dep ();
    2807             goals->file = default_goal_file;
    2808           }
    2809       }
    2810     else
    2811       lastgoal->next = 0;
    2812 
    2813 
    2814     if (!goals)
    2815       {
    2816         if (read_makefiles == 0)
    2817           fatal (NILF, _("No targets specified and no makefile found"));
    2818 
    2819         fatal (NILF, _("No targets"));
    2820       }
    2821 
    2822     /* Update the goals.  */
    2823 
    2824     DB (DB_BASIC, (_("Updating goal targets....\n")));
    28252894
    28262895    switch (update_goal_chain (goals))
     
    29333002    /* Ignore plain `-' for compatibility.  */
    29343003    return;
    2935 #ifndef CONFIG_WITH_VALUE_LENGTH
    2936   v = try_variable_definition (0, arg, o_command, 0);
    2937 #else
    2938   v = try_variable_definition (0, arg, NULL, o_command, 0);
    2939 #endif
     3004  v = try_variable_definition (0, arg IF_WITH_VALUE_LENGTH_PARAM(NULL), o_command, 0);
    29403005  if (v != 0)
    29413006    {
     
    29993064            value = vp;
    30003065          }
    3001         define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
     3066        define_variable_cname ("MAKECMDGOALS", value, o_default, 0);
    30023067      }
    30033068    }
     
    31103175                  else if (*optarg == '\0')
    31113176                    {
    3112                       error (NILF, _("the `-%c' option requires a non-empty string argument"),
    3113                              cs->c);
     3177                      char opt[2] = "c";
     3178                      const char *op = opt;
     3179
     3180                      if (short_option (cs->c))
     3181                        opt[0] = cs->c;
     3182                      else
     3183                        op = cs->long_name;
     3184
     3185                      error (NILF, _("the `%s%s' option requires a non-empty string argument"),
     3186                             short_option (cs->c) ? "-" : "--", op);
    31143187                      bad = 1;
    31153188                    }
     
    31283201                    {
    31293202                      sl->max += 5;
    3130                       sl->list = xrealloc ((void *)sl->list, /* bird */
     3203                      /* MSVC erroneously warns without a cast here.  */
     3204                      sl->list = xrealloc ((void *)sl->list,
    31313205                                           sl->max * sizeof (char *));
    31323206                    }
     
    32753349       need permanent storage for this in case decode_switches saves
    32763350       pointers into the value.  */
    3277     argv[1] = xstrdup (concat ("-", argv[1], ""));
     3351    argv[1] = xstrdup (concat (2, "-", argv[1]));
    32783352
    32793353  /* Parse those words.  */
     
    33073381   Don't include options with the `no_makefile' flag set if MAKEFILE.  */
    33083382
    3309 static void
     3383static const char *
    33103384define_makeflags (int all, int makefile)
    33113385{
     
    33133387  static const char ref[] = "$(KMK_OVERRIDES)";
    33143388#else
    3315   static const char ref[] = "$(MAKEOVERRIDES)";
    3316 #endif
    3317   static const char posixref[] = "$(-*-command-variables-*-)";
    3318   register const struct command_switch *cs;
     3389  static /*<- bird*/ const char ref[] = "$(MAKEOVERRIDES)";
     3390#endif
     3391  static /*<- bird*/ const char posixref[] = "$(-*-command-variables-*-)";
     3392  static /*<- bird*/ const char evalref[] = "$(-*-eval-flags-*-)";
     3393  const struct command_switch *cs;
    33193394  char *flagstring;
    33203395  register char *p;
     
    33373412#define ADD_FLAG(ARG, LEN) \
    33383413  do {                                                                        \
    3339     struct flag *new = alloca (sizeof (struct flag));                         \
     3414    struct flag *new = alloca (sizeof (struct flag));                         \
    33403415    new->cs = cs;                                                             \
    33413416    new->arg = (ARG);                                                         \
     
    33453420      ++flagslen;               /* Just a single flag letter.  */             \
    33463421    else                                                                      \
    3347       flagslen += 1 + 1 + 1 + 1 + 3 * (LEN); /* " -x foo" */                  \
     3422      /* " -x foo", plus space to expand "foo".  */                           \
     3423      flagslen += 1 + 1 + 1 + 1 + (3 * (LEN));                                \
    33483424    if (!short_option (cs->c))                                                \
    33493425      /* This switch has no single-letter version, so we use the long.  */    \
     
    34343510        }
    34353511
    3436   flagslen += 4 + sizeof posixref; /* Four more for the possible " -- ".  */
     3512  /* Four more for the possible " -- ".  */
     3513  flagslen += 4 + sizeof (posixref) + sizeof (evalref);
    34373514
    34383515#undef  ADD_FLAG
     
    35073584  /* Since MFLAGS is not parsed for flags, there is no reason to
    35083585     override any makefile redefinition.  */
    3509   (void) define_variable ("MFLAGS", 6, flagstring, o_env, 1);
     3586  define_variable_cname ("MFLAGS", flagstring, o_env, 1);
    35103587#endif /* !KMK */
     3588
     3589  /* Write a reference to -*-eval-flags-*-, which contains all the --eval
     3590     flag options.  */
     3591  if (eval_strings)
     3592    {
     3593      if (p == &flagstring[1])
     3594        /* No flags written, so elide the leading dash already written.  */
     3595        p = flagstring;
     3596      else
     3597        *p++ = ' ';
     3598      memcpy (p, evalref, sizeof (evalref) - 1);
     3599      p += sizeof (evalref) - 1;
     3600    }
    35113601
    35123602  if (all && command_variables != 0)
     
    35353625      if (posix_pedantic)
    35363626        {
    3537           memcpy (p, posixref, sizeof posixref - 1);
    3538           p += sizeof posixref - 1;
     3627          memcpy (p, posixref, sizeof (posixref) - 1);
     3628          p += sizeof (posixref) - 1;
    35393629        }
    35403630      else
    35413631        {
    3542           memcpy (p, ref, sizeof ref - 1);
    3543           p += sizeof ref - 1;
     3632          memcpy (p, ref, sizeof (ref) - 1);
     3633          p += sizeof (ref) - 1;
    35443634        }
    35453635    }
     
    35553645  *p = '\0';
    35563646
     3647  /* If there are switches, omit the leading dash unless it is a single long
     3648     option with two leading dashes.  */
     3649  if (flagstring[0] == '-' && flagstring[1] != '-')
     3650    ++flagstring;
     3651
    35573652#ifdef KMK
    3558   v = define_variable ("KMK_FLAGS", 9,
    3559                        /* If there are switches, omit the leading dash
    3560                           unless it is a single long option with two
    3561                           leading dashes.  */
    3562                        &flagstring[(flagstring[0] == '-'
    3563                                     && flagstring[1] != '-')
    3564                                    ? 1 : 0],
    3565                        /* This used to use o_env, but that lost when a
    3566                           makefile defined MAKEFLAGS.  Makefiles set
    3567                           MAKEFLAGS to add switches, but we still want
    3568                           to redefine its value with the full set of
    3569                           switches.  Of course, an override or command
    3570                           definition will still take precedence.  */
    3571                        o_file, 1);
     3653  v = define_variable_cname ("KMK_FLAGS", flagstring,
     3654                             /* This used to use o_env, but that lost when a
     3655                                makefile defined MAKEFLAGS.  Makefiles set
     3656                                MAKEFLAGS to add switches, but we still want
     3657                                to redefine its value with the full set of
     3658                                switches.  Of course, an override or command
     3659                                definition will still take precedence.  */
     3660                             o_file, 1);
    35723661#else
    3573   v = define_variable ("MAKEFLAGS", 9,
    3574                        /* If there are switches, omit the leading dash
    3575                           unless it is a single long option with two
    3576                           leading dashes.  */
    3577                        &flagstring[(flagstring[0] == '-'
    3578                                     && flagstring[1] != '-')
    3579                                    ? 1 : 0],
    3580                        /* This used to use o_env, but that lost when a
    3581                           makefile defined MAKEFLAGS.  Makefiles set
    3582                           MAKEFLAGS to add switches, but we still want
    3583                           to redefine its value with the full set of
    3584                           switches.  Of course, an override or command
    3585                           definition will still take precedence.  */
    3586                        o_file, 1);
    3587 #endif
     3662  v = define_variable_cname ("MAKEFLAGS", flagstring,
     3663                             /* This used to use o_env, but that lost when a
     3664                                makefile defined MAKEFLAGS.  Makefiles set
     3665                                MAKEFLAGS to add switches, but we still want
     3666                                to redefine its value with the full set of
     3667                                switches.  Of course, an override or command
     3668                                definition will still take precedence.  */
     3669                             o_file, 1);
     3670#endif
     3671
    35883672  if (! all)
    35893673    /* The first time we are called, set MAKEFLAGS to always be exported.
     
    35973681    char val[32];
    35983682    sprintf (val, "%u", job_slots);
    3599     define_variable ("KMK_OPTS_JOBS", sizeof("KMK_OPTS_JOBS") - 1,
    3600                      val, o_default, 1);
    3601     define_variable ("KMK_OPTS_KEEP_GOING", sizeof("KMK_OPTS_KEEP_GOING") - 1,
    3602                      keep_going_flag ? "1" : "0", o_default, 1);
    3603     define_variable ("KMK_OPTS_JUST_PRINT", sizeof("KMK_OPTS_JUST_PRINT") - 1,
    3604                      just_print_flag ? "1" : "0", o_default, 1);
    3605     define_variable ("KMK_OPTS_PRETTY_COMMAND_PRINTING", sizeof("KMK_OPTS_PRETTY_COMMAND_PRINTING") - 1,
    3606                      pretty_command_printing ? "1" : "0", o_default, 1);
     3683    define_variable_cname ("KMK_OPTS_JOBS", val, o_default, 1);
     3684    define_variable_cname ("KMK_OPTS_KEEP_GOING", keep_going_flag ? "1" : "0", o_default, 1);
     3685    define_variable_cname ("KMK_OPTS_JUST_PRINT", just_print_flag ? "1" : "0", o_default, 1);
     3686    define_variable_cname ("KMK_OPTS_PRETTY_COMMAND_PRINTING",
     3687                           pretty_command_printing ? "1" : "0", o_default, 1);
    36073688    sprintf (val, "%u", process_priority);
    3608     define_variable ("KMK_OPTS_PRORITY", sizeof("KMK_OPTS_PRORITY") - 1,
    3609                      val, o_default, 1);
     3689    define_variable_cname ("KMK_OPTS_PRORITY", val, o_default, 1);
    36103690    sprintf (val, "%u", process_affinity);
    3611     define_variable ("KMK_OPTS_AFFINITY", sizeof("KMK_OPTS_AFFINITY") - 1,
    3612                      val, o_default, 1);
    3613 #if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
    3614     define_variable ("KMK_OPTS_STATISTICS", sizeof("KMK_OPTS_STATISTICS") - 1,
    3615                      make_expensive_statistics ? "1" : "0", o_default, 1);
     3691    define_variable_cname ("KMK_OPTS_AFFINITY", val, o_default, 1);
     3692# if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
     3693    define_variable_cname ("KMK_OPTS_STATISTICS", make_expensive_statistics ? "1" : "0",
     3694                           o_default, 1);
    36163695# endif
    3617 #ifdef CONFIG_WITH_PRINT_TIME_SWITCH
     3696# ifdef CONFIG_WITH_PRINT_TIME_SWITCH
    36183697    sprintf (val, "%u", print_time_min);
    3619     define_variable ("KMK_OPTS_PRINT_TIME", sizeof("KMK_OPTS_PRINT_TIME") - 1,
    3620                      val, o_default, 1);
    3621 #endif
     3698    define_variable_cname ("KMK_OPTS_PRINT_TIME", val, o_default, 1);
     3699# endif
    36223700  }
    36233701#endif
     3702
     3703  return v->value;
    36243704}
    36253705
     
    36613741     word "Copyright", so it hardly seems worth it.  */
    36623742
    3663   printf ("%sCopyright (C) 2007  Free Software Foundation, Inc.\n", precede);
     3743  printf ("%sCopyright (C) 2010  Free Software Foundation, Inc.\n", precede);
    36643744
    36653745  printf (_("%sLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
     
    38183898
    38193899      close (job_fds[0]);
     3900
     3901      /* Clean out jobserver_fds so we don't pass this information to any
     3902         sub-makes.  Also reset job_slots since it will be put on the command
     3903         line, not in MAKEFLAGS.  */
     3904      job_slots = default_job_slots;
     3905      if (jobserver_fds)
     3906        {
     3907          /* MSVC erroneously warns without a cast here.  */
     3908          free ((void *)jobserver_fds->list);
     3909          free (jobserver_fds);
     3910          jobserver_fds = 0;
     3911        }
    38203912    }
    38213913}
     
    38823974         of relative pathnames fail.  */
    38833975      if (directory_before_chdir != 0)
    3884         chdir (directory_before_chdir);
     3976        {
     3977          /* If it fails we don't care: shut up GCC.  */
     3978          int _x;
     3979          _x = chdir (directory_before_chdir);
     3980        }
    38853981
    38863982#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
Note: See TracChangeset for help on using the changeset viewer.