]> git.ipfire.org Git - thirdparty/bash.git/blob - support/rlvers.sh
Imported from ../bash-2.04.tar.gz.
[thirdparty/bash.git] / support / rlvers.sh
1 #! /bin/sh
2 #
3 # rlvers.sh -- run a program that prints out the readline version number
4 # using locally-installed readline libraries
5 #
6
7 PROGNAME=`basename $0`
8 TDIR=/tmp/rlvers
9
10 # defaults
11 CC=cc
12 RL_LIBDIR=/usr/local/lib
13
14 TERMCAP_LIB="-ltermcap"
15
16 while [ $# -gt 0 ]; do
17 case "$1" in
18 -C) shift ; CC="$1"; shift ;;
19 -L) shift ; RL_LIBDIR="$1" ; shift ;;
20 -T) shift ; TERMCAP_LIB="$1" ; shift ;;
21 -v) shift ; verbose=y ;;
22 --) shift ; break ;;
23 *) echo "${PROGNAME}: usage: $PROGNAME [-C compiler] [-L libdir] [-v]" >&2 ; exit 2;;
24 esac
25 done
26
27 # if someone happened to install examples/rlversion, use it (it's not
28 # installed by default)
29 if test -f ${RL_LIBDIR}/rlversion ; then
30 if [ -n "$verbose" ]; then
31 echo "${PROGNAME}: using installed rlversion from ${RL_LIBDIR}/rlversion"
32 fi
33 v=`${RL_LIBDIR}/rlversion 2>/dev/null`
34 case "$v" in
35 unknown | "") echo 0 ;;
36 *) echo "$v" ;;
37 esac
38 exit 0
39 fi
40
41 if [ -n "$verbose" ]; then
42 echo "${PROGNAME}: using ${RL_LIBDIR} to find libreadline"
43 echo "${PROGNAME}: attempting program compilation"
44 fi
45
46 # make $TDIR mode 0700
47 mkdir $TDIR || {
48 echo "${PROGNAME}: ${TDIR}: file exists" >&2
49 echo 0
50 exit 1
51 }
52 chmod 700 $TDIR
53
54 trap 'rm -f $TDIR/rlvers $TDIR/rlvers.? ; rmdir $TDIR' 0 1 2 3 6 15
55
56 cat > $TDIR/rlvers.c << EOF
57 #include <stdio.h>
58 extern char *rl_library_version;
59
60 main()
61 {
62 printf("%s\n", rl_library_version ? rl_library_version : "0");
63 exit(0);
64 }
65 EOF
66
67 if eval ${CC} -L${RL_LIBDIR} -o $TDIR/rlvers $TDIR/rlvers.c -lreadline ${TERMCAP_LIB};
68 then
69 v=`$TDIR/rlvers`
70 else
71 if [ -n "$verbose" ] ; then
72 echo "${PROGNAME}: compilation failed: status $?"
73 echo "${PROGNAME}: using version 0"
74 fi
75 v=0
76 fi
77
78 case "$v" in
79 unknown | "") echo 0 ;;
80 *) echo "$v" ;;
81 esac
82
83 exit 0