Introduce a list of tools to check for at ./configure time.
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jul 16 21:59:49 2008 +0000 (2008-07-16)
changeset 673a78a4bcc62d6
parent 672 889b448303ae
child 674 ab1fa87c138d
Introduce a list of tools to check for at ./configure time.
Move some functions around (no code change).
Only tell about applying contribs when there are contribs to apply.
Some eye-candy here and there.

/trunk/configure | 94 75 19 0 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 75 insertions(+), 19 deletions(-)
configure
     1.1 --- a/configure	Wed Jul 16 21:57:12 2008 +0000
     1.2 +++ b/configure	Wed Jul 16 21:59:49 2008 +0000
     1.3 @@ -3,6 +3,27 @@
     1.4  VERSION=$(cat .version)
     1.5  DATE=$(date +%Y%m%d)
     1.6  
     1.7 +# All absolutely required tools, one per line to ease diff.
     1.8 +# See function 'has_or_abort, below, for syntax
     1.9 +#  - Hopefully, if gcc is present, then all associated tools will be
    1.10 +#  - awk must be GNU awk
    1.11 +#  - makeinfo for building docs, even if discarded later on
    1.12 +#  - others obvious... :-/
    1.13 +TOOLS_TO_CHECK='
    1.14 +make/^GNU
    1.15 +gcc
    1.16 +awk/^GNU
    1.17 +sed
    1.18 +bison
    1.19 +flex
    1.20 +makeinfo
    1.21 +patch
    1.22 +tar
    1.23 +gzip
    1.24 +bzip2
    1.25 +foo/^GNU
    1.26 +'
    1.27 +
    1.28  PREFIX_DEFAULT=/usr/local
    1.29  
    1.30  BINDIR_set=
    1.31 @@ -14,6 +35,37 @@
    1.32  do_quit=
    1.33  CONTRIB_list=
    1.34  
    1.35 +# Simply print the error message, and exit. Obvious, he?
    1.36 +do_error() {
    1.37 +    echo "${@}"
    1.38 +    exit 1
    1.39 +}
    1.40 +
    1.41 +# A small function to test for existence of various tools
    1.42 +# Usage: has_or_abort foobar
    1.43 +#          -> foobar must exist in PATH
    1.44 +# Usage: has_or_abort foobar/string
    1.45 +#          -> foobar must exist in PATH, and $(foobar --version) must contain 'string'
    1.46 +has_or_abort() {
    1.47 +    tool=$(echo "${1}/" |cut -d / -f 1)
    1.48 +    regexp=$(echo "${1}/" |cut -d / -f 2)
    1.49 +    printf "Checking for '${tool}'... "
    1.50 +    where=$(which "${tool}" 2>/dev/null || true)
    1.51 +    if [ -z "${where}" ]; then
    1.52 +        do_error "not found!"
    1.53 +    else
    1.54 +        printf "${where}"
    1.55 +        if [ -n "${regexp}" ]; then
    1.56 +            str=$(${tool} --version 2>&1 |egrep "${regexp}" |head -n 1)
    1.57 +            if [ -z "${str}" ]; then
    1.58 +                do_error " failed: '${tool} --version' does not match regexp '${regexp}'"
    1.59 +            fi
    1.60 +        fi
    1.61 +        echo
    1.62 +    fi
    1.63 +    return 0
    1.64 +}
    1.65 +
    1.66  # Given an option string and the following argument,
    1.67  # echoes the value of the option.
    1.68  # If --var=val => echoes val and returns 0, meaning second arg was not consumed
    1.69 @@ -124,11 +176,6 @@
    1.70  __EOF__
    1.71  }
    1.72  
    1.73 -do_error() {
    1.74 -    echo "[ERROR] ${@}"
    1.75 -    exit 1
    1.76 -}
    1.77 -
    1.78  #---------------------------------------------------------------------
    1.79  # Set user's options
    1.80  
    1.81 @@ -193,24 +240,32 @@
    1.82  [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
    1.83  
    1.84  # Check bash is present, and at least version 3.0
    1.85 -printf "Checking bash is at least bash-3.0... "
    1.86 -[ -x /bin/bash ] || do_error "bash 3.0 or above was not found in /bin/bash"
    1.87 +printf "Checking '/bin/bash' is at least bash-3.0... "
    1.88 +[ -x /bin/bash ] || do_error "bash 3.0 or above was not found in '/bin/bash'"
    1.89  bash_version=$(/bin/bash -c 'echo ${BASH_VERSION}')
    1.90  bash_major=$(/bin/bash -c 'echo ${BASH_VERSINFO[0]}')
    1.91 -[ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed (/bin/bash is ${bash_version})"
    1.92 -echo "ok (${bash_version})"
    1.93 +[ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed ('/bin/bash' is '${bash_version}')"
    1.94 +echo "${bash_version}"
    1.95  
    1.96 -printf "Applying contributed code: "
    1.97 +# Check the existence of absolutely required tools
    1.98 +for tool in ${TOOLS_TO_CHECK}; do
    1.99 +    has_or_abort "${tool}"
   1.100 +done
   1.101 +
   1.102  # It's safer to change all ',' to spaces rather than setting IFS
   1.103  CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g;')
   1.104 -for c in ${CONTRIB_list}; do
   1.105 -    printf "${c}, "
   1.106 -    if [ ! -f "contrib/${c}.patch.lzma" ]; then
   1.107 -        do_error "Contribution '${c}' does not exist"
   1.108 -    fi
   1.109 -    lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   1.110 -done
   1.111 -echo "done"
   1.112 +if [ -n "${CONTRIB_list}" ]; then
   1.113 +    has_or_abort lzcat
   1.114 +    printf "Applying contributed code: "
   1.115 +    for c in ${CONTRIB_list}; do
   1.116 +        printf "${c}, "
   1.117 +        if [ ! -f "contrib/${c}.patch.lzma" ]; then
   1.118 +            do_error "Contribution '${c}' does not exist"
   1.119 +        fi
   1.120 +        lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   1.121 +    done
   1.122 +    echo "done"
   1.123 +fi
   1.124  
   1.125  printf "Building up Makefile... "
   1.126  sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   1.127 @@ -221,9 +276,10 @@
   1.128         -e "s,@@DATE@@,${DATE},g;"       \
   1.129         -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   1.130         Makefile.in >Makefile
   1.131 -echo "ok"
   1.132 +echo "done"
   1.133  
   1.134  cat <<__EOF__
   1.135 +
   1.136  crosstool-NG configured as follows:
   1.137    PREFIX='${PREFIX}'
   1.138    BINDIR='${BINDIR}'