Subject: updated install and other patches
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Michael L. VanLoon -- Iowa State University <michaelv@iastate.edu>
List: current-users
Date: 01/09/1994 14:46:46
OK, I've had lots of people ask for my install patches, so here they
are.  I've included four patches.  The first two are for xinstall.c
and install.1 (the man page).  These can stand by themselves if you
just want the functionality.

In order to make it so your libraries don't get new times each
time you install them, and instead keep the time/date of when they
were last compiled, you need two additional patches, which are the
last two included below.  The bsd.own.mk patch simply adds the -p flag
to the COPY variable (which is kind of a perversion, but if people
think this is worthwhile, I'll take time and fix it right).

The bsd.lib.mk patch adds a command to touch the installed library
with the time from the one in your obj dir.  I discovered while
playing with all this that the installation runs a ranlib on the
library after installing it anyway, nullifying the effect of install
-p in this case.  So, I added a touch as the last thing after
installing a library so it looks like it was last modified when it was
last compiled, even though the SYMDEF table gets updated with the
current time.  Since the SYMDEF time is newer, I don't think this
should cause any problems anywhere.

Remember you have to patch the files in src/share/mk if you want the
last two patches to stick through a build.  Feedback on all this much
encouraged.  Here's the stuff:

---------- xinstall.c patch ---------- >8 --- snip --- 8< -------------
*** xinstall.c.orig	Fri Dec 17 01:22:39 1993
--- xinstall.c	Sun Jan  9 14:08:21 1994
***************
*** 45,50 ****
--- 45,52 ----
  #include <sys/param.h>
  #include <sys/stat.h>
  #include <sys/file.h>
+ #include <sys/types.h>
+ #include <utime.h>
  #include <grp.h>
  #include <pwd.h>
  #include <stdio.h>
***************
*** 55,61 ****
  
  static struct passwd *pp;
  static struct group *gp;
! static int docopy, dostrip, dodir, mode = 0755;
  static char *group, *owner, pathbuf[MAXPATHLEN];
  
  main(argc, argv)
--- 57,63 ----
  
  static struct passwd *pp;
  static struct group *gp;
! static int docopy, dostrip, dodir, preserve, mode = 0755;
  static char *group, *owner, pathbuf[MAXPATHLEN];
  
  main(argc, argv)
***************
*** 69,79 ****
          int ch, no_target;
          char *to_name;
  
!         while ((ch = getopt(argc, argv, "cg:m:o:sd")) != EOF)
                  switch((char)ch) {
                  case 'c':
                          docopy = 1;
                          break;
                  case 'g':
                          group = optarg;
                          break;
--- 71,84 ----
          int ch, no_target;
          char *to_name;
  
!         while ((ch = getopt(argc, argv, "cpg:m:o:sd")) != EOF)
                  switch((char)ch) {
                  case 'c':
                          docopy = 1;
                          break;
+                 case 'p':
+                         preserve = 1;
+                         break;
                  case 'g':
                          group = optarg;
                          break;
***************
*** 168,173 ****
--- 173,179 ----
          struct stat from_sb;
          int devnull, from_fd, to_fd;
          char *C, *rindex();
+         struct utimbuf to_times;
  
          /* if try to install NULL file to a directory, fails */
          if (isdir || strcmp(from_name, _PATH_DEVNULL)) {
***************
*** 185,192 ****
                          to_name = pathbuf;
                  }
                  devnull = 0;
!         } else
                  devnull = 1;
  
          /* unlink now... avoid ETXTBSY errors later */
          (void)unlink(to_name);
--- 191,200 ----
                          to_name = pathbuf;
                  }
                  devnull = 0;
!         } else {
                  devnull = 1;
+                 preserve = 0; /* can't preserve times/dates from /dev/null */
+         }
  
          /* unlink now... avoid ETXTBSY errors later */
          (void)unlink(to_name);
***************
*** 218,223 ****
--- 226,240 ----
                  bad(to_name);
          }
          (void)close(to_fd);
+         /*
+          * preserve from-file modification times/dates
+          */
+         if (preserve) {
+                 to_times.actime  = from_sb.st_atime;
+                 to_times.modtime = from_sb.st_mtime;
+                 if (utime(to_name, &to_times) < 0)
+                         error(to_name); /* non-fatal error */
+         }
          if (!docopy && !devnull && unlink(from_name)) {
                  error(from_name);
                  exit(1);
***************
*** 335,342 ****
  usage()
  {
          (void)fprintf(stderr, "\
! usage: install [-cs] [-g group] [-m mode] [-o owner] file1 file2\n\
!        install [-cs] [-g group] [-m mode] [-o owner] file1 ... fileN directory\n\
         install  -d   [-g group] [-m mode] [-o owner] directory ...\n");
          exit(1);
  }
--- 352,359 ----
  usage()
  {
          (void)fprintf(stderr, "\
! usage: install [-cps] [-g group] [-m mode] [-o owner] file1 file2\n\
!        install [-cps] [-g group] [-m mode] [-o owner] file1 ... fileN directory\n\
         install  -d   [-g group] [-m mode] [-o owner] directory ...\n");
          exit(1);
  }
---------- xinstall.c patch ---------- >8 --- snip --- 8< -------------


---------- install.1 patch ---------- >8 --- snip --- 8< --------------
*** install.1.orig	Fri Dec 17 01:22:38 1993
--- install.1	Sun Jan  9 14:30:53 1994
***************
*** 40,52 ****
  .Nd install binaries
  .Sh SYNOPSIS
  .Nm install
! .Op Fl cs
  .Op Fl m Ar mode
  .Op Fl o Ar owner
  .Op Fl g Ar group
  .Ar file1 file2
  .Nm install
! .Op Fl cs
  .Op Fl m Ar mode
  .Op Fl o Ar owner
  .Op Fl g Ar group
--- 40,52 ----
  .Nd install binaries
  .Sh SYNOPSIS
  .Nm install
! .Op Fl cps
  .Op Fl m Ar mode
  .Op Fl o Ar owner
  .Op Fl g Ar group
  .Ar file1 file2
  .Nm install
! .Op Fl cps
  .Op Fl m Ar mode
  .Op Fl o Ar owner
  .Op Fl g Ar group
***************
*** 83,88 ****
--- 83,96 ----
  Specify an owner.
  .It Fl g
  Specify a group.
+ .It Fl p
+ Preserve access and modification times and dates from target file(s), and apply
+ them to destination file(s).  (Note, this is not exactly the same as the
+ .Fl p
+ option which
+ .Xr cp 1
+ provides, since it only replicates access and modification times, and pays no
+ attention to the other file attributes.)
  .It Fl s
  .Nm Install
  exec's the command
---------- install.1 patch ---------- >8 --- snip --- 8< --------------


---------- bsd.lib.mk patch ---------- >8 --- snip --- 8< --------------
*** bsd.lib.mk.orig	Wed Jan  5 06:28:17 1994
--- bsd.lib.mk	Sun Jan  9 02:31:03 1994
***************
*** 145,165 ****
--- 145,170 ----
          install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
              ${DESTDIR}${LIBDIR}
          ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
+         touch -amcr lib${LIB}.a ${DESTDIR}${LIBDIR}/lib${LIB}.a
  .if !defined(NOPROFILE)
  #       ranlib lib${LIB}_p.a
          install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
              lib${LIB}_p.a ${DESTDIR}${LIBDIR}
          ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
+         touch -amcr lib${LIB}_p.a ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
  .endif
  .if !defined(NOPIC)
  #       ranlib lib${LIB}_pic.a
          install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
              lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
          ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
+         touch -amcr lib${LIB}_pic.a ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
  .endif
  .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
          install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
              lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
+         touch -amcr lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
+             ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
  .endif
  #       install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
  #           llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
---------- bsd.lib.mk patch ---------- >8 --- snip --- 8< --------------


---------- bsd.own.mk patch ---------- >8 --- snip --- 8< --------------
*** bsd.own.mk.orig	Fri Dec 17 00:44:11 1993
--- bsd.own.mk	Sun Jan  9 02:00:10 1994
***************
*** 27,33 ****
  DOCOWN?=        ${BINOWN}
  DOCMODE?=       ${NONBINMODE}
  
! COPY?=          -c
  STRIP?=         -s
  
  # Define SYS_INCLUDE to indicate whether you want symbolic links to the system
--- 27,33 ----
  DOCOWN?=        ${BINOWN}
  DOCMODE?=       ${NONBINMODE}
  
! COPY?=          -cp
  STRIP?=         -s
  
  # Define SYS_INCLUDE to indicate whether you want symbolic links to the system
---------- bsd.own.mk patch ---------- >8 --- snip --- 8< --------------

				--Michael

------------------------------------------------------------------------------
    Michael L. VanLoon  --  michaelv@iastate.edu  --  gg.mlv@isumvs.bitnet
 Iowa State University of Science and Technology -- The way cool place to be!
   Project Vincent Systems Staff, Iowa State University Computation Center
------------------------------------------------------------------------------



------------------------------------------------------------------------------