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