home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / MAK358AS.ZIP / REMAKE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-22  |  21.5 KB  |  842 lines

  1. /* Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  2. This file is part of GNU Make.
  3.  
  4. GNU Make is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8.  
  9. GNU Make is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with GNU Make; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  * MS-DOS port (c) 1990 by Thorsten Ohl <ohl@gnu.ai.mit.edu>
  20.  *
  21.  * To this port, the same copying conditions apply as to the
  22.  * original release.
  23.  *
  24.  * IMPORTANT:
  25.  * This file is not identical to the original GNU release!
  26.  * You should have received this code as patch to the official
  27.  * GNU release.
  28.  *
  29.  * MORE IMPORTANT:
  30.  * This port comes with ABSOLUTELY NO WARRANTY.
  31.  *
  32.  * $Header: e:/gnu/make/RCS/remake.c'v 3.58.0.1 90/07/17 00:59:46 tho Exp $
  33.  */
  34.  
  35. #include "make.h"
  36. #include "commands.h"
  37. #include "job.h"
  38. #include "dep.h"
  39. #include "file.h"
  40.  
  41. #ifndef USG
  42. #include <sys/file.h>
  43. #else
  44. #include <fcntl.h>
  45. #endif
  46.  
  47. #ifdef MSDOS
  48. #include <io.h>
  49. #include <time.h>
  50. #else /* not MSDOS */
  51. extern int open (), fstat (), read (), lseek (), write (), close ();
  52. extern time_t time ();
  53. #endif /* not MSDOS */
  54.  
  55. extern int try_implicit_rule ();
  56. extern time_t ar_member_date ();
  57.  
  58.  
  59. /* Incremented when a file has been remade.  */
  60. unsigned int files_remade = 0;
  61.  
  62. #ifdef MSDOS
  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, long this_mtime, int *must_make_ptr);
  66. static  void remake_file (struct file *file);
  67. static  long name_mtime (char *name);
  68. static  long library_file_mtime (char *lib);
  69. static  int touch_file (struct file *file);
  70. #else /* not MSDOS */
  71. static int update_file (), update_file_1 (), check_dep ();
  72. static void remake_file ();
  73. static time_t name_mtime (), library_file_mtime ();
  74. extern time_t f_mtime ();
  75. #endif /* not MSDOS */
  76.  
  77. /* Remake all the goals in the `struct dep' chain GOALS.  Return -1 if nothing
  78.    was done, 0 if all goals were updated successfully, or 1 if a goal failed.
  79.    If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
  80.    be disabled for them unless they were also command-line targets, and we
  81.    should only make one goal at a time and return as soon as one goal whose
  82.    `changed' member is nonzero is successfully made.  */
  83.  
  84. int
  85. update_goal_chain (goals, makefiles)
  86.      register struct dep *goals;
  87.      int makefiles;
  88. {
  89.   int t = touch_flag, q = question_flag, n = just_print_flag;
  90.   unsigned int j = job_slots;
  91.   int status = -1;
  92.  
  93. #define    MTIME(file) (makefiles ? file_mtime_no_search (file) \
  94.              : file_mtime (file))
  95.  
  96.   /* Duplicate the chain so we can remove things from it.  */
  97.  
  98.   goals = copy_dep_chain (goals);
  99.  
  100.   if (makefiles)
  101.     /* Only run one job at a time.  */
  102.     job_slots = 1;
  103.  
  104.   /* Update all the goals until they are all finished.  */
  105.  
  106.   while (goals != 0)
  107.     {
  108.       register struct dep *g, *lastgoal;
  109.  
  110.       /* Wait for a child to die.  */
  111.  
  112.       wait_for_children (1, 0);
  113.  
  114.       lastgoal = 0;
  115.       g = goals;
  116.       while (g != 0)
  117.     {
  118.       int x;
  119.       time_t mtime = MTIME (g->file);
  120.  
  121.       if (makefiles)
  122.         {
  123.           if (g->file->cmd_target)
  124.         {
  125.           touch_flag = t;
  126.           question_flag = q;
  127.           just_print_flag = n;
  128.         }
  129.           else
  130.         touch_flag = question_flag = just_print_flag = 0;
  131.         }
  132.  
  133.       x = update_file (g->file, makefiles ? 1 : 0);
  134.       check_renamed (g->file);
  135.       if (x != 0 || g->file->updated)
  136.         {
  137.           int stop = 0;
  138.           /* If STATUS was not already 1, set it to 1 if
  139.          updating failed, or to 0 if updating succeeded.
  140.          Leave STATUS as it is if no updating was done.  */
  141.           if (status < 1)
  142.         {
  143.           if (g->file->update_status != 0)
  144.             {
  145.               /* Updating failed.  */
  146.               status = 1;
  147.               stop = !keep_going_flag && !makefiles;
  148.             }
  149.           else if (MTIME (g->file) != mtime)
  150.             {
  151.               /* Updating was done.
  152.              If this is a makefile and just_print_flag or
  153.              question_flag is set (meaning -n or -q was given
  154.              and this file was specified as a command-line target),
  155.              don't change STATUS.  If STATUS is changed, we will
  156.              get re-exec'd, and fall into an infinite loop.  */
  157.               if (!makefiles || (!just_print_flag && !question_flag))
  158.             status = 0;
  159.               if (makefiles && g->file->dontcare)
  160.             /* This is a default makefile.  Stop remaking.  */
  161.             stop = 1;
  162.             }
  163.         }
  164.  
  165.           /* This goal is finished.  Remove it from the chain.  */
  166.           if (lastgoal == 0)
  167.         goals = g->next;
  168.           else
  169.         lastgoal->next = g->next;
  170.  
  171.           /* Free the storage.  */
  172.           free ((char *) g);
  173.  
  174.           g = lastgoal == 0 ? goals : lastgoal->next;
  175.  
  176.           if (stop)
  177.         break;
  178.         }
  179.       else
  180.         {
  181.           lastgoal = g;
  182.           g = g->next;
  183.         }
  184.     }
  185.     }
  186.  
  187.   if (makefiles)
  188.     {
  189.       touch_flag = t;
  190.       question_flag = q;
  191.       just_print_flag = n;
  192.       job_slots = j;
  193.     }
  194.  
  195.   return status;
  196. }
  197.  
  198. /* If FILE is not up to date, execute the commands for it.
  199.    Return 0 if successful, 1 if unsuccessful;
  200.    but with some flag settings, just call `exit' if unsuccessful.
  201.  
  202.    DEPTH is the depth in recursions of this function.
  203.    We increment it during the consideration of our dependencies,
  204.    then decrement it again after finding out whether this file
  205.    is out of date.
  206.  
  207.    If there are multiple double-colon entries for FILE,
  208.    each is considered in turn.  */
  209.  
  210. static int
  211. update_file (file, depth)
  212.      struct file *file;
  213.      unsigned int depth;
  214. {
  215.   register int status = 0;
  216.   register struct file *f;
  217.   unsigned int ofiles_remade = files_remade;
  218.   char commands_finished = 0;
  219.  
  220.   for (f = file; f != 0; f = f->prev)
  221.     {
  222.       char not_started = f->command_state == cs_not_started;
  223.       status |= update_file_1 (f, depth);
  224.       check_renamed (f);
  225.       if (status != 0 && !keep_going_flag)
  226.     return status;
  227.       commands_finished |= not_started && f->command_state == cs_finished;
  228.     }
  229.  
  230.   /* For a top level target, if we have found nothing whatever to do for it,
  231.      print a message saying nothing needs doing.  */
  232.  
  233.   if (status == 0 && !file->phony && files_remade == ofiles_remade
  234.       && commands_finished && depth == 0 && !silent_flag && !question_flag)
  235.     {
  236.       printf ("%s: `%s' is up to date.\n", program, file->name);
  237.       fflush (stdout);
  238.     }
  239.  
  240.   return status;
  241. }
  242.  
  243. /* Consider a single `struct file' and update it as appropriate.  */
  244.  
  245. static int
  246. update_file_1 (file, depth)
  247.      struct file *file;
  248.      unsigned int depth;
  249. {
  250.   register time_t this_mtime;
  251.   int noexist, must_make, deps_changed;
  252.   int dep_status = 0;
  253.   register struct dep *d, *lastd;
  254.   char running = 0;
  255.  
  256.   DEBUGPR ("Considering target file `%s'.\n");
  257.  
  258.   if (file->updated)
  259.     {
  260.       if (file->update_status > 0)
  261.     {
  262.       DEBUGPR ("Recently tried and failed to update file `%s'.\n");
  263.       return file->update_status;
  264.     }
  265.  
  266.       DEBUGPR ("File `%s' was considered already.\n");
  267.       return 0;
  268.     }
  269.  
  270.   switch (file->command_state)
  271.     {
  272.     case cs_not_started:
  273.     case cs_deps_running:
  274.       break;
  275.     case cs_running:
  276.       DEBUGPR ("Still updating file `%s'.\n");
  277.       return 0;
  278.     case cs_finished:
  279.       DEBUGPR ("Finished updating file `%s'.\n");
  280.       return file->update_status;
  281.     case cs_invalid:
  282.     default:
  283.       abort ();
  284.     }
  285.  
  286.   ++depth;
  287.  
  288.   /* Notice recursive update of the same file.  */
  289.   file->updating = 1;
  290.  
  291.   /* Looking at the file's modtime beforehand allows the possibility
  292.      that its name may be changed by a VPATH search, and thus it may
  293.      not need an implicit rule.  If this were not done, the file
  294.      might get implicit commands that apply to its initial name, only
  295.      to have that name replaced with another found by VPATH search.  */
  296.  
  297.   this_mtime = file_mtime (file);
  298.   check_renamed (file);
  299.   noexist = this_mtime == (time_t) -1;
  300.   if (noexist)
  301.     DEBUGPR ("File `%s' does not exist.\n");
  302.  
  303.   must_make = noexist;
  304.  
  305.   /* If file was specified as a target with no commands,
  306.      come up with some default commands.  */
  307.  
  308.   if (!file->phony && file->cmds == 0 && !file->tried_implicit)
  309.     {
  310.       if (try_implicit_rule (file, depth))
  311.     DEBUGPR ("Found an implicit rule for `%s'.\n");
  312.       else
  313.     {
  314.       DEBUGPR ("No implicit rule found for `%s'.\n");
  315.       if (default_file != 0 && default_file->cmds != 0)
  316.         {
  317.           DEBUGPR ("Using default commands for `%s'.\n");
  318.           file->cmds = default_file->cmds;
  319.         }
  320.       file->also_make = 0;
  321.     }
  322.       file->tried_implicit = 1;
  323.     }
  324.  
  325.   /* Update all non-intermediate files we depend on, if necessary,
  326.      and see whether any of them is more recent than this file.  */
  327.  
  328.   lastd = 0;
  329.   d = file->deps;
  330.   while (d != 0)
  331.     {
  332.       time_t mtime;
  333.  
  334.       if (d->file->updating)
  335.     {
  336.       error ("Circular %s <- %s dependency dropped.",
  337.          file->name, d->file->name);
  338.       if (lastd == 0)
  339.         {
  340.           file->deps = d->next;
  341.           free ((char *) d);
  342.           d = file->deps;
  343.         }
  344.       else
  345.         {
  346.           lastd->next = d->next;
  347.           free ((char *) d);
  348.           d = lastd->next;
  349.         }
  350.       continue;
  351.     }
  352.  
  353.       mtime = file_mtime (d->file);
  354.       check_renamed (d->file);
  355.       d->file->parent = file;
  356.       dep_status |= check_dep (d->file, depth, this_mtime, &must_make);
  357.       check_renamed (d->file);
  358.  
  359.       running |= (d->file->command_state == cs_running
  360.           || d->file->command_state == cs_deps_running);
  361.  
  362.       if (dep_status != 0 && !keep_going_flag)
  363.     break;
  364.  
  365.       if (!running)
  366.     d->changed = file_mtime (d->file) != mtime;
  367.  
  368.       lastd = d;
  369.       d = d->next;
  370.     }
  371.  
  372.   /* Now we know whether this target needs updating.
  373.      If it does, update all the intermediate files we depend on.  */
  374.  
  375.   if (must_make)
  376.     {
  377.       for (d = file->deps; d != 0; d = d->next)
  378.     if (d->file->intermediate)
  379.       {
  380.         time_t mtime = file_mtime (d->file);
  381.         check_renamed (d->file);
  382.         d->file->parent = file;
  383.         dep_status |= update_file (d->file, depth);
  384.         check_renamed (d->file);
  385.  
  386.         running |= (d->file->command_state == cs_running
  387.             || d->file->command_state == cs_deps_running);
  388.  
  389.         if (dep_status != 0 && !keep_going_flag)
  390.           break;
  391.  
  392.         if (!running)
  393.           d->changed = ((file->phony && file->cmds != 0)
  394.                 || file_mtime (d->file) != mtime);
  395.       }
  396.     }
  397.  
  398.   file->updating = 0;
  399.  
  400.   DEBUGPR ("Finished dependencies of target file `%s'.\n");
  401.  
  402.   /* If any dependency failed, give up now.  */
  403.  
  404.   if (dep_status != 0)
  405.     {
  406.       file->command_state = cs_finished;
  407.       file->update_status = dep_status;
  408.       file->updated = 1;
  409.  
  410.       depth--;
  411.  
  412.       DEBUGPR ("Giving up on target file `%s'.\n");
  413.  
  414.       if (depth == 0 && keep_going_flag
  415.       && !just_print_flag && !question_flag)
  416.     error ("Target `%s' not remade because of errors.", file->name);
  417.  
  418.       return dep_status;
  419.     }
  420.  
  421.   if (running)
  422.     {
  423.       file->command_state = cs_deps_running;
  424.       --depth;
  425.       DEBUGPR ("The dependencies of `%s' are being made.\n");
  426.       return 0;
  427.     }
  428.  
  429.   file->command_state = cs_not_started;
  430.  
  431.   /* Now record which dependencies are more
  432.      recent than this file, so we can define $?.  */
  433.  
  434.   deps_changed = 0;
  435.   for (d = file->deps; d != 0; d = d->next)
  436.     {
  437.       time_t d_mtime = file_mtime (d->file);
  438.       check_renamed (d->file);
  439.  
  440. #if 1    /* %%% In version 4, remove this code completely to
  441.        implement not remaking deps if their deps are newer
  442.        than their parents.  */
  443.       if (d_mtime == (time_t) -1 && !d->file->intermediate)
  444.     /* We must remake if this dep does not
  445.        exist and is not intermediate.  */
  446.     must_make = 1;
  447. #endif
  448.  
  449.       /* Set DEPS_CHANGED if this dep actually changed.  */
  450.       deps_changed |= d->changed;
  451.  
  452.       /* Set D->changed if either this dep actually changed,
  453.      or its dependent, FILE, is older or does not exist.  */
  454.       d->changed |= noexist || d_mtime > this_mtime;
  455.  
  456.       if (debug_flag && !noexist)
  457.     {
  458.       print_spaces (depth);
  459.       if (d_mtime == (time_t) -1)
  460.         printf ("Dependency `%s' does not exist.\n", dep_name (d));
  461.       else
  462.         printf ("Dependency `%s' is %s than dependent `%s'.\n",
  463.             dep_name (d), d->changed ? "newer" : "older", file->name);
  464.       fflush (stdout);
  465.     }
  466.     }
  467.  
  468.   /* Here depth returns to the value it had when we were called.  */
  469.   depth--;
  470.  
  471.   if (file->double_colon && file->deps == 0)
  472.     {
  473.       must_make = 1;
  474.       DEBUGPR ("Target `%s' is double-colon and has no dependencies.\n");
  475.     }
  476.   else if (file->is_target && !deps_changed && file->cmds == 0)
  477.     {
  478.       must_make = 0;
  479.       DEBUGPR ("No commands for `%s' and no dependencies actually changed.\n");
  480.     }
  481.  
  482.   if (!must_make)
  483.     {
  484.       DEBUGPR ("No need to remake target `%s'.\n");
  485.       file->command_state = cs_finished;
  486.       file->update_status = 0;
  487.       file->updated = 1;
  488.       return 0;
  489.     }
  490.  
  491.   DEBUGPR ("Must remake target `%s'.\n");
  492.  
  493.   /* Now, take appropriate actions to remake the file.  */
  494.   remake_file (file);
  495.  
  496.   if (file->command_state != cs_finished)
  497.     {
  498.       DEBUGPR ("Commands of `%s' are being run.\n");
  499.       return 0;
  500.     }
  501.  
  502.   switch (file->update_status)
  503.     {
  504.     case 1:
  505.       DEBUGPR ("Failed to remake target file `%s'.\n");
  506.       break;
  507.     case 0:
  508.       DEBUGPR ("Successfully remade target file `%s'.\n");
  509.       break;
  510.     case -1:
  511.       error ("internal error: `%s' update_status is -1 at cs_finished!",
  512.          file->name);
  513.       abort ();
  514.     default:
  515.       error ("internal error: `%s' update_status invalid!", file->name);
  516.       abort ();
  517.     }
  518.  
  519.   file->updated = 1;
  520.   return file->update_status;
  521. }
  522.  
  523. /* Set FILE's `updated' flag and re-check its mtime and the mtime's
  524.    of all files listed in its `also_make' member.  */
  525.  
  526. void
  527. notice_finished_file (file)
  528.      register struct file *file;
  529. {
  530.   file->updated = 1;
  531.  
  532.   if (!file->phony)
  533.     {
  534.       if (just_print_flag || question_flag
  535.       || (file->is_target && file->cmds == 0))
  536.     file->last_mtime = time ((time_t *) 0);
  537.       else
  538.     file->last_mtime = 0;
  539.     }
  540.  
  541.   if (file->also_make != 0)
  542.     {
  543.       register unsigned int i;
  544.       for (i = 0; file->also_make[i] != 0; ++i)
  545.     {
  546.       register struct file *f = enter_file (file->also_make[i]);
  547.       f->updated = 1;
  548.       f->update_status = file->update_status;
  549.       if (just_print_flag || question_flag)
  550.         f->last_mtime = file->last_mtime;
  551.       else
  552.         f->last_mtime = 0;
  553.     }
  554.     }
  555. }
  556.  
  557. /* Check whether another file (whose mtime is THIS_MTIME)
  558.    needs updating on account of a dependency which is file FILE.
  559.    If it does, store 1 in *MUST_MAKE_PTR.
  560.    In the process, update any non-intermediate files
  561.    that FILE depends on (including FILE itself).
  562.    Return nonzero if any updating failed.  */
  563.  
  564. static int
  565. check_dep (file, depth, this_mtime, must_make_ptr)
  566.      struct file *file;
  567.      unsigned int depth;
  568.      time_t this_mtime;
  569.      int *must_make_ptr;
  570. {
  571.   register struct dep *d;
  572.   int dep_status = 0;
  573.  
  574.   ++depth;
  575.   file->updating = 1;
  576.  
  577.   if (!file->intermediate)
  578.     /* If this is a non-intermediate file, update it and record
  579.        whether it is newer than THIS_MTIME.  */
  580.     {
  581.       time_t mtime;
  582.       dep_status = update_file (file, depth);
  583.       mtime = file_mtime (file);
  584.       check_renamed (file);
  585.       if (mtime == (time_t) -1 || mtime > this_mtime)
  586.     *must_make_ptr = 1;
  587.     }
  588.   else
  589.     {
  590.       /* FILE is an intermediate file.
  591.      Update all non-intermediate files we depend on, if necessary,
  592.      and see whether any of them is more recent than the file
  593.      on whose behalf we are checking.  */
  594.       register struct dep *lastd;
  595.       lastd = 0;
  596.       d = file->deps;
  597.       while (d != 0)
  598.     {
  599.       if (d->file->updating)
  600.         {
  601.           error ("Circular %s <- %s dependency dropped.",
  602.              file->name, d->file->name);
  603.           if (lastd == 0)
  604.         {
  605.           file->deps = d->next;
  606.           free ((char *) d);
  607.           d = file->deps;
  608.         }
  609.           else
  610.         {
  611.           lastd->next = d->next;
  612.           free ((char *) d);
  613.           d = lastd->next;
  614.         }
  615.           continue;
  616.         }
  617.  
  618.       d->file->parent = file;
  619.       dep_status |= check_dep (d->file, depth, this_mtime, must_make_ptr);
  620.       check_renamed (d->file);
  621.       if (dep_status != 0 && !keep_going_flag)
  622.         break;
  623.  
  624.       lastd = d;
  625.       d = d->next;
  626.     }
  627.     }
  628.  
  629.   file->updating = 0;
  630.   return dep_status;
  631. }
  632.  
  633. /* Touch FILE.  Return zero if successful, nonzero if not.  */
  634.  
  635. #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
  636.  
  637. static int
  638. touch_file (file)
  639.      register struct file *file;
  640. {
  641.   if (!silent_flag)
  642.     {
  643.       printf ("touch %s\n", file->name);
  644.       fflush (stdout);
  645.     }
  646.  
  647. #ifndef    NO_ARCHIVES
  648.   if (ar_name (file->name))
  649.     return ar_touch (file->name);
  650.   else
  651. #endif
  652.     {
  653.       int fd = open (file->name, O_RDWR | O_CREAT, 0666);
  654.  
  655.       if (fd < 0)
  656.     TOUCH_ERROR ("touch: open: ");
  657.       else
  658.     {
  659.       struct stat statbuf;
  660.       char buf;
  661.  
  662.       if (fstat (fd, &statbuf) < 0)
  663.         TOUCH_ERROR ("touch: fstat: ");
  664.       /* Rewrite character 0 same as it already is.  */
  665.       if (read (fd, &buf, 1) < 0)
  666.         TOUCH_ERROR ("touch: read: ");
  667.       if (lseek (fd, 0L, 0) < 0L)
  668.         TOUCH_ERROR ("touch: lseek: ");
  669.       if (write (fd, &buf, 1) < 0)
  670.         TOUCH_ERROR ("touch: write: ");
  671.       /* If file length was 0, we just
  672.          changed it, so change it back.  */
  673.       if (statbuf.st_size == 0)
  674.         {
  675.           (void) close (fd);
  676.           fd = open (file->name, O_RDWR | O_TRUNC, 0666);
  677.           if (fd < 0)
  678.         TOUCH_ERROR ("touch: open: ");
  679.         }
  680.       (void) close (fd);
  681.     }
  682.     }
  683.  
  684.   return 0;
  685. }
  686.  
  687. /* Having checked and updated the dependencies of FILE,
  688.    do whatever is appropriate to remake FILE itself.
  689.    Return the status from executing FILE's commands.  */
  690.  
  691. static void
  692. remake_file (file)
  693.      struct file *file;
  694. {
  695.   if (file->cmds == 0 && !(touch_flag && !file->is_target))
  696.     {
  697.       if (file->phony)
  698.     /* Phony target.  Pretend it succeeded.  */
  699.     file->update_status = 0;
  700.       else if (file->is_target)
  701.     /* This is a nonexistent target file we cannot make.
  702.        Pretend it was successfully remade.  */
  703.     file->update_status = 0;
  704.       else
  705.     {
  706.       /* This is a dependency file we cannot remake.  Fail.  */
  707.       static char noway[] = "*** No way to make target";
  708.       if (keep_going_flag || file->dontcare)
  709.         {
  710.           if (!file->dontcare)
  711.         error ("%s `%s'.", noway, file->name);
  712.            file->update_status = 1;
  713.         }
  714.       else
  715.         fatal ("%s `%s'", noway, file->name);
  716.     }
  717.     }
  718.   else
  719.     {
  720.       chop_commands (file->cmds);
  721.  
  722.       if (touch_flag && file->cmds != 0 && !file->cmds->any_recurse)
  723.     {
  724.       if (file->phony)
  725.         file->update_status = 0;
  726.       else
  727.         /* Should set file's modification date and do nothing else.  */
  728.         file->update_status = touch_file (file);
  729.     }
  730.       else
  731.     {
  732.       execute_file_commands (file);
  733.       return;
  734.     }
  735.     }
  736.  
  737.   file->command_state = cs_finished;
  738.   notice_finished_file (file);
  739. }
  740.  
  741. /* Return the mtime of a file, given a `struct file'.
  742.    Caches the time in the struct file to avoid excess stat calls.  If the file
  743.    is not found, and SEARCH is nonzero, VPATH searching and replacement is
  744.    done.  If that fails, a library (-lLIBNAME) is tried but the library's
  745.    actual name (/lib/libLIBNAME.a, etc.) is not substituted into FILE.  */
  746.  
  747. time_t
  748. f_mtime (file, search)
  749.      register struct file *file;
  750.      int search;
  751. {
  752.   register time_t mtime;
  753.  
  754.   /* File's mtime is not known; must get it from the system.  */
  755.  
  756.   mtime = name_mtime (file->name);
  757.  
  758.   if (mtime == (time_t) -1 && search)
  759.     {
  760.       /* If name_mtime failed, search VPATH.  */
  761.       char *name = file->name;
  762.       if (vpath_search (&name))
  763.     {
  764.       rename_file (file, name);
  765.       file = file->renamed;
  766.       mtime = name_mtime (name);
  767.     }
  768.       else
  769.     /* Last resort, is it a library (-lxxx)?  */
  770.     if (name[0] == '-' && name[1] == 'l')
  771.       mtime = library_file_mtime (&name[2]);
  772.     }
  773.  
  774.   /* Store the mtime into all the entries for this file.  */
  775.  
  776.   while (file != 0)
  777.     {
  778.       file->last_mtime = mtime;
  779.       file = file->prev;
  780.     }
  781.  
  782.   return mtime;
  783. }
  784.  
  785.  
  786. /* Return the mtime of the file or archive-member reference NAME.  */
  787.  
  788. static time_t
  789. name_mtime (name)
  790.      register char *name;
  791. {
  792.   struct stat st;
  793.  
  794. #ifndef    NO_ARCHIVES
  795.   if (ar_name (name))
  796.     return ar_member_date (name);
  797. #endif
  798.  
  799.   if (stat (name, &st) < 0)
  800.     return (time_t) -1;
  801.   return (time_t) st.st_mtime;
  802. }
  803.  
  804.  
  805. /* Return the mtime of a library file specified as -lLIBNAME,
  806.    searching for a suitable library file in the system library directories
  807.    and the VPATH directories.  */
  808.  
  809. static time_t
  810. library_file_mtime (lib)
  811.      char *lib;
  812. {
  813.   time_t mtime;
  814.   char *name;
  815.  
  816.   name = concat ("/usr/lib/lib", lib, ".a");
  817.   mtime = name_mtime (name);
  818.   if (mtime == (time_t) -1)
  819.     mtime = name_mtime (name + 4);
  820.   if (mtime == (time_t) -1)
  821.     {
  822.       char *local = concat ("/usr/local/lib/lib", lib,  ".a");
  823.       mtime = name_mtime (local);
  824.       free (local);
  825.     }
  826.   if (mtime == (time_t) -1)
  827.     mtime = name_mtime (name + 9);
  828.   if (mtime == (time_t) -1)
  829.     {
  830.       char *newname = name + 9;
  831.       if (vpath_search (&newname))
  832.     {
  833.       mtime = name_mtime (newname);
  834.       free (newname);
  835.     }
  836.     }
  837.  
  838.   free (name);
  839.  
  840.   return mtime;
  841. }
  842.