configure: create some convenience AC_SUBST's for the global includes
[oweals/cde.git] / cde / lib / tt / ttinstall.sh
1 #!/bin/sh
2 # %%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
3 # %%  (c) Copyright 1993, 1994 International Business Machines Corp.    
4 # %%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
5 # %%  (c) Copyright 1993, 1994 Novell, Inc.                             
6 # %%  $XConsortium: ttinstall.sh /main/3 1995/10/20 16:23:17 rswiston $                                                         
7 # @(#)ttinstall.sh      1.10 30 Jul 1993
8 # Shell script for doing installs.
9 # The old bsd install did pretty much what we want, but the SYSV install
10 # doesn't.  Hence this shell script which does what we need.
11
12 # Usage:  ttinstall <version> <dest-dir> file...
13
14 # ttinstall will create dest-dir if needed and copy each named file
15 # to that directory.  If a file's name ends in .so.[0-9] or .so.[0-9][0-9],
16 # a symlink is created in the destination directory without the version.
17 # (This breaks if any shared library has a version over 99, but I'm not
18 # worried.)
19 # If the file is ELF (binary or shared library), then mcs is used to
20 # strip the comment and replace it with a short one containing
21 # the version.
22
23 if [ "$RECURSING_ON" != "$0" ]; then
24         RECURSING_ON="$0"
25         export RECURSING_ON
26         exec ksh "$0" "$@"
27 fi
28
29 # HP-UX mkdir -p fails to work if any of the components
30 # in the name are automounter symlinks... so fake mkdir -p with
31 # a recursive shell function.
32
33 function mkdir_p
34 {
35 # if directory names have trailing /, we get called with a null string  
36         if      [[ "$1" = "" ]]
37         then    return
38         fi
39 # bail out if directory already exists -- this means recursion stops
40 # as soon as we back up into an existing directory      
41         if      [[ -d $1 ]]
42         then    return
43         fi
44 # only recurse if path has a slash in it.       
45         case $1 in
46           */*)  mkdir_p ${1%/*}
47                 mkdir $1
48                 ;;
49           *)    mkdir $1
50                 ;;
51         esac
52         return
53 }                       
54
55 version=$1; shift
56 destdir=$1; shift
57 datestamp=`date '+%d %h %y'`
58
59 if [[ ! -d $destdir ]]
60 then    print -n -u2 Creating directory $destdir ...
61         rm -f $destdir
62         mkdir_p $destdir
63         print done.
64 fi
65
66 while test "$1"
67 do      file="`basename $1`"
68         print -n -u2 Installing $1 in $destdir ...
69         rm -f $destdir/${1##*/}
70         # Try to install by linking, otherwise copy
71         ln $1 $destdir || cp $1 $destdir
72         case $1 in
73             *.so.[0-9]) print -n -u2 adding symlink ...
74                         rm -f $destdir/${file%.[0-9]}
75                         ln -s $file $destdir/${file%.[0-9]}
76                         ;;
77             *.so.[0-9][0-9]) print -n -u2 adding symlink ...
78                         rm -f $destdir/${file%.[0-9][0-9]}
79                         ln -s $file $destdir/${file%.[0-9][0-9]}
80                         ;;
81         esac
82         print -u2 done.
83         filetype=`file $1`
84         case $filetype in
85             *ELF*) print -n -u2 stripping comments ...
86                 mcs -d -a "@(#)ToolTalk $version $datestamp" $destdir/${1##*/}
87                 print -u2 done.
88                 ;;
89         esac
90         shift
91 done