Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libreadline / support / shlib-install
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 #
14 INSTALLDIR=/usr/local/lib
15 LDCONFIG=ldconfig
16
17 PROGNAME=`basename $0`
18 USAGE="$PROGNAME [-D] -O host_os -d installation-dir -i install-prog [-U] library"
19
20 # process options
21
22 while [ $# -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
32 done
33
34 # set install target name
35 LIBNAME="$1"
36
37 if [ -z "$LIBNAME" ]; then
38         echo "$USAGE" >&2
39         exit 2
40 fi
41
42 OLDSUFF=old
43 MV=mv
44 RM="rm -f"
45 LN="ln -s"
46
47 # pre-install
48
49 if [ -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
54 fi
55
56 # install/uninstall
57
58 if [ -z "$uninstall" ] ; then
59         ${echo} eval ${INSTALLPROG} $LIBNAME ${INSTALLDIR}/${LIBNAME}
60 else
61         ${echo} ${RM} ${INSTALLDIR}/${LIBNAME}
62 fi
63
64 # post-install/uninstall
65
66 # HP-UX requires that a shared library have execute permission
67 case "$host_os" in
68 hpux*)  if [ -z "$uninstall" ]; then
69                 chmod 755 ${INSTALLDIR}/${LIBNAME}
70         fi ;;
71 *)      ;;
72 esac
73
74 case "$LIBNAME" in
75 *.*.[0-9].[0-9])        # libname.so.M.N
76         LINK2=`echo $LIBNAME | sed 's:\(.*\..*\.[0-9]\)\.[0-9]:\1:'`    # libname.so.M
77         LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]\.[0-9]:\1:'`    # libname.so
78         ;;
79 *.*.[0-9])              # libname.so.M
80         LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]:\1:'`           # libname.so
81         ;;
82 *.[0-9])                # libname.M
83         LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]:\1:'`               # libname
84         ;;
85 esac
86
87 #
88 # Create symlinks to the installed library.  This section is incomplete.
89 #
90 case "$host_os" in
91 *linux*|bsdi4*)
92         # libname.so.M -> libname.so.M.N
93         ${echo} ${RM} ${INSTALLDIR}/$LINK2
94         if [ -z "$uninstall" ]; then
95                 ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK2
96         fi
97
98         # libname.so -> libname.so.M.N
99         ${echo} ${RM} ${INSTALLDIR}/$LINK1
100         if [ -z "$uninstall" ]; then
101                 ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
102         fi
103         ;;
104
105 solaris2*|aix4.[2-9]*|osf*|irix[56]*)
106         # libname.so -> libname.so.M
107         ${echo} ${RM} ${INSTALLDIR}/$LINK1
108         if [ -z "$uninstall" ]; then
109                 ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
110         fi
111         ;;
112
113
114 # FreeBSD 3.x can have either a.out or ELF shared libraries
115 freebsd3*)
116         if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then
117                 # libname.so -> libname.so.M
118                 ${echo} ${RM} ${INSTALLDIR}/$LINK1
119                 if [ -z "$uninstall" ]; then
120                         ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
121                 fi
122         else
123                 # libname.so.M -> libname.so.M.N
124                 ${echo} ${RM} ${INSTALLDIR}/$LINK2
125                 if [ -z "$uninstall" ]; then
126                         ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK2
127                 fi
128
129                 # libname.so -> libname.so.M.N
130                 ${echo} ${RM} ${INSTALLDIR}/$LINK1
131                 if [ -z "$uninstall" ]; then
132                         ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
133                 fi
134         fi
135         ;;
136
137 hpux1*)
138         # libname.sl -> libname.M
139         ${echo} ${RM} ${INSTALLDIR}/$LINK1.sl
140         if [ -z "$uninstall" ]; then
141                 ${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/${LINK1}.sl
142         fi
143         ;;
144
145 *)      ;;
146 esac
147
148 exit 0