1#! /bin/sh 2# 3# shlib-install - install a shared library and do any necessary host-specific 4# post-installation configuration (like ldconfig) 5# 6# usage: shlib-install [-D] -O host_os -d installation-dir -i install-prog [-U] library 7# 8# Chet Ramey 9# chet@po.cwru.edu 10 11# 12# defaults 13# 14INSTALLDIR=/usr/local/lib 15LDCONFIG=ldconfig 16 17PROGNAME=`basename $0` 18USAGE="$PROGNAME [-D] -O host_os -d installation-dir -i install-prog [-U] library" 19 20# process options 21 22while [ $# -gt 0 ]; do 23 case "$1" in 24 -O) shift; host_os="$1"; shift ;; 25 -d) shift; INSTALLDIR="$1"; shift ;; 26 -i) shift; INSTALLPROG="$1" ; shift ;; 27 -D) echo=echo ; shift ;; 28 -U) uninstall=true ; shift ;; 29 -*) echo "$USAGE" >&2 ; exit 2;; 30 *) break ;; 31 esac 32done 33 34# set install target name 35LIBNAME="$1" 36 37if [ -z "$LIBNAME" ]; then 38 echo "$USAGE" >&2 39 exit 2 40fi 41 42OLDSUFF=old 43MV=mv 44RM="rm -f" 45LN="ln -s" 46 47# pre-install 48 49if [ -z "$uninstall" ]; then 50 ${echo} $RM ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} 51 if [ -f "$INSTALLDIR/$LIBNAME" ]; then 52 ${echo} $MV $INSTALLDIR/$LIBNAME ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} 53 fi 54fi 55 56# install/uninstall 57 58if [ -z "$uninstall" ] ; then 59 ${echo} eval ${INSTALLPROG} $LIBNAME ${INSTALLDIR}/${LIBNAME} 60else 61 ${echo} ${RM} ${INSTALLDIR}/${LIBNAME} 62fi 63 64# post-install/uninstall 65 66# HP-UX and Darwin/MacOS X require that a shared library have execute permission 67case "$host_os" in 68hpux*|darwin*|macosx*) 69 if [ -z "$uninstall" ]; then 70 chmod 555 ${INSTALLDIR}/${LIBNAME} 71 fi ;; 72*) ;; 73esac 74 75case "$LIBNAME" in 76*.*.[0-9].[0-9]) # libname.so.M.N 77 LINK2=`echo $LIBNAME | sed 's:\(.*\..*\.[0-9]\)\.[0-9]:\1:'` # libname.so.M 78 LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]\.[0-9]:\1:'` # libname.so 79 ;; 80*.*.[0-9]) # libname.so.M 81 LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]:\1:'` # libname.so 82 ;; 83*.[0-9]) # libname.M 84 LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]:\1:'` # libname 85 ;; 86*.[0-9].[0-9].dylib) # libname.M.N.dylib 87 LINK2=`echo $LIBNAME | sed 's:\(.*\.[0-9]\)\.[0-9]:\1:'` # libname.M.dylib 88 LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]\.[0-9]:\1:'` # libname.dylib 89esac 90 91INSTALL_LINK1='cd $INSTALLDIR ; ln -s $LIBNAME $LINK1' 92INSTALL_LINK2='cd $INSTALLDIR ; ln -s $LIBNAME $LINK2' 93 94# 95# Create symlinks to the installed library. This section is incomplete. 96# 97case "$host_os" in 98*linux*|bsdi4*|*gnu*|darwin*|macosx*) 99 # libname.so.M -> libname.so.M.N 100 ${echo} ${RM} ${INSTALLDIR}/$LINK2 101 if [ -z "$uninstall" ]; then 102 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK2 103 fi 104 105 # libname.so -> libname.so.M.N 106 ${echo} ${RM} ${INSTALLDIR}/$LINK1 107 if [ -z "$uninstall" ]; then 108 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 109 fi 110 ;; 111 112solaris2*|aix4.[2-9]*|osf*|irix[56]*|sysv[45]*|dgux*) 113 # libname.so -> libname.so.M 114 ${echo} ${RM} ${INSTALLDIR}/$LINK1 115 if [ -z "$uninstall" ]; then 116 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 117 fi 118 ;; 119 120 121# FreeBSD 3.x and above can have either a.out or ELF shared libraries 122freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*) 123 if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then 124 # libname.so -> libname.so.M 125 ${echo} ${RM} ${INSTALLDIR}/$LINK1 126 if [ -z "$uninstall" ]; then 127 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 128 fi 129 else 130 # libname.so.M -> libname.so.M.N 131 ${echo} ${RM} ${INSTALLDIR}/$LINK2 132 if [ -z "$uninstall" ]; then 133 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK2 134 fi 135 136 # libname.so -> libname.so.M.N 137 ${echo} ${RM} ${INSTALLDIR}/$LINK1 138 if [ -z "$uninstall" ]; then 139 ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 140 fi 141 fi 142 ;; 143 144hpux1*) 145 # libname.sl -> libname.M 146 ${echo} ${RM} ${INSTALLDIR}/$LINK1.sl 147 if [ -z "$uninstall" ]; then 148# ${echo} ln -s $LIBNAME ${INSTALLDIR}/${LINK1}.sl 149 ${echo} ln -s $LIBNAME ${INSTALLDIR}/${LINK1} 150 fi 151 ;; 152 153*) ;; 154esac 155 156exit 0 157