configure
changeset 1105 3ba2a43353df
parent 1103 fab1755d2998
child 1106 2051ee3d1b75
     1.1 --- a/configure	Fri Dec 19 19:04:43 2008 +0000
     1.2 +++ b/configure	Mon Dec 22 18:21:51 2008 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  #!/bin/sh
     1.5  
     1.6 -VERSION=$(cat .version)
     1.7 -DATE=$(date +%Y%m%d)
     1.8 +VERSION=$( cat .version )
     1.9 +DATE=$( date +%Y%m%d )
    1.10  
    1.11  # All absolutely required tools, one per line to ease diff.
    1.12  # See function 'has_or_abort, below, for syntax
    1.13 @@ -12,42 +12,43 @@
    1.14  #
    1.15  # Format of a pattern to check for, one per line:
    1.16  #   pattern := tool_test  OR  pattern|tool_test
    1.17 -#   tool_test := tool/regexp
    1.18 -#   tool := name of the tool  OR  absolute pathname to the tool
    1.19 -#   regexp := valid grep(1) extended regular expression  OR  empty
    1.20 +#   tool_test := tool=regexp OR tool
    1.21 +#   tool := basename of the tool  OR  absolute pathname to the tool
    1.22 +#   regexp := valid grep(1) extended regular expression, $( tool --version)
    1.23 +#             will be matched against this regexp.
    1.24  #
    1.25  # In case a pattern list is given (eg foo|bar|buz), then tests are performed
    1.26  # from left to right, stopping at the first matching test (like the shell
    1.27  # would parse 'foo || bar || buz' ).
    1.28  #
    1.29  # Examples:
    1.30 -#    /bin/bash/^GNU bash, version 3\.
    1.31 -#       will ensure that /bin/bash exists, and that $(/bin/bash --version)
    1.32 +#    /bin/bash=^GNU bash, version 3\.
    1.33 +#       will ensure that /bin/bash exists, and that $( /bin/bash --version )
    1.34  #       matches the regexp '^GNU bash, version 3\.'
    1.35 -#    autoconf/(GNU Autoconf)|autoconf2.50/
    1.36 +#    autoconf=(GNU Autoconf)|autoconf2.50
    1.37  #       will ensure that:
    1.38 -#         - 'autoconf' is to be found in the PATH, and that $(autoconf
    1.39 -#           --version) matches the regexp '(GNU Autoconf)' (which btw is
    1.40 -#           the signature of autoconf >= 2.50),
    1.41 +#         - 'autoconf' is to be found in the PATH, and that $( autoconf --version )
    1.42 +#           matches the regexp '(GNU Autoconf)' (which btw is the signature of
    1.43 +#           autoconf >= 2.50),
    1.44  #       OR that:
    1.45  #         - 'autoconf2.50' is to be found in the PATH
    1.46  #
    1.47  TOOLS_TO_CHECK='
    1.48 -/bin/bash/^GNU bash, version 3\.
    1.49 -make/^GNU Make
    1.50 -gcc/
    1.51 -gawk/^GNU Awk
    1.52 -sed/
    1.53 -bison/
    1.54 -flex/
    1.55 -makeinfo/
    1.56 -automake/\(GNU automake\) [[:digit:]]+\.[[:digit:]]{2,}|automake/\(GNU automake\) [2-9][[:digit:]]*\.
    1.57 -libtool/
    1.58 -curl/|wget/
    1.59 -patch/
    1.60 -tar/
    1.61 -gzip/
    1.62 -bzip2/
    1.63 +/bin/bash=^GNU bash, version 3\.
    1.64 +make=^GNU Make
    1.65 +gcc
    1.66 +gawk=^GNU Awk
    1.67 +sed
    1.68 +bison
    1.69 +flex
    1.70 +makeinfo
    1.71 +automake=\(GNU automake\) [[:digit:]]+\.[[:digit:]]{2,}|automake=\(GNU automake\) [2-9][[:digit:]]*\.
    1.72 +libtool
    1.73 +curl|wget
    1.74 +patch
    1.75 +tar
    1.76 +gzip
    1.77 +bzip2
    1.78  '
    1.79  
    1.80  PREFIX_DEFAULT=/usr/local
    1.81 @@ -73,31 +74,40 @@
    1.82  # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
    1.83  #                                   complete pattern format)
    1.84  has_or_abort() {
    1.85 -    { IFS="|"; for item in ${1}; do
    1.86 -          tool="${item%/*}"
    1.87 -          regexp="${item##*/}"
    1.88 -          printf "Checking for '${tool}'... "
    1.89 -          where=$(which "${tool}" 2>/dev/null || true)
    1.90 -          if [ -z "${where}" ]; then
    1.91 -              echo "not found"
    1.92 -              where=
    1.93 -              continue
    1.94 -          else
    1.95 -              if [ -n "${regexp}" ]; then
    1.96 -                  tool_version=$(${tool} --version 2>&1)
    1.97 -                  str=$(echo "${tool_version}" |grep -E "${regexp}" |head -n 1)
    1.98 -                  if [ -z "${str}" ]; then
    1.99 -                      echo "${where}: wrong version string: expecting regexp '${regexp}'"
   1.100 -                      where=""
   1.101 -                      continue
   1.102 -                  fi
   1.103 -              fi
   1.104 -              echo "${where}"
   1.105 -              return 0
   1.106 -          fi
   1.107 -      done;
   1.108 -    }
   1.109 -    [ ${FORCE} -eq 0 ] && do_error "Bailing out..."
   1.110 +    save_IFS="${IFS}"
   1.111 +    IFS="|"
   1.112 +    for item in ${1}; do
   1.113 +        case "${item}" in
   1.114 +            *=*)
   1.115 +                tool="${item%%=*}"
   1.116 +                regexp="${item#*=}"
   1.117 +                ;;
   1.118 +            *)  tool="${item}"
   1.119 +                regexp=
   1.120 +                ;;
   1.121 +        esac
   1.122 +        printf "Checking for '${tool}'... "
   1.123 +        where=$( which "${tool}" 2>/dev/null )
   1.124 +        if [ -z "${where}" ]; then
   1.125 +            echo "not found"
   1.126 +            where=
   1.127 +            continue
   1.128 +        else
   1.129 +            if [ -n "${regexp}" ]; then
   1.130 +                tool_version=$( ${tool} --version 2>&1 )
   1.131 +                str=$( echo "${tool_version}" |grep -E "${regexp}" |head -n 1 )
   1.132 +                if [ -z "${str}" ]; then
   1.133 +                    echo "${where}: wrong version string: expecting regexp '${regexp}'"
   1.134 +                    where=""
   1.135 +                    continue
   1.136 +                fi
   1.137 +            fi
   1.138 +            echo "${where}"
   1.139 +            break
   1.140 +        fi
   1.141 +    done;
   1.142 +    IFS="${save_IFS}"
   1.143 +    [ -z "${where}" -a ${FORCE} -eq 0 ] && do_error "Bailing out..."
   1.144      return 0
   1.145  }
   1.146  
   1.147 @@ -106,45 +116,38 @@
   1.148  # If --var=val => echoes val and returns 0, meaning second arg was not consumed
   1.149  # If --var val => echoes val and returns non null, meaning second arg was used
   1.150  get_optval(){
   1.151 -    local ret
   1.152      case "$1" in
   1.153          --*=?*)
   1.154              echo "${1}" |cut -d '=' -f 2-
   1.155 -            ret=0
   1.156 +            return 0
   1.157              ;;
   1.158          *)
   1.159              echo "${2}"
   1.160 -            ret=1
   1.161 +            return 1
   1.162              ;;
   1.163      esac
   1.164 -    return ${ret}
   1.165  }
   1.166  
   1.167  # The set_xxx functions will set the corresponding configuration variable
   1.168  # They return 0 if second arg was not consumed, and non-zero if it was consumed.
   1.169  set_prefix() {
   1.170 -    PREFIX=$(get_optval "$1" "$2")
   1.171 -    return $?
   1.172 +    PREFIX="$( get_optval "$1" "$2" )"
   1.173  }
   1.174  set_bindir() {
   1.175      BINDIR_set=1
   1.176 -    BINDIR=$(get_optval "$1" "$2")
   1.177 -    return $?
   1.178 +    BINDIR="$( get_optval "$1" "$2" )"
   1.179  }
   1.180  set_libdir() {
   1.181      LIBDIR_set=1
   1.182 -    LIBDIR=$(get_optval "$1" "$2")
   1.183 -    return $?
   1.184 +    LIBDIR="$( get_optval "$1" "$2" )"
   1.185  }
   1.186  set_docdir() {
   1.187      DOCDIR_set=1
   1.188 -    DOCDIR=$(get_optval "$1" "$2")
   1.189 -    return $?
   1.190 +    DOCDIR="$( get_optval "$1" "$2" )"
   1.191  }
   1.192  set_mandir() {
   1.193      MANDIR_set=1
   1.194 -    MANDIR=$(get_optval "$1" "$2")
   1.195 -    return $?
   1.196 +    MANDIR="$( get_optval "$1" "$2" )"
   1.197  }
   1.198  
   1.199  # The set_contrib function is different in that it will work like the others,
   1.200 @@ -154,21 +157,21 @@
   1.201  # caller to quit immediately by setting do_quit to non null.
   1.202  # (can't use the return code, see above).
   1.203  set_contrib() {
   1.204 -    opt_val=$(get_optval "$1" "$2")
   1.205 -    local ret=$?
   1.206 +    opt_val="$( get_optval "$1" "$2" )"
   1.207 +    ret=$?
   1.208      case "${opt_val}" in
   1.209          all)
   1.210 -            CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma  \
   1.211 -                           |xargs -I {} basename {} .patch.lzma \
   1.212 -                           |sed -r -e ':a; /$/N; s/\n/,/; ta;'
   1.213 -                          )
   1.214 +            CONTRIB_list="$( LC_ALL=C ls -1 contrib/*.patch.lzma            \
   1.215 +                                      |xargs -I {} basename {} .patch.lzma  \
   1.216 +                                      |sed -r -e ':a; /$/N; s/\n/,/; ta;'   \
   1.217 +                           )"
   1.218              ;;
   1.219          list)
   1.220              do_quit=1
   1.221              echo "Available contributions:"
   1.222 -            LC_ALL=C ls -1 contrib/*.patch.lzma     \
   1.223 -            |xargs -I {} basename {} .patch.lzma    \
   1.224 -            |sed -r -e 's/^/  /;'
   1.225 +            LC_ALL=C ls -1 contrib/*.patch.lzma             \
   1.226 +                     |xargs -I {} basename {} .patch.lzma   \
   1.227 +                     |sed -r -e 's/^/  /;'
   1.228              ;;
   1.229          *)  CONTRIB_list="${CONTRIB_list},${opt_val}";;
   1.230      esac
   1.231 @@ -184,7 +187,7 @@
   1.232  Defaults for the options are specified in brackets.
   1.233  
   1.234  Configuration:
   1.235 -  -h, --help              display this help and exit                                                                                                                  
   1.236 +  -h, --help              display this help and exit
   1.237        --force             force ./configure to complete, even if one or more
   1.238                            tools were not found. Use at your own risk, only if
   1.239                            you know what you are doing!
   1.240 @@ -240,11 +243,11 @@
   1.241  
   1.242  # Special case when installing locally
   1.243  if [ "${LOCAL_set}" = "1" ]; then
   1.244 -    set_prefix "" $(pwd)
   1.245 -    set_bindir "" $(pwd)
   1.246 -    set_libdir "" $(pwd)
   1.247 -    set_docdir "" $(pwd)/docs
   1.248 -    set_mandir "" $(pwd)/docs
   1.249 +    set_prefix "" "$( pwd )"
   1.250 +    set_bindir "" "$( pwd )"
   1.251 +    set_libdir "" "$( pwd )"
   1.252 +    set_docdir "" "$( pwd )/docs"
   1.253 +    set_mandir "" "$( pwd )/docs"
   1.254  fi
   1.255  
   1.256  #---------------------------------------------------------------------
   1.257 @@ -254,21 +257,27 @@
   1.258  # If we can't get the revision number, use date
   1.259  printf "Computing version string... "
   1.260  case "${VERSION}" in
   1.261 -  *+svn|svn)
   1.262 -    REVISION=$(LC_ALL=C svnversion)
   1.263 -    case "${REVISION}" in
   1.264 -      exported)
   1.265 -        VERSION="${VERSION}_unknown@$(date +%Y%m%d.%H%M%S)";;
   1.266 -      *)
   1.267 -        URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
   1.268 -        ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
   1.269 -        VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   1.270 +    *+svn|svn)
   1.271 +        REVISION="$( LC_ALL=C svnversion )"
   1.272 +        case "${REVISION}" in
   1.273 +            exported)
   1.274 +                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
   1.275 +            *)
   1.276 +                URL="$( LC_ALL=C svn info 2>/dev/null   \
   1.277 +                                 |egrep 'URL: '         \
   1.278 +                                 |cut -d ' ' -f 2-      \
   1.279 +                      )"
   1.280 +                ROOT="$( LC_ALL=C svn info 2>/dev/null  \
   1.281 +                         |egrep 'Repository Root: '     \
   1.282 +                         |cut -d ' ' -f 3-              \
   1.283 +                       )"
   1.284 +                VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   1.285 +                ;;
   1.286 +        esac
   1.287 +        # Arrange to have no / in the directory name, no need to create an
   1.288 +        # arbitrarily deep directory structure
   1.289 +        VERSION="$( echo "${VERSION}" |sed -r -e 's|/+|_|g;' )"
   1.290          ;;
   1.291 -    esac
   1.292 -    # Arrange to have no / in the directory name, no need to create an
   1.293 -    # arbitrarily deep directory structure
   1.294 -    VERSION=$(echo "${VERSION}" |sed -r -e 's|/+|_|g;')
   1.295 -    ;;
   1.296  esac
   1.297  echo "${VERSION}"
   1.298  
   1.299 @@ -280,26 +289,29 @@
   1.300  
   1.301  # Check that install PATHs are absolute
   1.302  for p in BIN LIB DOC MAN; do
   1.303 -  var="${p}DIR"
   1.304 -  eval v="\${${var}}"
   1.305 -  case "${v}" in
   1.306 -    /*) ;;
   1.307 -    *)  do_error "'${var}' is not an absolute path: '${v}'"
   1.308 -  esac
   1.309 +    var="${p}DIR"
   1.310 +    eval v='"${'"${var}"'}"'
   1.311 +    case "${v}" in
   1.312 +        /*) ;;
   1.313 +        *)  do_error "'${var}' is not an absolute path: '${v}'"
   1.314 +    esac
   1.315  done
   1.316  
   1.317  # Check the existence of absolutely required tools
   1.318 -{ IFS='
   1.319 -';
   1.320 -  for tool in ${TOOLS_TO_CHECK}; do
   1.321 -      has_or_abort "${tool}"
   1.322 -  done;
   1.323 -}
   1.324 +save_IFS="${IFS}"
   1.325 +IFS='
   1.326 +'
   1.327 +for tool in ${TOOLS_TO_CHECK}; do
   1.328 +    has_or_abort "${tool}"
   1.329 +done
   1.330 +IFS="${save_IFS}"
   1.331  
   1.332  # It's safer to change all ',' to spaces rather than setting IFS
   1.333 -CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;')
   1.334 +CONTRIB_list="$( echo "${CONTRIB_list}"                             \
   1.335 +                 |sed -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;' \
   1.336 +               )"
   1.337  if [ -n "${CONTRIB_list}" ]; then
   1.338 -    has_or_abort 'lzcat/'
   1.339 +    has_or_abort 'lzcat'
   1.340      printf "Applying contributed code: "
   1.341      for c in ${CONTRIB_list}; do
   1.342          printf "${c}, "
   1.343 @@ -312,14 +324,13 @@
   1.344  fi
   1.345  
   1.346  printf "Building up Makefile... "
   1.347 -sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   1.348 -       -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   1.349 -       -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   1.350 -       -e "s,@@MANDIR@@,${MANDIR},g;"   \
   1.351 -       -e "s,@@VERSION@@,${VERSION},g;" \
   1.352 -       -e "s,@@DATE@@,${DATE},g;"       \
   1.353 -       -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   1.354 -       Makefile.in >Makefile
   1.355 +sed -r -e "s,@@BINDIR@@,${BINDIR},g
   1.356 +           s,@@LIBDIR@@,${LIBDIR},g
   1.357 +           s,@@DOCDIR@@,${DOCDIR},g
   1.358 +           s,@@MANDIR@@,${MANDIR},g
   1.359 +           s,@@VERSION@@,${VERSION},g
   1.360 +           s,@@DATE@@,${DATE},g
   1.361 +           s,@@LOCAL@@,${LOCAL_set},g"  Makefile.in >Makefile
   1.362  echo "done"
   1.363  
   1.364  cat <<__EOF__