| 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 | # Copyright (C) 1996-2002 Free Software Foundation, Inc.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is free software; you can redistribute it and/or modify
|
|---|
| 10 | # it under the terms of the GNU General Public License as published by
|
|---|
| 11 | # the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 12 | # any later version.
|
|---|
| 13 | #
|
|---|
| 14 | # This program is distributed in the hope that it will be useful,
|
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | # GNU General Public License for more details.
|
|---|
| 18 | #
|
|---|
| 19 | # You should have received a copy of the GNU General Public License
|
|---|
| 20 | # along with this program; if not, write to the Free Software
|
|---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|---|
| 22 |
|
|---|
| 23 | PROGNAME=`basename $0`
|
|---|
| 24 |
|
|---|
| 25 | : ${TMPDIR:=/tmp}
|
|---|
| 26 | TDIR=$TMPDIR/rlvers
|
|---|
| 27 |
|
|---|
| 28 | # defaults
|
|---|
| 29 | CC=cc
|
|---|
| 30 | RL_LIBDIR=/usr/local/lib
|
|---|
| 31 | RL_INCDIR=/usr/local/include
|
|---|
| 32 |
|
|---|
| 33 | TERMCAP_LIB="-ltermcap"
|
|---|
| 34 |
|
|---|
| 35 | # cannot rely on the presence of getopts
|
|---|
| 36 | while [ $# -gt 0 ]; do
|
|---|
| 37 | case "$1" in
|
|---|
| 38 | -C) shift ; CC="$1"; shift ;;
|
|---|
| 39 | -I) shift ; RL_INCDIR="$1" ; shift ;;
|
|---|
| 40 | -L) shift ; RL_LIBDIR="$1" ; shift ;;
|
|---|
| 41 | -T) shift ; TERMCAP_LIB="$1" ; shift ;;
|
|---|
| 42 | -v) shift ; verbose=y ;;
|
|---|
| 43 | --) shift ; break ;;
|
|---|
| 44 | *) echo "${PROGNAME}: usage: $PROGNAME [-C compiler] [-L libdir] [-v]" >&2 ; exit 2;;
|
|---|
| 45 | esac
|
|---|
| 46 | done
|
|---|
| 47 |
|
|---|
| 48 | # if someone happened to install examples/rlversion, use it (it's not
|
|---|
| 49 | # installed by default)
|
|---|
| 50 | if test -f ${RL_LIBDIR}/rlversion ; then
|
|---|
| 51 | if [ -n "$verbose" ]; then
|
|---|
| 52 | echo "${PROGNAME}: using installed rlversion from ${RL_LIBDIR}/rlversion"
|
|---|
| 53 | fi
|
|---|
| 54 | v=`${RL_LIBDIR}/rlversion 2>/dev/null`
|
|---|
| 55 | case "$v" in
|
|---|
| 56 | unknown | "") echo 0 ;;
|
|---|
| 57 | *) echo "$v" ;;
|
|---|
| 58 | esac
|
|---|
| 59 | exit 0
|
|---|
| 60 | fi
|
|---|
| 61 |
|
|---|
| 62 | if [ -n "$verbose" ]; then
|
|---|
| 63 | echo "${PROGNAME}: using ${RL_LIBDIR} to find libreadline"
|
|---|
| 64 | echo "${PROGNAME}: attempting program compilation"
|
|---|
| 65 | fi
|
|---|
| 66 |
|
|---|
| 67 | # make $TDIR mode 0700
|
|---|
| 68 | mkdir $TDIR || {
|
|---|
| 69 | echo "${PROGNAME}: ${TDIR}: file exists" >&2
|
|---|
| 70 | echo 0
|
|---|
| 71 | exit 1
|
|---|
| 72 | }
|
|---|
| 73 | chmod 700 $TDIR
|
|---|
| 74 |
|
|---|
| 75 | trap 'rm -f $TDIR/rlvers $TDIR/rlvers.? ; rmdir $TDIR' 0 1 2 3 6 15
|
|---|
| 76 |
|
|---|
| 77 | cat > $TDIR/rlvers.c << EOF
|
|---|
| 78 | #include <stdio.h>
|
|---|
| 79 | extern char *rl_library_version;
|
|---|
| 80 |
|
|---|
| 81 | main()
|
|---|
| 82 | {
|
|---|
| 83 | printf("%s\n", rl_library_version ? rl_library_version : "0");
|
|---|
| 84 | exit(0);
|
|---|
| 85 | }
|
|---|
| 86 | EOF
|
|---|
| 87 |
|
|---|
| 88 | opwd=`pwd`
|
|---|
| 89 |
|
|---|
| 90 | cd $TDIR || {
|
|---|
| 91 | echo "${PROGNAME}: cannot cd to $TDIR" >&2
|
|---|
| 92 | echo 0
|
|---|
| 93 | exit 1
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | if eval ${CC} -L${RL_LIBDIR} -I${RL_INCDIR} -o $TDIR/rlvers $TDIR/rlvers.c -lreadline ${TERMCAP_LIB};
|
|---|
| 97 | then
|
|---|
| 98 | v=`$TDIR/rlvers`
|
|---|
| 99 | else
|
|---|
| 100 | if [ -n "$verbose" ] ; then
|
|---|
| 101 | echo "${PROGNAME}: compilation failed: status $?"
|
|---|
| 102 | echo "${PROGNAME}: using version 0"
|
|---|
| 103 | fi
|
|---|
| 104 | v=0
|
|---|
| 105 | fi
|
|---|
| 106 |
|
|---|
| 107 | case "$v" in
|
|---|
| 108 | unknown | "") echo 0 ;;
|
|---|
| 109 | *) echo "$v" ;;
|
|---|
| 110 | esac
|
|---|
| 111 |
|
|---|
| 112 | cd $opwd
|
|---|
| 113 | exit 0
|
|---|