configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Feb 17 21:07:15 2009 +0000 (2009-02-17)
branch1.3
changeset 1214 01543123355a
parent 1163 1469c4f9fb7e
permissions -rwxr-xr-x
Backport 1382 from /trunk:
- Recognise bash-4 as a usable bash.

/branches/1.3/configure | 2 1 1 0 +-
1 file changed, 1 insertion(+), 1 deletion(-)
     1 #!/bin/sh
     2 
     3 VERSION=$(cat .version)
     4 DATE=$(date +%Y%m%d)
     5 
     6 # All absolutely required tools, one per line to ease diff.
     7 # See function 'has_or_abort, below, for syntax
     8 #  - Hopefully, if gcc is present, then all associated tools will be
     9 #  - awk must be GNU awk
    10 #  - makeinfo for building docs, even if discarded later on
    11 #  - others obvious... :-/
    12 #
    13 # Format of a pattern to check for, one per line:
    14 #   pattern := tool_test  OR  pattern|tool_test
    15 #   tool_test := tool/regexp
    16 #   tool := name of the tool  OR  absolute pathname to the tool
    17 #   regexp := valid grep(1) extended regular expression  OR  empty
    18 #
    19 # In case a pattern list is given (eg foo|bar|buz), then tests are performed
    20 # from left to right, stopping at the first matching test (like the shell
    21 # would parse 'foo || bar || buz' ).
    22 #
    23 # Examples:
    24 #    /bin/bash/^GNU bash, version 3\.
    25 #       will ensure that /bin/bash exists, and that $(/bin/bash --version)
    26 #       matches the regexp '^GNU bash, version 3\.'
    27 #    autoconf/(GNU Autoconf)|autoconf2.50/
    28 #       will ensure that:
    29 #         - 'autoconf' is to be found in the PATH, and that $(autoconf
    30 #           --version) matches the regexp '(GNU Autoconf)' (which btw is
    31 #           the signature of autoconf >= 2.50),
    32 #       OR that:
    33 #         - 'autoconf2.50' is to be found in the PATH
    34 #
    35 TOOLS_TO_CHECK='
    36 /bin/bash/^GNU bash, version [34]\.
    37 make/^GNU Make
    38 gcc/
    39 gawk/^GNU Awk
    40 sed/
    41 bison/
    42 flex/
    43 makeinfo/
    44 automake/\(GNU automake\) [[:digit:]]+\.[[:digit:]]{2,}|automake/\(GNU automake\) [2-9][[:digit:]]*\.
    45 libtool/
    46 curl/|wget/
    47 patch/
    48 tar/
    49 gzip/
    50 bzip2/
    51 '
    52 
    53 PREFIX_DEFAULT=/usr/local
    54 
    55 BINDIR_set=
    56 LIBDIR_set=
    57 DOCDIR_set=
    58 MANDIR_set=
    59 LOCAL_set=
    60 
    61 FORCE=0
    62 
    63 do_quit=
    64 CONTRIB_list=
    65 
    66 # Simply print the error message, and exit. Obvious, he?
    67 do_error() {
    68     echo "${@}"
    69     exit 1
    70 }
    71 
    72 # A small function to test for existence of various tools
    73 # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
    74 #                                   complete pattern format)
    75 has_or_abort() {
    76     { IFS="|"; for item in ${1}; do
    77           tool="${item%/*}"
    78           regexp="${item##*/}"
    79           printf "Checking for '${tool}'... "
    80           where=$(which "${tool}" 2>/dev/null || true)
    81           if [ -z "${where}" ]; then
    82               echo "not found"
    83               where=
    84               continue
    85           else
    86               if [ -n "${regexp}" ]; then
    87                   tool_version=$(${tool} --version 2>&1)
    88                   str=$(echo "${tool_version}" |grep -E "${regexp}" |head -n 1)
    89                   if [ -z "${str}" ]; then
    90                       echo "${where}: wrong version string: expecting regexp '${regexp}'"
    91                       where=""
    92                       continue
    93                   fi
    94               fi
    95               echo "${where}"
    96               return 0
    97           fi
    98       done;
    99     }
   100     [ ${FORCE} -eq 0 ] && do_error "Bailing out..."
   101     return 0
   102 }
   103 
   104 # Given an option string and the following argument,
   105 # echoes the value of the option.
   106 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
   107 # If --var val => echoes val and returns non null, meaning second arg was used
   108 get_optval(){
   109     local ret
   110     case "$1" in
   111         --*=?*)
   112             echo "${1}" |cut -d '=' -f 2-
   113             ret=0
   114             ;;
   115         *)
   116             echo "${2}"
   117             ret=1
   118             ;;
   119     esac
   120     return ${ret}
   121 }
   122 
   123 # The set_xxx functions will set the corresponding configuration variable
   124 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
   125 set_prefix() {
   126     PREFIX=$(get_optval "$1" "$2")
   127     return $?
   128 }
   129 set_bindir() {
   130     BINDIR_set=1
   131     BINDIR=$(get_optval "$1" "$2")
   132     return $?
   133 }
   134 set_libdir() {
   135     LIBDIR_set=1
   136     LIBDIR=$(get_optval "$1" "$2")
   137     return $?
   138 }
   139 set_docdir() {
   140     DOCDIR_set=1
   141     DOCDIR=$(get_optval "$1" "$2")
   142     return $?
   143 }
   144 set_mandir() {
   145     MANDIR_set=1
   146     MANDIR=$(get_optval "$1" "$2")
   147     return $?
   148 }
   149 
   150 # The set_contrib function is different in that it will work like the others,
   151 # except in two cases:
   152 # If all => replaces all with the list of all available contribs
   153 # If list => just echoes the list of all available contribs, and instructs
   154 # caller to quit immediately by setting do_quit to non null.
   155 # (can't use the return code, see above).
   156 set_contrib() {
   157     opt_val=$(get_optval "$1" "$2")
   158     local ret=$?
   159     case "${opt_val}" in
   160         all)
   161             CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma  \
   162                            |xargs -I {} basename {} .patch.lzma \
   163                            |sed -r -e ':a; /$/N; s/\n/,/; ta;'
   164                           )
   165             ;;
   166         list)
   167             do_quit=1
   168             echo "Available contributions:"
   169             LC_ALL=C ls -1 contrib/*.patch.lzma     \
   170             |xargs -I {} basename {} .patch.lzma    \
   171             |sed -r -e 's/^/  /;'
   172             ;;
   173         *)  CONTRIB_list="${CONTRIB_list},${opt_val}";;
   174     esac
   175     return $ret
   176 }
   177 
   178 do_help() {
   179     cat <<__EOF__
   180 \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
   181 
   182 USAGE: ./configure [OPTION]...
   183 
   184 Defaults for the options are specified in brackets.
   185 
   186 Configuration:
   187   -h, --help              display this help and exit                                                                                                                  
   188       --force             force ./configure to complete, even if one or more
   189                           tools were not found. Use at your own risk, only if
   190                           you know what you are doing!
   191 
   192 Installation directories:
   193   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
   194   --local                 don't install, and use current directory
   195 
   196 By default, \`make install' will install all the files in
   197 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
   198 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
   199 for instance \`--prefix=\${HOME}'.
   200 
   201 For better control, use the options below.
   202 
   203 Fine tuning of the installation directories:
   204   --bindir=DIR            user executables [PREFIX/bin]
   205   --libdir=DIR            object code libraries [PREFIX/lib]
   206   --docdir=DIR            info documentation [PREFIX/share/doc]
   207   --mandir=DIR            man documentation [PREFIX/share/man]
   208 
   209 Optional Features:
   210   --with-contrib=XXX      Include externally contributed features found in the
   211                           contrib/ sub-directory. Set to a comma-separated list
   212                           of features. Use 'all' to use all contributions, and
   213                           'list' to see which are available.
   214 __EOF__
   215 }
   216 
   217 #---------------------------------------------------------------------
   218 # Set user's options
   219 
   220 while [ $# -ne 0 ]; do
   221     case "$1" in
   222         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   223         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   224         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   225         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   226         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   227         --local)    LOCAL_set=1; shift;;
   228         --force)    FORCE=1; shift;;
   229         --with-contrib*)
   230                     set_contrib "$1" "$2" && shift || shift 2
   231                     [ "${do_quit}" = "1" ] && exit 0
   232                     ;;
   233         --help|-h)  do_help; exit 0;;
   234         *)          do_help; exit 1;;
   235     esac
   236 done
   237 
   238 # Use defaults
   239 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   240 
   241 # Special case when installing locally
   242 if [ "${LOCAL_set}" = "1" ]; then
   243     set_prefix "" $(pwd)
   244     set_bindir "" $(pwd)
   245     set_libdir "" $(pwd)
   246     set_docdir "" $(pwd)/docs
   247     set_mandir "" $(pwd)/docs
   248 fi
   249 
   250 #---------------------------------------------------------------------
   251 # Some sanity checks, now
   252 
   253 # If this version is a svn snapshot, try to get the revision number
   254 # If we can't get the revision number, use date
   255 printf "Computing version string... "
   256 case "${VERSION}" in
   257   *+svn)
   258     REVISION=$(LC_ALL=C svnversion)
   259     case "${REVISION}" in
   260       exported)
   261         VERSION="${VERSION}unknown@$(date +%Y%m%d.%H%M%S)";;
   262       *)
   263         URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
   264         ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
   265         VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   266         ;;
   267     esac
   268     # Arrange to have no / in the directory name, no need to create an
   269     # arbitrarily deep directory structure
   270     VERSION=$(echo "${VERSION}" |sed -r -e 's|/+|_|g;')
   271     ;;
   272 esac
   273 echo "${VERSION}"
   274 
   275 # Now we have the version string, we can build up the paths
   276 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   277 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   278 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   279 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   280 
   281 # Check that install PATHs are absolute
   282 for p in BIN LIB DOC MAN; do
   283   var="${p}DIR"
   284   eval v="\${${var}}"
   285   case "${v}" in
   286     /*) ;;
   287     *)  do_error "'${var}' is not an absolute path: '${v}'"
   288   esac
   289 done
   290 
   291 # Check the existence of absolutely required tools
   292 { IFS='
   293 ';
   294   for tool in ${TOOLS_TO_CHECK}; do
   295       has_or_abort "${tool}"
   296   done;
   297 }
   298 
   299 # It's safer to change all ',' to spaces rather than setting IFS
   300 CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;')
   301 if [ -n "${CONTRIB_list}" ]; then
   302     has_or_abort 'lzcat/'
   303     printf "Applying contributed code: "
   304     for c in ${CONTRIB_list}; do
   305         printf "${c}, "
   306         if [ ! -f "contrib/${c}.patch.lzma" ]; then
   307             do_error "Contribution '${c}' does not exist"
   308         fi
   309         lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1
   310     done
   311     echo "done"
   312 fi
   313 
   314 printf "Building up Makefile... "
   315 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   316        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   317        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   318        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   319        -e "s,@@VERSION@@,${VERSION},g;" \
   320        -e "s,@@DATE@@,${DATE},g;"       \
   321        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   322        Makefile.in >Makefile
   323 echo "done"
   324 
   325 cat <<__EOF__
   326 
   327 crosstool-NG configured as follows:
   328   PREFIX='${PREFIX}'
   329   BINDIR='${BINDIR}'
   330   LIBDIR='${LIBDIR}'
   331   DOCDIR='${DOCDIR}'
   332   MANDIR='${MANDIR}'
   333   CONTRIB='${CONTRIB_list}'
   334 __EOF__