147558Sache#! /bin/sh 247558Sache# 347558Sache# shlib-install - install a shared library and do any necessary host-specific 447558Sache# post-installation configuration (like ldconfig) 547558Sache# 6157184Sache# usage: shlib-install [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library 747558Sache# 847558Sache# Chet Ramey 947558Sache# chet@po.cwru.edu 1047558Sache 1147558Sache# 1247558Sache# defaults 1347558Sache# 1447558SacheINSTALLDIR=/usr/local/lib 1547558SacheLDCONFIG=ldconfig 1647558Sache 1747558SachePROGNAME=`basename $0` 18157184SacheUSAGE="$PROGNAME [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library" 1947558Sache 2047558Sache# process options 2147558Sache 2247558Sachewhile [ $# -gt 0 ]; do 2347558Sache case "$1" in 2447558Sache -O) shift; host_os="$1"; shift ;; 2547558Sache -d) shift; INSTALLDIR="$1"; shift ;; 26157184Sache -b) shift; BINDIR="$1" ; shift ;; 2747558Sache -i) shift; INSTALLPROG="$1" ; shift ;; 2847558Sache -D) echo=echo ; shift ;; 2947558Sache -U) uninstall=true ; shift ;; 3047558Sache -*) echo "$USAGE" >&2 ; exit 2;; 3147558Sache *) break ;; 3247558Sache esac 3347558Sachedone 3447558Sache 3547558Sache# set install target name 3647558SacheLIBNAME="$1" 3747558Sache 3847558Sacheif [ -z "$LIBNAME" ]; then 3947558Sache echo "$USAGE" >&2 4047558Sache exit 2 4147558Sachefi 4247558Sache 4347558SacheOLDSUFF=old 4447558SacheMV=mv 4547558SacheRM="rm -f" 4647558SacheLN="ln -s" 4747558Sache 4847558Sache# pre-install 4947558Sache 5047558Sacheif [ -z "$uninstall" ]; then 5147558Sache ${echo} $RM ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} 5247558Sache if [ -f "$INSTALLDIR/$LIBNAME" ]; then 5358310Sache ${echo} $MV $INSTALLDIR/$LIBNAME ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} 5447558Sache fi 5547558Sachefi 5647558Sache 5747558Sache# install/uninstall 5847558Sache 5947558Sacheif [ -z "$uninstall" ] ; then 6047558Sache ${echo} eval ${INSTALLPROG} $LIBNAME ${INSTALLDIR}/${LIBNAME} 6147558Sacheelse 6247558Sache ${echo} ${RM} ${INSTALLDIR}/${LIBNAME} 6347558Sachefi 6447558Sache 6547558Sache# post-install/uninstall 6647558Sache 67119610Sache# HP-UX and Darwin/MacOS X require that a shared library have execute permission 68165670Sache# Linux does, too, and ldd warns about it 69157184Sache# Cygwin installs both a dll (which must go in $BINDIR) and an implicit 70157184Sache# link library (in $libdir) 7158310Sachecase "$host_os" in 72165670Sachehpux*|darwin*|macosx*|linux*) 73119610Sache if [ -z "$uninstall" ]; then 7475406Sache chmod 555 ${INSTALLDIR}/${LIBNAME} 7558310Sache fi ;; 76157184Sachecygwin*) 77157184Sache IMPLIBNAME=`echo ${LIBNAME} \ 78157184Sache | sed -e 's,^cyg,lib,' -e 's,[0-9]*.dll$,.dll.a,'` 79157184Sache if [ -z "$uninstall" ]; then 80157184Sache ${echo} $RM ${BINDIR}/${LIBNAME}.${OLDSUFF} 81157184Sache if [ -f "$BINDIR/$LIBNAME" ]; then 82157184Sache ${echo} $MV $BINDIR/$LIBNAME $BINDIR/$LIBNAME.$OLDSUFF 83157184Sache fi 84157184Sache ${echo} $MV ${INSTALLDIR}/${LIBNAME} ${BINDIR}/${LIBNAME} 85157184Sache ${echo} chmod a+x ${BINDIR}/${LIBNAME} 86157184Sache ${echo} eval ${INSTALLPROG} ${LIBNAME}.a \ 87157184Sache ${INSTALLDIR}/${IMPLIBNAME} 88157184Sache else 89157184Sache ${echo} ${RM} ${BINDIR}/${LIBNAME} 90157184Sache ${echo} ${RM} ${INSTALLDIR}/${IMPLIBNAME} 91157184Sache fi ;; 92157184Sache 9358310Sache*) ;; 9458310Sacheesac 9558310Sache 9647558Sachecase "$LIBNAME" in 9747558Sache*.*.[0-9].[0-9]) # libname.so.M.N 9847558Sache LINK2=`echo $LIBNAME | sed 's:\(.*\..*\.[0-9]\)\.[0-9]:\1:'` # libname.so.M 9947558Sache LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]\.[0-9]:\1:'` # libname.so 10047558Sache ;; 10147558Sache*.*.[0-9]) # libname.so.M 10247558Sache LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]:\1:'` # libname.so 10347558Sache ;; 10458310Sache*.[0-9]) # libname.M 10558310Sache LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]:\1:'` # libname 10658310Sache ;; 107119610Sache*.[0-9].[0-9].dylib) # libname.M.N.dylib 108119610Sache LINK2=`echo $LIBNAME | sed 's:\(.*\.[0-9]\)\.[0-9]:\1:'` # libname.M.dylib 109119610Sache LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]\.[0-9]:\1:'` # libname.dylib 11047558Sacheesac 11147558Sache 112136644SacheINSTALL_LINK1='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK1' 113136644SacheINSTALL_LINK2='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK2' 11475406Sache 11547558Sache# 11647558Sache# Create symlinks to the installed library. This section is incomplete. 11747558Sache# 11847558Sachecase "$host_os" in 119136644Sache*linux*) 12047558Sache # libname.so.M -> libname.so.M.N 12147558Sache ${echo} ${RM} ${INSTALLDIR}/$LINK2 12247558Sache if [ -z "$uninstall" ]; then 123136644Sache eval $INSTALL_LINK2 12447558Sache fi 12547558Sache 126136644Sache # libname.so -> libname.so.M 127136644Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1 128136644Sache if [ -z "$uninstall" ]; then 129136644Sache ${echo} cd $INSTALLDIR && ${echo} ${LN} $LINK2 $LINK1 130136644Sache fi 131136644Sache ;; 132136644Sache 133136644Sachebsdi4*|*gnu*|darwin*|macosx*|k*bsd*-gnu) 134136644Sache # libname.so.M -> libname.so.M.N 135136644Sache ${echo} ${RM} ${INSTALLDIR}/$LINK2 136136644Sache if [ -z "$uninstall" ]; then 137136644Sache eval $INSTALL_LINK2 138136644Sache fi 139136644Sache 14047558Sache # libname.so -> libname.so.M.N 14147558Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1 14247558Sache if [ -z "$uninstall" ]; then 143136644Sache eval $INSTALL_LINK1 14447558Sache fi 14547558Sache ;; 14647558Sache 147119610Sachesolaris2*|aix4.[2-9]*|osf*|irix[56]*|sysv[45]*|dgux*) 14847558Sache # libname.so -> libname.so.M 14947558Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1 15047558Sache if [ -z "$uninstall" ]; then 151136644Sache eval $INSTALL_LINK1 15247558Sache fi 15347558Sache ;; 15447558Sache 15558310Sache 156119610Sache# FreeBSD 3.x and above can have either a.out or ELF shared libraries 157119610Sachefreebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*) 15858310Sache if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then 15958310Sache # libname.so -> libname.so.M 16058310Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1 16158310Sache if [ -z "$uninstall" ]; then 162136644Sache eval $INSTALL_LINK1 16358310Sache fi 16458310Sache else 16558310Sache # libname.so.M -> libname.so.M.N 16658310Sache ${echo} ${RM} ${INSTALLDIR}/$LINK2 16758310Sache if [ -z "$uninstall" ]; then 168136644Sache eval $INSTALL_LINK2 16958310Sache fi 17058310Sache 17158310Sache # libname.so -> libname.so.M.N 17258310Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1 17358310Sache if [ -z "$uninstall" ]; then 174136644Sache eval $INSTALL_LINK1 17558310Sache fi 17658310Sache fi 17758310Sache ;; 17858310Sache 17958310Sachehpux1*) 18058310Sache # libname.sl -> libname.M 18158310Sache ${echo} ${RM} ${INSTALLDIR}/$LINK1.sl 18258310Sache if [ -z "$uninstall" ]; then 183136644Sache eval $INSTALL_LINK1 18458310Sache fi 18558310Sache ;; 18658310Sache 187157184Sachecygwin*) 188157184Sache # Links to .dlls don't work. Hence shobj-conf used DLLVERSION.dll 189157184Sache # instead of so.SHLIB_MAJOR.SHLIB_MINOR. The postinstall above 190157184Sache # took care of everything else. 191157184Sache ;; 192157184Sache 19347558Sache*) ;; 19447558Sacheesac 19547558Sache 19647558Sacheexit 0 197