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