aboutsummaryrefslogtreecommitdiff
path: root/readline/support/shlib-install
blob: e43a7c0935fba0af6aac2eb647beb58d493e750c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#! /bin/sh
#
# shlib-install - install a shared library and do any necessary host-specific
#		  post-installation configuration (like ldconfig)
#
# usage: shlib-install [-D] -O host_os -d installation-dir -i install-prog [-U] library
#
# Chet Ramey
# chet@po.cwru.edu

#
# defaults
#
INSTALLDIR=/usr/local/lib
LDCONFIG=ldconfig

PROGNAME=`basename $0`
USAGE="$PROGNAME [-D] -O host_os -d installation-dir -i install-prog [-U] library"

# process options

while [ $# -gt 0 ]; do
	case "$1" in
	-O)	shift; host_os="$1"; shift ;;
	-d)	shift; INSTALLDIR="$1"; shift ;;
	-i)	shift; INSTALLPROG="$1" ; shift ;;
	-D)	echo=echo ; shift ;;
	-U)	uninstall=true ; shift ;;
	-*)	echo "$USAGE" >&2 ; exit 2;;
	*)	break ;;
	esac
done

# set install target name
LIBNAME="$1"

if [ -z "$LIBNAME" ]; then
	echo "$USAGE" >&2
	exit 2
fi

OLDSUFF=old
MV=mv
RM="rm -f"
LN="ln -s"

# pre-install

if [ -z "$uninstall" ]; then
	${echo} $RM ${INSTALLDIR}/${LIBNAME}.${OLDSUFF}
	if [ -f "$INSTALLDIR/$LIBNAME" ]; then
		${echo} $MV $INSTALLDIR/$LIBNAME ${INSTALLDIR}/${LIBNAME}${OLDSUFF}
	fi
fi

# install/uninstall

if [ -z "$uninstall" ] ; then
	${echo} eval ${INSTALLPROG} $LIBNAME ${INSTALLDIR}/${LIBNAME}
else
	${echo} ${RM} ${INSTALLDIR}/${LIBNAME}
fi

# post-install/uninstall

case "$LIBNAME" in
*.*.[0-9].[0-9])	# libname.so.M.N
	LINK2=`echo $LIBNAME | sed 's:\(.*\..*\.[0-9]\)\.[0-9]:\1:'`	# libname.so.M
	LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]\.[0-9]:\1:'`	# libname.so
	;;
*.*.[0-9])		# libname.so.M
	LINK1=`echo $LIBNAME | sed 's:\(.*\..*\)\.[0-9]:\1:'`		# libname.so
	;;
esac

#
# Create symlinks to the installed library.  This section is incomplete.
#
case "$host_os" in
*linux*|bsdi4*)
	# libname.so.M -> libname.so.M.N
	${echo} ${RM} ${INSTALLDIR}/$LINK2
	if [ -z "$uninstall" ]; then
		${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK2
	fi

	# libname.so -> libname.so.M.N
	${echo} ${RM} ${INSTALLDIR}/$LINK1
	if [ -z "$uninstall" ]; then
		${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
	fi
	;;

solaris2*|aix4.[2-9]*|hpux1*)
	# libname.so -> libname.so.M
	${echo} ${RM} ${INSTALLDIR}/$LINK1
	if [ -z "$uninstall" ]; then
		${echo} ln -s $INSTALLDIR/$LIBNAME ${INSTALLDIR}/$LINK1
	fi
	;;

*)	;;
esac

exit 0