*** remake.c.orig	Tue Oct 29 20:57:32 1991
--- remake.c	Mon Apr 13 19:17:56 1992
***************
*** 278,291 ****
    /* Notice recursive update of the same file.  */
    file->updating = 1;
  
!   /* Looking at the file's modtime beforehand allows the possibility
!      that its name may be changed by a VPATH search, and thus it may
!      not need an implicit rule.  If this were not done, the file
!      might get implicit commands that apply to its initial name, only
!      to have that name replaced with another found by VPATH search.  */
  
    this_mtime = file_mtime (file);
-   check_renamed (file);
    noexist = this_mtime == (time_t) -1;
    if (noexist)
      DEBUGPR ("File `%s' does not exist.\n");
--- 315,328 ----
    /* Notice recursive update of the same file.  */
    file->updating = 1;
  
!   /*
!    * Look up the file's mtime.  A vpath search is performed if the
!    * file does not exist locally.  Under the new vpath functionality
!    * the file will not be renamed, however, instead the path will be
!    * stored for later.
!    */
  
    this_mtime = file_mtime (file);
    noexist = this_mtime == (time_t) -1;
    if (noexist)
      DEBUGPR ("File `%s' does not exist.\n");
***************
*** 491,500 ****
--- 528,564 ----
        file->command_state = cs_finished;
        file->update_status = 0;
        file->updated = 1;
+ 
+       /* If we found this target on the VPATH, modify the target name */
+       if (file->vpath != NULL)
+       {
+           time_t mtime = file->last_mtime;
+ 
+           rename_file(file, file->vpath);
+           check_renamed(file);
+           DEBUGPR ("Changing target to vpath `%s'.\n");
+           /* Store the mtime into all the entries for this file.  */
+           while (file != 0)
+           {
+               file->last_mtime = mtime;
+               file = file->prev;
+           }
+       }
        return 0;
      }
  
    DEBUGPR ("Must remake target `%s'.\n");
+   if (file->vpath != NULL)
+     {
+       if (debug_flag)
+ 	{
+ 	  print_spaces(depth);
+ 	  printf("Throwing out vpath `%s'.\n", file->vpath);
+ 	  fflush(stdout);
+ 	}
+       free(file->vpath);
+       file->vpath = NULL;
+     }
  
    /* Now, take appropriate actions to remake the file.  */
    remake_file (file);
***************
*** 828,839 ****
  	{
  	  /* If name_mtime failed, search VPATH.  */
  	  char *name = file->name;
! 	  if (vpath_search (&name))
! 	    {
! 	      rename_file (file, name);
! 	      check_renamed (file);
! 	      return file_mtime (file);
! 	    }
  	  else
  	    /* Last resort, is it a library (-lxxx)?  */
  	    if (name[0] == '-' && name[1] == 'l')
--- 892,899 ----
  	{
  	  /* If name_mtime failed, search VPATH.  */
  	  char *name = file->name;
! 	  if ((file->vpath = vpath_search (name)) != NULL)
! 	    mtime = name_mtime(file->vpath);
  	  else
  	    /* Last resort, is it a library (-lxxx)?  */
  	    if (name[0] == '-' && name[1] == 'l')
***************
*** 893,904 ****
      mtime = name_mtime (name + 9);
    if (mtime == (time_t) -1)
      {
!       char *newname = name + 9;
!       if (vpath_search (&newname))
! 	{
! 	  mtime = name_mtime (newname);
! 	  free (newname);
! 	}
      }
  
    free (name);
--- 953,961 ----
      mtime = name_mtime (name + 9);
    if (mtime == (time_t) -1)
      {
!       char *newname = vpath_search (name+9);
!       if (newname != NULL)
! 	mtime = name_mtime (newname);
      }
  
    free (name);
*** ../make-3.62/file.h.orig	Tue Oct  8 16:04:17 1991
--- ../make-3.62/file.h	Wed Jan  8 13:49:33 1992
***************
*** 27,32 ****
--- 27,33 ----
      struct commands *cmds;	/* Commands to execute for this target */
      char *stem;			/* Implicit stem, if an implicit
      				   rule has been used */
+     char *vpath;		/* VPATH path if one has been found */
      struct dep *also_make;	/* Targets that are made by making this.  */
      time_t last_mtime;		/* File's modtime, if already known.  */
      struct file *prev;		/* Previous entry for same file name;
*** ../make-3.62/vpath.c.orig	Mon Jun  3 16:37:37 1991
--- ../make-3.62/vpath.c	Wed Nov 20 13:12:45 1991
***************
*** 40,46 ****
  
  static struct vpath *general_vpath;
  
! static int selective_vpath_search ();
  
  /* Reverse the chain of selective VPATH lists so they
     will be searched in the order given in the makefiles
--- 40,46 ----
  
  static struct vpath *general_vpath;
  
! static char *selective_vpath_search ();
  
  /* Reverse the chain of selective VPATH lists so they
     will be searched in the order given in the makefiles
***************
*** 234,277 ****
  }
  
  /* Search the VPATH list whose pattern matches *FILE for a directory
!    where the name pointed to by FILE exists.  If it is found, the pointer
!    in FILE is set to the newly malloc'd name of the existing file and
!    we return 1.  Otherwise we return 0.  */
  
! int
  vpath_search (file)
!      char **file;
  {
    register struct vpath *v;
  
    /* If there are no VPATH entries or FILENAME starts at the root,
       there is nothing we can do.  */
  
!   if (**file == '/' || (vpaths == 0 && general_vpath == 0))
!     return 0;
  
    for (v = vpaths; v != 0; v = v->next)
!     if (pattern_matches (v->pattern, v->percent, *file))
!       if (selective_vpath_search (v, file))
! 	return 1;
  
    if (general_vpath != 0
!       && selective_vpath_search (general_vpath, file))
!     return 1;
  
!   return 0;
  }
  
  
  /* Search the given VPATH list for a directory where the name pointed
!    to by FILE exists.  If it is found, the pointer in FILE
!    is set to the newly malloc'd name of the existing file and we return 1.
!    Otherwise we return 0.  */
  
! static int
  selective_vpath_search (path, file)
       struct vpath *path;
!      char **file;
  {
    int not_target;
    char *name, *n;
--- 234,277 ----
  }
  
  /* Search the VPATH list whose pattern matches *FILE for a directory
!    where the name pointed to by FILE exists.  If it is found, return a
!    pointer to the newly malloc'd name of the existing file.
!    Otherwise we return NULL.  */
  
! char *
  vpath_search (file)
!      char *file;
  {
+   char *new;
    register struct vpath *v;
  
    /* If there are no VPATH entries or FILENAME starts at the root,
       there is nothing we can do.  */
  
!   if (*file == '/' || (vpaths == 0 && general_vpath == 0))
!     return NULL;
  
    for (v = vpaths; v != 0; v = v->next)
!     if (pattern_matches (v->pattern, v->percent, file))
!       if ((new = selective_vpath_search (v, file)) != NULL)
! 	return new;
  
    if (general_vpath != 0
!       && (new = selective_vpath_search (general_vpath, file)) != NULL)
!     return new;
  
!   return NULL;
  }
  
  
  /* Search the given VPATH list for a directory where the name pointed
!    to by FILE exists.  If it is found, return the newly malloc'd name
!    of the existing file.   Otherwise we return 0.  */
  
! static char *
  selective_vpath_search (path, file)
       struct vpath *path;
!      char *file;
  {
    int not_target;
    char *name, *n;
***************
*** 282,309 ****
    unsigned int flen, vlen, name_dplen;
    int exists = 0;
  
!   /* Find out if *FILE is a target.
       If and only if it is NOT a target, we will accept prospective
       files that don't exist but are mentioned in a makefile.  */
    {
!     struct file *f = lookup_file (*file);
      not_target = f == 0 || !f->is_target;
    }
  
!   flen = strlen (*file);
  
!   /* Split *FILE into a directory prefix and a name-within-directory.
       NAME_DPLEN gets the length of the prefix; FILENAME gets the
       pointer to the name-within-directory and FLEN is its length.  */
  
!   n = rindex (*file, '/');
!   name_dplen = n != 0 ? n - *file : 0;
!   filename = name_dplen > 0 ? n + 1 : *file;
    if (name_dplen > 0)
      flen -= name_dplen + 1;
  
    /* Allocate enough space for the biggest VPATH entry,
!      a slash, the directory prefix that came with *FILE,
       another slash (although this one may not always be
       necessary), the filename, and a null terminator.  */
    name = (char *) alloca (maxvpath + 1 + name_dplen + 1 + flen + 1);
--- 282,309 ----
    unsigned int flen, vlen, name_dplen;
    int exists = 0;
  
!   /* Find out if FILE is a target.
       If and only if it is NOT a target, we will accept prospective
       files that don't exist but are mentioned in a makefile.  */
    {
!     struct file *f = lookup_file (file);
      not_target = f == 0 || !f->is_target;
    }
  
!   flen = strlen (file);
  
!   /* Split FILE into a directory prefix and a name-within-directory.
       NAME_DPLEN gets the length of the prefix; FILENAME gets the
       pointer to the name-within-directory and FLEN is its length.  */
  
!   n = rindex (file, '/');
!   name_dplen = n != 0 ? n - file : 0;
!   filename = name_dplen > 0 ? n + 1 : file;
    if (name_dplen > 0)
      flen -= name_dplen + 1;
  
    /* Allocate enough space for the biggest VPATH entry,
!      a slash, the directory prefix that came with FILE,
       another slash (although this one may not always be
       necessary), the filename, and a null terminator.  */
    name = (char *) alloca (maxvpath + 1 + name_dplen + 1 + flen + 1);
***************
*** 318,328 ****
        bcopy (vpath[i], n, vlen);
        n += vlen;
  
!       /* Add the directory prefix already in *FILE.  */
        if (name_dplen > 0)
  	{
  	  *n++ = '/';
! 	  bcopy (*file, n, name_dplen);
  	  n += name_dplen;
  	}
  
--- 318,328 ----
        bcopy (vpath[i], n, vlen);
        n += vlen;
  
!       /* Add the directory prefix already in FILE.  */
        if (name_dplen > 0)
  	{
  	  *n++ = '/';
! 	  bcopy (file, n, name_dplen);
  	  n += name_dplen;
  	}
  
***************
*** 332,338 ****
        bcopy (filename, n + 1, flen + 1);
  
        if (not_target)
! 	/* Since *FILE is not a target, if the file is
  	   mentioned in a makefile, we consider it existent.  */
  	exists = lookup_file (name) != 0;
  
--- 332,338 ----
        bcopy (filename, n + 1, flen + 1);
  
        if (not_target)
! 	/* Since FILE is not a target, if the file is
  	   mentioned in a makefile, we consider it existent.  */
  	exists = lookup_file (name) != 0;
  
***************
*** 359,376 ****
        if (exists)
  	{
  	  /* We have found a file.
! 	     Store the name we found into *FILE for the caller.  */
  
  	  /* Put the slash back in NAME.  */
  	  *n = '/';
  
! 	  *file = savestring (name, (n + 1 - name) + flen);
  
! 	  return 1;
  	}
      }
  
!   return 0;
  }
  
  /* Print the data base of VPATH search paths.  */
--- 359,376 ----
        if (exists)
  	{
  	  /* We have found a file.
! 	     Store the name we found into FILE for the caller.  */
  
  	  /* Put the slash back in NAME.  */
  	  *n = '/';
  
! 	  file = savestring (name, (n + 1 - name) + flen);
  
! 	  return file;
  	}
      }
  
!   return NULL;
  }
  
  /* Print the data base of VPATH search paths.  */
*** make.h.orig	Sat Oct 26 17:19:58 1991
--- make.h	Wed Nov 20 13:12:43 1991
***************
*** 194,200 ****
  extern void create_pattern_rule ();
  
  extern void build_vpath_lists (), construct_vpath_list ();
! extern int vpath_search ();
  
  extern void construct_include_path ();
  extern void uniquize_deps ();
--- 194,200 ----
  extern void create_pattern_rule ();
  
  extern void build_vpath_lists (), construct_vpath_list ();
! extern char *vpath_search ();
  
  extern void construct_include_path ();
  extern void uniquize_deps ();
