Commit | Line | Data |
---|---|---|
c862e87b JM |
1 | #! /bin/sh |
2 | # | |
3 | # shlib-install - install a shared library and do any necessary host-specific | |
4 | # post-installation configuration (like ldconfig) | |
5 | # | |
5bdf8622 | 6 | # usage: shlib-install [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library |
c862e87b JM |
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` | |
5bdf8622 | 18 | USAGE="$PROGNAME [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library" |
c862e87b JM |
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 ;; | |
5bdf8622 | 26 | -b) shift; BINDIR="$1" ; shift ;; |
c862e87b JM |
27 | -i) shift; INSTALLPROG="$1" ; shift ;; |
28 | -D) echo=echo ; shift ;; | |
29 | -U) uninstall=true ; shift ;; | |
30 | -*) echo "$USAGE" >&2 ; exit 2;; | |
31 | *) break ;; | |
32 | esac | |
33 | done | |
34 | ||
35 | # set install target name | |
36 | LIBNAME="$1" | |
37 | ||
38 | if [ -z "$LIBNAME" ]; then | |
39 | echo "$USAGE" >&2 | |
40 | exit 2 | |
41 | fi | |
42 | ||
43 | OLDSUFF=old | |
44 | MV=mv | |
45 | RM="rm -f" | |
46 | LN="ln -s" | |
47 | ||
48 | # pre-install | |
49 | ||
50 | if [ -z "$uninstall" ]; then | |
51 | ${echo} $RM ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} | |
52 | if [ -f "$INSTALLDIR/$LIBNAME" ]; then | |
1b17e766 | 53 | ${echo} $MV $INSTALLDIR/$LIBNAME ${INSTALLDIR}/${LIBNAME}.${OLDSUFF} |
c862e87b JM |
54 | fi |
55 | fi | |
56 | ||
57 | # install/uninstall | |
58 | ||
59 | if [ -z "$uninstall" ] ; then | |
60 | ${echo} eval ${INSTALLPROG} $LIBNAME ${INSTALLDIR}/${LIBNAME} | |
61 | else | |
62 | ${echo} ${RM} ${INSTALLDIR}/${LIBNAME} | |
63 | fi | |
64 | ||
65 | # post-install/uninstall | |
66 | ||
9255ee31 | 67 | # HP-UX and Darwin/MacOS X require that a shared library have execute permission |
5bdf8622 DJ |
68 | # Cygwin installs both a dll (which must go in $BINDIR) and an implicit |
69 | # link library (in $libdir) | |
1b17e766 | 70 | case "$host_os" in |
9255ee31 EZ |
71 | hpux*|darwin*|macosx*) |
72 | if [ -z "$uninstall" ]; then | |
73 | chmod 555 ${INSTALLDIR}/${LIBNAME} | |
1b17e766 | 74 | fi ;; |
5bdf8622 DJ |
75 | cygwin*) |
76 | IMPLIBNAME=`echo ${LIBNAME} \ | |
77 | | sed -e 's,^cyg,lib,' -e 's,[0-9]*.dll$,.dll.a,'` | |
78 | if [ -z "$uninstall" ]; then | |
79 | ${echo} $RM ${BINDIR}/${LIBNAME}.${OLDSUFF} | |
80 | if [ -f "$BINDIR/$LIBNAME" ]; then | |
81 | ${echo} $MV $BINDIR/$LIBNAME $BINDIR/$LIBNAME.$OLDSUFF | |
82 | fi | |
83 | ${echo} $MV ${INSTALLDIR}/${LIBNAME} ${BINDIR}/${LIBNAME} | |
84 | ${echo} chmod a+x ${BINDIR}/${LIBNAME} | |
85 | ${echo} eval ${INSTALLPROG} ${LIBNAME}.a \ | |
86 | ${INSTALLDIR}/${IMPLIBNAME} | |
87 | else | |
88 | ${echo} ${RM} ${BINDIR}/${LIBNAME} | |
89 | ${echo} ${RM} ${INSTALLDIR}/${IMPLIBNAME} | |
90 | fi ;; | |
91 | ||
1b17e766 EZ |
92 | *) ;; |
93 | esac | |
94 | ||
c862e87b JM |
95 | case "$LIBNAME" in |
96 | *.*.[0-9].[0-9]) # libname.so.M.N | |
97 | LINK2=`echo $LIBNAME | sed 's:\(.*\..*\.[0-9]\)\.[0-9]:\1:'` # libname.so.M | |
98 | LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]\.[0-9]:\1:'` # libname.so | |
99 | ;; | |
100 | *.*.[0-9]) # libname.so.M | |
101 | LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]:\1:'` # libname.so | |
102 | ;; | |
1b17e766 EZ |
103 | *.[0-9]) # libname.M |
104 | LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]:\1:'` # libname | |
105 | ;; | |
9255ee31 EZ |
106 | *.[0-9].[0-9].dylib) # libname.M.N.dylib |
107 | LINK2=`echo $LIBNAME | sed 's:\(.*\.[0-9]\)\.[0-9]:\1:'` # libname.M.dylib | |
108 | LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]\.[0-9]:\1:'` # libname.dylib | |
c862e87b JM |
109 | esac |
110 | ||
5bdf8622 DJ |
111 | INSTALL_LINK1='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK1' |
112 | INSTALL_LINK2='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK2' | |
9255ee31 | 113 | |
c862e87b JM |
114 | # |
115 | # Create symlinks to the installed library. This section is incomplete. | |
116 | # | |
117 | case "$host_os" in | |
5bdf8622 DJ |
118 | *linux*) |
119 | # libname.so.M -> libname.so.M.N | |
120 | ${echo} ${RM} ${INSTALLDIR}/$LINK2 | |
121 | if [ -z "$uninstall" ]; then | |
122 | eval $INSTALL_LINK2 | |
123 | fi | |
124 | ||
125 | # libname.so -> libname.so.M | |
126 | ${echo} ${RM} ${INSTALLDIR}/$LINK1 | |
127 | if [ -z "$uninstall" ]; then | |
128 | ${echo} cd $INSTALLDIR && ${echo} ${LN} $LINK2 $LINK1 | |
129 | fi | |
130 | ;; | |
131 | ||
132 | bsdi4*|*gnu*|darwin*|macosx*|k*bsd*-gnu) | |
c862e87b JM |
133 | # libname.so.M -> libname.so.M.N |
134 | ${echo} ${RM} ${INSTALLDIR}/$LINK2 | |
135 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 136 | eval $INSTALL_LINK2 |
c862e87b JM |
137 | fi |
138 | ||
139 | # libname.so -> libname.so.M.N | |
140 | ${echo} ${RM} ${INSTALLDIR}/$LINK1 | |
141 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 142 | eval $INSTALL_LINK1 |
c862e87b JM |
143 | fi |
144 | ;; | |
145 | ||
9255ee31 | 146 | solaris2*|aix4.[2-9]*|osf*|irix[56]*|sysv[45]*|dgux*) |
c862e87b JM |
147 | # libname.so -> libname.so.M |
148 | ${echo} ${RM} ${INSTALLDIR}/$LINK1 | |
149 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 150 | eval $INSTALL_LINK1 |
c862e87b JM |
151 | fi |
152 | ;; | |
153 | ||
1b17e766 | 154 | |
9255ee31 EZ |
155 | # FreeBSD 3.x and above can have either a.out or ELF shared libraries |
156 | freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*) | |
1b17e766 EZ |
157 | if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then |
158 | # libname.so -> libname.so.M | |
159 | ${echo} ${RM} ${INSTALLDIR}/$LINK1 | |
160 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 161 | eval $INSTALL_LINK1 |
1b17e766 EZ |
162 | fi |
163 | else | |
164 | # libname.so.M -> libname.so.M.N | |
165 | ${echo} ${RM} ${INSTALLDIR}/$LINK2 | |
166 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 167 | eval $INSTALL_LINK2 |
1b17e766 EZ |
168 | fi |
169 | ||
170 | # libname.so -> libname.so.M.N | |
171 | ${echo} ${RM} ${INSTALLDIR}/$LINK1 | |
172 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 173 | eval $INSTALL_LINK1 |
1b17e766 EZ |
174 | fi |
175 | fi | |
176 | ;; | |
177 | ||
178 | hpux1*) | |
179 | # libname.sl -> libname.M | |
180 | ${echo} ${RM} ${INSTALLDIR}/$LINK1.sl | |
181 | if [ -z "$uninstall" ]; then | |
5bdf8622 | 182 | eval $INSTALL_LINK1 |
1b17e766 EZ |
183 | fi |
184 | ;; | |
185 | ||
5bdf8622 DJ |
186 | cygwin*) |
187 | # Links to .dlls don't work. Hence shobj-conf used DLLVERSION.dll | |
188 | # instead of so.SHLIB_MAJOR.SHLIB_MINOR. The postinstall above | |
189 | # took care of everything else. | |
190 | ;; | |
191 | ||
c862e87b JM |
192 | *) ;; |
193 | esac | |
194 | ||
195 | exit 0 |