Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/remake.c

    r2857 r3140  
    11/* Basic dependency engine for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
    2018#include "filedef.h"
    2119#include "job.h"
     
    4038#endif
    4139
    42 extern int try_implicit_rule (struct file *file, unsigned int depth);
    43 
    4440
    4541/* The test for circular dependencies is based on the 'updating' bit in
    46    `struct file'.  However, double colon targets have seperate `struct
     42   'struct file'.  However, double colon targets have separate 'struct
    4743   file's; make sure we always use the base of the double colon chain. */
    4844
     
    5854unsigned int commands_started = 0;
    5955
    60 /* Current value for pruning the scan of the goal chain (toggle 0/1).  */
    61 static unsigned int considered;
    62 
    63 static int update_file (struct file *file, unsigned int depth);
    64 static int update_file_1 (struct file *file, unsigned int depth);
    65 static int check_dep (struct file *file, unsigned int depth,
    66                       FILE_TIMESTAMP this_mtime, int *must_make_ptr);
    67 #ifdef CONFIG_WITH_DOT_MUST_MAKE
    68 static int call_must_make_target_var (struct file *file, unsigned int depth);
    69 #endif
    70 #ifdef CONFIG_WITH_DOT_IS_CHANGED
    71 static int call_is_changed_target_var (struct file *file);
    72 #endif
    73 static int touch_file (struct file *file);
     56/* Set to the goal dependency.  Mostly needed for remaking makefiles.  */
     57static struct goaldep *goal_list;
     58static struct dep *goal_dep;
     59
     60/* Current value for pruning the scan of the goal chain.
     61   All files start with considered == 0.  */
     62static unsigned int considered = 0;
     63
     64static enum update_status update_file (struct file *file, unsigned int depth);
     65static enum update_status update_file_1 (struct file *file, unsigned int depth);
     66static enum update_status check_dep (struct file *file, unsigned int depth,
     67                                     FILE_TIMESTAMP this_mtime, int *must_make);
     68static enum update_status touch_file (struct file *file);
    7469static void remake_file (struct file *file);
    7570static FILE_TIMESTAMP name_mtime (const char *name);
    7671static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
    7772
    78 
    79 
    80 /* Remake all the goals in the `struct dep' chain GOALS.  Return -1 if nothing
     73#ifdef CONFIG_WITH_DOT_MUST_MAKE
     74static int call_must_make_target_var (struct file *file, unsigned int depth);
     75#endif
     76#ifdef CONFIG_WITH_DOT_IS_CHANGED
     77static int call_is_changed_target_var (struct file *file);
     78#endif
     79
     80
     81
     82/* Remake all the goals in the 'struct dep' chain GOALS.  Return -1 if nothing
    8183   was done, 0 if all goals were updated successfully, or 1 if a goal failed.
    8284
     
    8486   and -n should be disabled for them unless they were also command-line
    8587   targets, and we should only make one goal at a time and return as soon as
    86    one goal whose `changed' member is nonzero is successfully made.  */
    87 
    88 int
    89 update_goal_chain (struct dep *goals)
     88   one goal whose 'changed' member is nonzero is successfully made.  */
     89
     90enum update_status
     91update_goal_chain (struct goaldep *goaldeps)
    9092{
    9193  int t = touch_flag, q = question_flag, n = just_print_flag;
    92   int status = -1;
    93 
    94 #define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
    95                      : file_mtime (file))
     94  enum update_status status = us_none;
    9695
    9796  /* Duplicate the chain so we can remove things from it.  */
    9897
    99   goals = copy_dep_chain (goals);
    100 
    101   {
    102     /* Clear the `changed' flag of each goal in the chain.
    103        We will use the flag below to notice when any commands
    104        have actually been run for a target.  When no commands
    105        have been run, we give an "up to date" diagnostic.  */
    106 
    107     struct dep *g;
    108     for (g = goals; g != 0; g = g->next)
    109       g->changed = 0;
    110   }
    111 
    112   /* All files start with the considered bit 0, so the global value is 1.  */
    113   considered = 1;
     98  struct dep *goals = copy_dep_chain ((struct dep *)goaldeps);
     99
     100  goal_list = rebuilding_makefiles ? goaldeps : NULL;
     101
     102#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
     103                     : file_mtime (file))
     104
     105  /* Start a fresh batch of consideration.  */
     106  ++considered;
    114107
    115108  /* Update all the goals until they are all finished.  */
     
    130123      g = goals;
    131124      while (g != 0)
    132         {
    133           /* Iterate over all double-colon entries for this file.  */
    134           struct file *file;
    135           int stop = 0, any_not_updated = 0;
    136 
    137           for (file = g->file->double_colon ? g->file->double_colon : g->file;
    138                file != NULL;
    139                file = file->prev)
    140             {
    141               unsigned int ocommands_started;
    142               int x;
    143 
    144               file->dontcare = g->dontcare;
    145 
    146               check_renamed (file);
    147               if (rebuilding_makefiles)
    148                 {
    149                   if (file->cmd_target)
    150                     {
    151                       touch_flag = t;
    152                       question_flag = q;
    153                       just_print_flag = n;
    154                     }
    155                   else
    156                     touch_flag = question_flag = just_print_flag = 0;
    157                 }
    158 
    159               /* Save the old value of `commands_started' so we can compare
    160                  later.  It will be incremented when any commands are
    161                  actually run.  */
    162               ocommands_started = commands_started;
    163 
    164               x = update_file (file, rebuilding_makefiles ? 1 : 0);
    165               check_renamed (file);
    166 
    167               /* Set the goal's `changed' flag if any commands were started
    168                  by calling update_file above.  We check this flag below to
    169                  decide when to give an "up to date" diagnostic.  */
     125        {
     126          /* Iterate over all double-colon entries for this file.  */
     127          struct file *file;
     128          int stop = 0, any_not_updated = 0;
     129
     130          goal_dep = g;
     131
     132          for (file = g->file->double_colon ? g->file->double_colon : g->file;
     133               file != NULL;
     134               file = file->prev)
     135            {
     136              unsigned int ocommands_started;
     137              enum update_status fail;
     138
     139              file->dontcare = ANY_SET (g->flags, RM_DONTCARE);
     140
     141              check_renamed (file);
     142              if (rebuilding_makefiles)
     143                {
     144                  if (file->cmd_target)
     145                    {
     146                      touch_flag = t;
     147                      question_flag = q;
     148                      just_print_flag = n;
     149                    }
     150                  else
     151                    touch_flag = question_flag = just_print_flag = 0;
     152                }
     153
     154              /* Save the old value of 'commands_started' so we can compare
     155                 later.  It will be incremented when any commands are
     156                 actually run.  */
     157              ocommands_started = commands_started;
     158
     159              fail = update_file (file, rebuilding_makefiles ? 1 : 0);
     160              check_renamed (file);
     161
     162              /* Set the goal's 'changed' flag if any commands were started
     163                 by calling update_file above.  We check this flag below to
     164                 decide when to give an "up to date" diagnostic.  */
    170165              if (commands_started > ocommands_started)
    171166                g->changed = 1;
    172167
    173               /* If we updated a file and STATUS was not already 1, set it to
    174                  1 if updating failed, or to 0 if updating succeeded.  Leave
    175                  STATUS as it is if no updating was done.  */
    176 
    177               stop = 0;
    178               if ((x != 0 || file->updated) && status < 1)
     168              stop = 0;
     169              if ((fail || file->updated) && status < us_question)
    179170                {
    180                   if (file->update_status != 0)
     171                  /* We updated this goal.  Update STATUS and decide whether
     172                     to stop.  */
     173                  if (file->update_status)
    181174                    {
    182175                      /* Updating failed, or -q triggered.  The STATUS value
     
    205198                          if (!rebuilding_makefiles
    206199                              || (!just_print_flag && !question_flag))
    207                             status = 0;
     200                            status = us_success;
    208201                          if (rebuilding_makefiles && file->dontcare)
    209202                            /* This is a default makefile; stop remaking.  */
     
    213206                }
    214207
    215               /* Keep track if any double-colon entry is not finished.
     208              /* Keep track if any double-colon entry is not finished.
    216209                 When they are all finished, the goal is finished.  */
    217               any_not_updated |= !file->updated;
     210              any_not_updated |= !file->updated;
    218211
    219212              file->dontcare = 0;
    220213
    221               if (stop)
    222                 break;
    223             }
    224 
    225           /* Reset FILE since it is null at the end of the loop.  */
    226           file = g->file;
    227 
    228           if (stop || !any_not_updated)
    229             {
    230               /* If we have found nothing whatever to do for the goal,
    231                 print a message saying nothing needs doing.  */
    232 
    233               if (!rebuilding_makefiles
    234                   /* If the update_status is zero, we updated successfully
    235                      or not at all.  G->changed will have been set above if
    236                      any commands were actually started for this goal.  */
    237                   && file->update_status == 0 && !g->changed
    238                   /* Never give a message under -s or -q.  */
    239                   && !silent_flag && !question_flag)
    240                 message (1, ((file->phony || file->cmds == 0)
    241                              ? _("Nothing to be done for `%s'.")
    242                              : _("`%s' is up to date.")),
    243                         file->name);
    244 
    245               /* This goal is finished.  Remove it from the chain.  */
    246               if (lastgoal == 0)
    247                 goals = g->next;
    248               else
    249                 lastgoal->next = g->next;
    250 
    251               /* Free the storage.  */
     214              if (stop)
     215                break;
     216            }
     217
     218          /* Reset FILE since it is null at the end of the loop.  */
     219          file = g->file;
     220
     221          if (stop || !any_not_updated)
     222            {
     223              /* If we have found nothing whatever to do for the goal,
     224                print a message saying nothing needs doing.  */
     225
     226              if (!rebuilding_makefiles
     227                  /* If the update_status is success, we updated successfully
     228                     or not at all.  G->changed will have been set above if
     229                     any commands were actually started for this goal.  */
     230                  && file->update_status == us_success && !g->changed
     231                  /* Never give a message under -s or -q.  */
     232                  && !silent_flag && !question_flag)
     233                OS (message, 1, ((file->phony || file->cmds == 0)
     234                                 ? _("Nothing to be done for '%s'.")
     235                                 : _("'%s' is up to date.")),
     236                    file->name);
     237
     238              /* This goal is finished.  Remove it from the chain.  */
     239              if (lastgoal == 0)
     240                goals = g->next;
     241              else
     242                lastgoal->next = g->next;
     243
     244              /* Free the storage.  */
    252245#ifndef CONFIG_WITH_ALLOC_CACHES
    253               free (g);
     246              free (g);
    254247#else
    255248              free_dep (g);
    256249#endif
    257250
    258               g = lastgoal == 0 ? goals : lastgoal->next;
    259 
    260               if (stop)
    261                 break;
    262             }
    263           else
    264             {
    265               lastgoal = g;
    266               g = g->next;
    267             }
    268         }
    269 
    270       /* If we reached the end of the dependency graph toggle the considered
    271          flag for the next pass.  */
     251              g = lastgoal == 0 ? goals : lastgoal->next;
     252
     253              if (stop)
     254                break;
     255            }
     256          else
     257            {
     258              lastgoal = g;
     259              g = g->next;
     260            }
     261        }
     262
     263      /* If we reached the end of the dependency graph update CONSIDERED
     264         for the next pass.  */
    272265      if (g == 0)
    273         considered = !considered;
     266        ++considered;
    274267    }
    275268
     
    285278
    286279
     280/* If we're rebuilding an included makefile that failed, and we care
     281   about errors, show an error message the first time.  */
     282
     283void
     284show_goal_error (void)
     285{
     286  struct goaldep *goal;
     287
     288  if ((goal_dep->flags & (RM_INCLUDED|RM_DONTCARE)) != RM_INCLUDED)
     289    return;
     290
     291  for (goal = goal_list; goal; goal = goal->next)
     292    if (goal_dep->file == goal->file)
     293      {
     294        if (goal->error)
     295          {
     296            OSS (error, &goal->floc, "%s: %s",
     297                 goal->file->name, strerror ((int)goal->error));
     298            goal->error = 0;
     299          }
     300        return;
     301      }
     302}
     303
     304
    287305/* If FILE is not up to date, execute the commands for it.
    288    Return 0 if successful, 1 if unsuccessful;
    289    but with some flag settings, just call `exit' if unsuccessful.
     306   Return 0 if successful, non-0 if unsuccessful;
     307   but with some flag settings, just call 'exit' if unsuccessful.
    290308
    291309   DEPTH is the depth in recursions of this function.
     
    297315   each is considered in turn.  */
    298316
    299 static int
     317static enum update_status
    300318update_file (struct file *file, unsigned int depth)
    301319{
    302   register int status = 0;
    303   register struct file *f;
     320  enum update_status status = us_success;
     321  struct file *f;
    304322
    305323  f = file->double_colon ? file->double_colon : file;
     
    312330    {
    313331      /* Check for the case where a target has been tried and failed but
    314          the diagnostics hasn't been issued. If we need the diagnostics
     332         the diagnostics haven't been issued. If we need the diagnostics
    315333         then we will have to continue. */
    316       if (!(f->updated && f->update_status > 0 && !f->dontcare && f->no_diag))
    317         {
    318           DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
    319           return f->command_state == cs_finished ? f->update_status : 0;
     334      if (!(f->updated && f->update_status > us_none
     335            && !f->dontcare && f->no_diag))
     336        {
     337          DBF (DB_VERBOSE, _("Pruning file '%s'.\n"));
     338          return f->command_state == cs_finished ? f->update_status : us_success;
    320339        }
    321340    }
     
    325344  for (; f != 0; f = f->prev)
    326345    {
     346      enum update_status new;
     347
    327348      f->considered = considered;
    328349
    329       status |= update_file_1 (f, depth);
     350      new = update_file_1 (f, depth);
    330351      check_renamed (f);
    331352
     
    334355
    335356      /* If we got an error, don't bother with double_colon etc.  */
    336       if (status != 0 && !keep_going_flag)
    337         return status;
     357      if (new && !keep_going_flag)
     358        return new;
    338359
    339360      if (f->command_state == cs_running
    340361          || f->command_state == cs_deps_running)
    341         {
    342           /* Don't run the other :: rules for this
    343              file until this rule is finished.  */
    344           status = 0;
    345           break;
    346         }
     362        /* Don't run other :: rules for this target until
     363           this rule is finished.  */
     364        return us_success;
     365
     366      if (new > status)
     367        status = new;
    347368    }
    348369
     
    357378
    358379        for (d = f->deps; d != 0; d = d->next)
    359           status |= update_file (d->file, depth + 1);
     380          {
     381            enum update_status new = update_file (d->file, depth + 1);
     382            if (new > status)
     383              status = new;
     384          }
    360385      }
    361386
     
    369394complain (struct file *file)
    370395{
    371   const char *msg_noparent
    372     = _("%sNo rule to make target `%s'%s");
    373   const char *msg_parent
    374     = _("%sNo rule to make target `%s', needed by `%s'%s");
    375 
    376396  /* If this file has no_diag set then it means we tried to update it
    377397     before in the dontcare mode and failed. The target that actually
     
    384404  for (d = file->deps; d != 0; d = d->next)
    385405    {
    386       if (d->file->updated && d->file->update_status > 0 && file->no_diag)
     406      if (d->file->updated && d->file->update_status > us_none && file->no_diag)
    387407        {
    388408          complain (d->file);
     
    393413  if (d == 0)
    394414    {
     415      show_goal_error ();
     416
    395417      /* Didn't find any dependencies to complain about. */
    396418
     
    435457#endif /* KMK */
    436458
    437       if (!keep_going_flag)
    438         {
    439           if (file->parent == 0)
    440             fatal (NILF, msg_noparent, "", file->name, "");
    441 
    442           fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
    443         }
    444 
    445       if (file->parent == 0)
    446         error (NILF, msg_noparent, "*** ", file->name, ".");
     459      if (file->parent)
     460        {
     461          size_t l = strlen (file->name) + strlen (file->parent->name) + 4;
     462          const char *m = _("%sNo rule to make target '%s', needed by '%s'%s");
     463
     464          if (!keep_going_flag)
     465            fatal (NILF, l, m, "", file->name, file->parent->name, "");
     466
     467          error (NILF, l, m, "*** ", file->name, file->parent->name, ".");
     468        }
    447469      else
    448         error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
     470        {
     471          size_t l = strlen (file->name) + 4;
     472          const char *m = _("%sNo rule to make target '%s'%s");
     473
     474          if (!keep_going_flag)
     475            fatal (NILF, l, m, "", file->name, "");
     476
     477          error (NILF, l, m, "*** ", file->name, ".");
     478        }
    449479
    450480      file->no_diag = 0;
     
    452482}
    453483
    454 /* Consider a single `struct file' and update it as appropriate.  */
    455 
    456 static int
     484/* Consider a single 'struct file' and update it as appropriate.
     485   Return 0 on success, or non-0 on failure.  */
     486
     487static enum update_status
    457488update_file_1 (struct file *file, unsigned int depth)
    458489{
     490  enum update_status dep_status = us_success;
    459491  FILE_TIMESTAMP this_mtime;
    460492  int noexist, must_make, deps_changed;
    461   int dep_status = 0;
    462493  struct file *ofile;
    463494  struct dep *d, *ad;
     
    482513    {
    483514      if (file->multi_head == file)
    484         DBS (DB_VERBOSE, (_("Considering target file `%s'  (multi head).\n"), file->name));
     515        DBS (DB_VERBOSE, (_("Considering target file '%s'  (multi head).\n"), file->name));
    485516      else
    486517        {
    487518          org_file = file = file->multi_head;
    488           DBS (DB_VERBOSE, (_("Considering target file `%s' -> multi head `%s'.\n"),
     519          DBS (DB_VERBOSE, (_("Considering target file '%s' -> multi head '%s'.\n"),
    489520                              req_file->name, file->name));
    490521          assert (file->multi_head == file);
     
    493524  else
    494525#endif /* CONFIG_WITH_EXPLICIT_MULTITARGET */
    495     DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
     526    DBF (DB_VERBOSE, _("Considering target file '%s'.\n"));
    496527
    497528  if (file->updated)
    498529    {
    499       if (file->update_status > 0)
    500         {
    501           DBF (DB_VERBOSE,
    502                _("Recently tried and failed to update file `%s'.\n"));
     530      if (file->update_status > us_none)
     531        {
     532          DBF (DB_VERBOSE,
     533               _("Recently tried and failed to update file '%s'.\n"));
    503534
    504535          /* If the file we tried to make is marked no_diag then no message
     
    509540              complain (file);
    510541
    511           return file->update_status;
    512         }
    513 
    514       DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
     542          return file->update_status;
     543        }
     544
     545      DBF (DB_VERBOSE, _("File '%s' was considered already.\n"));
    515546      return 0;
    516547    }
     
    522553      break;
    523554    case cs_running:
    524       DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
     555      DBF (DB_VERBOSE, _("Still updating file '%s'.\n"));
    525556      return 0;
    526557    case cs_finished:
    527       DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
     558      DBF (DB_VERBOSE, _("Finished updating file '%s'.\n"));
    528559      return file->update_status;
    529560    default:
     
    582613  noexist = this_mtime == NONEXISTENT_MTIME;
    583614  if (noexist)
    584     DBS (DB_BASIC, (_("File `%s' does not exist.\n"), f3->name));
     615    DBS (DB_BASIC, (_("File '%s' does not exist.\n"), f3->name));
    585616#else /* !CONFIG_WITH_EXPLICIT_MULTITARGET */
    586617  this_mtime = file_mtime (file);
     
    588619  noexist = this_mtime == NONEXISTENT_MTIME;
    589620  if (noexist)
    590     DBF (DB_BASIC, _("File `%s' does not exist.\n"));
     621    DBF (DB_BASIC, _("File '%s' does not exist.\n"));
    591622#endif /* !CONFIG_WITH_EXPLICIT_MULTITARGET */
    592623  else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
    593            && file->low_resolution_time)
     624           && file->low_resolution_time)
    594625    {
    595626      /* Avoid spurious rebuilds due to low resolution time stamps.  */
    596627      int ns = FILE_TIMESTAMP_NS (this_mtime);
    597628      if (ns != 0)
    598         error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file `%s' has a high resolution time stamp"),
    599                file->name);
     629        OS (error, NILF,
     630            _("*** Warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"),
     631            file->name);
    600632      this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
    601633    }
     
    609641    {
    610642      if (try_implicit_rule (file, depth))
    611         DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
     643        DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
    612644      else
    613         DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
     645        DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
    614646      file->tried_implicit = 1;
    615647    }
     
    617649      && default_file != 0 && default_file->cmds != 0)
    618650    {
    619       DBF (DB_IMPLICIT, _("Using default recipe for `%s'.\n"));
     651      DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n"));
    620652      file->cmds = default_file->cmds;
    621653    }
     
    648680      while (d)
    649681        {
     682          enum update_status new;
    650683          FILE_TIMESTAMP mtime;
    651684          int maybe_make;
     
    669702#endif
    670703
    671               error (NILF, _("Circular %s <- %s dependency dropped."),
    672                      file->name, d->file->name);
     704              OSS (error, NILF, _("Circular %s <- %s dependency dropped."),
     705                   file->name, d->file->name);
    673706              /* We cannot free D here because our the caller will still have
    674707                 a reference to it when we were called recursively via
     
    692725            }
    693726
    694           dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
     727          new = check_dep (d->file, depth, this_mtime, &maybe_make);
     728          if (new > dep_status)
     729            dep_status = new;
    695730
    696731          /* Restore original dontcare flag. */
     
    716751          }
    717752
    718           if (dep_status != 0 && !keep_going_flag)
     753          if (dep_status && !keep_going_flag)
    719754            break;
    720755
    721756          if (!running)
    722             /* The prereq is considered changed if the timestamp has changed while
    723                it was built, OR it doesn't exist.  */
     757            /* The prereq is considered changed if the timestamp has changed
     758               while it was built, OR it doesn't exist.  */
    724759            d->changed = ((file_mtime (d->file) != mtime)
    725760                          || (mtime == NONEXISTENT_MTIME));
     
    757792    {
    758793#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    759       for (file = f2 = org_file; f2; file = f2 = f2->multi_next)
    760 #endif
    761         for (d = file->deps; d != 0; d = d->next)
    762           if (d->file->intermediate)
     794     for (file = f2 = org_file; f2; file = f2 = f2->multi_next)
     795#endif
     796      for (d = file->deps; d != 0; d = d->next)
     797        if (d->file->intermediate)
     798          {
     799            enum update_status new;
     800            int dontcare = 0;
     801
     802            FILE_TIMESTAMP mtime = file_mtime (d->file);
     803            check_renamed (d->file);
     804            d->file->parent = file;
     805
     806            /* Inherit dontcare flag from our parent. */
     807            if (rebuilding_makefiles)
     808              {
     809                dontcare = d->file->dontcare;
     810                d->file->dontcare = file->dontcare;
     811              }
     812
     813            /* We may have already considered this file, when we didn't know
     814               we'd need to update it.  Force update_file() to consider it and
     815               not prune it.  */
     816            d->file->considered = 0;
     817
     818            new = update_file (d->file, depth);
     819            if (new > dep_status)
     820              dep_status = new;
     821
     822            /* Restore original dontcare flag. */
     823            if (rebuilding_makefiles)
     824              d->file->dontcare = dontcare;
     825
     826            check_renamed (d->file);
     827
    763828            {
    764               int dontcare = 0;
    765 
    766               FILE_TIMESTAMP mtime = file_mtime (d->file);
    767               check_renamed (d->file);
    768               d->file->parent = file;
    769 
    770               /* Inherit dontcare flag from our parent. */
    771               if (rebuilding_makefiles)
     829              register struct file *f = d->file;
     830              if (f->double_colon)
     831                f = f->double_colon;
     832              do
    772833                {
    773                   dontcare = d->file->dontcare;
    774                   d->file->dontcare = file->dontcare;
     834                  running |= (f->command_state == cs_running
     835                              || f->command_state == cs_deps_running);
     836                  f = f->prev;
    775837                }
    776 
    777 
    778               dep_status |= update_file (d->file, depth);
    779 
    780               /* Restore original dontcare flag. */
    781               if (rebuilding_makefiles)
    782                 d->file->dontcare = dontcare;
    783 
    784               check_renamed (d->file);
    785 
    786               {
    787                 register struct file *f = d->file;
    788                 if (f->double_colon)
    789                 f = f->double_colon;
    790                 do
    791                 {
    792                   running |= (f->command_state == cs_running
    793                               || f->command_state == cs_deps_running);
    794                   f = f->prev;
    795                 }
    796                 while (f != 0);
    797               }
    798 
    799               if (dep_status != 0 && !keep_going_flag)
    800                 break;
    801 
    802               if (!running)
    803                 d->changed = ((file->phony && file->cmds != 0)
    804                             || file_mtime (d->file) != mtime);
     838              while (f != 0);
    805839            }
     840
     841            if (dep_status && !keep_going_flag)
     842              break;
     843
     844            if (!running)
     845              d->changed = ((file->phony && file->cmds != 0)
     846                            || file_mtime (d->file) != mtime);
     847          }
    806848#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    807849      file = org_file;
     
    812854  finish_updating (ofile);
    813855
    814   DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
     856  DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n"));
    815857
    816858  if (running)
     
    818860      set_command_state (file, cs_deps_running);
    819861      --depth;
    820       DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
     862      DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n"));
    821863      return 0;
    822864    }
     
    824866  /* If any dependency failed, give up now.  */
    825867
    826   if (dep_status != 0)
    827     {
    828       file->update_status = dep_status;
     868  if (dep_status)
     869    {
     870      /* I'm not sure if we can't just assign dep_status...  */
     871      file->update_status = dep_status == us_none ? us_failed : dep_status;
    829872      notice_finished_file (file);
    830873
    831874      --depth;
    832875
    833       DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
     876      DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n"));
    834877
    835878      if (depth == 0 && keep_going_flag
    836           && !just_print_flag && !question_flag)
    837         error (NILF,
    838                _("Target `%s' not remade because of errors."), file->name);
     879          && !just_print_flag && !question_flag)
     880        OS (error, NILF,
     881            _("Target '%s' not remade because of errors."), file->name);
    839882
    840883      return dep_status;
     
    857900  deps_changed = 0;
    858901#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    859   for (file = f2 = org_file; f2; file = f2 = f2->multi_next)
    860 #endif
    861     for (d = file->deps; d != 0; d = d->next)
    862       {
    863         FILE_TIMESTAMP d_mtime = file_mtime (d->file);
     902 for (file = f2 = org_file; f2; file = f2 = f2->multi_next)
     903#endif
     904  for (d = file->deps; d != 0; d = d->next)
     905    {
     906      FILE_TIMESTAMP d_mtime = file_mtime (d->file);
    864907#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    865908        if (d->file == file && file->multi_maybe)
    866909          continue;
    867910#endif
    868         check_renamed (d->file);
    869 
    870         if (! d->ignore_mtime)
    871           {
     911      check_renamed (d->file);
     912
     913      if (! d->ignore_mtime)
     914        {
    872915#if 1
    873             /* %%% In version 4, remove this code completely to
    874              implement not remaking deps if their deps are newer
    875              than their parents.  */
    876             if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
    877               /* We must remake if this dep does not
    878                  exist and is not intermediate.  */
    879               must_make = 1;
    880 #endif
    881 
    882             /* Set DEPS_CHANGED if this dep actually changed.  */
    883             deps_changed |= d->changed;
    884           }
    885 
    886         /* Set D->changed if either this dep actually changed,
    887            or its dependent, FILE, is older or does not exist.  */
    888         d->changed |= noexist || d_mtime > this_mtime;
    889 
    890         if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
    891           {
    892             const char *fmt = 0;
    893 
    894             if (d->ignore_mtime)
    895               {
    896                 if (ISDB (DB_VERBOSE))
    897                   fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
    898               }
    899             else if (d_mtime == NONEXISTENT_MTIME)
    900               {
    901                 if (ISDB (DB_BASIC))
    902                   fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
    903               }
    904             else if (d->changed)
    905               {
    906                 if (ISDB (DB_BASIC))
    907                   fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
    908               }
    909             else if (ISDB (DB_VERBOSE))
    910               fmt = _("Prerequisite `%s' is older than target `%s'.\n");
    911 
    912             if (fmt)
    913               {
    914                 print_spaces (depth);
    915                 printf (fmt, dep_name (d), file->name);
    916                 fflush (stdout);
    917               }
    918           }
    919       }
     916          /* %%% In version 4, remove this code completely to
     917           implement not remaking deps if their deps are newer
     918           than their parents.  */
     919          if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
     920            /* We must remake if this dep does not
     921               exist and is not intermediate.  */
     922            must_make = 1;
     923#endif
     924
     925          /* Set DEPS_CHANGED if this dep actually changed.  */
     926          deps_changed |= d->changed;
     927        }
     928
     929      /* Set D->changed if either this dep actually changed,
     930         or its dependent, FILE, is older or does not exist.  */
     931      d->changed |= noexist || d_mtime > this_mtime;
     932
     933      if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
     934        {
     935          const char *fmt = 0;
     936
     937          if (d->ignore_mtime)
     938            {
     939              if (ISDB (DB_VERBOSE))
     940                fmt = _("Prerequisite '%s' is order-only for target '%s'.\n");
     941            }
     942          else if (d_mtime == NONEXISTENT_MTIME)
     943            {
     944              if (ISDB (DB_BASIC))
     945                fmt = _("Prerequisite '%s' of target '%s' does not exist.\n");
     946            }
     947          else if (d->changed)
     948            {
     949              if (ISDB (DB_BASIC))
     950                fmt = _("Prerequisite '%s' is newer than target '%s'.\n");
     951            }
     952          else if (ISDB (DB_VERBOSE))
     953            fmt = _("Prerequisite '%s' is older than target '%s'.\n");
     954
     955          if (fmt)
     956            {
     957              print_spaces (depth);
     958              printf (fmt, dep_name (d), file->name);
     959              fflush (stdout);
     960            }
     961        }
     962    }
    920963#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    921964  file = org_file;
     
    929972      must_make = 1;
    930973      DBF (DB_BASIC,
    931            _("Target `%s' is double-colon and has no prerequisites.\n"));
     974           _("Target '%s' is double-colon and has no prerequisites.\n"));
    932975    }
    933976  else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
     
    936979      must_make = 0;
    937980      DBF (DB_VERBOSE,
    938            _("No recipe for `%s' and no prerequisites actually changed.\n"));
     981           _("No recipe for '%s' and no prerequisites actually changed.\n"));
    939982    }
    940983  else if (!must_make && file->cmds != 0 && always_make_flag)
    941984    {
    942985      must_make = 1;
    943       DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
     986      DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n"));
    944987    }
    945988
     
    949992        {
    950993          print_spaces (depth);
    951           printf (_("No need to remake target `%s'"), file->name);
     994          printf (_("No need to remake target '%s'"), file->name);
    952995          if (!streq (file->name, file->hname))
    953               printf (_("; using VPATH name `%s'"), file->hname);
     996              printf (_("; using VPATH name '%s'"), file->hname);
    954997          puts (".");
    955998          fflush (stdout);
     
    9711014    }
    9721015
    973   DBF (DB_BASIC, _("Must remake target `%s'.\n"));
     1016  DBF (DB_BASIC, _("Must remake target '%s'.\n"));
    9741017
    9751018  /* It needs to be remade.  If it's VPATH and not reset via GPATH, toss the
    9761019     VPATH.  */
    977   if (!streq(file->name, file->hname))
    978     {
    979       DB (DB_BASIC, (_("  Ignoring VPATH name `%s'.\n"), file->hname));
     1020  if (!streq (file->name, file->hname))
     1021    {
     1022      DB (DB_BASIC, (_("  Ignoring VPATH name '%s'.\n"), file->hname));
    9801023      file->ignore_vpath = 1;
    9811024    }
     
    9861029  if (file->command_state != cs_finished)
    9871030    {
    988       DBF (DB_VERBOSE, _("Recipe of `%s' is being run.\n"));
     1031      DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n"));
    9891032      return 0;
    9901033    }
     
    9921035  switch (file->update_status)
    9931036    {
    994     case 2:
    995       DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
     1037    case us_failed:
     1038      DBF (DB_BASIC, _("Failed to remake target file '%s'.\n"));
    9961039      break;
    997     case 0:
    998       DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
     1040    case us_success:
     1041      DBF (DB_BASIC, _("Successfully remade target file '%s'.\n"));
    9991042      break;
    1000     case 1:
    1001       DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
     1043    case us_question:
     1044      DBF (DB_BASIC, _("Target file '%s' needs to be remade under -q.\n"));
    10021045      break;
    1003     default:
    1004       assert (file->update_status >= 0 && file->update_status <= 2);
     1046    case us_none:
    10051047      break;
    10061048    }
     
    10091051  return file->update_status;
    10101052}
     1053
     1054
    10111055#ifdef CONFIG_WITH_DOT_MUST_MAKE
    1012 
    1013 
    10141056/* Consider the .MUST_MAKE target variable if present.
    10151057
     
    10481090
    10491091          ch = *str;
    1050           while (isspace (ch))
     1092          while (ISSPACE (ch))
    10511093            ch = *++str;
    10521094
     
    10661108}
    10671109#endif /* CONFIG_WITH_DOT_MUST_MAKE */
     1110
     1111
    10681112#ifdef CONFIG_WITH_DOT_IS_CHANGED
    1069 
    1070 
    10711113/* Consider the .IS_CHANGED target variable if present.
    10721114
     
    11041146          do
    11051147            ch = *str++;
    1106           while (isspace (ch));
     1148          while (ISSPACE (ch));
    11071149
    11081150          return (ch != '\0');
     
    11141156
    11151157
    1116 /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
    1117    files listed in its `also_make' member.  Under -t, this function also
     1158/* Set FILE's 'updated' flag and re-check its mtime and the mtime's of all
     1159   files listed in its 'also_make' member.  Under -t, this function also
    11181160   touches FILE.
    11191161
    1120    On return, FILE->update_status will no longer be -1 if it was.  */
     1162   On return, FILE->update_status will no longer be us_none if it was.  */
    11211163
    11221164void
     
    11611203  if (touch_flag
    11621204      /* The update status will be:
    1163                 -1      if this target was not remade;
    1164                 0       if 0 or more commands (+ or ${MAKE}) were run and won;
    1165                 1       if some commands were run and lost.
    1166         We touch the target if it has commands which either were not run
    1167         or won when they ran (i.e. status is 0).  */
    1168       && file->update_status == 0)
     1205           us_success   if 0 or more commands (+ or ${MAKE}) were run and won;
     1206           us_none      if this target was not remade;
     1207           >us_none     if some commands were run and lost.
     1208        We touch the target if it has commands which either were not run
     1209        or won when they ran (i.e. status is 0).  */
     1210      && file->update_status == us_success)
    11691211    {
    11701212      if (file->cmds != 0 && file->cmds->any_recurse)
    1171         {
    1172           /* If all the command lines were recursive,
    1173              we don't want to do the touching.  */
    1174           unsigned int i;
    1175           for (i = 0; i < file->cmds->ncommand_lines; ++i)
    1176             if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
    1177               goto have_nonrecursing;
    1178         }
     1213        {
     1214          /* If all the command lines were recursive,
     1215             we don't want to do the touching.  */
     1216          unsigned int i;
     1217          for (i = 0; i < file->cmds->ncommand_lines; ++i)
     1218            if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
     1219              goto have_nonrecursing;
     1220        }
    11791221      else
    1180         {
    1181         have_nonrecursing:
    1182           if (file->phony)
     1222        {
     1223        have_nonrecursing:
     1224          if (file->phony)
    11831225#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    11841226            {
    1185               file->update_status = 0;
     1227              file->update_status = us_success;
    11861228              if (file->multi_head)
    11871229                for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
    1188                   f2->update_status = 0;
     1230                  f2->update_status = us_success;
    11891231            }
    11901232#else
    1191             file->update_status = 0;
     1233            file->update_status = us_success;
    11921234#endif
    11931235          /* According to POSIX, -t doesn't affect targets with no cmds.  */
    1194           else if (file->cmds != 0)
     1236          else if (file->cmds != 0)
    11951237            {
    11961238              /* Should set file's modification date and do nothing else.  */
     
    12051247
    12061248              /* Pretend we ran a real touch command, to suppress the
    1207                  "`foo' is up to date" message.  */
     1249                 "'foo' is up to date" message.  */
    12081250              commands_started++;
    12091251
     
    12141256              touched = 1;
    12151257            }
    1216         }
     1258        }
    12171259    }
    12181260
     
    12441286
    12451287      else if (file->is_target && file->cmds == 0)
    1246         i = 1;
     1288        i = 1;
    12471289
    12481290      file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
     
    12821324    }
    12831325
    1284   if (ran && file->update_status != -1)
     1326  if (ran && file->update_status != us_none)
    12851327#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    1286     {
    1287 #endif
    1288       /* We actually tried to update FILE, which has
    1289          updated its also_make's as well (if it worked).
    1290          If it didn't work, it wouldn't work again for them.
    1291          So mark them as updated with the same status.  */
    1292       for (d = file->also_make; d != 0; d = d->next)
    1293         {
    1294           d->file->command_state = cs_finished;
    1295           d->file->updated = 1;
    1296           d->file->update_status = file->update_status;
    1297 
    1298           if (ran && !d->file->phony)
    1299             /* Fetch the new modification time.
    1300                We do this instead of just invalidating the cached time
    1301                so that a vpath_search can happen.  Otherwise, it would
    1302                never be done because the target is already updated.  */
    1303             f_mtime (d->file, 0);
    1304         }
     1328   {
     1329#endif
     1330    /* We actually tried to update FILE, which has
     1331       updated its also_make's as well (if it worked).
     1332       If it didn't work, it wouldn't work again for them.
     1333       So mark them as updated with the same status.  */
     1334    for (d = file->also_make; d != 0; d = d->next)
     1335      {
     1336        d->file->command_state = cs_finished;
     1337        d->file->updated = 1;
     1338        d->file->update_status = file->update_status;
     1339
     1340        if (ran && !d->file->phony)
     1341          /* Fetch the new modification time.
     1342             We do this instead of just invalidating the cached time
     1343             so that a vpath_search can happen.  Otherwise, it would
     1344             never be done because the target is already updated.  */
     1345          f_mtime (d->file, 0);
     1346      }
    13051347#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    1306       /* Same as above but for explicit multi target rules. */
    1307       if (file->multi_head)
    1308         for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
    1309           {
    1310             f2->update_status = file->update_status;
    1311             if (!f2->phony)
    1312               f_mtime (f2, 0);
    1313           }
    1314     }
    1315 #endif
    1316   else if (file->update_status == -1)
     1348    /* Same as above but for explicit multi target rules. */
     1349    if (file->multi_head)
     1350      for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
     1351        {
     1352          f2->update_status = file->update_status;
     1353          if (!f2->phony)
     1354            f_mtime (f2, 0);
     1355        }
     1356   }
     1357#endif
     1358  else if (file->update_status == us_none)
    13171359#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
    13181360    {
     
    13271369    /* Nothing was done for FILE, but it needed nothing done.
    13281370       So mark it now as "succeeded".  */
    1329     file->update_status = 0;
     1371    file->update_status = us_success;
    13301372#endif
    13311373
     
    13451387   failed.  */
    13461388
    1347 static int
     1389static enum update_status
    13481390check_dep (struct file *file, unsigned int depth,
    13491391           FILE_TIMESTAMP this_mtime, int *must_make_ptr)
     
    13511393  struct file *ofile;
    13521394  struct dep *d;
    1353   int dep_status = 0;
     1395  enum update_status dep_status = us_success;
    13541396
    13551397  ++depth;
     
    13701412      check_renamed (file);
    13711413      if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
    1372         *must_make_ptr = 1;
     1414        *must_make_ptr = 1;
    13731415#ifdef CONFIG_WITH_DOT_IS_CHANGED
    13741416      else if (   *must_make_ptr == 0
     
    13831425
    13841426      if (!file->phony && file->cmds == 0 && !file->tried_implicit)
    1385         {
    1386           if (try_implicit_rule (file, depth))
    1387             DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
    1388           else
    1389             DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
    1390           file->tried_implicit = 1;
    1391         }
     1427        {
     1428          if (try_implicit_rule (file, depth))
     1429            DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
     1430          else
     1431            DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
     1432          file->tried_implicit = 1;
     1433        }
    13921434      if (file->cmds == 0 && !file->is_target
    1393           && default_file != 0 && default_file->cmds != 0)
    1394         {
    1395           DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
    1396           file->cmds = default_file->cmds;
    1397         }
     1435          && default_file != 0 && default_file->cmds != 0)
     1436        {
     1437          DBF (DB_IMPLICIT, _("Using default commands for '%s'.\n"));
     1438          file->cmds = default_file->cmds;
     1439        }
    13981440
    13991441      check_renamed (file);
     
    14031445        /* If the intermediate file actually exists and is newer, then we
    14041446           should remake from it.  */
    1405         *must_make_ptr = 1;
     1447        *must_make_ptr = 1;
    14061448      else
    1407         {
     1449        {
    14081450          /* Otherwise, update all non-intermediate files we depend on, if
    14091451             necessary, and see whether any of them is more recent than the
    14101452             file on whose behalf we are checking.  */
    1411           struct dep *ld;
     1453          struct dep *ld;
    14121454          int deps_running = 0;
    14131455
     
    14161458             prerequisite and so wasn't rebuilt then, but should be now.  */
    14171459          if (file->command_state != cs_running)
    1418             set_command_state (file, cs_not_started);
    1419 
    1420           ld = 0;
    1421           d = file->deps;
    1422           while (d != 0)
    1423             {
     1460            {
     1461              /* If the target was waiting for a dependency it has to be
     1462                 reconsidered, as that dependency might have finished.  */
     1463              if (file->command_state == cs_deps_running)
     1464                file->considered = 0;
     1465
     1466              set_command_state (file, cs_not_started);
     1467            }
     1468
     1469          ld = 0;
     1470          d = file->deps;
     1471          while (d != 0)
     1472            {
     1473              enum update_status new;
    14241474              int maybe_make;
    14251475
    1426               if (is_updating (d->file))
    1427                 {
    1428                   error (NILF, _("Circular %s <- %s dependency dropped."),
    1429                         file->name, d->file->name);
    1430                   if (ld == 0)
    1431                     {
    1432                       file->deps = d->next;
     1476              if (is_updating (d->file))
     1477                {
     1478                  OSS (error, NILF, _("Circular %s <- %s dependency dropped."),
     1479                      file->name, d->file->name);
     1480                  if (ld == 0)
     1481                    {
     1482                      file->deps = d->next;
    14331483                      free_dep (d);
    1434                       d = file->deps;
    1435                     }
    1436                   else
    1437                     {
    1438                       ld->next = d->next;
     1484                      d = file->deps;
     1485                    }
     1486                  else
     1487                    {
     1488                      ld->next = d->next;
    14391489                      free_dep (d);
    1440                       d = ld->next;
    1441                     }
    1442                   continue;
    1443                 }
    1444 
    1445               d->file->parent = file;
     1490                      d = ld->next;
     1491                    }
     1492                  continue;
     1493                }
     1494
     1495              d->file->parent = file;
    14461496              maybe_make = *must_make_ptr;
    1447               dep_status |= check_dep (d->file, depth, this_mtime,
    1448                                        &maybe_make);
     1497              new = check_dep (d->file, depth, this_mtime, &maybe_make);
     1498              if (new > dep_status)
     1499                dep_status = new;
     1500
    14491501              if (! d->ignore_mtime)
    14501502                *must_make_ptr = maybe_make;
    1451               check_renamed (d->file);
    1452               if (dep_status != 0 && !keep_going_flag)
    1453                 break;
    1454 
    1455               if (d->file->command_state == cs_running
    1456                   || d->file->command_state == cs_deps_running)
    1457                 deps_running = 1;
    1458 
    1459               ld = d;
    1460               d = d->next;
    1461             }
     1503              check_renamed (d->file);
     1504              if (dep_status && !keep_going_flag)
     1505                break;
     1506
     1507              if (d->file->command_state == cs_running
     1508                  || d->file->command_state == cs_deps_running)
     1509                deps_running = 1;
     1510
     1511              ld = d;
     1512              d = d->next;
     1513            }
    14621514
    14631515          if (deps_running)
     
    14661518               commands are finished.  */
    14671519            set_command_state (file, cs_deps_running);
    1468         }
     1520        }
    14691521    }
    14701522
     
    14761528
    14771529
    1478 /* Touch FILE.  Return zero if successful, one if not.  */
    1479 
    1480 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
    1481 
    1482 static int
     1530/* Touch FILE.  Return us_success if successful, us_failed if not.  */
     1531
     1532#define TOUCH_ERROR(call) do{ perror_with_name ((call), file->name);    \
     1533                              return us_failed; }while(0)
     1534
     1535static enum update_status
    14831536touch_file (struct file *file)
    14841537{
    14851538  if (!silent_flag)
    1486     message (0, "touch %s", file->name);
    1487 
    1488 #ifndef NO_ARCHIVES
     1539    OS (message, 0, "touch %s", file->name);
     1540
     1541  /* Print-only (-n) takes precedence over touch (-t).  */
     1542  if (just_print_flag)
     1543    return us_success;
     1544
     1545#ifndef NO_ARCHIVES
    14891546  if (ar_name (file->name))
    1490     return ar_touch (file->name);
     1547    return ar_touch (file->name) ? us_failed : us_success;
    14911548  else
    14921549#endif
    14931550    {
    1494       int fd = open (file->name, O_RDWR | O_CREAT, 0666);
    1495 
     1551      int fd;
     1552
     1553      EINTRLOOP (fd, open (file->name, O_RDWR | O_CREAT, 0666));
    14961554      if (fd < 0)
    1497         TOUCH_ERROR ("touch: open: ");
     1555        TOUCH_ERROR ("touch: open: ");
    14981556      else
    1499         {
    1500           struct stat statbuf;
    1501           char buf = 'x';
     1557        {
     1558          struct stat statbuf;
     1559          char buf = 'x';
    15021560          int e;
    15031561
    15041562          EINTRLOOP (e, fstat (fd, &statbuf));
    1505           if (e < 0)
    1506             TOUCH_ERROR ("touch: fstat: ");
    1507           /* Rewrite character 0 same as it already is.  */
    1508           if (read (fd, &buf, 1) < 0)
    1509             TOUCH_ERROR ("touch: read: ");
    1510           if (lseek (fd, 0L, 0) < 0L)
    1511             TOUCH_ERROR ("touch: lseek: ");
    1512           if (write (fd, &buf, 1) < 0)
    1513             TOUCH_ERROR ("touch: write: ");
    1514           /* If file length was 0, we just
    1515              changed it, so change it back.  */
    1516           if (statbuf.st_size == 0)
    1517             {
    1518               (void) close (fd);
    1519               fd = open (file->name, O_RDWR | O_TRUNC, 0666);
    1520               if (fd < 0)
    1521                 TOUCH_ERROR ("touch: open: ");
    1522             }
    1523           (void) close (fd);
    1524         }
    1525     }
    1526 
    1527   return 0;
     1563          if (e < 0)
     1564            TOUCH_ERROR ("touch: fstat: ");
     1565          /* Rewrite character 0 same as it already is.  */
     1566          EINTRLOOP (e, read (fd, &buf, 1));
     1567          if (e < 0)
     1568            TOUCH_ERROR ("touch: read: ");
     1569          {
     1570            off_t o;
     1571            EINTRLOOP (o, lseek (fd, 0L, 0));
     1572            if (o < 0L)
     1573              TOUCH_ERROR ("touch: lseek: ");
     1574          }
     1575          EINTRLOOP (e, write (fd, &buf, 1));
     1576          if (e < 0)
     1577            TOUCH_ERROR ("touch: write: ");
     1578
     1579          /* If file length was 0, we just changed it, so change it back.  */
     1580          if (statbuf.st_size == 0)
     1581            {
     1582              (void) close (fd);
     1583              EINTRLOOP (fd, open (file->name, O_RDWR | O_TRUNC, 0666));
     1584              if (fd < 0)
     1585                TOUCH_ERROR ("touch: open: ");
     1586            }
     1587          (void) close (fd);
     1588        }
     1589    }
     1590
     1591  return us_success;
    15281592}
    15291593
     
    15431607    {
    15441608      if (file->phony)
    1545         /* Phony target.  Pretend it succeeded.  */
    1546         file->update_status = 0;
     1609        /* Phony target.  Pretend it succeeded.  */
     1610        file->update_status = us_success;
    15471611      else if (file->is_target)
    1548         /* This is a nonexistent target file we cannot make.
    1549            Pretend it was successfully remade.  */
    1550         file->update_status = 0;
     1612        /* This is a nonexistent target file we cannot make.
     1613           Pretend it was successfully remade.  */
     1614        file->update_status = us_success;
    15511615      else
    15521616        {
     
    15541618          if (!rebuilding_makefiles || !file->dontcare)
    15551619            complain (file);
    1556           file->update_status = 2;
     1620          file->update_status = us_failed;
    15571621        }
    15581622    }
     
    15631627      /* The normal case: start some commands.  */
    15641628      if (!touch_flag || file->cmds->any_recurse)
    1565         {
    1566           execute_file_commands (file);
    1567           return;
    1568         }
     1629        {
     1630          execute_file_commands (file);
     1631          return;
     1632        }
    15691633
    15701634      /* This tells notice_finished_file it is ok to touch the file.  */
    1571       file->update_status = 0;
     1635      file->update_status = us_success;
    15721636    }
    15731637
     
    15771641
    15781642
    1579 /* Return the mtime of a file, given a `struct file'.
     1643/* Return the mtime of a file, given a 'struct file'.
    15801644   Caches the time in the struct file to avoid excess stat calls.
    15811645
     
    15891653{
    15901654  FILE_TIMESTAMP mtime;
     1655  int propagate_timestamp;
    15911656
    15921657  /* File's mtime is not known; must get it from the system.  */
    15931658
    1594 #ifndef NO_ARCHIVES
     1659#ifndef NO_ARCHIVES
    15951660  if (ar_name (file->name))
    15961661    {
     
    16051670
    16061671      /* Find the modification time of the archive itself.
    1607         Also allow for its name to be changed via VPATH search.  */
     1672        Also allow for its name to be changed via VPATH search.  */
    16081673      arfile = lookup_file (arname);
    16091674      if (arfile == 0)
     
    16121677      check_renamed (arfile);
    16131678      if (search && strcmp (arfile->hname, arname))
    1614         {
    1615           /* The archive's name has changed.
    1616              Change the archive-member reference accordingly.  */
     1679        {
     1680          /* The archive's name has changed.
     1681             Change the archive-member reference accordingly.  */
    16171682
    16181683          char *name;
    1619           unsigned int arlen, memlen;
    1620 
    1621           arlen = strlen (arfile->hname);
    1622           memlen = strlen (memname);
    1623 
    1624           name = xmalloc (arlen + 1 + memlen + 2);
    1625           memcpy (name, arfile->hname, arlen);
    1626           name[arlen] = '(';
    1627           memcpy (name + arlen + 1, memname, memlen);
    1628           name[arlen + 1 + memlen] = ')';
    1629           name[arlen + 1 + memlen + 1] = '\0';
     1684          unsigned int arlen, memlen;
     1685
     1686          arlen = strlen (arfile->hname);
     1687          memlen = strlen (memname);
     1688
     1689          name = alloca (arlen + 1 + memlen + 2);
     1690          memcpy (name, arfile->hname, arlen);
     1691          name[arlen] = '(';
     1692          memcpy (name + arlen + 1, memname, memlen);
     1693          name[arlen + 1 + memlen] = ')';
     1694          name[arlen + 1 + memlen + 1] = '\0';
    16301695
    16311696          /* If the archive was found with GPATH, make the change permanent;
    16321697             otherwise defer it until later.  */
    16331698          if (arfile->name == arfile->hname)
    1634             rename_file (file, name);
     1699            rename_file (file, strcache_add (name));
    16351700          else
    1636             rehash_file (file, name);
     1701            rehash_file (file, strcache_add (name));
    16371702          check_renamed (file);
    1638         }
     1703        }
    16391704
    16401705      free (arname);
     
    16431708
    16441709      if (mtime == NONEXISTENT_MTIME)
    1645         /* The archive doesn't exist, so its members don't exist either.  */
    1646         return NONEXISTENT_MTIME;
     1710        /* The archive doesn't exist, so its members don't exist either.  */
     1711        return NONEXISTENT_MTIME;
    16471712
    16481713      member_date = ar_member_date (file->hname);
     
    16571722
    16581723      if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
    1659         {
    1660           /* If name_mtime failed, search VPATH.  */
    1661           const char *name = vpath_search (file->name, &mtime, NULL, NULL);
    1662           if (name
    1663               /* Last resort, is it a library (-lxxx)?  */
    1664               || (file->name[0] == '-' && file->name[1] == 'l'
    1665                   && (name = library_search (file->name, &mtime)) != 0))
    1666             {
    1667               if (mtime != UNKNOWN_MTIME)
    1668                 /* vpath_search and library_search store UNKNOWN_MTIME
    1669                    if they didn't need to do a stat call for their work.  */
    1670                 file->last_mtime = mtime;
     1724        {
     1725          /* If name_mtime failed, search VPATH.  */
     1726          const char *name = vpath_search (file->name, &mtime, NULL, NULL);
     1727          if (name
     1728              /* Last resort, is it a library (-lxxx)?  */
     1729              || (file->name[0] == '-' && file->name[1] == 'l'
     1730                  && (name = library_search (file->name, &mtime)) != 0))
     1731            {
     1732              int name_len;
     1733
     1734              if (mtime != UNKNOWN_MTIME)
     1735                /* vpath_search and library_search store UNKNOWN_MTIME
     1736                   if they didn't need to do a stat call for their work.  */
     1737                file->last_mtime = mtime;
    16711738
    16721739              /* If we found it in VPATH, see if it's in GPATH too; if so,
    16731740                 change the name right now; if not, defer until after the
    16741741                 dependencies are updated. */
    1675               if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
     1742#ifndef VMS
     1743              name_len = strlen (name) - strlen (file->name) - 1;
     1744#else
     1745              name_len = strlen (name) - strlen (file->name);
     1746              if (name[name_len - 1] == '/')
     1747                  name_len--;
     1748#endif
     1749              if (gpath_search (name, name_len))
    16761750                {
    16771751                  rename_file (file, name);
     
    16801754                }
    16811755
    1682               rehash_file (file, name);
    1683               check_renamed (file);
     1756              rehash_file (file, name);
     1757              check_renamed (file);
    16841758              /* If the result of a vpath search is -o or -W, preserve it.
    16851759                 Otherwise, find the mtime of the resulting file.  */
    16861760              if (mtime != OLD_MTIME && mtime != NEW_MTIME)
    16871761                mtime = name_mtime (name);
    1688             }
    1689         }
     1762            }
     1763        }
    16901764    }
    16911765
     
    17331807            {
    17341808#ifdef NO_FLOAT
    1735               error (NILF, _("Warning: File `%s' has modification time in the future"),
    1736                      file->name);
     1809              OS (error, NILF,
     1810                  _("Warning: File '%s' has modification time in the future"),
     1811                  file->name);
    17371812#else
    17381813              double from_now =
     
    17461821              else
    17471822                sprintf (from_now_string, "%.2g", from_now);
    1748               error (NILF, _("Warning: File `%s' has modification time %s s in the future"),
    1749                      file->name, from_now_string);
     1823              OSS (error, NILF,
     1824                   _("Warning: File '%s' has modification time %s s in the future"),
     1825                   file->name, from_now_string);
    17501826#endif
    17511827              clock_skew_detected = 1;
     
    17541830    }
    17551831
    1756   /* Store the mtime into all the entries for this file.  */
     1832  /* Store the mtime into all the entries for this file for which it is safe
     1833     to do so: avoid propagating timestamps to double-colon rules that haven't
     1834     been examined so they're run or not based on the pre-update timestamp.  */
    17571835  if (file->double_colon)
    17581836    file = file->double_colon;
    17591837
     1838  propagate_timestamp = file->updated;
    17601839  do
    17611840    {
    17621841      /* If this file is not implicit but it is intermediate then it was
    1763         made so by the .INTERMEDIATE target.  If this file has never
    1764         been built by us but was found now, it existed before make
    1765         started.  So, turn off the intermediate bit so make doesn't
    1766         delete it, since it didn't create it.  */
     1842        made so by the .INTERMEDIATE target.  If this file has never
     1843        been built by us but was found now, it existed before make
     1844        started.  So, turn off the intermediate bit so make doesn't
     1845        delete it, since it didn't create it.  */
    17671846      if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
    1768           && file->command_state == cs_not_started
    1769           && !file->tried_implicit && file->intermediate)
    1770         file->intermediate = 0;
    1771 
    1772       file->last_mtime = mtime;
     1847          && !file->tried_implicit && file->intermediate)
     1848        file->intermediate = 0;
     1849
     1850      if (file->updated == propagate_timestamp)
     1851        file->last_mtime = mtime;
    17731852      file = file->prev;
    17741853    }
     
    18901969library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
    18911970{
    1892   static char *dirs[] =
     1971  static const char *dirs[] =
    18931972    {
    18941973#ifdef KMK
     
    19071986#endif
    19081987# ifdef LIBDIR      /* bird */
    1909       LIBDIR,                   /* Defined by configuration.  */
     1988      LIBDIR,                   /* Defined by configuration.  */
    19101989# else              /* bird */
    19111990      ".",          /* bird */
     
    19262005
    19272006  /* Information about the earliest (in the vpath sequence) match.  */
    1928   unsigned int best_vpath = 0, best_path = 0; /* bird: gcc maybe used uninitialized (both) */
    1929   unsigned int std_dirs = 0;
    1930 
    1931   char **dp;
     2007  unsigned int best_vpath = 0, best_path = 0;
     2008
     2009  const char **dp;
    19322010
    19332011  libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)"));
     
    19462024      static unsigned int buflen = 0;
    19472025      static int libdir_maxlen = -1;
     2026      static unsigned int std_dirs = 0;
    19482027      char *libbuf = variable_expand ("");
    19492028      const size_t libbuf_offset = libbuf - variable_buffer; /* bird */
     
    19512030      /* Expand the pattern using LIB as a replacement.  */
    19522031      {
    1953         char c = p[len];
    1954         char *p3, *p4;
    1955 
    1956         p[len] = '\0';
    1957         p3 = find_percent (p);
    1958         if (!p3)
    1959           {
    1960             /* Give a warning if there is no pattern.  */
    1961             error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
     2032        char c = p[len];
     2033        char *p3, *p4;
     2034
     2035        p[len] = '\0';
     2036        p3 = find_percent (p);
     2037        if (!p3)
     2038          {
     2039            /* Give a warning if there is no pattern.  */
     2040            OS (error, NILF,
     2041                _(".LIBPATTERNS element '%s' is not a pattern"), p);
    19622042            p[len] = c;
    1963             continue;
    1964           }
    1965         p4 = variable_buffer_output (libbuf, p, p3-p);
    1966         p4 = variable_buffer_output (p4, lib, liblen);
    1967         p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
    1968         p[len] = c;
    1969         libbuf = variable_buffer + libbuf_offset; /* bird - variable_buffer may have been reallocated. */
     2043            continue;
     2044          }
     2045        p4 = variable_buffer_output (libbuf, p, p3-p);
     2046        p4 = variable_buffer_output (p4, lib, liblen);
     2047        p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
     2048        p[len] = c;
     2049        libbuf = variable_buffer + libbuf_offset; /* bird - variable_buffer may have been reallocated. UPSTREAM */
    19702050      }
    19712051
    1972       /* Look first for `libNAME.a' in the current directory.  */
     2052      /* Look first for 'libNAME.a' in the current directory.  */
    19732053      mtime = name_mtime (libbuf);
    19742054      if (mtime != NONEXISTENT_MTIME)
    1975         {
    1976           if (mtime_ptr != 0)
    1977             *mtime_ptr = mtime;
    1978           file = strcache_add (libbuf);
     2055        {
     2056          if (mtime_ptr != 0)
     2057            *mtime_ptr = mtime;
     2058          file = strcache_add (libbuf);
    19792059          /* This by definition will have the best index, so stop now.  */
    19802060          break;
    1981         }
     2061        }
    19822062
    19832063      /* Now try VPATH search on that.  */
     
    20162096            }
    20172097          buflen = strlen (libbuf);
    2018           buf = xmalloc(libdir_maxlen + buflen + 2);
     2098          buf = xmalloc (libdir_maxlen + buflen + 2);
    20192099        }
    20202100      else if (buflen < strlen (libbuf))
     
    20302110
    20312111        for (dp = dirs; *dp != 0; ++dp)
    2032           {
     2112          {
    20332113            sprintf (buf, "%s/%s", *dp, libbuf);
    20342114            mtime = name_mtime (buf);
    20352115            if (mtime != NONEXISTENT_MTIME)
    2036               {
     2116              {
    20372117                if (file == 0 || vpath_index < best_vpath)
    20382118                  {
Note: See TracChangeset for help on using the changeset viewer.