VirtualBox

Changeset 287 in kBuild for trunk


Ignore:
Timestamp:
May 16, 2005 11:34:55 PM (20 years ago)
Author:
bird
Message:

join + optimizations.

Location:
trunk/src/gmake
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/Makefile.kmk

    r278 r287  
    1313kmk_DEFS            = \
    1414        HAVE_CONFIG_H \
     15    NO_ARCHIVES \
    1516        CONFIG_NO_DEFAULT_SUFFIXES \
    1617        CONFIG_NO_DEFAULT_PATTERN_RULES \
     
    111112#                       
    112113$(PATH_TARGET)/config.h: config.h.$(BUILD_TARGET)
     114        $(MKDIR) -p $(dir $@)
    113115        $(CP) $^ $@
    114116
  • trunk/src/gmake/commands.c

    r225 r287  
    4040/* Set FILE's automatic variables up.  */
    4141
    42 static void
     42void
    4343set_file_variables (struct file *file)
    4444{
     45  struct dep *d;
    4546  char *at, *percent, *star, *less;
    4647
     
    107108  star = file->stem;
    108109
    109   /* $< is the first dependency.  */
    110   less = file->deps != 0 ? dep_name (file->deps) : "";
     110  /* $< is the first not order-only dependency.  */
     111  less = "";
     112  for (d = file->deps; d != 0; d = d->next)
     113    if (!d->ignore_mtime)
     114      {
     115        less = dep_name (d);
     116        break;
     117      }
    111118
    112119  if (file->cmds == default_file->cmds)
     
    136143    char *qp;
    137144    char *bp;
    138     struct dep *d;
    139145    unsigned int len;
    140146
     
    343349            break;
    344350          }
    345       if (!(flags & COMMANDS_RECURSE))
    346         {
    347           unsigned int len = strlen (p);
    348           if (sindex (p, len, "$(MAKE)", 7) != 0
    349               || sindex (p, len, "${MAKE}", 7) != 0)
    350             flags |= COMMANDS_RECURSE;
    351         }
     351
     352      /* If no explicit '+' was given, look for MAKE variable references.  */
     353      if (!(flags & COMMANDS_RECURSE)
     354          && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
     355        flags |= COMMANDS_RECURSE;
     356
    352357#ifdef CONFIG_WITH_KMK_BUILTIN
     358      /* check if kmk builtin command */
    353359      if (!strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
    354           flags |= COMMANDS_BUILTIN;
     360        flags |= COMMANDS_BUILTIN;
    355361#endif
    356362
     
    486492#endif
    487493
     494#ifdef WINDOWS32
     495  /* Cannot call W32_kill with a pid (it needs a handle) */
     496  exit (EXIT_FAILURE);
     497#else
    488498  /* Signal the same code; this time it will really be fatal.  The signal
    489499     will be unblocked when we return and arrive then to kill us.  */
    490500  if (kill (getpid (), sig) < 0)
    491501    pfatal_with_name ("kill");
     502#endif /* not WINDOWS32 */
    492503#endif /* not Amiga */
    493504#endif /* not __MSDOS__  */
  • trunk/src/gmake/commands.h

    r225 r287  
    4343extern void delete_child_targets PARAMS ((struct child *child));
    4444extern void chop_commands PARAMS ((struct commands *cmds));
     45extern void set_file_variables PARAMS ((struct file *file));
  • trunk/src/gmake/default.c

    r192 r287  
    318318#ifdef __ALPHA
    319319    "ARCH", "ALPHA",
    320 #else
     320#endif
     321#ifdef __ia64
     322    "ARCH", "IA64",
     323#endif
     324#ifdef __VAX
    321325    "ARCH", "VAX",
    322326#endif
  • trunk/src/gmake/dir.c

    r57 r287  
    124124downcase (char *filename)
    125125{
    126 #ifdef _AMIGA
    127   static char new_filename[136];
    128 #else
    129   static char new_filename[PATH_MAX];
    130 #endif
     126  static PATH_VAR (new_filename);
    131127  char *df;
    132128  int i;
     
    11421138          d = (struct dirent *) buf;
    11431139#ifdef __MINGW32__
    1144 # if __MINGW32_VERSION_MAJOR < 3 || (__MINGW32_VERSION_MAJOR == 3 && \
    1145                                      __MINGW32_VERSION_MINOR == 0)
     1140# if __MINGW32_MAJOR_VERSION < 3 || (__MINGW32_MAJOR_VERSION == 3 && \
     1141                                     __MINGW32_MINOR_VERSION == 0)
    11461142          d->d_name = xmalloc(len);
    11471143# endif
     
    11631159
    11641160static void
    1165 ansi_free(void *p)
    1166 {
    1167     if (p)
    1168       free(p);
     1161ansi_free (void *p)
     1162{
     1163  if (p)
     1164    free(p);
    11691165}
    11701166
  • trunk/src/gmake/file.c

    r218 r287  
    3131#include "hash.h"
    3232
     33
     34/* Remember whether snap_deps has been invoked: we need this to be sure we
     35   don't add new rules (via $(eval ...)) afterwards.  In the future it would
     36   be nice to support this, but it means we'd need to re-run snap_deps() or
     37   at least its functionality... it might mean changing snap_deps() to be run
     38   per-file, so we can invoke it after the eval... or remembering which files
     39   in the hash have been snapped (a new boolean flag?) and having snap_deps()
     40   only work on files which have not yet been snapped. */
     41int snapped_deps = 0;
    3342
    3443/* Hash table of files the makefile knows how to make.  */
     
    345354      {
    346355        register struct file *f = *file_slot;
     356        /* Is this file eligible for automatic deletion?
     357           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
     358           given on the command-line, and it's either a -include makefile or
     359           it's not precious.  */
    347360        if (f->intermediate && (f->dontcare || !f->precious)
    348361            && !f->secondary && !f->cmd_target)
     
    405418}
    406419
     420/* Expand and parse each dependency line. */
     421static void
     422expand_deps (struct file *f)
     423{
     424  struct dep *d, *d1;
     425  struct dep *new = 0;
     426  struct dep *old = f->deps;
     427  unsigned int last_dep_has_cmds = f->updating;
     428  int initialized = 0;
     429
     430  f->updating = 0;
     431  f->deps = 0;
     432
     433  for (d = old; d != 0; d = d->next)
     434    {
     435      if (d->name != 0)
     436        {
     437          char *p;
     438
     439          /* If we need a second expansion on these, set up the file
     440             variables, etc.  It takes a lot of extra memory and processing
     441             to do this, so only do it if it's needed.  */
     442          if (! d->need_2nd_expansion)
     443            p = d->name;
     444          else
     445            {
     446              /* We are going to do second expansion so initialize file
     447                 variables for the file. */
     448              if (!initialized)
     449                {
     450                  initialize_file_variables (f, 0);
     451                  initialized = 1;
     452                }
     453
     454              set_file_variables (f);
     455
     456              p = variable_expand_for_file (d->name, f);
     457            }
     458
     459          /* Parse the dependencies.  */
     460          new = (struct dep *)
     461            multi_glob (
     462              parse_file_seq (&p, '|', sizeof (struct dep), 1),
     463              sizeof (struct dep));
     464
     465          if (*p)
     466            {
     467              /* Files that follow '|' are special prerequisites that
     468                 need only exist in order to satisfy the dependency.
     469                 Their modification times are irrelevant.  */
     470              struct dep **d_ptr;
     471
     472              for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
     473                ;
     474              ++p;
     475
     476              *d_ptr = (struct dep *)
     477                multi_glob (
     478                  parse_file_seq (&p, '\0', sizeof (struct dep), 1),
     479                  sizeof (struct dep));
     480
     481              for (d1 = *d_ptr; d1 != 0; d1 = d1->next)
     482                d1->ignore_mtime = 1;
     483            }
     484
     485          /* Enter them as files. */
     486          for (d1 = new; d1 != 0; d1 = d1->next)
     487            {
     488              d1->file = lookup_file (d1->name);
     489              if (d1->file == 0)
     490                d1->file = enter_file (d1->name);
     491              else
     492                free (d1->name);
     493              d1->name = 0;
     494              d1->need_2nd_expansion = 0;
     495            }
     496
     497          /* Add newly parsed deps to f->deps. If this is the last
     498             dependency line and this target has commands then put
     499             it in front so the last dependency line (the one with
     500             commands) ends up being the first. This is important
     501             because people expect $< to hold first prerequisite
     502             from the rule with commands. If it is not the last
     503             dependency line or the rule does not have commands
     504             then link it at the end so it appears in makefile
     505             order.  */
     506
     507          if (new != 0)
     508            {
     509              if (d->next == 0 && last_dep_has_cmds)
     510                {
     511                  struct dep **d_ptr;
     512                  for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
     513                    ;
     514
     515                  *d_ptr = f->deps;
     516                  f->deps = new;
     517                }
     518              else
     519                {
     520                  struct dep **d_ptr;
     521                  for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
     522                    ;
     523
     524                  *d_ptr = new;
     525                }
     526            }
     527        }
     528    }
     529
     530  free_ns_chain ((struct nameseq *) old);
     531}
     532
    407533/* For each dependency of each file, make the `struct dep' point
    408534   at the appropriate `struct file' (which may have to be created).
     
    414540snap_deps (void)
    415541{
    416   register struct file *f;
    417   register struct file *f2;
    418   register struct dep *d;
    419   register struct file **file_slot_0;
    420   register struct file **file_slot;
    421   register struct file **file_end;
    422 
    423   /* Enter each dependency name as a file.  */
     542  struct file *f;
     543  struct file *f2;
     544  struct dep *d;
     545  struct file **file_slot_0;
     546  struct file **file_slot;
     547  struct file **file_end;
     548
     549  /* Perform second expansion and enter each dependency
     550     name as a file. */
     551
     552  /* Expand .SUFFIXES first; it's dependencies are used for
     553     $$* calculation. */
     554  for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
     555    expand_deps (f);
     556
    424557  /* We must use hash_dump (), because within this loop
    425558     we might add new files to the table, possibly causing
     
    428561  file_end = file_slot_0 + files.ht_fill;
    429562  for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
    430     for (f2 = *file_slot; f2 != 0; f2 = f2->prev)
    431       for (d = f2->deps; d != 0; d = d->next)
    432         if (d->name != 0)
    433           {
    434             d->file = lookup_file (d->name);
    435             if (d->file == 0)
    436               d->file = enter_file (d->name);
    437             else
    438               free (d->name);
    439             d->name = 0;
    440           }
     563    for (f = *file_slot; f != 0; f = f->prev)
     564      {
     565        if (strcmp (f->name, ".SUFFIXES") != 0)
     566          expand_deps (f);
     567      }
    441568  free (file_slot_0);
    442569
     
    455582      for (f2 = d->file; f2 != 0; f2 = f2->prev)
    456583        {
    457           /* Mark this file as phony and nonexistent.  */
     584          /* Mark this file as phony nonexistent target.  */
    458585          f2->phony = 1;
     586          f2->is_target = 1;
    459587          f2->last_mtime = NONEXISTENT_MTIME;
    460588          f2->mtime_before_update = NONEXISTENT_MTIME;
     
    537665    }
    538666
     667  /* Remember that we've done this. */
     668  snapped_deps = 1;
    539669}
    540670
     
    699829    puts (_("#  Command-line target."));
    700830  if (f->dontcare)
    701     puts (_("#  A default or MAKEFILES makefile."));
     831    puts (_("#  A default, MAKEFILES, or -include/sinclude makefile."));
    702832  puts (f->tried_implicit
    703833        ? _("#  Implicit rule search has been done.")
  • trunk/src/gmake/function.c

    r160 r287  
    7474   the length of SUBST and RLEN is the length of REPLACE.  If BY_WORD is
    7575   nonzero, substitutions are done only on matches which are complete
    76    whitespace-delimited words.  If SUFFIX_ONLY is nonzero, substitutions are
    77    done only at the ends of whitespace-delimited words.  */
     76   whitespace-delimited words.  */
    7877
    7978char *
    8079subst_expand (char *o, char *text, char *subst, char *replace,
    81               unsigned int slen, unsigned int rlen,
    82               int by_word, int suffix_only)
     80              unsigned int slen, unsigned int rlen, int by_word)
    8381{
    8482  char *t = text;
    85   unsigned int tlen = strlen (text);
    8683  char *p;
    8784
    88   if (slen == 0 && !by_word && !suffix_only)
     85  if (slen == 0 && !by_word)
    8986    {
    9087      /* The first occurrence of "" in any string is its end.  */
    91       o = variable_buffer_output (o, t, tlen);
     88      o = variable_buffer_output (o, t, strlen (t));
    9289      if (rlen > 0)
    9390        o = variable_buffer_output (o, replace, rlen);
     
    9794  do
    9895    {
    99       if ((by_word | suffix_only) && slen == 0)
     96      if (by_word && slen == 0)
    10097        /* When matching by words, the empty string should match
    10198           the end of each word, rather than the end of the whole text.  */
     
    103100      else
    104101        {
    105           p = sindex (t, tlen, subst, slen);
     102          p = strstr (t, subst);
    106103          if (p == 0)
    107104            {
    108105              /* No more matches.  Output everything left on the end.  */
    109               o = variable_buffer_output (o, t, tlen);
     106              o = variable_buffer_output (o, t, strlen (t));
    110107              return o;
    111108            }
     
    118115      /* If we're substituting only by fully matched words,
    119116         or only at the ends of words, check that this case qualifies.  */
    120       if ((by_word
    121            && ((p > t && !isblank ((unsigned char)p[-1]))
    122                || (p[slen] != '\0' && !isblank ((unsigned char)p[slen]))))
    123           || (suffix_only
    124               && (p[slen] != '\0' && !isblank ((unsigned char)p[slen]))))
     117      if (by_word
     118          && ((p > text && !isblank ((unsigned char)p[-1]))
     119              || (p[slen] != '\0' && !isblank ((unsigned char)p[slen]))))
    125120        /* Struck out.  Output the rest of the string that is
    126121           no longer to be replaced.  */
     
    130125        o = variable_buffer_output (o, replace, rlen);
    131126
    132       /* Advance T past the string to be replaced; adjust tlen.  */
     127      /* Advance T past the string to be replaced.  */
    133128      {
    134129        char *nt = p + slen;
    135         tlen -= nt - t;
    136130        t = nt;
    137131      }
     
    140134  return o;
    141135}
     136
    142137
    143138
     
    147142   run through find_percent, and PATTERN_PERCENT is the result.
    148143   If REPLACE_PERCENT is not nil, REPLACE has already been
    149    run through find_percent, and REPLACE_PERCENT is the result.  */
     144   run through find_percent, and REPLACE_PERCENT is the result.
     145   Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the
     146   character _AFTER_ the %, not to the % itself.
     147*/
    150148
    151149char *
     
    154152{
    155153  unsigned int pattern_prepercent_len, pattern_postpercent_len;
    156   unsigned int replace_prepercent_len, replace_postpercent_len = 0;
     154  unsigned int replace_prepercent_len, replace_postpercent_len;
    157155  char *t;
    158156  unsigned int len;
     
    161159  /* We call find_percent on REPLACE before checking PATTERN so that REPLACE
    162160     will be collapsed before we call subst_expand if PATTERN has no %.  */
    163   if (replace_percent == 0)
    164     replace_percent = find_percent (replace);
    165   if (replace_percent != 0)
    166     {
    167       /* Record the length of REPLACE before and after the % so
    168          we don't have to compute these lengths more than once.  */
    169       replace_prepercent_len = replace_percent - replace;
    170       replace_postpercent_len = strlen (replace_percent + 1);
     161  if (!replace_percent)
     162    {
     163      replace_percent = find_percent (replace);
     164      if (replace_percent)
     165        ++replace_percent;
     166    }
     167
     168  /* Record the length of REPLACE before and after the % so we don't have to
     169     compute these lengths more than once.  */
     170  if (replace_percent)
     171    {
     172      replace_prepercent_len = replace_percent - replace - 1;
     173      replace_postpercent_len = strlen (replace_percent);
    171174    }
    172175  else
    173     /* We store the length of the replacement
    174        so we only need to compute it once.  */
    175     replace_prepercent_len = strlen (replace);
    176 
    177   if (pattern_percent == 0)
    178     pattern_percent = find_percent (pattern);
    179   if (pattern_percent == 0)
     176    {
     177      replace_prepercent_len = strlen (replace);
     178      replace_postpercent_len = 0;
     179    }
     180
     181  if (!pattern_percent)
     182    {
     183      pattern_percent = find_percent (pattern);
     184      if (pattern_percent)
     185        ++pattern_percent;
     186    }
     187  if (!pattern_percent)
    180188    /* With no % in the pattern, this is just a simple substitution.  */
    181189    return subst_expand (o, text, pattern, replace,
    182                          strlen (pattern), strlen (replace), 1, 0);
     190                         strlen (pattern), strlen (replace), 1);
    183191
    184192  /* Record the length of PATTERN before and after the %
    185193     so we don't have to compute it more than once.  */
    186   pattern_prepercent_len = pattern_percent - pattern;
    187   pattern_postpercent_len = strlen (pattern_percent + 1);
     194  pattern_prepercent_len = pattern_percent - pattern - 1;
     195  pattern_postpercent_len = strlen (pattern_percent);
    188196
    189197  while ((t = find_next_token (&text, &len)) != 0)
     
    198206      if (!fail && pattern_prepercent_len > 0
    199207          && (*t != *pattern
    200               || t[pattern_prepercent_len - 1] != pattern_percent[-1]
     208              || t[pattern_prepercent_len - 1] != pattern_percent[-2]
    201209              || !strneq (t + 1, pattern + 1, pattern_prepercent_len - 1)))
    202210        fail = 1;
     
    204212      /* Does the suffix match? */
    205213      if (!fail && pattern_postpercent_len > 0
    206           && (t[len - 1] != pattern_percent[pattern_postpercent_len]
    207               || t[len - pattern_postpercent_len] != pattern_percent[1]
     214          && (t[len - 1] != pattern_percent[pattern_postpercent_len - 1]
     215              || t[len - pattern_postpercent_len] != *pattern_percent
    208216              || !strneq (&t[len - pattern_postpercent_len],
    209                           &pattern_percent[1], pattern_postpercent_len - 1)))
     217                          pattern_percent, pattern_postpercent_len - 1)))
    210218        fail = 1;
    211219
     
    228236                                                 + pattern_postpercent_len));
    229237              /* Output the part of the replacement after the %.  */
    230               o = variable_buffer_output (o, replace_percent + 1,
     238              o = variable_buffer_output (o, replace_percent,
    231239                                          replace_postpercent_len);
    232240            }
     
    648656{
    649657  o = subst_expand (o, argv[2], argv[0], argv[1], strlen (argv[0]),
    650                     strlen (argv[1]), 0, 0);
     658                    strlen (argv[1]), 0);
    651659
    652660  return o;
     
    667675}
    668676
     677static char *
     678func_lastword (char *o, char **argv, const char *funcname UNUSED)
     679{
     680  unsigned int i;
     681  char *words = argv[0];    /* Use a temp variable for find_next_token */
     682  char *p = 0;
     683  char *t;
     684
     685  while ((t = find_next_token (&words, &i)))
     686    p = t;
     687
     688  if (p != 0)
     689    o = variable_buffer_output (o, p, i);
     690
     691  return o;
     692}
    669693
    670694static char *
     
    690714 * begpp-1.
    691715 */
    692 static char *
     716char *
    693717strip_whitespace (const char **begpp, const char **endpp)
    694718{
     
    755779
    756780  start = atoi (argv[0]);
     781  if (start < 1)
     782    fatal (reading_file,
     783           "invalid first argument to `wordlist' function: `%d'", start);
     784
    757785  count = atoi (argv[1]) - start + 1;
    758786
     
    784812{
    785813  /* Find the first occurrence of the first string in the second.  */
    786   int i = strlen (argv[0]);
    787   if (sindex (argv[1], 0, argv[0], i) != 0)
    788     o = variable_buffer_output (o, argv[0], i);
     814  if (strstr (argv[1], argv[0]) != 0)
     815    o = variable_buffer_output (o, argv[0], strlen (argv[0]));
    789816
    790817  return o;
     
    10671094  strcpy (p, *argvp);
    10681095
    1069   if (*funcname == 'e')
    1070     fatal (reading_file, "%s", msg);
     1096  switch (*funcname) {
     1097    case 'e':
     1098      fatal (reading_file, "%s", msg);
     1099
     1100    case 'w':
     1101      error (reading_file, "%s", msg);
     1102      break;
     1103
     1104    case 'i':
     1105      printf ("%s\n", msg);
     1106      break;
     1107
     1108    default:
     1109      fatal (reading_file, "Internal error: func_error: '%s'", funcname);
     1110  }
    10711111
    10721112  /* The warning function expands to the empty string.  */
    1073   error (reading_file, "%s", msg);
    1074 
    10751113  return o;
    10761114}
     
    14571495
    14581496  /* For error messages.  */
    1459   if (reading_file != 0)
     1497  if (reading_file && reading_file->filenm)
    14601498    {
    14611499      error_prefix = (char *) alloca (strlen (reading_file->filenm)+11+4);
     
    17001738 */
    17011739static char *
    1702 func_eq (char* o, char **argv, char *funcname)
     1740func_eq (char *o, char **argv, char *funcname)
    17031741{
    17041742  int result = ! strcmp (argv[0], argv[1]);
     
    17121750 */
    17131751static char *
    1714 func_not (char* o, char **argv, char *funcname)
    1715 {
    1716   char * s = argv[0];
     1752func_not (char *o, char **argv, char *funcname)
     1753{
     1754  char *s = argv[0];
    17171755  int result = 0;
    17181756  while (isspace ((unsigned char)*s))
     
    17261764
    17271765
     1766/* Return the absolute name of file NAME which does not contain any `.',
     1767   `..' components nor any repeated path separators ('/').   */
     1768
     1769static char *
     1770abspath (const char *name, char *apath)
     1771{
     1772  char *dest;
     1773  const char *start, *end, *apath_limit;
     1774
     1775  if (name[0] == '\0' || apath == NULL)
     1776    return NULL;
     1777
     1778  apath_limit = apath + GET_PATH_MAX;
     1779
     1780  if (name[0] != '/')
     1781    {
     1782      /* It is unlikely we would make it until here but just to make sure. */
     1783      if (!starting_directory)
     1784        return NULL;
     1785
     1786      strcpy (apath, starting_directory);
     1787
     1788      dest = strchr (apath, '\0');
     1789    }
     1790  else
     1791    {
     1792      apath[0] = '/';
     1793      dest = apath + 1;
     1794    }
     1795
     1796  for (start = end = name; *start != '\0'; start = end)
     1797    {
     1798      unsigned long len;
     1799
     1800      /* Skip sequence of multiple path-separators.  */
     1801      while (*start == '/')
     1802        ++start;
     1803
     1804      /* Find end of path component.  */
     1805      for (end = start; *end != '\0' && *end != '/'; ++end)
     1806        ;
     1807
     1808      len = end - start;
     1809
     1810      if (len == 0)
     1811        break;
     1812      else if (len == 1 && start[0] == '.')
     1813        /* nothing */;
     1814      else if (len == 2 && start[0] == '.' && start[1] == '.')
     1815        {
     1816          /* Back up to previous component, ignore if at root already.  */
     1817          if (dest > apath + 1)
     1818            while ((--dest)[-1] != '/');
     1819        }
     1820      else
     1821        {
     1822          if (dest[-1] != '/')
     1823            *dest++ = '/';
     1824
     1825          if (dest + len >= apath_limit)
     1826            return NULL;
     1827
     1828          dest = memcpy (dest, start, len);
     1829          dest += len;
     1830          *dest = '\0';
     1831        }
     1832    }
     1833
     1834  /* Unless it is root strip trailing separator.  */
     1835  if (dest > apath + 1 && dest[-1] == '/')
     1836    --dest;
     1837
     1838  *dest = '\0';
     1839
     1840  return apath;
     1841}
     1842
     1843
     1844static char *
     1845func_realpath (char *o, char **argv, const char *funcname UNUSED)
     1846{
     1847  /* Expand the argument.  */
     1848  char *p = argv[0];
     1849  char *path = 0;
     1850  int doneany = 0;
     1851  unsigned int len = 0;
     1852  PATH_VAR (in);
     1853  PATH_VAR (out);
     1854
     1855  while ((path = find_next_token (&p, &len)) != 0)
     1856    {
     1857      if (len < GET_PATH_MAX)
     1858        {
     1859          strncpy (in, path, len);
     1860          in[len] = '\0';
     1861
     1862          if
     1863          (
     1864#ifdef HAVE_REALPATH
     1865            realpath (in, out)
     1866#else
     1867            abspath (in, out)
     1868#endif
     1869          )
     1870            {
     1871              o = variable_buffer_output (o, out, strlen (out));
     1872              o = variable_buffer_output (o, " ", 1);
     1873              doneany = 1;
     1874            }
     1875        }
     1876    }
     1877
     1878  /* Kill last space.  */
     1879  if (doneany)
     1880    --o;
     1881
     1882 return o;
     1883}
     1884
     1885static char *
     1886func_abspath (char *o, char **argv, const char *funcname UNUSED)
     1887{
     1888  /* Expand the argument.  */
     1889  char *p = argv[0];
     1890  char *path = 0;
     1891  int doneany = 0;
     1892  unsigned int len = 0;
     1893  PATH_VAR (in);
     1894  PATH_VAR (out);
     1895
     1896  while ((path = find_next_token (&p, &len)) != 0)
     1897    {
     1898      if (len < GET_PATH_MAX)
     1899        {
     1900          strncpy (in, path, len);
     1901          in[len] = '\0';
     1902
     1903          if (abspath (in, out))
     1904            {
     1905              o = variable_buffer_output (o, out, strlen (out));
     1906              o = variable_buffer_output (o, " ", 1);
     1907              doneany = 1;
     1908            }
     1909        }
     1910    }
     1911
     1912  /* Kill last space.  */
     1913  if (doneany)
     1914    --o;
     1915
     1916 return o;
     1917}
     1918
    17281919/* Lookup table for builtin functions.
    17291920
     
    17441935{
    17451936 /* Name/size */                    /* MIN MAX EXP? Function */
     1937  { STRING_SIZE_TUPLE("abspath"),       0,  1,  1,  func_abspath},
    17461938  { STRING_SIZE_TUPLE("addprefix"),     2,  2,  1,  func_addsuffix_addprefix},
    17471939  { STRING_SIZE_TUPLE("addsuffix"),     2,  2,  1,  func_addsuffix_addprefix},
     
    17561948  { STRING_SIZE_TUPLE("firstword"),     0,  1,  1,  func_firstword},
    17571949  { STRING_SIZE_TUPLE("join"),          2,  2,  1,  func_join},
     1950  { STRING_SIZE_TUPLE("lastword"),      0,  1,  1,  func_lastword},
    17581951  { STRING_SIZE_TUPLE("patsubst"),      3,  3,  1,  func_patsubst},
     1952  { STRING_SIZE_TUPLE("realpath"),      0,  1,  1,  func_realpath},
    17591953  { STRING_SIZE_TUPLE("shell"),         0,  1,  1,  func_shell},
    17601954  { STRING_SIZE_TUPLE("sort"),          0,  1,  1,  func_sort},
     
    17671961  { STRING_SIZE_TUPLE("foreach"),       3,  3,  0,  func_foreach},
    17681962  { STRING_SIZE_TUPLE("call"),          1,  0,  1,  func_call},
     1963  { STRING_SIZE_TUPLE("info"),          0,  1,  1,  func_error},
    17691964  { STRING_SIZE_TUPLE("error"),         0,  1,  1,  func_error},
    17701965  { STRING_SIZE_TUPLE("warning"),       0,  1,  1,  func_error},
  • trunk/src/gmake/hash.h

    r53 r287  
    8383/* hash and comparison macros for case-sensitive string keys. */
    8484
     85#if 0
    8586#define STRING_HASH_1(KEY, RESULT) do { \
    8687  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
     
    8889    (RESULT) += (*_key_ << (_key_[1] & 0xf)); \
    8990} while (0)
     91#else
     92#define STRING_HASH_1(KEY, RESULT) do { \
     93  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     94  unsigned int _ch_ = *_key_; \
     95  while (_ch_) \
     96    { \
     97      unsigned char _ch2_ = *++_key_; \
     98     (RESULT) += (_ch_ << (_ch2_ & 0xf)); \
     99     _ch_ = _ch2_; \
     100    } \
     101} while (0)
     102#endif
    90103#define return_STRING_HASH_1(KEY) do { \
    91104  unsigned long _result_ = 0; \
     
    94107} while (0)
    95108
     109#if 0
    96110#define STRING_HASH_2(KEY, RESULT) do { \
    97111  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
     
    99113    (RESULT) += (*_key_ << (_key_[1] & 0x7)); \
    100114} while (0)
     115#else
     116#define STRING_HASH_2(KEY, RESULT) do { \
     117  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     118  unsigned int _ch_ = *_key_; \
     119  while (_ch_) \
     120    { \
     121      unsigned char _ch2_ = *++_key_; \
     122     (RESULT) += (_ch_ << (_ch2_ & 0x7)); \
     123     _ch_ = _ch2_; \
     124    } \
     125} while (0)
     126#endif
    101127#define return_STRING_HASH_2(KEY) do { \
    102128  unsigned long _result_ = 0; \
     
    112138} while (0)
    113139
    114 
    115 #define STRING_N_HASH_1(KEY, N, RESULT) do { \
     140#if 0
     141#define _STRING_N_HASH_1(KEY, N, RESULT) do { \
    116142  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
    117143  int _n_ = (N); \
     
    121147  (RESULT) += *++_key_; \
    122148} while (0)
     149#else
     150#define STRING_N_HASH_1(KEY, N, RESULT) do { \
     151  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     152  unsigned int _ch_ = *_key_; \
     153  int _n_ = (N); \
     154  if (_n_) \
     155    { \
     156      for (;;) \
     157        { \
     158          unsigned char _ch2_; \
     159          if (!--_n_) \
     160            { \
     161              (RESULT) += _ch_; \
     162              break; \
     163            } \
     164          _ch2_ = *++_key_; \
     165          (RESULT) += (_ch_ << (_ch2_ & 0xf)); \
     166          _ch_ = _ch2_; \
     167          if (!_ch_) break; \
     168        } \
     169    } \
     170  else \
     171    (RESULT) += _ch_; \
     172} while (0)
     173#endif
    123174#define return_STRING_N_HASH_1(KEY, N) do { \
    124175  unsigned long _result_ = 0; \
     
    127178} while (0)
    128179
     180#if 0
    129181#define STRING_N_HASH_2(KEY, N, RESULT) do { \
    130182  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
     
    135187  (RESULT) += *++_key_; \
    136188} while (0)
     189#else
     190#define STRING_N_HASH_2(KEY, N, RESULT) do { \
     191  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     192  unsigned int _ch_ = *_key_; \
     193  int _n_ = (N); \
     194  if (_n_) \
     195    { \
     196      for (;;) \
     197        { \
     198          unsigned char _ch2_; \
     199          if (!--_n_) \
     200            { \
     201              (RESULT) += _ch_; \
     202              break; \
     203            } \
     204          _ch2_ = *++_key_; \
     205          (RESULT) += (_ch_ << (_ch2_ & 0x7)); \
     206          _ch_ = _ch2_; \
     207          if (!_ch_) break; \
     208        } \
     209    } \
     210  else \
     211    (RESULT) += _ch_; \
     212} while (0)
     213#endif
    137214#define return_STRING_N_HASH_2(KEY, N) do { \
    138215  unsigned long _result_ = 0; \
     
    152229/* hash and comparison macros for case-insensitive string _key_s. */
    153230
     231#if 1 /* testme */
    154232#define ISTRING_HASH_1(KEY, RESULT) do { \
    155233  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
     
    157235    (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0xf)); \
    158236} while (0)
     237#else
     238#define ISTRING_HASH_1(KEY, RESULT) do { \
     239  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     240  unsigned int _ch_ = *_key_;
     241  while (_ch_) \
     242    { \
     243      unsigned _ch2_ = *++_key_; \
     244      (RESULT) += ((isupper (_ch_) ? tolower (_ch_) : _ch_) << (_ch2_ & 0xf)); \
     245      _ch_ = _ch2_; \
     246    } \
     247} while (0)
     248#endif
    159249#define return_ISTRING_HASH_1(KEY) do { \
    160250  unsigned long _result_ = 0; \
     
    163253} while (0)
    164254
     255#if 1 /* testme */
    165256#define ISTRING_HASH_2(KEY, RESULT) do { \
    166257  unsigned char const *_key_ = (unsigned char const *) (KEY) - 1; \
     
    168259    (RESULT) += ((isupper (*_key_) ? tolower (*_key_) : *_key_) << (_key_[1] & 0x7)); \
    169260} while (0)
     261#else
     262#define ISTRING_HASH_2(KEY, RESULT) do { \
     263  unsigned char const *_key_ = (unsigned char const *) (KEY); \
     264  unsigned int _ch_ = *_key_;
     265  while (_ch_) \
     266    { \
     267      unsigned _ch2_ = *++_key_; \
     268      (RESULT) += ((isupper (_ch_) ? tolower (_ch_) : _ch_) << (_ch2_ & 0x7)); \
     269      _ch_ = _ch2_; \
     270    } \
     271} while (0)
     272#endif
    170273#define return_ISTRING_HASH_2(KEY) do { \
    171274  unsigned long _result_ = 0; \
  • trunk/src/gmake/job.c

    r232 r287  
    11/* Job execution and handling for GNU Make.
    2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 Free Software Foundation, Inc.
     2Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1999,
     32000,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
    34This file is part of GNU Make.
    45
     
    6970
    7071# include <descrip.h>
     72char default_shell[] = "";
     73int batch_mode_shell = 0;
     74
     75#elif defined (__riscos__)
     76
    7177char default_shell[] = "";
    7278int batch_mode_shell = 0;
     
    176182#endif  /* Don't have `union wait'.  */
    177183
    178 #ifdef VMS
    179 static int vms_jobsefnmask = 0;
    180 #endif /* !VMS */
    181 
    182184#ifndef HAVE_UNISTD_H
    183185extern int dup2 ();
     
    207209static int job_next_command PARAMS ((struct child *));
    208210static int start_waiting_job PARAMS ((struct child *));
    209 #ifdef VMS
    210 static void vmsWaitForChildren PARAMS ((int *));
    211 #endif
    212211#ifdef MAKE_DLLSHELL
    213212static int spawn_command PARAMS ((char **argv, char **envp, struct child *child));
     
    239238unsigned long job_counter = 0;
    240239
     240/* Number of jobserver tokens this instance is currently using.  */
     241
     242unsigned int jobserver_tokens = 0;
    241243
    242244
     
    248250w32_kill(int pid, int sig)
    249251{
    250   return ((process_kill(pid, sig) == TRUE) ? 0 : -1);
     252  return ((process_kill((HANDLE)pid, sig) == TRUE) ? 0 : -1);
     253}
     254
     255/* This function creates a temporary file name with the given extension
     256 * the unixy param controls both the extension and the path separator
     257 * return an xmalloc'ed string of a newly created temp file or die.  */
     258static char *
     259create_batch_filename(char const *base, int unixy)
     260{
     261  const char *const ext = unixy ? "sh" : "bat";
     262  const char *error = NULL;
     263  char temp_path[MAXPATHLEN]; /* need to know its length */
     264  unsigned path_size = GetTempPath(sizeof temp_path, temp_path);
     265  int path_is_dot = 0;
     266  unsigned uniq = 1;
     267  const unsigned sizemax = strlen (base) + strlen (ext) + 10;
     268
     269  if (path_size == 0)
     270    {
     271      path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
     272      path_is_dot = 1;
     273    }
     274
     275  while (path_size > 0 &&
     276         path_size + sizemax < sizeof temp_path &&
     277         uniq < 0x10000)
     278    {
     279      unsigned size = sprintf (temp_path + path_size,
     280                               "%s%s-%x.%s",
     281                               temp_path[path_size - 1] == '\\' ? "" : "\\",
     282                               base, uniq, ext);
     283      HANDLE h = CreateFile (temp_path,  /* file name */
     284                             GENERIC_READ | GENERIC_WRITE, /* desired access */
     285                             0,                            /* no share mode */
     286                             NULL,                         /* default security attributes */
     287                             CREATE_NEW,                   /* creation disposition */
     288                             FILE_ATTRIBUTE_NORMAL |       /* flags and attributes */
     289                             FILE_ATTRIBUTE_TEMPORARY,     /* we'll delete it */
     290                             NULL);                        /* no template file */
     291
     292      if (h == INVALID_HANDLE_VALUE)
     293        {
     294          const DWORD er = GetLastError();
     295
     296          if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS)
     297            ++uniq;
     298
     299          /* the temporary path is not guaranteed to exist */
     300          else if (path_is_dot == 0)
     301            {
     302              path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
     303              path_is_dot = 1;
     304            }
     305
     306          else
     307            {
     308              error = map_windows32_error_to_string (er);
     309              break;
     310            }
     311        }
     312      else
     313        {
     314          const unsigned final_size = path_size + size + 1;
     315          char *const path = (char *) xmalloc (final_size);
     316          memcpy (path, temp_path, final_size);
     317          CloseHandle (h);
     318          if (unixy)
     319            {
     320              char *p;
     321              int ch;
     322              for (p = path; (ch = *p) != 0; ++p)
     323                if (ch == '\\')
     324                  *p = '/';
     325            }
     326          return path; /* good return */
     327        }
     328    }
     329
     330  if (error == NULL)
     331    error = _("Cannot create a temporary file\n");
     332  fatal (NILF, error);
     333
     334  /* not reached */
     335  return NULL;
    251336}
    252337#endif /* WINDOWS32 */
     
    328413
    329414
    330 #ifdef VMS
    331 /* Wait for nchildren children to terminate */
    332 static void
    333 vmsWaitForChildren(int *status)
    334 {
    335   while (1)
    336     {
    337       if (!vms_jobsefnmask)
    338         {
    339           *status = 0;
    340           return;
    341         }
    342 
    343       *status = sys$wflor (32, vms_jobsefnmask);
    344     }
    345   return;
    346 }
    347 
    348 /* Set up IO redirection.  */
    349 
    350 char *
    351 vms_redirect (struct dsc$descriptor_s *desc, char *fname, char *ibuf)
    352 {
    353   char *fptr;
    354   extern char *vmsify ();
    355 
    356   ibuf++;
    357   while (isspace ((unsigned char)*ibuf))
    358     ibuf++;
    359   fptr = ibuf;
    360   while (*ibuf && !isspace ((unsigned char)*ibuf))
    361     ibuf++;
    362   *ibuf = 0;
    363   if (strcmp (fptr, "/dev/null") != 0)
    364     {
    365       strcpy (fname, vmsify (fptr, 0));
    366       if (strchr (fname, '.') == 0)
    367         strcat (fname, ".");
    368     }
    369   desc->dsc$w_length = strlen(fname);
    370   desc->dsc$a_pointer = fname;
    371   desc->dsc$b_dtype = DSC$K_DTYPE_T;
    372   desc->dsc$b_class = DSC$K_CLASS_S;
    373 
    374   if (*fname == 0)
    375     printf (_("Warning: Empty redirection\n"));
    376   return ibuf;
    377 }
    378 
    379 
    380 /* found apostrophe at (p-1)
    381    inc p until after closing apostrophe.
    382  */
    383 
    384 static char *
    385 vms_handle_apos (char *p)
    386 {
    387   int alast;
    388 
    389 #define SEPCHARS ",/()= "
    390 
    391   alast = 0;
    392 
    393   while (*p != 0)
    394     {
    395       if (*p == '"')
    396         {
    397           if (alast)
    398             {
    399               alast = 0;
    400               p++;
    401             }
    402           else
    403             {
    404               p++;
    405               if (strchr (SEPCHARS, *p))
    406                 break;
    407               alast = 1;
    408             }
    409         }
    410       else
    411         p++;
    412     }
    413 
    414   return p;
    415 }
    416 
    417 #endif
    418 
    419415
    420416/* Handle a dead child.  This handler may or may not ever be installed.
     
    485481    {
    486482      int remote = 0;
    487       register int pid;
     483      pid_t pid;
    488484      int exit_code, exit_sig, coredump;
    489485      register struct child *lastc, *c;
     
    569565            {
    570566#ifdef VMS
     567              static void vmsWaitForChildren PARAMS ((int *));
    571568              vmsWaitForChildren (&status);
    572569              pid = c->pid;
     
    644641            HANDLE hPID;
    645642            int err;
     643            exit_code = 0;
     644            exit_sig = 0;
     645            coredump = 0;
    646646
    647647            /* wait for anything to finish */
    648             if (hPID = process_wait_for_any()) {
    649 
    650               /* was an error found on this process? */
    651               err = process_last_err(hPID);
    652 
    653               /* get exit data */
    654               exit_code = process_exit_code(hPID);
    655 
    656               if (err)
    657                 fprintf(stderr, "make (e=%d): %s",
    658                   exit_code, map_windows32_error_to_string(exit_code));
    659 
    660               /* signal */
    661               exit_sig = process_signal(hPID);
    662 
    663               /* cleanup process */
    664               process_cleanup(hPID);
    665 
    666               coredump = 0;
    667             }
    668             pid = (int) hPID;
     648            hPID = process_wait_for_any();
     649            if (hPID)
     650              {
     651
     652                /* was an error found on this process? */
     653                err = process_last_err(hPID);
     654
     655                /* get exit data */
     656                exit_code = process_exit_code(hPID);
     657
     658                if (err)
     659                  fprintf(stderr, "make (e=%d): %s",
     660                          exit_code, map_windows32_error_to_string(exit_code));
     661
     662                /* signal */
     663                exit_sig = process_signal(hPID);
     664
     665                /* cleanup process */
     666                process_cleanup(hPID);
     667
     668                coredump = 0;
     669              }
     670            pid = (pid_t) hPID;
    669671          }
    670672#endif /* WINDOWS32 */
     
    840842free_child (struct child *child)
    841843{
    842   /* If this child is the only one it was our "free" job, so don't put a
    843      token back for it.  This child has already been removed from the list,
    844      so if there any left this wasn't the last one.  */
    845 
    846   if (job_fds[1] >= 0 && children)
     844  if (!jobserver_tokens)
     845    fatal (NILF, "INTERNAL: Freeing child 0x%08lx (%s) but no tokens left!\n",
     846           (unsigned long int) child, child->file->name);
     847
     848  /* If we're using the jobserver and this child is not the only outstanding
     849     job, put a token back into the pipe for it.  */
     850
     851  if (job_fds[1] >= 0 && jobserver_tokens > 1)
    847852    {
    848853      char token = '+';
     
    858863                    (unsigned long int) child, child->file->name));
    859864    }
     865
     866  --jobserver_tokens;
    860867
    861868  if (handling_fatal_signal) /* Don't bother free'ing if about to die.  */
     
    898905}
    899906
    900 #ifdef  POSIX
     907#ifdef POSIX
    901908void
    902909unblock_sigs (void)
     
    909916
    910917#ifdef MAKE_JOBSERVER
     918RETSIGTYPE
     919job_noop (int sig UNUSED)
     920{
     921}
    911922/* Set the child handler action flags to FLAGS.  */
    912923static void
    913 set_child_handler_action_flags (int flags)
     924set_child_handler_action_flags (int set_handler, int set_alarm)
    914925{
    915926  struct sigaction sa;
     927
     928#ifdef __EMX__
     929  /* The child handler must be turned off here.  */
     930  signal (SIGCHLD, SIG_DFL);
     931#endif
     932
    916933  bzero ((char *) &sa, sizeof sa);
    917934  sa.sa_handler = child_handler;
    918   sa.sa_flags = flags;
     935  sa.sa_flags = set_handler ? 0 : SA_RESTART;
    919936#if defined SIGCHLD
    920937  sigaction (SIGCHLD, &sa, NULL);
     
    922939#if defined SIGCLD && SIGCLD != SIGCHLD
    923940  sigaction (SIGCLD, &sa, NULL);
     941#endif
     942#if defined SIGALRM
     943  if (set_alarm)
     944    {
     945      /* If we're about to enter the read(), set an alarm to wake up in a
     946         second so we can check if the load has dropped and we can start more
     947         work.  On the way out, turn off the alarm and set SIG_DFL.  */
     948      alarm (set_handler ? 1 : 0);
     949      sa.sa_handler = set_handler ? job_noop : SIG_DFL;
     950      sa.sa_flags = 0;
     951      sigaction (SIGALRM, &sa, NULL);
     952    }
    924953#endif
    925954}
     
    12261255
    12271256#ifdef VMS
    1228 
    12291257      if (!child_execute_job (argv, child)) {
    12301258        /* Fork failed!  */
     
    16701698
    16711699        /* If we don't already have a job started, use our "free" token.  */
    1672         if (!children)
     1700        if (!jobserver_tokens)
    16731701          break;
    16741702
     
    17051733        reap_children (0, 0);
    17061734
    1707         /* If our "free" token has become available, use it.  */
     1735        /* Kick off any jobs we have waiting for an opportunity that
     1736           can run now (ie waiting for load). */
     1737        start_waiting_jobs ();
     1738
     1739        /* If our "free" slot has become available, use it; we don't need an
     1740           actual token.  */
     1741        if (!jobserver_tokens)
     1742          break;
     1743
     1744        /* There must be at least one child already, or we have no business
     1745           waiting for a token. */
    17081746        if (!children)
    1709           break;
     1747          fatal (NILF, "INTERNAL: no children as we go to sleep on read\n");
    17101748
    17111749        /* Set interruptible system calls, and read() for a job token.  */
    1712         set_child_handler_action_flags (0);
     1750        set_child_handler_action_flags (1, waiting_jobs != NULL);
    17131751        got_token = read (job_rfd, &token, 1);
    17141752        saved_errno = errno;
    1715 #if defined(__EMX__) && !defined(__INNOTEK_LIBC__)
    1716         /* The child handler must be turned off here.  */
    1717         signal (SIGCHLD, SIG_DFL);
    1718 #endif
    1719         set_child_handler_action_flags (SA_RESTART);
     1753        set_child_handler_action_flags (0, waiting_jobs != NULL);
    17201754
    17211755        /* If we got one, we're done here.  */
     
    17361770      }
    17371771#endif
     1772
     1773  ++jobserver_tokens;
    17381774
    17391775  /* The job is now primed.  Start it running.
     
    18161852load_too_high (void)
    18171853{
    1818 #if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA)
     1854#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__)
    18191855  return 1;
    18201856#else
     
    19001936
    19011937#ifndef WINDOWS32
    1902 #ifdef VMS
    1903 #include <descrip.h>
    1904 #include <clidef.h>
    1905 
    1906 /* This is called as an AST when a child process dies (it won't get
    1907    interrupted by anything except a higher level AST).
    1908 */
    1909 int vmsHandleChildTerm(struct child *child)
    1910 {
    1911     int status;
    1912     register struct child *lastc, *c;
    1913     int child_failed;
    1914 
    1915     vms_jobsefnmask &= ~(1 << (child->efn - 32));
    1916 
    1917     lib$free_ef(&child->efn);
    1918 
    1919     (void) sigblock (fatal_signal_mask);
    1920 
    1921     child_failed = !(child->cstatus & 1 || ((child->cstatus & 7) == 0));
    1922 
    1923     /* Search for a child matching the deceased one.  */
    1924     lastc = 0;
    1925 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
    1926     for (c = children; c != 0 && c != child; lastc = c, c = c->next);
    1927 #else
    1928     c = child;
    1929 #endif
    1930 
    1931     if (child_failed && !c->noerror && !ignore_errors_flag)
    1932       {
    1933         /* The commands failed.  Write an error message,
    1934            delete non-precious targets, and abort.  */
    1935         child_error (c->file->name, c->cstatus, 0, 0, 0);
    1936         c->file->update_status = 1;
    1937         delete_child_targets (c);
    1938       }
    1939     else
    1940       {
    1941         if (child_failed)
    1942           {
    1943             /* The commands failed, but we don't care.  */
    1944             child_error (c->file->name, c->cstatus, 0, 0, 1);
    1945             child_failed = 0;
    1946           }
    1947 
    1948 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
    1949         /* If there are more commands to run, try to start them.  */
    1950         start_job (c);
    1951 
    1952         switch (c->file->command_state)
    1953           {
    1954           case cs_running:
    1955             /* Successfully started.  */
    1956             break;
    1957 
    1958           case cs_finished:
    1959             if (c->file->update_status != 0) {
    1960                 /* We failed to start the commands.  */
    1961                 delete_child_targets (c);
    1962             }
    1963             break;
    1964 
    1965           default:
    1966             error (NILF, _("internal error: `%s' command_state"),
    1967                    c->file->name);
    1968             abort ();
    1969             break;
    1970           }
    1971 #endif /* RECURSIVEJOBS */
    1972       }
    1973 
    1974     /* Set the state flag to say the commands have finished.  */
    1975     c->file->command_state = cs_finished;
    1976     notice_finished_file (c->file);
    1977 
    1978 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
    1979     /* Remove the child from the chain and free it.  */
    1980     if (lastc == 0)
    1981       children = c->next;
    1982     else
    1983       lastc->next = c->next;
    1984     free_child (c);
    1985 #endif /* RECURSIVEJOBS */
    1986 
    1987     /* There is now another slot open.  */
    1988     if (job_slots_used > 0)
    1989       --job_slots_used;
    1990 
    1991     /* If the job failed, and the -k flag was not given, die.  */
    1992     if (child_failed && !keep_going_flag)
    1993       die (EXIT_FAILURE);
    1994 
    1995     (void) sigsetmask (sigblock (0) & ~(fatal_signal_mask));
    1996 
    1997     return 1;
    1998 }
    1999 
    2000 /* VMS:
    2001    Spawn a process executing the command in ARGV and return its pid. */
    2002 
    2003 #define MAXCMDLEN 200
    2004 
    2005 /* local helpers to make ctrl+c and ctrl+y working, see below */
    2006 #include <iodef.h>
    2007 #include <libclidef.h>
    2008 #include <ssdef.h>
    2009 
    2010 static int ctrlMask= LIB$M_CLI_CTRLY;
    2011 static int oldCtrlMask;
    2012 static int setupYAstTried= 0;
    2013 static int pidToAbort= 0;
    2014 static int chan= 0;
    2015 
    2016 static void reEnableAst(void) {
    2017         lib$enable_ctrl (&oldCtrlMask,0);
    2018 }
    2019 
    2020 static astHandler (void) {
    2021         if (pidToAbort) {
    2022                 sys$forcex (&pidToAbort, 0, SS$_ABORT);
    2023                 pidToAbort= 0;
    2024         }
    2025         kill (getpid(),SIGQUIT);
    2026 }
    2027 
    2028 static void tryToSetupYAst(void) {
    2029         $DESCRIPTOR(inputDsc,"SYS$COMMAND");
    2030         int     status;
    2031         struct {
    2032                 short int       status, count;
    2033                 int     dvi;
    2034         } iosb;
    2035 
    2036         setupYAstTried++;
    2037 
    2038         if (!chan) {
    2039                 status= sys$assign(&inputDsc,&chan,0,0);
    2040                 if (!(status&SS$_NORMAL)) {
    2041                         lib$signal(status);
    2042                         return;
    2043                 }
    2044         }
    2045         status= sys$qiow (0, chan, IO$_SETMODE|IO$M_CTRLYAST,&iosb,0,0,
    2046                 astHandler,0,0,0,0,0);
    2047         if (status==SS$_ILLIOFUNC) {
    2048                 sys$dassgn(chan);
    2049 #ifdef  CTRLY_ENABLED_ANYWAY
    2050                 fprintf (stderr,
    2051                          _("-warning, CTRL-Y will leave sub-process(es) around.\n"));
    2052 #else
    2053                 return;
    2054 #endif
    2055         }
    2056         if (status==SS$_NORMAL)
    2057                 status= iosb.status;
    2058         if (!(status&SS$_NORMAL)) {
    2059                 lib$signal(status);
    2060                 return;
    2061         }
    2062 
    2063         /* called from AST handler ? */
    2064         if (setupYAstTried>1)
    2065                 return;
    2066         if (atexit(reEnableAst))
    2067                 fprintf (stderr,
    2068                          _("-warning, you may have to re-enable CTRL-Y handling from DCL.\n"));
    2069         status= lib$disable_ctrl (&ctrlMask, &oldCtrlMask);
    2070         if (!(status&SS$_NORMAL)) {
    2071                 lib$signal(status);
    2072                 return;
    2073         }
    2074 }
    2075 int
    2076 child_execute_job (char *argv, struct child *child)
    2077 {
    2078   int i;
    2079   static struct dsc$descriptor_s cmddsc;
    2080   static struct dsc$descriptor_s pnamedsc;
    2081   static struct dsc$descriptor_s ifiledsc;
    2082   static struct dsc$descriptor_s ofiledsc;
    2083   static struct dsc$descriptor_s efiledsc;
    2084   int have_redirection = 0;
    2085   int have_newline = 0;
    2086 
    2087   int spflags = CLI$M_NOWAIT;
    2088   int status;
    2089   char *cmd = alloca (strlen (argv) + 512), *p, *q;
    2090   char ifile[256], ofile[256], efile[256];
    2091   char *comname = 0;
    2092   char procname[100];
    2093 
    2094   /* Parse IO redirection.  */
    2095 
    2096   ifile[0] = 0;
    2097   ofile[0] = 0;
    2098   efile[0] = 0;
    2099 
    2100   DB (DB_JOBS, ("child_execute_job (%s)\n", argv));
    2101 
    2102   while (isspace ((unsigned char)*argv))
    2103     argv++;
    2104 
    2105   if (*argv == 0)
    2106     return 0;
    2107 
    2108   sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff);
    2109   pnamedsc.dsc$w_length = strlen(procname);
    2110   pnamedsc.dsc$a_pointer = procname;
    2111   pnamedsc.dsc$b_dtype = DSC$K_DTYPE_T;
    2112   pnamedsc.dsc$b_class = DSC$K_CLASS_S;
    2113 
    2114   /* Handle comments and redirection. */
    2115   for (p = argv, q = cmd; *p; p++, q++)
    2116     {
    2117       switch (*p)
    2118         {
    2119           case '#':
    2120             *p-- = 0;
    2121             *q-- = 0;
    2122             break;
    2123           case '\\':
    2124             p++;
    2125             if (*p == '\n')
    2126               p++;
    2127             if (isspace ((unsigned char)*p))
    2128               {
    2129                 do { p++; } while (isspace ((unsigned char)*p));
    2130                 p--;
    2131               }
    2132             *q = *p;
    2133             break;
    2134           case '<':
    2135             p = vms_redirect (&ifiledsc, ifile, p);
    2136             *q = ' ';
    2137             have_redirection = 1;
    2138             break;
    2139           case '>':
    2140             have_redirection = 1;
    2141             if (*(p-1) == '2')
    2142               {
    2143                 q--;
    2144                 if (strncmp (p, ">&1", 3) == 0)
    2145                   {
    2146                     p += 3;
    2147                     strcpy (efile, "sys$output");
    2148                     efiledsc.dsc$w_length = strlen(efile);
    2149                     efiledsc.dsc$a_pointer = efile;
    2150                     efiledsc.dsc$b_dtype = DSC$K_DTYPE_T;
    2151                     efiledsc.dsc$b_class = DSC$K_CLASS_S;
    2152                   }
    2153                 else
    2154                   {
    2155                     p = vms_redirect (&efiledsc, efile, p);
    2156                   }
    2157               }
    2158             else
    2159               {
    2160                 p = vms_redirect (&ofiledsc, ofile, p);
    2161               }
    2162             *q = ' ';
    2163             break;
    2164           case '\n':
    2165             have_newline = 1;
    2166           default:
    2167             *q = *p;
    2168             break;
    2169         }
    2170     }
    2171   *q = *p;
    2172 
    2173   if (strncmp (cmd, "builtin_", 8) == 0)
    2174     {
    2175       child->pid = 270163;
    2176       child->efn = 0;
    2177       child->cstatus = 1;
    2178 
    2179       DB (DB_JOBS, (_("BUILTIN [%s][%s]\n"), cmd, cmd+8));
    2180 
    2181       p = cmd + 8;
    2182 
    2183       if ((*(p) == 'c')
    2184           && (*(p+1) == 'd')
    2185           && ((*(p+2) == ' ') || (*(p+2) == '\t')))
    2186         {
    2187           p += 3;
    2188           while ((*p == ' ') || (*p == '\t'))
    2189             p++;
    2190           DB (DB_JOBS, (_("BUILTIN CD %s\n"), p));
    2191           if (chdir (p))
    2192             return 0;
    2193           else
    2194             return 1;
    2195         }
    2196       else if ((*(p) == 'r')
    2197           && (*(p+1) == 'm')
    2198           && ((*(p+2) == ' ') || (*(p+2) == '\t')))
    2199         {
    2200           int in_arg;
    2201 
    2202           /* rm  */
    2203           p += 3;
    2204           while ((*p == ' ') || (*p == '\t'))
    2205             p++;
    2206           in_arg = 1;
    2207 
    2208           DB (DB_JOBS, (_("BUILTIN RM %s\n"), p));
    2209           while (*p)
    2210             {
    2211               switch (*p)
    2212                 {
    2213                   case ' ':
    2214                   case '\t':
    2215                     if (in_arg)
    2216                       {
    2217                         *p++ = ';';
    2218                         in_arg = 0;
    2219                       }
    2220                     break;
    2221                   default:
    2222                     break;
    2223                 }
    2224               p++;
    2225             }
    2226         }
    2227       else
    2228         {
    2229           printf(_("Unknown builtin command '%s'\n"), cmd);
    2230           fflush(stdout);
    2231           return 0;
    2232         }
    2233     }
    2234 
    2235   /* Create a *.com file if either the command is too long for
    2236      lib$spawn, or the command contains a newline, or if redirection
    2237      is desired. Forcing commands with newlines into DCLs allows to
    2238      store search lists on user mode logicals.  */
    2239 
    2240   if (strlen (cmd) > MAXCMDLEN
    2241       || (have_redirection != 0)
    2242       || (have_newline != 0))
    2243     {
    2244       FILE *outfile;
    2245       char c;
    2246       char *sep;
    2247       int alevel = 0;   /* apostrophe level */
    2248 
    2249       if (strlen (cmd) == 0)
    2250         {
    2251           printf (_("Error, empty command\n"));
    2252           fflush (stdout);
    2253           return 0;
    2254         }
    2255 
    2256       outfile = open_tmpfile (&comname, "sys$scratch:CMDXXXXXX.COM");
    2257       if (outfile == 0)
    2258         pfatal_with_name (_("fopen (temporary file)"));
    2259 
    2260       if (ifile[0])
    2261         {
    2262           fprintf (outfile, "$ assign/user %s sys$input\n", ifile);
    2263           DB (DB_JOBS, (_("Redirected input from %s\n"), ifile));
    2264           ifiledsc.dsc$w_length = 0;
    2265         }
    2266 
    2267       if (efile[0])
    2268         {
    2269           fprintf (outfile, "$ define sys$error %s\n", efile);
    2270           DB (DB_JOBS, (_("Redirected error to %s\n"), efile));
    2271           efiledsc.dsc$w_length = 0;
    2272         }
    2273 
    2274       if (ofile[0])
    2275         {
    2276           fprintf (outfile, "$ define sys$output %s\n", ofile);
    2277           DB (DB_JOBS, (_("Redirected output to %s\n"), ofile));
    2278           ofiledsc.dsc$w_length = 0;
    2279         }
    2280 
    2281       p = sep = q = cmd;
    2282       for (c = '\n'; c; c = *q++)
    2283         {
    2284           switch (c)
    2285             {
    2286             case '\n':
    2287               /* At a newline, skip any whitespace around a leading $
    2288                  from the command and issue exactly one $ into the DCL. */
    2289               while (isspace ((unsigned char)*p))
    2290                 p++;
    2291               if (*p == '$')
    2292                 p++;
    2293               while (isspace ((unsigned char)*p))
    2294                 p++;
    2295               fwrite (p, 1, q - p, outfile);
    2296               fputc ('$', outfile);
    2297               fputc (' ', outfile);
    2298               /* Reset variables. */
    2299               p = sep = q;
    2300               break;
    2301 
    2302               /* Nice places for line breaks are after strings, after
    2303                  comma or space and before slash. */
    2304             case '"':
    2305               q = vms_handle_apos (q);
    2306               sep = q;
    2307               break;
    2308             case ',':
    2309             case ' ':
    2310               sep = q;
    2311               break;
    2312             case '/':
    2313             case '\0':
    2314               sep = q - 1;
    2315               break;
    2316             default:
    2317               break;
    2318             }
    2319           if (sep - p > 78)
    2320             {
    2321               /* Enough stuff for a line. */
    2322               fwrite (p, 1, sep - p, outfile);
    2323               p = sep;
    2324               if (*sep)
    2325                 {
    2326                   /* The command continues.  */
    2327                   fputc ('-', outfile);
    2328                 }
    2329               fputc ('\n', outfile);
    2330             }
    2331         }
    2332 
    2333       fwrite (p, 1, q - p, outfile);
    2334       fputc ('\n', outfile);
    2335 
    2336       fclose (outfile);
    2337 
    2338       sprintf (cmd, "$ @%s", comname);
    2339 
    2340       DB (DB_JOBS, (_("Executing %s instead\n"), cmd));
    2341     }
    2342 
    2343   cmddsc.dsc$w_length = strlen(cmd);
    2344   cmddsc.dsc$a_pointer = cmd;
    2345   cmddsc.dsc$b_dtype = DSC$K_DTYPE_T;
    2346   cmddsc.dsc$b_class = DSC$K_CLASS_S;
    2347 
    2348   child->efn = 0;
    2349   while (child->efn < 32 || child->efn > 63)
    2350     {
    2351       status = lib$get_ef ((unsigned long *)&child->efn);
    2352       if (!(status & 1))
    2353         return 0;
    2354     }
    2355 
    2356   sys$clref (child->efn);
    2357 
    2358   vms_jobsefnmask |= (1 << (child->efn - 32));
    2359 
    2360 /*
    2361              LIB$SPAWN  [command-string]
    2362                         [,input-file]
    2363                         [,output-file]
    2364                         [,flags]
    2365                         [,process-name]
    2366                         [,process-id] [,completion-status-address] [,byte-integer-event-flag-num]
    2367                         [,AST-address] [,varying-AST-argument]
    2368                         [,prompt-string] [,cli] [,table]
    2369 */
    2370 
    2371 #ifndef DONTWAITFORCHILD
    2372 /*
    2373  *      Code to make ctrl+c and ctrl+y working.
    2374  *      The problem starts with the synchronous case where after lib$spawn is
    2375  *      called any input will go to the child. But with input re-directed,
    2376  *      both control characters won't make it to any of the programs, neither
    2377  *      the spawning nor to the spawned one. Hence the caller needs to spawn
    2378  *      with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr
    2379  *      has to follow to simulate the wanted synchronous behaviour.
    2380  *      The next problem is ctrl+y which isn't caught by the crtl and
    2381  *      therefore isn't converted to SIGQUIT (for a signal handler which is
    2382  *      already established). The only way to catch ctrl+y, is an AST
    2383  *      assigned to the input channel. But ctrl+y handling of DCL needs to be
    2384  *      disabled, otherwise it will handle it. Not to mention the previous
    2385  *      ctrl+y handling of DCL needs to be re-established before make exits.
    2386  *      One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will
    2387  *      make it to the signal handler after the child "normally" terminates.
    2388  *      This isn't enough. It seems reasonable for simple command lines like
    2389  *      a 'cc foobar.c' spawned in a subprocess but it is unacceptable for
    2390  *      spawning make. Therefore we need to abort the process in the AST.
    2391  *
    2392  *      Prior to the spawn it is checked if an AST is already set up for
    2393  *      ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general
    2394  *      this will work except if make is run in a batch environment, but there
    2395  *      nobody can press ctrl+y. During the setup the DCL handling of ctrl+y
    2396  *      is disabled and an exit handler is established to re-enable it.
    2397  *      If the user interrupts with ctrl+y, the assigned AST will fire, force
    2398  *      an abort to the subprocess and signal SIGQUIT, which will be caught by
    2399  *      the already established handler and will bring us back to common code.
    2400  *      After the spawn (now /nowait) a sys$waitfr simulates the /wait and
    2401  *      enables the ctrl+y be delivered to this code. And the ctrl+c too,
    2402  *      which the crtl converts to SIGINT and which is caught by the common
    2403  *      signal handler. Because signals were blocked before entering this code
    2404  *      sys$waitfr will always complete and the SIGQUIT will be processed after
    2405  *      it (after termination of the current block, somewhere in common code).
    2406  *      And SIGINT too will be delayed. That is ctrl+c can only abort when the
    2407  *      current command completes. Anyway it's better than nothing :-)
    2408  */
    2409 
    2410   if (!setupYAstTried)
    2411     tryToSetupYAst();
    2412   status = lib$spawn (&cmddsc,                                  /* cmd-string  */
    2413                       (ifiledsc.dsc$w_length == 0)?0:&ifiledsc, /* input-file  */
    2414                       (ofiledsc.dsc$w_length == 0)?0:&ofiledsc, /* output-file */
    2415                       &spflags,                                 /* flags  */
    2416                       &pnamedsc,                                /* proc name  */
    2417                       &child->pid, &child->cstatus, &child->efn,
    2418                       0, 0,
    2419                       0, 0, 0);
    2420   if (status & 1)
    2421     {
    2422       pidToAbort= child->pid;
    2423       status= sys$waitfr (child->efn);
    2424       pidToAbort= 0;
    2425       vmsHandleChildTerm(child);
    2426     }
    2427 #else
    2428   status = lib$spawn (&cmddsc,
    2429                       (ifiledsc.dsc$w_length == 0)?0:&ifiledsc,
    2430                       (ofiledsc.dsc$w_length == 0)?0:&ofiledsc,
    2431                       &spflags,
    2432                       &pnamedsc,
    2433                       &child->pid, &child->cstatus, &child->efn,
    2434                       vmsHandleChildTerm, child,
    2435                       0, 0, 0);
    2436 #endif
    2437 
    2438   if (!(status & 1))
    2439     {
    2440       printf (_("Error spawning, %d\n") ,status);
    2441       fflush (stdout);
    2442       switch (status)
    2443         {
    2444         case 0x1c:
    2445           errno = EPROCLIM;
    2446           break;
    2447         default:
    2448           errno = EFAIL;
    2449         }
    2450     }
    2451 
    2452   if (comname && !ISDB (DB_JOBS))
    2453     unlink (comname);
    2454 
    2455   return (status & 1);
    2456 }
    2457 
    2458 #else /* !VMS */
    24591938
    24601939/* EMX: Start a child process. This function returns the new pid.  */
    2461 # if defined __MSDOS__ ||  defined __EMX__
    24621940/* The child argument can be NULL (that's why we return the pid), if it is
    24631941   and the shell is a dllshell:// a child structure is created and inserted
     
    24661944   BTW. the name of this function in this port is very misleading, spawn_job
    24671945   would perhaps be more appropriate. */
    2468 
     1946# if defined __MSDOS__ || defined __EMX__
    24691947int
    24701948child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp,
     
    25091987#endif
    25101988
    2511   /* Restore stdout/stdin of the parent process.  */
    2512   if (stdin_fd != 0 && dup2 (save_stdin, 0) != 0)
    2513     fatal (NILF, _("restoring of stdin failed\n"));
    2514   if (stdout_fd != 1 && dup2 (save_stdout, 1) != 1)
    2515     fatal (NILF, _("restoring of stdout failed\n"));
    2516 
    2517   /* Cleanup handles */
     1989  /* Restore stdout/stdin of the parent and close temporary FDs.  */
    25181990  if (stdin_fd != 0)
    2519     close (save_stdin);
     1991    {
     1992      if (dup2 (save_stdin, 0) != 0)
     1993        fatal (NILF, _("Could not restore stdin\n"));
     1994      else
     1995        close (save_stdin);
     1996    }
     1997
    25201998  if (stdout_fd != 1)
    2521     close (save_stdout);
     1999    {
     2000      if (dup2 (save_stdout, 1) != 1)
     2001        fatal (NILF, _("Could not restore stdout\n"));
     2002      else
     2003        close (save_stdout);
     2004    }
    25222005
    25232006  return pid;
     
    25462029}
    25472030#endif /* !AMIGA && !__MSDOS__ */
    2548 #endif /* !VMS */
    25492031#endif /* !WINDOWS32 */
    25502032
     
    26782160int
    26792161# else
    2680  void
     2162void
    26812163# endif
    26822164exec_command (char **argv, char **envp)
     
    27182200
    27192201  /* wait and reap last child */
    2720   while (hWaitPID = process_wait_for_any())
     2202  hWaitPID = process_wait_for_any();
     2203  while (hWaitPID)
    27212204    {
    27222205      /* was an error found on this process? */
     
    27862269        char **new_argv;
    27872270        int argc;
     2271        int i=1;
    27882272
    27892273# ifdef __EMX__
     
    28042288          ++argc;
    28052289
     2290# ifdef __EMX__
     2291        if (!unixy_shell)
     2292          ++argc;
     2293# endif
     2294
    28062295        new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *));
    28072296        new_argv[0] = shell;
    2808         new_argv[1] = argv[0];
     2297
     2298# ifdef __EMX__
     2299        if (!unixy_shell)
     2300          {
     2301            new_argv[1] = "/c";
     2302            ++i;
     2303            --argc;
     2304          }
     2305# endif
     2306
     2307        new_argv[i] = argv[0];
    28092308        while (argc > 0)
    28102309          {
    2811             new_argv[1 + argc] = argv[argc];
     2310            new_argv[i + argc] = argv[argc];
    28122311            --argc;
    28132312          }
     
    29772476  char*  sh_chars;
    29782477  char** sh_cmds;
     2478#elif defined(__riscos__)
     2479  static char sh_chars[] = "";
     2480  static char *sh_cmds[] = { 0 };
    29792481#else  /* must be UNIX-ish */
    29802482  static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~!";
     
    32542756                register int j;
    32552757                for (j = 0; sh_cmds[j] != 0; ++j)
    3256                   if (streq (sh_cmds[j], new_argv[0]))
    3257                     goto slow;
     2758                  {
     2759                    if (streq (sh_cmds[j], new_argv[0]))
     2760                      goto slow;
     2761# ifdef __EMX__
     2762                    /* Non-Unix shells are case insensitive.  */
     2763                    if (!unixy_shell
     2764                        && strcasecmp (sh_cmds[j], new_argv[0]) == 0)
     2765                      goto slow;
     2766# endif
     2767                  }
    32582768              }
    32592769
     
    32932803    /* Line was empty.  */
    32942804    return 0;
    3295   else
    3296     return new_argv;
     2805
     2806  return new_argv;
    32972807
    32982808 slow:;
     
    34432953      int id = GetCurrentProcessId();
    34442954      PATH_VAR(fbuf);
    3445       char* fname = NULL;
    34462955
    34472956      /* create a file name */
    34482957      sprintf(fbuf, "make%d", id);
    3449       fname = tempnam(".", fbuf);
    3450 
    3451           /* create batch file name */
    3452       *batch_filename_ptr = xmalloc(strlen(fname) + 5);
    3453       strcpy(*batch_filename_ptr, fname);
    3454 
    3455       /* make sure path name is in DOS backslash format */
    3456       if (!unixy_shell) {
    3457         fname = *batch_filename_ptr;
    3458         for (i = 0; fname[i] != '\0'; ++i)
    3459           if (fname[i] == '/')
    3460             fname[i] = '\\';
    3461         strcat(*batch_filename_ptr, ".bat");
    3462       } else {
    3463         strcat(*batch_filename_ptr, ".sh");
    3464       }
     2958      *batch_filename_ptr = create_batch_filename (fbuf, unixy_shell);
    34652959
    34662960      DB (DB_JOBS, (_("Creating temporary batch file %s\n"),
     
    34912985                                                  (char *) 0, (char *) 0,
    34922986                                                  (char **) 0);
    3493 # ifdef __EMX__
     2987#ifdef __EMX__
    34942988    else if (!unixy_shell)
    34952989      {
    3496         /* new_line is local, must not be freed therefore */
    3497         char *p, *q;
    3498         int quote;
    3499         size_t index;
    3500         size_t len;
    3501 
    3502         /* handle quotes
    3503            We have to remove all double quotes and to split the line
    3504            into distinct arguments because of the strange handling
    3505            of builtin commands by cmd: 'echo "bla"' prints "bla"
    3506            (with quotes) while 'c:\bin\echo.exe "bla"' prints bla
    3507            (without quotes). Some programs like autoconf rely
    3508            on the second behaviour. */
    3509 
    3510         len = strlen (new_line) + 1;
    3511 
    3512         /* More than 1 arg per character is impossible.  */
    3513         new_argv = (char **) xmalloc (len * sizeof (char *));
    3514 
    3515         /* All the args can fit in a buffer as big as new_line is.   */
    3516         new_argv[0] = (char *) xmalloc (len);
    3517 
    3518         index = 0;
    3519         quote = 0;
    3520         q = new_line;
    3521         p = new_argv[index];
    3522         while(*q != '\0')
    3523           {
    3524             /* searching for closing quote */
    3525             if (quote)
    3526               {
    3527                 if (*q == quote)
    3528                   {
    3529                     /* remove the quote */
    3530                     q++;
    3531                     quote = 0;
    3532                   }
    3533                 else /* normal character: copy it */
    3534                   *p++ = *q++;
    3535               }
    3536 
    3537             /* searching for opening quote */
    3538             else if (*q == '\"'
    3539 #  ifndef NO_CMD_DEFAULT
    3540                      || *q == '\''
    3541 #  endif
    3542                      )
    3543               {
    3544                 /* remove opening quote */
    3545                 quote = *q;
    3546                 q++;
    3547               }
    3548 
    3549             /* spaces outside of a quoted string: remove them
    3550                and start a new argument */
    3551             else if (*q == ' ' || *q == '\t')
    3552               {
    3553                 *p++ = '\0'; /* trailing '\0' for last argument */
    3554 
    3555                 /* remove all successive spaces */
    3556                 do
    3557                   {
    3558                     q++;
    3559                   }
    3560                 while(*q == ' ' || *q == '\t');
    3561 
    3562                 /* start new argument */
    3563                 index++;
    3564                 new_argv[index] = p;
    3565               }
    3566 
    3567             /* normal character (no space) outside a quoted string*/
    3568             else
    3569               *p++ = *q++;
    3570           } /* end while() */
    3571 
    3572         *p = '\0'; /* trailing '\0' for the last argument */
    3573         new_argv[index + 1] = NULL;
    3574 
    3575 #  ifndef NO_CMD_DEFAULT
    3576         /* special case: echo x="y"
    3577            (e.g. autoconf uses this to determine whether make works)
    3578            this is pure idioty but cmd works this way:
    3579            if 'echo' and 'x="y"' are two different arguments cmd
    3580            will print '"x="y""' but if they are only one argument
    3581            cmd will print 'bla="blurb"' as it should be
    3582            note: if we do not allow cmd to be the default shell
    3583            we do not need this kind of voodoo */
    3584         if (index == 3 && strcasecmp(new_argv[2], "echo") == 0)
    3585           {
    3586             new_argv[2][4] = ' ';
    3587             new_argv[3] = NULL;
    3588           }
    3589 #  endif
     2990        /* new_line is local, must not be freed therefore
     2991           We use line here instead of new_line because we run the shell
     2992           manually.  */
     2993        size_t line_len = strlen (line);
     2994        char *p = new_line;
     2995        char *q = new_line;
     2996        memcpy (new_line, line, line_len + 1);
     2997        /* replace all backslash-newline combination and also following tabs */
     2998        while (*q != '\0')
     2999          {
     3000            if (q[0] == '\\' && q[1] == '\n')
     3001              {
     3002                q += 2; /* remove '\\' and '\n' */
     3003                if (q[0] == '\t')
     3004                  q++; /* remove 1st tab in the next line */
     3005              }
     3006            else
     3007              *p++ = *q++;
     3008          }
     3009        *p = '\0';
     3010
     3011# ifndef NO_CMD_DEFAULT
     3012        if (strnicmp (new_line, "echo", 4) == 0
     3013            && (new_line[4] == ' ' || new_line[4] == '\t'))
     3014          {
     3015            /* the builtin echo command: handle it separately */
     3016            size_t echo_len = line_len - 5;
     3017            char *echo_line = new_line + 5;
     3018
     3019            /* special case: echo 'x="y"'
     3020               cmd works this way: a string is printed as is, i.e., no quotes
     3021               are removed. But autoconf uses a command like echo 'x="y"' to
     3022               determine whether make works. autoconf expects the output x="y"
     3023               so we will do exactly that.
     3024               Note: if we do not allow cmd to be the default shell
     3025               we do not need this kind of voodoo */
     3026            if (echo_line[0] == '\''
     3027                && echo_line[echo_len - 1] == '\''
     3028                && strncmp (echo_line + 1, "ac_maketemp=",
     3029                            strlen ("ac_maketemp=")) == 0)
     3030              {
     3031                /* remove the enclosing quotes */
     3032                memmove (echo_line, echo_line + 1, echo_len - 2);
     3033                echo_line[echo_len - 2] = '\0';
     3034              }
     3035          }
     3036# endif
     3037
     3038        {
     3039          /* Let the shell decide what to do. Put the command line into the
     3040             2nd command line argument and hope for the best ;-)  */
     3041          size_t sh_len = strlen (shell);
     3042
     3043          /* exactly 3 arguments + NULL */
     3044          new_argv = (char **) xmalloc (4 * sizeof (char *));
     3045          /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times
     3046             the trailing '\0' */
     3047          new_argv[0] = (char *) malloc (sh_len + line_len + 5);
     3048          memcpy (new_argv[0], shell, sh_len + 1);
     3049          new_argv[1] = new_argv[0] + sh_len + 1;
     3050          memcpy (new_argv[1], "/c", 3);
     3051          new_argv[2] = new_argv[1] + 3;
     3052          memcpy (new_argv[2], new_line, line_len + 1);
     3053          new_argv[3] = NULL;
     3054        }
    35903055      }
    35913056#elif defined(__MSDOS__)
     
    37683233}
    37693234#endif /* !HAPE_DUP2 && !_AMIGA */
     3235
     3236/* On VMS systems, include special VMS functions.  */
     3237
     3238#ifdef VMS
     3239#include "vmsjobs.c"
     3240#endif
  • trunk/src/gmake/job.h

    r227 r287  
    109109#endif
    110110
     111extern unsigned int jobserver_tokens;
     112
    111113#ifdef MAKE_DLLSHELL
    112114extern pid_t wait_jobs PARAMS ((int *status, int block));
  • trunk/src/gmake/main.c

    r218 r287  
    11/* Argument parsing and main program of GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
    3 2002, 2003 Free Software Foundation, Inc.
     32002, 2003, 2005 Free Software Foundation, Inc.
    44This file is part of GNU Make.
    55
     
    3636#ifdef WINDOWS32
    3737#include <windows.h>
     38#include <io.h>
    3839#include "pathstuff.h"
    3940#endif
     
    4445#ifdef HAVE_FCNTL_H
    4546# include <fcntl.h>
     47#endif
     48
     49#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
     50# define SET_STACK_SIZE
     51#endif
     52
     53#ifdef SET_STACK_SIZE
     54# include <sys/resource.h>
    4655#endif
    4756
     
    186195int default_keep_going_flag = 0;
    187196
     197/* Nonzero means check symlink mtimes.  */
     198
     199int check_symlink_flag = 0;
     200
    188201/* Nonzero means print directory before starting and when done (-w).  */
    189202
     
    207220unsigned int job_slots = 1;
    208221unsigned int default_job_slots = 1;
     222static unsigned int master_job_slots = 0;
    209223
    210224/* Value of job_slots that means no limit.  */
     
    260274
    261275int always_make_flag = 0;
     276
     277/* If nonzero, we're in the "try to rebuild makefiles" phase.  */
     278
     279int rebuilding_makefiles = 0;
     280
     281/* Remember the original value of the SHELL variable, from the environment.  */
     282
     283struct variable shell_var;
     284
    262285
    263286
     
    301324                              Don't start multiple jobs unless load is below N.\n"),
    302325    N_("\
     326  -L, --check-symlink-times   Use the latest mtime between symlinks and target.\n"),
     327    N_("\
    303328  -n, --just-print, --dry-run, --recon\n\
    304329                              Don't actually run any commands; just print them.\n"),
     
    348373#endif
    349374    { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
    350         "environment-overrides", },
     375      "environment-overrides", },
    351376    { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" },
    352377    { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" },
    353378    { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
    354         "ignore-errors" },
     379      "ignore-errors" },
    355380    { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
    356         "include-dir" },
     381      "include-dir" },
    357382    { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs,
    358         (char *) &default_job_slots, "jobs" },
     383      (char *) &default_job_slots, "jobs" },
    359384    { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0,
    360         "jobserver-fds" },
     385      "jobserver-fds" },
    361386    { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0,
    362         (char *) &default_keep_going_flag, "keep-going" },
     387      (char *) &default_keep_going_flag, "keep-going" },
    363388#ifndef NO_FLOAT
    364389    { 'l', floating, (char *) &max_load_average, 1, 1, 0,
    365         (char *) &default_load_average, (char *) &default_load_average,
    366         "load-average" },
     390      (char *) &default_load_average, (char *) &default_load_average,
     391      "load-average" },
    367392#else
    368393    { 'l', positive_int, (char *) &max_load_average, 1, 1, 0,
    369         (char *) &default_load_average, (char *) &default_load_average,
    370         "load-average" },
    371 #endif
     394      (char *) &default_load_average, (char *) &default_load_average,
     395      "load-average" },
     396#endif
     397    { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0,
     398      "check-symlink-times" },
    372399    { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 },
    373400    { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
    374401    { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" },
    375402    { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
    376         "print-data-base" },
     403      "print-data-base" },
    377404    { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" },
    378405    { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
    379406      "no-builtin-rules" },
    380407    { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0,
    381         "no-builtin-variables" },
     408      "no-builtin-variables" },
    382409    { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" },
    383410    { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0,
     
    386413    { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" },
    387414    { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
    388         "print-directory" },
     415      "print-directory" },
    389416    { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
    390         "no-print-directory" },
     417      "no-print-directory" },
    391418    { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" },
    392419    { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    393         "warn-undefined-variables" },
     420      "warn-undefined-variables" },
    394421    { 0 }
    395422  };
     
    446473
    447474struct file *default_goal_file;
     475
     476/* Pointer to the value of the .DEFAULT_GOAL special
     477   variable.  */
     478char ** default_goal_name;
    448479
    449480/* Pointer to structure for the file .DEFAULT
     
    551582/* Toggle -d on receipt of SIGUSR1.  */
    552583
     584#ifdef SIGUSR1
    553585static RETSIGTYPE
    554586debug_signal_handler (int sig UNUSED)
     
    556588  db_level = db_level ? DB_NONE : DB_BASIC;
    557589}
     590#endif
    558591
    559592static void
     
    701734{
    702735  int sh_found = 0;
    703   char* search_token;
     736  char *search_token;
     737  char *tokend;
    704738  PATH_VAR(sh_path);
    705739  extern char *default_shell;
     
    710744    search_token = token;
    711745
    712   if (!no_default_sh_exe &&
    713       (token == NULL || !strcmp(search_token, default_shell))) {
     746
     747  /* If the user explicitly requests the DOS cmd shell, obey that request.
     748     However, make sure that's what they really want by requiring the value
     749     of SHELL either equal, or have a final path element of, "cmd" or
     750     "cmd.exe" case-insensitive.  */
     751  tokend = search_token + strlen (search_token) - 3;
     752  if (((tokend == search_token
     753        || (tokend > search_token
     754            && (tokend[-1] == '/' || tokend[-1] == '\\')))
     755       && !strcmpi (tokend, "cmd"))
     756      || ((tokend - 4 == search_token
     757           || (tokend - 4 > search_token
     758               && (tokend[-5] == '/' || tokend[-5] == '\\')))
     759          && !strcmpi (tokend - 4, "cmd.exe"))) {
     760    batch_mode_shell = 1;
     761    unixy_shell = 0;
     762    sh_found = 0;
     763  } else if (!no_default_sh_exe &&
     764             (token == NULL || !strcmp (search_token, default_shell))) {
    714765    /* no new information, path already set or known */
    715766    sh_found = 1;
     
    723774  } else {
    724775    char *p;
    725     struct variable *v = lookup_variable ("Path", 4);
    726 
    727     /*
    728      * Search Path for shell
    729      */
     776    struct variable *v = lookup_variable ("PATH", 4);
     777
     778    /* Search Path for shell */
    730779    if (v && v->value) {
    731780      char *ep;
     
    846895  struct file *f;
    847896  int i;
     897  int makefile_status = MAKE_SUCCESS;
    848898  char **p;
    849899  struct dep *read_makefiles;
     
    858908  unixy_shell = 0;
    859909  no_default_sh_exe = 1;
     910#endif
     911
     912#ifdef SET_STACK_SIZE
     913 /* Get rid of any avoidable limit on stack size.  */
     914  {
     915    struct rlimit rlim;
     916
     917    /* Set the stack limit huge so that alloca does not fail.  */
     918    if (getrlimit (RLIMIT_STACK, &rlim) == 0)
     919      {
     920        rlim.rlim_cur = rlim.rlim_max;
     921        setrlimit (RLIMIT_STACK, &rlim);
     922      }
     923  }
    860924#endif
    861925
     
    9831047        program = argv[0] + 1;
    9841048#endif
     1049#ifdef WINDOWS32
     1050      if (program == 0)
     1051        {
     1052          /* Extract program from full path */
     1053          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"))
     1060            {
     1061              /* Remove .exe extension */
     1062              p[argv0_len - 4] = '\0';
     1063              /* Increment past the initial '\' */
     1064              program = p + 1;
     1065            }
     1066        }
     1067#endif
    9851068      if (program == 0)
    9861069        program = argv[0];
     
    10031086    {
    10041087#ifdef  HAVE_GETCWD
    1005       perror_with_name ("getcwd: ", "");
     1088      perror_with_name ("getcwd", "");
    10061089#else
    10071090      error (NILF, "getwd: %s", current_directory);
     
    10191102  /* Initialize the special variables.  */
    10201103  define_variable (".VARIABLES", 10, "", o_default, 0)->special = 1;
    1021   /* define_variable (".TARGETS", 8, "", o_default, 0); */
     1104  /* define_variable (".TARGETS", 8, "", o_default, 0)->special = 1; */
     1105
     1106  /* Set up .FEATURES */
     1107  define_variable (".FEATURES", 9,
     1108                   "target-specific order-only second-expansion",
     1109                   o_default, 0);
     1110#ifdef MAKE_JOBSERVER
     1111  do_variable_definition (NILF, ".FEATURES", "jobserver",
     1112                          o_default, f_append, 0);
     1113#endif
     1114#ifdef MAKE_SYMLINKS
     1115  do_variable_definition (NILF, ".FEATURES", "check-symlink",
     1116                          o_default, f_append, 0);
     1117#endif
    10221118
    10231119  /* Read in variables from the environment.  It is important that this be
     
    10281124  for (i = 0; envp[i] != 0; ++i)
    10291125    {
    1030       int do_not_define;
    1031       register char *ep = envp[i];
    1032 
    1033       /* by default, everything gets defined and exported */
    1034       do_not_define = 0;
    1035 
    1036       while (*ep != '=')
     1126      int do_not_define = 0;
     1127      char *ep = envp[i];
     1128
     1129      while (*ep != '\0' && *ep != '=')
    10371130        ++ep;
    10381131#ifdef WINDOWS32
    10391132      if (!unix_path && strneq(envp[i], "PATH=", 5))
    10401133        unix_path = ep+1;
    1041       else if (!windows32_path && !strnicmp(envp[i], "Path=", 5)) {
     1134      else if (!strnicmp(envp[i], "Path=", 5)) {
    10421135        do_not_define = 1; /* it gets defined after loop exits */
    1043         windows32_path = ep+1;
     1136        if (!windows32_path)
     1137          windows32_path = ep+1;
    10441138      }
    10451139#endif
     
    10481142         the same.  */
    10491143      if (!do_not_define)
    1050         define_variable (envp[i], (unsigned int) (ep - envp[i]),
    1051                          ep + 1, o_env, 1)
    1052         /* Force exportation of every variable culled from the environment.
    1053            We used to rely on target_environment's v_default code to do this.
    1054            But that does not work for the case where an environment variable
    1055            is redefined in a makefile with `override'; it should then still
    1056            be exported, because it was originally in the environment.  */
    1057         ->export = v_export;
     1144        {
     1145          struct variable *v;
     1146
     1147          v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
     1148                               ep + 1, o_env, 1);
     1149          /* Force exportation of every variable culled from the environment.
     1150             We used to rely on target_environment's v_default code to do this.
     1151             But that does not work for the case where an environment variable
     1152             is redefined in a makefile with `override'; it should then still
     1153             be exported, because it was originally in the environment.  */
     1154          v->export = v_export;
     1155
     1156          /* 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)
     1160            {
     1161#ifndef __MSDOS__
     1162              v->export = v_noexport;
     1163#endif
     1164              shell_var.name = "SHELL";
     1165              shell_var.value = xstrdup (ep + 1);
     1166            }
     1167        }
    10581168    }
    10591169#ifdef WINDOWS32
    1060     /*
    1061      * Make sure that this particular spelling of 'Path' is available
     1170    /* If we didn't find a correctly spelled PATH we define PATH as
     1171     * either the first mispelled value or an empty string
    10621172     */
    1063     if (windows32_path)
    1064       define_variable("Path", 4, windows32_path, o_env, 1)->export = v_export;
    1065     else if (unix_path)
    1066       define_variable("Path", 4, unix_path, o_env, 1)->export = v_export;
    1067     else
    1068       define_variable("Path", 4, "", o_env, 1)->export = v_export;
    1069 
    1070     /*
    1071      * PATH defaults to Path iff PATH not found and Path is found.
    1072      */
    1073     if (!unix_path && windows32_path)
    1074       define_variable("PATH", 4, windows32_path, o_env, 1)->export = v_export;
     1173    if (!unix_path)
     1174      define_variable("PATH", 4,
     1175                      windows32_path ? windows32_path : "",
     1176                      o_env, 1)->export = v_export;
    10751177#endif
    10761178#else /* For Amiga, read the ENV: device, ignoring all dirs */
     
    12421344      {
    12431345        char *dir = directories->list[i];
     1346        char *expanded = 0;
    12441347        if (dir[0] == '~')
    12451348          {
    1246             char *expanded = tilde_expand (dir);
     1349            expanded = tilde_expand (dir);
    12471350            if (expanded != 0)
    12481351              dir = expanded;
    12491352          }
     1353#ifdef WINDOWS32
     1354        /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
     1355           But allow -C/ just in case someone wants that.  */
     1356        {
     1357          char *p = dir + strlen (dir) - 1;
     1358          while (p > dir && (p[0] == '/' || p[0] == '\\'))
     1359            --p;
     1360          p[1] = '\0';
     1361        }
     1362#endif
    12501363        if (chdir (dir) < 0)
    12511364          pfatal_with_name (dir);
    1252         if (dir != directories->list[i])
    1253           free (dir);
     1365        if (expanded)
     1366          free (expanded);
    12541367      }
    12551368
     
    13061419        {
    13071420#ifdef  HAVE_GETCWD
    1308           perror_with_name ("getcwd: ", "");
     1421          perror_with_name ("getcwd", "");
    13091422#else
    13101423          error (NILF, "getwd: %s", current_directory);
     
    13731486            if (outfile == 0)
    13741487              pfatal_with_name (_("fopen (temporary file)"));
    1375             while (!feof (stdin))
     1488            while (!feof (stdin) && ! ferror (stdin))
    13761489              {
    13771490                char buf[2048];
     
    14531566  define_default_variables ();
    14541567
     1568  default_file = enter_file (".DEFAULT");
     1569
     1570  {
     1571    struct variable *v = define_variable (".DEFAULT_GOAL", 13, "", o_file, 0);
     1572    default_goal_name = &v->value;
     1573  }
     1574
    14551575  /* Read all the makefiles.  */
    1456 
    1457   default_file = enter_file (".DEFAULT");
    14581576
    14591577  read_makefiles
     
    15851703         want job_slots to be 0 to indicate we're using the jobserver.  */
    15861704
     1705      master_job_slots = job_slots;
     1706
    15871707      while (--job_slots)
    15881708        {
     
    16041724      jobserver_fds->idx = 1;
    16051725      jobserver_fds->max = 1;
     1726    }
     1727#endif
     1728
     1729#ifndef MAKE_SYMLINKS
     1730  if (check_symlink_flag)
     1731    {
     1732      error (NILF, _("Symbolic links not supported: disabling -L."));
     1733      check_symlink_flag = 0;
    16061734    }
    16071735#endif
     
    16731801      int nargc = argc;
    16741802      int orig_db_level = db_level;
     1803      int status;
    16751804
    16761805      if (! ISDB (DB_MAKEFILES))
     
    17331862      define_makeflags (1, 1);
    17341863
    1735       switch (update_goal_chain (read_makefiles, 1))
     1864      rebuilding_makefiles = 1;
     1865      status = update_goal_chain (read_makefiles);
     1866      rebuilding_makefiles = 0;
     1867
     1868      switch (status)
    17361869        {
    17371870        case 1:
     
    17821915                        any_remade |= (mtime != NONEXISTENT_MTIME
    17831916                                       && mtime != makefile_mtimes[i]);
     1917                        makefile_status = MAKE_FAILURE;
    17841918                      }
    17851919                  }
     
    18712005#ifndef _AMIGA
    18722006          for (p = environ; *p != 0; ++p)
    1873             if ((*p)[MAKELEVEL_LENGTH] == '='
    1874                 && strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH))
     2007            if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
     2008                && (*p)[MAKELEVEL_LENGTH] == '=')
    18752009              {
    18762010                /* The SGI compiler apparently can't understand
     
    19272061            int pid;
    19282062            int status;
    1929             pid = child_execute_job(0, 1, nargv, environ, NULL);
     2063            pid = child_execute_job (0, 1, nargv, environ, NULL);
    19302064
    19312065            /* is this loop really necessary? */
    19322066            do {
    1933               pid = wait(&status);
    1934             } while(pid <= 0);
     2067              pid = wait (&status);
     2068            } while (pid <= 0);
    19352069            /* use the exit code of the child process */
    1936             exit(WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
     2070            exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
    19372071          }
    19382072#else
     
    19482082
    19492083      db_level = orig_db_level;
     2084
     2085      /* Free the makefile mtimes (if we allocated any).  */
     2086      if (makefile_mtimes)
     2087        free ((char *) makefile_mtimes);
    19502088    }
    19512089
     
    19642102    if (goals == 0)
    19652103      {
    1966         if (default_goal_file != 0)
    1967           {
    1968             goals = (struct dep *) xmalloc (sizeof (struct dep));
    1969             goals->next = 0;
    1970             goals->name = 0;
     2104        if (**default_goal_name != '\0')
     2105          {
     2106            if (default_goal_file == 0 ||
     2107                strcmp (*default_goal_name, default_goal_file->name) != 0)
     2108              {
     2109                default_goal_file = lookup_file (*default_goal_name);
     2110
     2111                /* In case user set .DEFAULT_GOAL to a non-existent target
     2112                   name let's just enter this name into the table and let
     2113                   the standard logic sort it out. */
     2114                if (default_goal_file == 0)
     2115                  {
     2116                    struct nameseq *ns;
     2117                    char *p = *default_goal_name;
     2118
     2119                    ns = multi_glob (
     2120                      parse_file_seq (&p, '\0', sizeof (struct nameseq), 1),
     2121                      sizeof (struct nameseq));
     2122
     2123                    /* .DEFAULT_GOAL should contain one target. */
     2124                    if (ns->next != 0)
     2125                      fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
     2126
     2127                    default_goal_file = enter_file (ns->name);
     2128
     2129                    ns->name = 0; /* It was reused by enter_file(). */
     2130                    free_ns_chain (ns);
     2131                  }
     2132              }
     2133
     2134            goals = (struct dep *) xmalloc (sizeof (struct dep));
     2135            goals->next = 0;
     2136            goals->name = 0;
    19712137            goals->ignore_mtime = 0;
    1972             goals->file = default_goal_file;
    1973           }
     2138            goals->need_2nd_expansion = 0;
     2139            goals->file = default_goal_file;
     2140          }
    19742141      }
    19752142    else
    19762143      lastgoal->next = 0;
     2144
    19772145
    19782146    if (!goals)
     
    19882156    DB (DB_BASIC, (_("Updating goal targets....\n")));
    19892157
    1990     switch (update_goal_chain (goals, 0))
     2158    switch (update_goal_chain (goals))
    19912159    {
    19922160      case -1:
     
    19942162      case 0:
    19952163        /* Updated successfully.  */
    1996         status = MAKE_SUCCESS;
     2164        status = makefile_status;
    19972165        break;
    19982166      case 1:
     
    20982266  if (v != 0)
    20992267    {
    2100       /* It is indeed a variable definition.  Record a pointer to
    2101          the variable for later use in define_makeflags.  */
    2102       struct command_variable *cv
    2103         = (struct command_variable *) xmalloc (sizeof (*cv));
    2104       cv->variable = v;
    2105       cv->next = command_variables;
    2106       command_variables = cv;
     2268      /* It is indeed a variable definition.  If we don't already have this
     2269         one, record a pointer to the variable for later use in
     2270         define_makeflags.  */
     2271      struct command_variable *cv;
     2272
     2273      for (cv = command_variables; cv != 0; cv = cv->next)
     2274        if (cv->variable == v)
     2275          break;
     2276
     2277      if (! cv) {
     2278        cv = (struct command_variable *) xmalloc (sizeof (*cv));
     2279        cv->variable = v;
     2280        cv->next = command_variables;
     2281        command_variables = cv;
     2282      }
    21072283    }
    21082284  else if (! env)
     
    21272303      lastgoal->file = f;
    21282304      lastgoal->ignore_mtime = 0;
     2305      lastgoal->need_2nd_expansion = 0;
    21292306
    21302307      {
     
    27752952  if (!dying)
    27762953    {
     2954      char token = '+';
    27772955      int err;
    27782956
     
    27942972      if (print_data_base_flag)
    27952973        print_data_base ();
     2974
     2975      /* Sanity: have we written all our jobserver tokens back?  If our
     2976         exit status is 2 that means some kind of syntax error; we might not
     2977         have written all our tokens so do that now.  If tokens are left
     2978         after any other error code, that's bad.  */
     2979
     2980      if (job_fds[0] != -1 && jobserver_tokens)
     2981        {
     2982          if (status != 2)
     2983            error (NILF,
     2984                   "INTERNAL: Exiting with %u jobserver tokens (should be 0)!",
     2985                   jobserver_tokens);
     2986          else
     2987            while (jobserver_tokens--)
     2988              {
     2989                int r;
     2990
     2991                EINTRLOOP (r, write (job_fds[1], &token, 1));
     2992                if (r != 1)
     2993                  perror_with_name ("write", "");
     2994              }
     2995        }
     2996
     2997
     2998      /* Sanity: If we're the master, were all the tokens written back?  */
     2999
     3000      if (master_job_slots)
     3001        {
     3002          /* We didn't write one for ourself, so start at 1.  */
     3003          unsigned int tcnt = 1;
     3004
     3005          /* Close the write side, so the read() won't hang.  */
     3006          close (job_fds[1]);
     3007
     3008          while ((err = read (job_fds[0], &token, 1)) == 1)
     3009            ++tcnt;
     3010
     3011          if (tcnt != master_job_slots)
     3012            error (NILF,
     3013                   "INTERNAL: Exiting with %u jobserver tokens available; should be %u!",
     3014                   tcnt, master_job_slots);
     3015        }
    27963016
    27973017      /* Try to move back to the original directory.  This is essential on
     
    28593079        printf (_("%s[%u]: Leaving directory `%s'\n"),
    28603080                program, makelevel, starting_directory);
     3081
     3082  /* Flush stdout to be sure this comes before any stderr output.  */
     3083  fflush (stdout);
    28613084}
  • trunk/src/gmake/read.c

    r191 r287  
    7979    unsigned int if_cmds;       /* Depth of conditional nesting.  */
    8080    unsigned int allocated;     /* Elts allocated in following arrays.  */
    81     char *ignoring;             /* Are we ignoring or interepreting?  */
     81    char *ignoring;             /* Are we ignoring or interpreting?
     82                                   0=interpreting, 1=not yet interpreted,
     83                                   2=already interpreted */
    8284    char *seen_else;            /* Have we already seen an `else'?  */
    8385  };
     
    131133                               enum variable_origin origin,
    132134                               struct ebuffer *ebuf));
    133 static int conditional_line PARAMS ((char *line, const struct floc *flocp));
     135static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp));
    134136static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent,
    135137                        struct dep *deps, unsigned int cmds_started, char *commands,
    136138                        unsigned int commands_idx, int two_colon,
    137                         int have_sysv_atvar,
    138                         const struct floc *flocp, int set_default));
     139                        const struct floc *flocp));
    139140static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
    140141                                       enum variable_origin origin,
     
    257258              d->file->dontcare = 1;
    258259              d->ignore_mtime = 0;
     260              d->need_2nd_expansion = 0;
    259261              /* Tell update_goal_chain to bail out as soon as this file is
    260262                 made, and main not to die if we can't make this file.  */
     
    372374  deps->file = lookup_file (filename);
    373375  if (deps->file == 0)
    374     {
    375       deps->file = enter_file (xstrdup (filename));
    376       if (flags & RM_DONTCARE)
    377         deps->file->dontcare = 1;
    378     }
     376    deps->file = enter_file (xstrdup (filename));
    379377  if (filename != ebuf.floc.filenm)
    380378    free (filename);
     
    382380  deps->changed = flags;
    383381  deps->ignore_mtime = 0;
     382  deps->need_2nd_expansion = 0;
     383  if (flags & RM_DONTCARE)
     384    deps->file->dontcare = 1;
    384385
    385386  /* If the makefile can't be found at all, give up entirely.  */
     
    413414
    414415  free (ebuf.bufstart);
     416  alloca (0);
    415417  return r;
    416418}
     
    444446  reading_file = curfile;
    445447
     448  alloca (0);
    446449  return r;
    447450}
     
    465468  int ignoring = 0, in_ignored_define = 0;
    466469  int no_targets = 0;           /* Set when reading a rule without targets.  */
    467   int have_sysv_atvar = 0;
    468470  struct nameseq *filenames = 0;
    469471  struct dep *deps = 0;
     
    482484          record_files (filenames, pattern, pattern_percent, deps,            \
    483485                        cmds_started, commands, commands_idx, two_colon,      \
    484                         have_sysv_atvar, &fi, set_default);                   \
     486                        &fi);                                                 \
    485487        }                                                                     \
    486488      filenames = 0;                                                          \
     
    619621         following lines.  */
    620622
    621       if (!in_ignored_define
    622           && (word1eq ("ifdef") || word1eq ("ifndef")
    623               || word1eq ("ifeq") || word1eq ("ifneq")
    624               || word1eq ("else") || word1eq ("endif")))
    625         {
    626           int i = conditional_line (p, fstart);
    627           if (i < 0)
    628             fatal (fstart, _("invalid syntax in conditional"));
    629 
    630           ignoring = i;
    631           continue;
     623      if (!in_ignored_define)
     624        {
     625          int i = conditional_line (p, len, fstart);
     626          if (i != -2)
     627            {
     628              if (i == -1)
     629                fatal (fstart, _("invalid syntax in conditional"));
     630
     631              ignoring = i;
     632              continue;
     633            }
    632634        }
    633635
     
    854856        goto rule_complete;
    855857
     858      /* This line starts with a tab but was not caught above because there
     859         was no preceding target, and the line might have been usable as a
     860         variable definition.  But now we know it is definitely lossage.  */
    856861      if (line[0] == '\t')
    857         {
    858           p = collapsed;        /* Ignore comments, etc.  */
    859           while (isblank ((unsigned char)*p))
    860             ++p;
    861           if (*p == '\0')
    862             /* The line is completely blank; that is harmless.  */
    863             continue;
    864 
    865           /* This line starts with a tab but was not caught above
    866              because there was no preceding target, and the line
    867              might have been usable as a variable definition.
    868              But now we know it is definitely lossage.  */
    869           fatal(fstart, _("commands commence before first target"));
    870         }
     862        fatal(fstart, _("commands commence before first target"));
    871863
    872864      /* This line describes some target files.  This is complicated by
     
    887879        unsigned int len, plen = 0;
    888880        char *colonp;
     881        const char *end, *beg; /* Helpers for whitespace stripping. */
    889882
    890883        /* Record the previous rule.  */
     
    935928
    936929        p2 = variable_expand_string(NULL, lb_next, len);
     930
    937931        while (1)
    938932          {
     
    10411035        if (*lb_next != '\0')
    10421036          {
    1043             unsigned int l = p - variable_buffer;
    1044             unsigned int l2 = p2 - variable_buffer;
     1037            unsigned int l = p2 - variable_buffer;
    10451038            plen = strlen (p2);
    10461039            (void) variable_buffer_output (p2+plen,
    10471040                                           lb_next, strlen (lb_next)+1);
    1048             p = variable_buffer + l;
    1049             p2 = variable_buffer + l2;
     1041            p2 = variable_buffer + l;
    10501042          }
    10511043
     
    11131105              }
    11141106          }
    1115 
    1116         /* Do any of the prerequisites appear to have $@ etc.?  */
    1117         have_sysv_atvar = 0;
    1118         if (!posix_pedantic)
    1119           for (p = strchr (p2, '$'); p != 0; p = strchr (p+1, '$'))
    1120             if (p[1] == '@' || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))
    1121               {
    1122                 have_sysv_atvar = 1;
    1123                 break;
    1124               }
    11251107
    11261108        /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
     
    11881170          pattern = 0;
    11891171
    1190         /* Parse the dependencies.  */
    1191         deps = (struct dep *)
    1192           multi_glob (parse_file_seq (&p2, '|', sizeof (struct dep), 1),
    1193                       sizeof (struct dep));
    1194         if (*p2)
     1172        /* Strip leading and trailing whitespaces. */
     1173        beg = p2;
     1174        end = beg + strlen (beg) - 1;
     1175        strip_whitespace (&beg, &end);
     1176
     1177        if (beg <= end && *beg != '\0')
    11951178          {
    1196             /* Files that follow '|' are special prerequisites that
    1197                need only exist in order to satisfy the dependency.
    1198                Their modification times are irrelevant.  */
    1199             struct dep **deps_ptr = &deps;
    1200             struct dep *d;
    1201             for (deps_ptr = &deps; *deps_ptr; deps_ptr = &(*deps_ptr)->next)
    1202               ;
    1203             ++p2;
    1204             *deps_ptr = (struct dep *)
    1205               multi_glob (parse_file_seq (&p2, '\0', sizeof (struct dep), 1),
    1206                           sizeof (struct dep));
    1207             for (d = *deps_ptr; d != 0; d = d->next)
    1208               d->ignore_mtime = 1;
     1179            char *top;
     1180            const char *fromp = beg;
     1181
     1182            /* Make a copy of the dependency string.  Note if we find '$'.  */
     1183            deps = (struct dep*) xmalloc (sizeof (struct dep));
     1184            deps->next = 0;
     1185            deps->name = top = (char *) xmalloc (end - beg + 2);
     1186            deps->need_2nd_expansion = 0;
     1187            while (fromp <= end)
     1188              {
     1189                if (*fromp == '$')
     1190                  deps->need_2nd_expansion = 1;
     1191                *(top++) = *(fromp++);
     1192              }
     1193            *top = '\0';
     1194            deps->file = 0;
    12091195          }
     1196        else
     1197          deps = 0;
    12101198
    12111199        commands_idx = 0;
     
    12261214            commands_idx += len;
    12271215            commands[commands_idx++] = '\n';
     1216          }
     1217
     1218        /* Determine if this target should be made default. We used to do
     1219           this in record_files() but because of the delayed target recording
     1220           and because preprocessor directives are legal in target's commands
     1221           it is too late. Consider this fragment for example:
     1222
     1223           foo:
     1224
     1225           ifeq ($(.DEFAULT_GOAL),foo)
     1226              ...
     1227           endif
     1228
     1229           Because the target is not recorded until after ifeq directive is
     1230           evaluated the .DEFAULT_GOAL does not contain foo yet as one
     1231           would expect. Because of this we have to move some of the logic
     1232           here.  */
     1233
     1234        if (**default_goal_name == '\0' && set_default)
     1235          {
     1236            char* name;
     1237            struct dep *d;
     1238            struct nameseq *t = filenames;
     1239
     1240            for (; t != 0; t = t->next)
     1241              {
     1242                int reject = 0;
     1243                name = t->name;
     1244
     1245                /* We have nothing to do if this is an implicit rule. */
     1246                if (strchr (name, '%') != 0)
     1247                  break;
     1248
     1249                /* See if this target's name does not start with a `.',
     1250                   unless it contains a slash.  */
     1251                if (*name == '.' && strchr (name, '/') == 0
     1252#ifdef HAVE_DOS_PATHS
     1253                    && strchr (name, '\\') == 0
     1254#endif
     1255                    )
     1256                  continue;
     1257
     1258
     1259                /* If this file is a suffix, don't let it be
     1260                   the default goal file.  */
     1261                for (d = suffix_file->deps; d != 0; d = d->next)
     1262                  {
     1263                    register struct dep *d2;
     1264                    if (*dep_name (d) != '.' && streq (name, dep_name (d)))
     1265                      {
     1266                        reject = 1;
     1267                        break;
     1268                      }
     1269                    for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
     1270                      {
     1271                        register unsigned int len = strlen (dep_name (d2));
     1272                        if (!strneq (name, dep_name (d2), len))
     1273                          continue;
     1274                        if (streq (name + len, dep_name (d)))
     1275                          {
     1276                            reject = 1;
     1277                            break;
     1278                          }
     1279                      }
     1280
     1281                    if (reject)
     1282                      break;
     1283                  }
     1284
     1285                if (!reject)
     1286                  {
     1287                    define_variable_global (".DEFAULT_GOAL", 13, t->name,
     1288                                            o_file, 0, NILF);
     1289                    break;
     1290                  }
     1291              }
    12281292          }
    12291293
     
    12841348      char *line;
    12851349
     1350      nlines = readline (ebuf);
    12861351      ebuf->floc.lineno += nlines;
    1287       nlines = readline (ebuf);
    12881352
    12891353      /* If there is nothing left to eval, we're done. */
     
    13661430   current makefile.  They are used for error messages.
    13671431
    1368    Value is -1 if the line is invalid,
     1432   Value is -2 if the line is not a conditional at all,
     1433   -1 if the line is an invalid conditional,
    13691434   0 if following text should be interpreted,
    13701435   1 if following text should be ignored.  */
    13711436
    13721437static int
    1373 conditional_line (char *line, const struct floc *flocp)
     1438conditional_line (char *line, int len, const struct floc *flocp)
    13741439{
    1375   int notdef;
    13761440  char *cmdname;
    1377   register unsigned int i;
    1378 
    1379   if (*line == 'i')
    1380     {
    1381       /* It's an "if..." command.  */
    1382       notdef = line[2] == 'n';
    1383       if (notdef)
    1384         {
    1385           cmdname = line[3] == 'd' ? "ifndef" : "ifneq";
    1386           line += cmdname[3] == 'd' ? 7 : 6;
    1387         }
    1388       else
    1389         {
    1390           cmdname = line[2] == 'd' ? "ifdef" : "ifeq";
    1391           line += cmdname[2] == 'd' ? 6 : 5;
    1392         }
    1393     }
     1441  enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
     1442  unsigned int i;
     1443  unsigned int o;
     1444
     1445  /* Compare a word, both length and contents. */
     1446#define word1eq(s)      (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
     1447#define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
     1448
     1449  /* Make sure this line is a conditional.  */
     1450  chkword ("ifdef", c_ifdef)
     1451  else chkword ("ifndef", c_ifndef)
     1452  else chkword ("ifeq", c_ifeq)
     1453  else chkword ("ifneq", c_ifneq)
     1454  else chkword ("else", c_else)
     1455  else chkword ("endif", c_endif)
    13941456  else
    1395     {
    1396       /* It's an "else" or "endif" command.  */
    1397       notdef = line[1] == 'n';
    1398       cmdname = notdef ? "endif" : "else";
    1399       line += notdef ? 5 : 4;
    1400     }
    1401 
    1402   line = next_token (line);
    1403 
    1404   if (*cmdname == 'e')
     1457    return -2;
     1458
     1459  /* Found one: skip past it and any whitespace after it.  */
     1460  line = next_token (line + len);
     1461
     1462#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
     1463
     1464  /* An 'endif' cannot contain extra text, and reduces the if-depth by 1  */
     1465  if (cmdtype == c_endif)
    14051466    {
    14061467      if (*line != '\0')
    1407         error (flocp, _("Extraneous text after `%s' directive"), cmdname);
    1408       /* "Else" or "endif".  */
    1409       if (conditionals->if_cmds == 0)
     1468        EXTRANEOUS ();
     1469
     1470      if (!conditionals->if_cmds)
    14101471        fatal (flocp, _("extraneous `%s'"), cmdname);
    1411       /* NOTDEF indicates an `endif' command.  */
    1412       if (notdef)
    1413         --conditionals->if_cmds;
    1414       else if (conditionals->seen_else[conditionals->if_cmds - 1])
    1415         fatal (flocp, _("only one `else' per conditional"));
     1472
     1473      --conditionals->if_cmds;
     1474
     1475      goto DONE;
     1476    }
     1477
     1478  /* An 'else' statement can either be simple, or it can have another
     1479     conditional after it.  */
     1480  if (cmdtype == c_else)
     1481    {
     1482      const char *p;
     1483
     1484      if (!conditionals->if_cmds)
     1485        fatal (flocp, _("extraneous `%s'"), cmdname);
     1486
     1487      o = conditionals->if_cmds - 1;
     1488
     1489      if (conditionals->seen_else[o])
     1490        fatal (flocp, _("only one `else' per conditional"));
     1491
     1492      /* Change the state of ignorance.  */
     1493      switch (conditionals->ignoring[o])
     1494        {
     1495          case 0:
     1496            /* We've just been interpreting.  Never do it again.  */
     1497            conditionals->ignoring[o] = 2;
     1498            break;
     1499          case 1:
     1500            /* We've never interpreted yet.  Maybe this time!  */
     1501            conditionals->ignoring[o] = 0;
     1502            break;
     1503        }
     1504
     1505      /* It's a simple 'else'.  */
     1506      if (*line == '\0')
     1507        {
     1508          conditionals->seen_else[o] = 1;
     1509          goto DONE;
     1510        }
     1511
     1512      /* The 'else' has extra text.  That text must be another conditional
     1513         and cannot be an 'else' or 'endif'.  */
     1514
     1515      /* Find the length of the next word.  */
     1516      for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
     1517        ;
     1518      len = p - line;
     1519
     1520      /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
     1521      if (word1eq("else") || word1eq("endif")
     1522          || conditional_line (line, len, flocp) < 0)
     1523        EXTRANEOUS ();
    14161524      else
    1417         {
    1418           /* Toggle the state of ignorance.  */
    1419           conditionals->ignoring[conditionals->if_cmds - 1]
    1420             = !conditionals->ignoring[conditionals->if_cmds - 1];
    1421           /* Record that we have seen an `else' in this conditional.
    1422              A second `else' will be erroneous.  */
    1423           conditionals->seen_else[conditionals->if_cmds - 1] = 1;
    1424         }
    1425       for (i = 0; i < conditionals->if_cmds; ++i)
    1426         if (conditionals->ignoring[i])
    1427           return 1;
    1428       return 0;
     1525        {
     1526          /* conditional_line() created a new level of conditional.
     1527             Raise it back to this level.  */
     1528          if (conditionals->ignoring[o] < 2)
     1529            conditionals->ignoring[o] = conditionals->ignoring[o+1];
     1530          --conditionals->if_cmds;
     1531        }
     1532
     1533      goto DONE;
    14291534    }
    14301535
     
    14361541    }
    14371542
    1438   ++conditionals->if_cmds;
     1543  o = conditionals->if_cmds++;
    14391544  if (conditionals->if_cmds > conditionals->allocated)
    14401545    {
     
    14471552
    14481553  /* Record that we have seen an `if...' but no `else' so far.  */
    1449   conditionals->seen_else[conditionals->if_cmds - 1] = 0;
     1554  conditionals->seen_else[o] = 0;
    14501555
    14511556  /* Search through the stack to see if we're already ignoring.  */
    1452   for (i = 0; i < conditionals->if_cmds - 1; ++i)
     1557  for (i = 0; i < o; ++i)
    14531558    if (conditionals->ignoring[i])
    14541559      {
    1455         /* We are already ignoring, so just push a level
    1456            to match the next "else" or "endif", and keep ignoring.
    1457            We don't want to expand variables in the condition.  */
    1458         conditionals->ignoring[conditionals->if_cmds - 1] = 1;
     1560        /* We are already ignoring, so just push a level to match the next
     1561           "else" or "endif", and keep ignoring.  We don't want to expand
     1562           variables in the condition.  */
     1563        conditionals->ignoring[o] = 1;
    14591564        return 1;
    14601565      }
    14611566
    1462   if (cmdname[notdef ? 3 : 2] == 'd')
     1567  if (cmdtype == c_ifdef || cmdtype == c_ifndef)
    14631568    {
    1464       /* "Ifdef" or "ifndef".  */
    14651569      char *var;
    14661570      struct variable *v;
    1467       register char *p;
     1571      char *p;
    14681572
    14691573      /* Expand the thing we're looking up, so we can use indirect and
     
    14791583
    14801584      var[i] = '\0';
    1481       v = lookup_variable (var, strlen (var));
    1482       conditionals->ignoring[conditionals->if_cmds - 1]
    1483         = (v != 0 && *v->value != '\0') == notdef;
     1585      v = lookup_variable (var, i);
     1586
     1587      conditionals->ignoring[o] =
     1588        ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
    14841589
    14851590      free (var);
     
    14991604      if (termin == ',')
    15001605        {
    1501           register int count = 0;
     1606          int count = 0;
    15021607          for (; *line != '\0'; ++line)
    15031608            if (*line == '(')
     
    15731678      line = next_token (++line);
    15741679      if (*line != '\0')
    1575         error (flocp, _("Extraneous text after `%s' directive"), cmdname);
     1680        EXTRANEOUS ();
    15761681
    15771682      s2 = variable_expand (s2);
    1578       conditionals->ignoring[conditionals->if_cmds - 1]
    1579         = streq (s1, s2) == notdef;
     1683      conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
    15801684    }
    15811685
     1686 DONE:
    15821687  /* Search through the stack to see if we're ignoring.  */
    15831688  for (i = 0; i < conditionals->if_cmds; ++i)
     
    16951800          p = create_pattern_var (name, percent);
    16961801          p->variable.fileinfo = *flocp;
     1802          /* I don't think this can fail since we already determined it was a
     1803             variable definition.  */
    16971804          v = parse_variable_definition (&p->variable, defn);
    1698           v->value = xstrdup (v->value);
    1699           if (!v)
    1700             error (flocp, _("Malformed pattern-specific variable definition"));
     1805          assert (v != 0);
     1806
     1807          if (v->flavor == f_simple)
     1808            v->value = allocated_variable_expand (v->value);
     1809          else
     1810            v->value = xstrdup (v->value);
     1811
    17011812          fname = p->target;
    17021813        }
     
    17721883              struct dep *deps, unsigned int cmds_started, char *commands,
    17731884              unsigned int commands_idx, int two_colon,
    1774               int have_sysv_atvar, const struct floc *flocp, int set_default)
     1885              const struct floc *flocp)
    17751886{
    17761887  struct nameseq *nextf;
     
    17791890  char **targets = 0, **target_percents = 0;
    17801891  struct commands *cmds;
     1892
     1893  /* If we've already snapped deps, that means we're in an eval being
     1894     resolved after the makefiles have been read in.  We can't add more rules
     1895     at this time, since they won't get snapped and we'll get core dumps.
     1896     See Savannah bug # 12124.  */
     1897  if (snapped_deps)
     1898    fatal (flocp, _("prerequisites cannot be defined in command scripts"));
    17811899
    17821900  if (commands_idx > 0)
     
    18441962      /* If there are multiple filenames, copy the chain DEPS
    18451963         for all but the last one.  It is not safe for the same deps
    1846          to go in more than one place in the data base.  */
     1964         to go in more than one place in the database.  */
    18471965      this = nextf != 0 ? copy_dep_chain (deps) : deps;
    18481966
     
    18611979            }
    18621980          else
    1863             {
    1864               /* We use patsubst_expand to do the work of translating
    1865                  the target pattern, the target's name and the dependencies'
    1866                  patterns into plain dependency names.  */
    1867               char *buffer = variable_expand ("");
    1868 
    1869               for (d = this; d != 0; d = d->next)
    1870                 {
    1871                   char *o;
    1872                   char *percent = find_percent (d->name);
    1873                   if (percent == 0)
    1874                     continue;
    1875                   o = patsubst_expand (buffer, name, pattern, d->name,
    1876                                        pattern_percent, percent);
    1877                   /* If the name expanded to the empty string, that's
    1878                      illegal.  */
    1879                   if (o == buffer)
    1880                     fatal (flocp,
    1881                            _("target `%s' leaves prerequisite pattern empty"),
    1882                            name);
    1883                   free (d->name);
    1884                   d->name = savestring (buffer, o - buffer);
    1885                 }
    1886             }
    1887         }
    1888 
    1889       /* If at least one of the dependencies uses $$@ etc. deal with that.
    1890          It would be very nice and very simple to just expand everything, but
    1891          it would break a lot of backward compatibility.  Maybe that's OK
    1892          since we're just emulating a SysV function, and if we do that then
    1893          why not emulate it completely (that's what SysV make does: it
    1894          re-expands the entire prerequisite list, all the time, with $@
    1895          etc. in scope).  But, it would be a pain indeed to document this
    1896          ("iff you use $$@, your prerequisite lists is expanded twice...")
    1897          Ouch.  Maybe better to make the code more complex.  */
    1898 
    1899       if (have_sysv_atvar)
    1900         {
    1901           char *p;
    1902           int tlen = strlen (name);
    1903           char *fnp = strrchr (name, '/');
    1904           int dlen;
    1905           int flen;
    1906 
    1907           if (fnp)
    1908             {
    1909               dlen = fnp - name;
    1910               ++fnp;
    1911               flen = strlen (fnp);
    1912             }
    1913           else
    1914             {
    1915               dlen = 0;
    1916               fnp = name;
    1917               flen = tlen;
    1918             }
    1919 
    1920 
    1921           for (d = this; d != 0; d = d->next)
    1922             for (p = strchr (d->name, '$'); p != 0; p = strchr (p+1, '$'))
     1981            /* We use subst_expand to do the work of translating % to $* in
     1982               the dependency line.  */
     1983
     1984            if (this != 0 && find_percent (this->name) != 0)
    19231985              {
    1924                 char *s = p;
    1925                 char *at;
    1926                 int atlen;
    1927 
    1928                 /* If it's '$@', '$(@', or '${@', it's escaped */
    1929                 if ((++p)[0] == '$'
    1930                     && (p[1] == '@'
    1931                         || ((p[1] == '(' || p[1] == '{') && p[2] == '@')))
    1932                   {
    1933                     bcopy (p, s, strlen (p)+1);
    1934                     continue;
    1935                   }
    1936 
    1937                 /* Maybe found one.  We like anything of any form matching @,
    1938                    [({]@[}):], or [({]@[DF][}):].  */
    1939 
    1940                 if (! (p[0] == '@'
    1941                        || ((p[0] == '(' || p[0] == '{') && (++p)[0] == '@'
    1942                            && (((++p)[0] == ')' || p[0] == '}' || p[0] == ':')
    1943                                || ((p[1] == ')' || p[1] == '}' || p[1] == ':')
    1944                                    && (p[0] == 'D' || p[0] == 'F'))))))
    1945                   continue;
    1946 
    1947                 /* Found one.  Compute the length and string ptr.  Move p
    1948                    past the variable reference.  */
    1949                 switch (p[0])
    1950                   {
    1951                   case 'D':
    1952                     atlen = dlen;
    1953                     at = name;
    1954                     p += 2;
    1955                     break;
    1956 
    1957                   case 'F':
    1958                     atlen = flen;
    1959                     at = fnp;
    1960                     p += 2;
    1961                     break;
    1962 
    1963                   default:
    1964                     atlen = tlen;
    1965                     at = name;
    1966                     ++p;
    1967                     break;
    1968                   }
    1969 
    1970                 /* Get more space.  */
    1971                 {
    1972                   int soff = s - d->name;
    1973                   int poff = p - d->name;
    1974                   d->name = (char *) xrealloc (d->name,
    1975                                                strlen (d->name) + atlen + 1);
    1976                   s = d->name + soff;
    1977                   p = d->name + poff;
    1978                 }
    1979 
    1980                 /* Copy the string over.  */
    1981                 bcopy(p, s+atlen, strlen (p)+1);
    1982                 bcopy(at, s, atlen);
    1983                 p = s + atlen - 1;
     1986                char *o;
     1987                char *buffer = variable_expand ("");
     1988
     1989                o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0);
     1990
     1991                free (this->name);
     1992                this->name = savestring (buffer, o - buffer);
     1993                this->need_2nd_expansion = 1;
    19841994              }
    1985         }
     1995        }
    19861996
    19871997      if (!two_colon)
     
    20222032          if (cmds != 0)
    20232033            f->cmds = cmds;
     2034
    20242035          /* Defining .SUFFIXES with no dependencies
    20252036             clears out the list of suffixes.  */
     
    20362047              f->deps = 0;
    20372048            }
    2038           else if (f->deps != 0)
     2049          else if (this != 0)
    20392050            {
    20402051              /* Add the file's old deps and the new ones in THIS together.  */
    20412052
    2042               struct dep *firstdeps, *moredeps;
    2043               if (cmds != 0)
    2044                 {
    2045                   /* This is the rule with commands, so put its deps first.
    2046                      The rationale behind this is that $< expands to the
    2047                      first dep in the chain, and commands use $< expecting
    2048                      to get the dep that rule specifies.  */
    2049                   firstdeps = this;
    2050                   moredeps = f->deps;
    2051                 }
    2052               else
    2053                 {
    2054                   /* Append the new deps to the old ones.  */
    2055                   firstdeps = f->deps;
    2056                   moredeps = this;
    2057                 }
    2058 
    2059               if (firstdeps == 0)
    2060                 firstdeps = moredeps;
    2061               else
    2062                 {
    2063                   d = firstdeps;
    2064                   while (d->next != 0)
    2065                     d = d->next;
    2066                   d->next = moredeps;
    2067                 }
    2068 
    2069               f->deps = firstdeps;
     2053              if (f->deps != 0)
     2054                {
     2055                  struct dep **d_ptr = &f->deps;
     2056
     2057                  while ((*d_ptr)->next != 0)
     2058                    d_ptr = &(*d_ptr)->next;
     2059
     2060                  if (cmds != 0)
     2061                    {
     2062                      /* This is the rule with commands, so put its deps
     2063                         last. The rationale behind this is that $< expands
     2064                         to the first dep in the chain, and commands use $<
     2065                         expecting to get the dep that rule specifies.
     2066                         However the second expansion algorithm reverses
     2067                         the order thus we need to make it last here.  */
     2068
     2069                      (*d_ptr)->next = this;
     2070                    }
     2071                  else
     2072                    {
     2073                      /* This is the rule without commands. Put its
     2074                         dependencies at the end but before dependencies
     2075                         from the rule with commands (if any). This way
     2076                         everything appears in makefile order.  */
     2077
     2078                      if (f->cmds != 0)
     2079                        {
     2080                          this->next = *d_ptr;
     2081                          *d_ptr = this;
     2082                        }
     2083                      else
     2084                        (*d_ptr)->next = this;
     2085                    }
     2086                }
     2087              else
     2088                f->deps = this;
     2089
     2090              /* This is a hack. I need a way to communicate to snap_deps()
     2091                 that the last dependency line in this file came with commands
     2092                 (so that logic in snap_deps() can put it in front and all
     2093                 this $< -logic works). I cannot simply rely on file->cmds
     2094                 being not 0 because of the cases like the following:
     2095
     2096                 foo: bar
     2097                 foo:
     2098                     ...
     2099
     2100                 I am going to temporarily "borrow" UPDATING member in
     2101                 `struct file' for this.   */
     2102
     2103              if (cmds != 0)
     2104                f->updating = 1;
    20702105            }
    2071           else
    2072             f->deps = this;
    20732106
    20742107          /* If this is a static pattern rule, set the file's stem to
     
    20802113              char *buffer = variable_expand ("");
    20812114              char *o = patsubst_expand (buffer, name, pattern, percent,
    2082                                          pattern_percent, percent);
     2115                                         pattern_percent+1, percent+1);
    20832116              f->stem = savestring (buffer, o - buffer);
    20842117            }
     
    21162149        }
    21172150
    2118       /* See if this is first target seen whose name does
    2119          not start with a `.', unless it contains a slash.  */
    2120       if (default_goal_file == 0 && set_default
    2121           && (*name != '.' || strchr (name, '/') != 0
    2122 #ifdef HAVE_DOS_PATHS
    2123                            || strchr (name, '\\') != 0
    2124 #endif
    2125               ))
    2126         {
    2127           int reject = 0;
    2128 
    2129           /* If this file is a suffix, don't
    2130              let it be the default goal file.  */
    2131 
    2132           for (d = suffix_file->deps; d != 0; d = d->next)
    2133             {
    2134               register struct dep *d2;
    2135               if (*dep_name (d) != '.' && streq (name, dep_name (d)))
    2136                 {
    2137                   reject = 1;
    2138                   break;
    2139                 }
    2140               for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    2141                 {
    2142                   register unsigned int len = strlen (dep_name (d2));
    2143                   if (!strneq (name, dep_name (d2), len))
    2144                     continue;
    2145                   if (streq (name + len, dep_name (d)))
    2146                     {
    2147                       reject = 1;
    2148                       break;
    2149                     }
    2150                 }
    2151               if (reject)
    2152                 break;
    2153             }
    2154 
    2155           if (!reject)
    2156             default_goal_file = f;
    2157         }
     2151      /* If this target is a default target, update DEFAULT_GOAL_FILE.  */
     2152      if (strcmp (*default_goal_name, name) == 0
     2153          && (default_goal_file == 0
     2154              || strcmp (default_goal_file->name, name) != 0))
     2155        default_goal_file = f;
    21582156    }
    21592157
     
    21792177  unsigned int string_len = 0;
    21802178  register char *p = string;
     2179  register int ch;
    21812180
    21822181  while (1)
    21832182    {
    21842183      if (stop2 && blank)
    2185         while (*p != '\0' && *p != stop1 && *p != stop2
    2186                && ! isblank ((unsigned char) *p))
     2184        while ((ch = *p) != '\0' && ch != stop1 && ch != stop2
     2185               && ! isblank ((unsigned char) ch))
    21872186          ++p;
    21882187      else if (stop2)
    2189         while (*p != '\0' && *p != stop1 && *p != stop2)
     2188        while ((ch = *p) != '\0' && ch != stop1 && ch != stop2)
    21902189          ++p;
    21912190      else if (blank)
    2192         while (*p != '\0' && *p != stop1
    2193                && ! isblank ((unsigned char) *p))
     2191        while ((ch = *p) != '\0' && ch != stop1
     2192               && ! isblank ((unsigned char) ch))
    21942193          ++p;
    21952194      else
    2196         while (*p != '\0' && *p != stop1)
     2195        while ((ch = *p) != '\0' && ch != stop1)
    21972196          ++p;
    21982197
    2199       if (*p == '\0')
     2198      if (ch == '\0')
    22002199        break;
    22012200
     
    24992498readstring (struct ebuffer *ebuf)
    25002499{
    2501   char *p;
     2500  char *eol;
    25022501
    25032502  /* If there is nothing left in this buffer, return 0.  */
    2504   if (ebuf->bufnext > ebuf->bufstart + ebuf->size)
     2503  if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
    25052504    return -1;
    25062505
     
    25082507     next logical line (taking into account backslash/newline pairs).  */
    25092508
    2510   p = ebuf->buffer = ebuf->bufnext;
     2509  eol = ebuf->buffer = ebuf->bufnext;
    25112510
    25122511  while (1)
    25132512    {
    25142513      int backslash = 0;
    2515 
    2516       /* Find the next newline.  Keep track of backslashes as we look.  */
    2517       for (; *p != '\n' && *p != '\0'; ++p)
    2518         if (*p == '\\')
    2519           backslash = !backslash;
    2520 
    2521       /* If we got to the end of the string or a newline with no backslash,
    2522          we're done. */
    2523       if (*p == '\0' || !backslash)
     2514      char *bol = eol;
     2515      char *p;
     2516
     2517      /* Find the next newline.  At EOS, stop.  */
     2518      eol = p = strchr (eol , '\n');
     2519      if (!eol)
     2520        {
     2521          ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
     2522          return 0;
     2523        }
     2524
     2525      /* Found a newline; if it's escaped continue; else we're done.  */
     2526      while (p > bol && *(--p) == '\\')
     2527        backslash = !backslash;
     2528      if (!backslash)
    25242529        break;
     2530      ++eol;
    25252531    }
    25262532
    25272533  /* Overwrite the newline char.  */
    2528   *p = '\0';
    2529   ebuf->bufnext = p+1;
     2534  *eol = '\0';
     2535  ebuf->bufnext = eol+1;
    25302536
    25312537  return 0;
  • trunk/src/gmake/remake.c

    r218 r287  
    7575/* Remake all the goals in the `struct dep' chain GOALS.  Return -1 if nothing
    7676   was done, 0 if all goals were updated successfully, or 1 if a goal failed.
    77    If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
    78    be disabled for them unless they were also command-line targets, and we
    79    should only make one goal at a time and return as soon as one goal whose
    80    `changed' member is nonzero is successfully made.  */
     77
     78   If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q,
     79   and -n should be disabled for them unless they were also command-line
     80   targets, and we should only make one goal at a time and return as soon as
     81   one goal whose `changed' member is nonzero is successfully made.  */
    8182
    8283int
    83 update_goal_chain (struct dep *goals, int makefiles)
     84update_goal_chain (struct dep *goals)
    8485{
    8586  int t = touch_flag, q = question_flag, n = just_print_flag;
     
    8788  int status = -1;
    8889
    89 #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
     90#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
    9091                     : file_mtime (file))
    9192
     
    137138              int x;
    138139              check_renamed (file);
    139               if (makefiles)
     140              if (rebuilding_makefiles)
    140141                {
    141142                  if (file->cmd_target)
     
    154155              ocommands_started = commands_started;
    155156
    156               x = update_file (file, makefiles ? 1 : 0);
     157              x = update_file (file, rebuilding_makefiles ? 1 : 0);
    157158              check_renamed (file);
    158159
     
    177178                         matter how much more we run, since we already know
    178179                         the answer to return.  */
    179                       stop = (!keep_going_flag && !question_flag
    180                               && !makefiles);
     180                      stop = (question_flag && !keep_going_flag
     181                              && !rebuilding_makefiles);
    181182                    }
    182183                  else
     
    194195                             If STATUS is changed, we will get re-exec'd, and
    195196                             enter an infinite loop.  */
    196                           if (!makefiles
     197                          if (!rebuilding_makefiles
    197198                              || (!just_print_flag && !question_flag))
    198199                            status = 0;
    199                           if (makefiles && file->dontcare)
     200                          if (rebuilding_makefiles && file->dontcare)
    200201                            /* This is a default makefile; stop remaking.  */
    201202                            stop = 1;
     
    220221                 print a message saying nothing needs doing.  */
    221222
    222               if (!makefiles
     223              if (!rebuilding_makefiles
    223224                  /* If the update_status is zero, we updated successfully
    224225                     or not at all.  G->changed will have been set above if
     
    259260    }
    260261
    261   if (makefiles)
     262  if (rebuilding_makefiles)
    262263    {
    263264      touch_flag = t;
     
    309310      check_renamed (f);
    310311
     312      /* If we got an error, don't bother with double_colon etc.  */
    311313      if (status != 0 && !keep_going_flag)
    312         break;
     314        return status;
    313315
    314316      if (f->command_state == cs_running
     
    324326  /* Process the remaining rules in the double colon chain so they're marked
    325327     considered.  Start their prerequisites, too.  */
    326   for (; f != 0 ; f = f->prev)
    327     {
    328       struct dep *d;
    329 
    330       f->considered = considered;
    331 
    332       for (d = f->deps; d != 0; d = d->next)
    333         status |= update_file (d->file, depth + 1);
    334     }
     328  if (file->double_colon)
     329    for (; f != 0 ; f = f->prev)
     330      {
     331        struct dep *d;
     332
     333        f->considered = considered;
     334
     335        for (d = f->deps; d != 0; d = d->next)
     336          status |= update_file (d->file, depth + 1);
     337      }
    335338
    336339  return status;
    337340}
    338341
     342
     343/* Show a message stating the target failed to build.  */
     344
     345static void
     346complain (const struct file *file)
     347{
     348  const char *msg_noparent
     349    = _("%sNo rule to make target `%s'%s");
     350  const char *msg_parent
     351    = _("%sNo rule to make target `%s', needed by `%s'%s");
     352
     353  if (!keep_going_flag)
     354    {
     355      if (file->parent == 0)
     356        fatal (NILF, msg_noparent, "", file->name, "");
     357
     358      fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
     359    }
     360
     361  if (file->parent == 0)
     362    error (NILF, msg_noparent, "*** ", file->name, ".");
     363  else
     364    error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
     365}
    339366
    340367/* Consider a single `struct file' and update it as appropriate.  */
     
    357384          DBF (DB_VERBOSE,
    358385               _("Recently tried and failed to update file `%s'.\n"));
     386
     387          /* If the file we tried to make is marked dontcare then no message
     388             was printed about it when it failed during the makefile rebuild.
     389             If we're trying to build it again in the normal rebuild, print a
     390             message now.  */
     391          if (file->dontcare && !rebuilding_makefiles)
     392            {
     393              file->dontcare = 0;
     394              complain (file);
     395            }
     396
    359397          return file->update_status;
    360398        }
     
    435473      FILE_TIMESTAMP mtime;
    436474      int maybe_make;
     475      int dontcare = 0;
    437476
    438477      check_renamed (d->file);
     
    458497      d->file->parent = file;
    459498      maybe_make = must_make;
     499
     500      /* Inherit dontcare flag from our parent. */
     501      if (rebuilding_makefiles)
     502        {
     503          dontcare = d->file->dontcare;
     504          d->file->dontcare = file->dontcare;
     505        }
     506
     507
    460508      dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
     509
     510      /* Restore original dontcare flag. */
     511      if (rebuilding_makefiles)
     512        d->file->dontcare = dontcare;
     513
    461514      if (! d->ignore_mtime)
    462515        must_make = maybe_make;
     
    495548        if (d->file->intermediate)
    496549          {
     550            int dontcare = 0;
     551
    497552            FILE_TIMESTAMP mtime = file_mtime (d->file);
    498553            check_renamed (d->file);
    499554            d->file->parent = file;
     555
     556            /* Inherit dontcare flag from our parent. */
     557            if (rebuilding_makefiles)
     558              {
     559                dontcare = d->file->dontcare;
     560                d->file->dontcare = file->dontcare;
     561              }
     562
     563
    500564            dep_status |= update_file (d->file, depth);
     565
     566            /* Restore original dontcare flag. */
     567            if (rebuilding_makefiles)
     568              d->file->dontcare = dontcare;
     569
    501570            check_renamed (d->file);
    502571
     
    856925  start_updating (file);
    857926
    858   if (!file->intermediate)
    859     /* If this is a non-intermediate file, update it and record
    860        whether it is newer than THIS_MTIME.  */
    861     {
     927  if (file->phony || !file->intermediate)
     928    {
     929      /* If this is a non-intermediate file, update it and record
     930         whether it is newer than THIS_MTIME.  */
    862931      FILE_TIMESTAMP mtime;
    863932      dep_status = update_file (file, depth);
     
    10261095      else
    10271096        {
    1028           const char *msg_noparent
    1029             = _("%sNo rule to make target `%s'%s");
    1030           const char *msg_parent
    1031             = _("%sNo rule to make target `%s', needed by `%s'%s");
    1032 
    10331097          /* This is a dependency file we cannot remake.  Fail.  */
    1034           if (!keep_going_flag && !file->dontcare)
    1035             {
    1036               if (file->parent == 0)
    1037                 fatal (NILF, msg_noparent, "", file->name, "");
    1038 
    1039               fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
    1040             }
    1041 
    1042           if (!file->dontcare)
    1043             {
    1044               if (file->parent == 0)
    1045                 error (NILF, msg_noparent, "*** ", file->name, ".");
    1046               else
    1047                 error (NILF, msg_parent, "*** ",
    1048                        file->name, file->parent->name, ".");
    1049             }
     1098          if (!rebuilding_makefiles || !file->dontcare)
     1099            complain (file);
    10501100          file->update_status = 2;
    10511101        }
     
    12831333/* Return the mtime of the file or archive-member reference NAME.  */
    12841334
     1335/* First, we check with stat().  If the file does not exist, then we return
     1336   NONEXISTENT_MTIME.  If it does, and the symlink check flag is set, then
     1337   examine each indirection of the symlink and find the newest mtime.
     1338   This causes one duplicate stat() when -L is being used, but the code is
     1339   much cleaner.  */
     1340
    12851341static FILE_TIMESTAMP
    12861342name_mtime (char *name)
    12871343{
     1344  FILE_TIMESTAMP mtime;
    12881345  struct stat st;
    12891346  int e;
     
    12931350    {
    12941351      if (errno != ENOENT && errno != ENOTDIR)
    1295         perror_with_name ("stat:", name);
     1352        perror_with_name ("stat: ", name);
    12961353      return NONEXISTENT_MTIME;
    12971354    }
    1298 
    1299   return FILE_TIMESTAMP_STAT_MODTIME (name, st);
     1355  mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
     1356
     1357#ifdef MAKE_SYMLINKS
     1358#ifndef S_ISLNK
     1359# define S_ISLNK(_m)     (((_m)&S_IFMT)==S_IFLNK)
     1360#endif
     1361  if (check_symlink_flag)
     1362    {
     1363      PATH_VAR (lpath);
     1364
     1365      /* Check each symbolic link segment (if any).  Find the latest mtime
     1366         amongst all of them (and the target file of course).
     1367         Note that we have already successfully dereferenced all the links
     1368         above.  So, if we run into any error trying to lstat(), or
     1369         readlink(), or whatever, something bizarre-o happened.  Just give up
     1370         and use whatever mtime we've already computed at that point.  */
     1371      strcpy (lpath, name);
     1372      while (1)
     1373        {
     1374          FILE_TIMESTAMP ltime;
     1375          PATH_VAR (lbuf);
     1376          long llen;
     1377          char *p;
     1378
     1379          EINTRLOOP (e, lstat (lpath, &st));
     1380          if (e)
     1381            {
     1382              /* Eh?  Just take what we have.  */
     1383              perror_with_name ("lstat: ", lpath);
     1384              break;
     1385            }
     1386
     1387          /* If this is not a symlink, we're done (we started with the real
     1388             file's mtime so we don't need to test it again).  */
     1389          if (!S_ISLNK (st.st_mode))
     1390            break;
     1391
     1392          /* If this mtime is newer than what we had, keep the new one.  */
     1393          ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st);
     1394          if (ltime > mtime)
     1395            mtime = ltime;
     1396
     1397          /* Set up to check the file pointed to by this link.  */
     1398          EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX));
     1399          if (llen < 0)
     1400            {
     1401              /* Eh?  Just take what we have.  */
     1402              perror_with_name ("readlink: ", lpath);
     1403              break;
     1404            }
     1405          lbuf[llen] = '\0';
     1406
     1407          /* If the target is fully-qualified or the source is just a
     1408             filename, then the new path is the target.  Otherwise it's the
     1409             source directory plus the target.  */
     1410          if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL)
     1411            strcpy (lpath, lbuf);
     1412          else if ((p - lpath) + llen + 2 > GET_PATH_MAX)
     1413            /* Eh?  Path too long!  Again, just go with what we have.  */
     1414            break;
     1415          else
     1416            /* Create the next step in the symlink chain.  */
     1417            strcpy (p+1, lbuf);
     1418        }
     1419    }
     1420#endif
     1421
     1422  return mtime;
    13001423}
    13011424
  • trunk/src/gmake/variable.c

    r225 r287  
    500500
    501501          do
    502             /* We found one, so insert it into the set.  */
    503             do_variable_definition (&p->variable.fileinfo, p->variable.name,
    504                                     p->variable.value, p->variable.origin,
    505                                     p->variable.flavor, 1);
     502            {
     503              /* We found one, so insert it into the set.  */
     504
     505              struct variable *v;
     506
     507              if (p->variable.flavor == f_simple)
     508                {
     509                  v = define_variable_loc (
     510                    p->variable.name, strlen (p->variable.name),
     511                    p->variable.value, p->variable.origin,
     512                    0, &p->variable.fileinfo);
     513
     514                  v->flavor = f_simple;
     515                }
     516              else
     517                {
     518                  v = do_variable_definition (
     519                    &p->variable.fileinfo, p->variable.name,
     520                    p->variable.value, p->variable.origin,
     521                    p->variable.flavor, 1);
     522                }
     523
     524              /* Also mark it as a per-target and copy export status. */
     525              v->per_target = p->variable.per_target;
     526              v->export = p->variable.export;
     527            }
    506528          while ((p = lookup_pattern_var (p, file->name)) != 0);
    507529
     
    735757#endif
    736758
    737   /* This won't override any definition, but it
    738      will provide one if there isn't one there.  */
     759  /* This won't override any definition, but it will provide one if there
     760     isn't one there.  */
    739761  v = define_variable ("SHELL", 5, default_shell, o_default, 0);
    740   v->export = v_export;         /* Always export SHELL.  */
    741 
    742   /* On MSDOS we do use SHELL from environment, since
    743      it isn't a standard environment variable on MSDOS,
    744      so whoever sets it, does that on purpose.
    745      On OS/2 we do not use SHELL from environment but
    746      we have already handled that problem above. */
     762
     763  /* On MSDOS we do use SHELL from environment, since it isn't a standard
     764     environment variable on MSDOS, so whoever sets it, does that on purpose.
     765     On OS/2 we do not use SHELL from environment but we have already handled
     766     that problem above. */
    747767#if !defined(__MSDOS__) && !defined(__EMX__)
    748768  /* Don't let SHELL come from the environment.  */
     
    862882
    863883              case v_noexport:
    864                 continue;
     884                /* If this is the SHELL variable and it's not exported, then
     885                   add the value from our original environment.  */
     886                if (streq (v->name, "SHELL"))
     887                  {
     888                    extern struct variable shell_var;
     889                    v = &shell_var;
     890                    break;
     891                  }
     892                continue;
    865893
    866894              case v_ifset:
     
    9771005            v = lookup_variable_in_set (varname, strlen (varname),
    9781006                                        current_variable_set_list->set);
     1007
     1008            /* Don't append from the global set if a previous non-appending
     1009               target-specific variable definition exists. */
     1010            if (v && !v->append)
     1011              append = 0;
    9791012          }
    9801013        else
     
    10351068      && strcmp (varname, "SHELL") == 0)
    10361069    {
    1037       char shellpath[PATH_MAX];
     1070      PATH_VAR (shellpath);
    10381071      extern char * __dosexec_find_on_path (const char *, char *[], char *);
    10391072
     
    14201453sync_Path_environment (void)
    14211454{
    1422   char *path = allocated_variable_expand ("$(Path)");
     1455  char *path = allocated_variable_expand ("$(PATH)");
    14231456  static char *environ_path = NULL;
    14241457
     
    14371470   */
    14381471  convert_Path_to_windows32 (path, ';');
    1439   environ_path = concat ("Path", "=", path);
     1472  environ_path = concat ("PATH", "=", path);
    14401473  putenv (environ_path);
    14411474  free (path);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette