summaryrefslogtreecommitdiff
path: root/readline/support/shlib-install
blob: 2cd252a3658042e2bf9a691a4ee25b68c9adffae (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /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 [-b bin-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 [-b bin-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 ;;
	-b)	shift; BINDIR="$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

# HP-UX and Darwin/MacOS X require that a shared library have execute permission
# Cygwin installs both a dll (which must go in $BINDIR) and an implicit
# link library (in $libdir)
case "$host_os" in
hpux*|darwin*|macosx*)
	if [ -z "$uninstall" ]; then
		chmod 555 ${INSTALLDIR}/${LIBNAME}
	fi ;;
cygwin*)
	IMPLIBNAME=`echo ${LIBNAME} \
		| sed -e 's,^cyg,lib,' -e 's,[0-9]*.dll$,.dll.a,'`
	if [ -z "$uninstall" ]; then
		${echo} $RM ${BINDIR}/${LIBNAME}.${OLDSUFF}
		if [ -f "$BINDIR/$LIBNAME" ]; then
			${echo} $MV $BINDIR/$LIBNAME $BINDIR/$LIBNAME.$OLDSUFF
		fi
		${echo} $MV ${INSTALLDIR}/${LIBNAME} ${BINDIR}/${LIBNAME}
		${echo} chmod a+x ${BINDIR}/${LIBNAME}
		${echo} eval ${INSTALLPROG} ${LIBNAME}.a \
			${INSTALLDIR}/${IMPLIBNAME}
	else
		${echo} ${RM} ${BINDIR}/${LIBNAME}
		${echo} ${RM} ${INSTALLDIR}/${IMPLIBNAME}
	fi ;;

*)	;;
esac

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
	;;
*.[0-9])		# libname.M
	LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]:\1:'`		# libname
	;;
*.[0-9].[0-9].dylib)	# libname.M.N.dylib
	LINK2=`echo $LIBNAME | sed 's:\(.*\.[0-9]\)\.[0-9]:\1:'`	# libname.M.dylib
	LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]\.[0-9]:\1:'`	# libname.dylib
esac

INSTALL_LINK1='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK1'
INSTALL_LINK2='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK2'

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

	# libname.so -> libname.so.M
	${echo} ${RM} ${INSTALLDIR}/$LINK1
	if [ -z "$uninstall" ]; then
		${echo} cd $INSTALLDIR && ${echo} ${LN} $LINK2 $LINK1
	fi
	;;

bsdi4*|*gnu*|darwin*|macosx*|k*bsd*-gnu)
	# libname.so.M -> libname.so.M.N
	${echo} ${RM} ${INSTALLDIR}/$LINK2
	if [ -z "$uninstall" ]; then
		eval $INSTALL_LINK2
	fi

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

solaris2*|aix4.[2-9]*|osf*|irix[56]*|sysv[45]*|dgux*)
	# libname.so -> libname.so.M
	${echo} ${RM} ${INSTALLDIR}/$LINK1
	if [ -z "$uninstall" ]; then
		eval $INSTALL_LINK1
	fi
	;;


# FreeBSD 3.x and above can have either a.out or ELF shared libraries
freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*)
	if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then
		# libname.so -> libname.so.M
		${echo} ${RM} ${INSTALLDIR}/$LINK1
		if [ -z "$uninstall" ]; then
			eval $INSTALL_LINK1
		fi
	else
		# libname.so.M -> libname.so.M.N
		${echo} ${RM} ${INSTALLDIR}/$LINK2
		if [ -z "$uninstall" ]; then
			eval $INSTALL_LINK2
		fi

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

hpux1*)
	# libname.sl -> libname.M
	${echo} ${RM} ${INSTALLDIR}/$LINK1.sl
	if [ -z "$uninstall" ]; then
		eval $INSTALL_LINK1
	fi
	;;

cygwin*)
	# Links to .dlls don't work.  Hence shobj-conf used DLLVERSION.dll
	# instead of so.SHLIB_MAJOR.SHLIB_MINOR.  The postinstall above
	# took care of everything else.
	;;

*)	;;
esac

exit 0