Ignore:
Timestamp:
May 17, 2005, 1:34:55 AM (20 years ago)
Author:
bird
Message:

join + optimizations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.