configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Apr 26 10:47:54 2009 +0000 (2009-04-26)
branch1.4
changeset 1308 5a2255049210
parent 1299 3448ac3f1a5d
child 1311 bcd9c49d74ef
child 1450 0505b0d5cd63
permissions -rwxr-xr-x
1.4: update version to 1.4.0+svn.

-------- diffstat follows --------
/branches/1.4/.version | 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 #  - makeinfo for building docs, even if discarded later on
    10 #  - others obvious... :-/
    11 #
    12 # Format of a pattern to check for, one per line:
    13 #   pattern := var_name : tool_pattern  OR  tool_pattern
    14 #   tool_pattern := tool_test  OR  tool_pattern || tool_test
    15 #   tool_test := tool=regexp OR tool
    16 #   tool := basename of the tool  OR  absolute pathname to the tool
    17 #   regexp := valid grep(1) extended regular expression, $( tool --version)
    18 #             will be matched against this regexp.
    19 #
    20 # In case a pattern list is given (eg foo || bar || buz), then tests are performed
    21 # from left to right, stopping at the first matching test (like the shell
    22 # would parse 'foo || bar || buz' ).
    23 #
    24 # Examples:
    25 #    bash:bash=^GNU bash, version 3\.
    26 #     - if ${bash} is set and non-null, does nothing
    27 #     - else ensures that bash exists in the PATH, and that $( bash --version )
    28 #       matches the regexp '^GNU bash, version 3\.'
    29 #       - if so, then sets bash="$( which bash )"
    30 #    autoconf=(GNU Autoconf) || autoconf2.50
    31 #     - does not look at an existing variable
    32 #     - ensures that:
    33 #         - 'autoconf' is to be found in the PATH, and that $( autoconf --version )
    34 #           matches the regexp '(GNU Autoconf)' (which btw is the signature of
    35 #           autoconf >= 2.50),
    36 #       OR that:
    37 #         - 'autoconf2.50' is to be found in the PATH
    38 #
    39 TOOLS_TO_CHECK='
    40 bash:bash=^GNU bash, version [34]\.
    41 cut
    42 xargs
    43 install:install=GNU coreutils
    44 make:make=^GNU Make
    45 gcc
    46 awk
    47 bison
    48 flex
    49 makeinfo
    50 automake=\(GNU automake\) (1\.[[:digit:]]{2,}\.|[2-9][[:digit:]]*\.)
    51 libtool=\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)
    52 curl || wget
    53 patch
    54 tar
    55 gzip
    56 bzip2
    57 '
    58 
    59 PREFIX_DEFAULT=/usr/local
    60 
    61 BINDIR_set=
    62 LIBDIR_set=
    63 DOCDIR_set=
    64 MANDIR_set=
    65 LOCAL_set=
    66 
    67 do_quit=
    68 
    69 # Simply print the error message, and exit. Obvious, he?
    70 do_error() {
    71     echo "${@}"
    72     exit 1
    73 }
    74 
    75 # A small function to test for existence of various tools
    76 # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
    77 #                                   complete pattern format)
    78 has_or_abort() {
    79     local save_IFS
    80     local var_name
    81     local var_value
    82     local tool_pattern
    83     local field
    84 
    85     var_name="$( echo "${1}" |"${sed}" -r -e 's/^(([^=:]+):.+|[^:=]+=.+|[^:=]+)$/\2/;' )"
    86     field="${var_name:+2}"
    87     field="${field:-1}"
    88     tool_pattern="$( echo "${1}" |cut -d : -f ${field}- |"${sed}" -r -e 's/ *\|\| */\n/g;' )"
    89 
    90     save_IFS="${IFS}"
    91     # Set IFS to \n only
    92     IFS='
    93 '
    94     for item in ${tool_pattern}; do
    95         case "${item}" in
    96             *=*)
    97                 tool="${item%%=*}"
    98                 regexp="${item#*=}"
    99                 ;;
   100             *)  tool="${item}"
   101                 regexp=
   102                 ;;
   103         esac
   104 
   105         printf "Checking for '${tool}'... "
   106         if [ -n "${var_name}" ]; then
   107             eval var_value='"${'"${var_name}"'}"'
   108             if [ -n "${var_value}" ]; then
   109                 echo "${var_value} (cached)"
   110                 return 0
   111             fi
   112         fi
   113         where=$( which "${tool}" 2>/dev/null )
   114         if [ -z "${where}" ]; then
   115             echo "not found"
   116             where=
   117             continue
   118         elif [ -n "${regexp}" ]; then
   119             tool_version=$( ${tool} --version 2>&1 )
   120             str=$( echo "${tool_version}" |"${grep}" -E "${regexp}" |head -n 1 )
   121             if [ -z "${str}" ]; then
   122                 echo "not found"
   123                 where=""
   124                 continue
   125             fi
   126         fi
   127         break
   128     done
   129     if [ -z "${where}" ]; then
   130         for item in ${tool_pattern}; do
   131             case "${item}" in
   132                 *=*)
   133                     tool="${item%%=*}"
   134                     regexp="${item#*=}"
   135                     ;;
   136                 *)  tool="${item}"
   137                     regexp=
   138                     ;;
   139             esac
   140             printf "  could not find '${tool}'"
   141             [ -n "${regexp}" ] && printf " matching regexp '${regexp}'"
   142             echo
   143         done
   144         echo "Either you are missing entirely the needed tool,"
   145         echo "or the version you have is too old."
   146         if [ -n "${var_name}" ]; then
   147             echo "You can give the path to this tool using: --with-${var_name}=PATH"
   148         fi
   149         # FORCE can be set in the environment
   150         [ -z "${FORCE}" ] && do_error "Bailing out..."
   151     else
   152         echo "${where}"
   153         if [ -n "${var_name}" ]; then
   154             eval ${var_name}='"'"${where}"'"'
   155         fi
   156     fi
   157     IFS="${save_IFS}"
   158     return 0
   159 }
   160 
   161 # Given an option string and the following argument,
   162 # echoes the value of the option.
   163 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
   164 # If --var val => echoes val and returns non null, meaning second arg was used
   165 get_optval(){
   166     case "$1" in
   167         --*=?*)
   168             echo "${1#*=}"
   169             return 0
   170             ;;
   171         *)
   172             echo "${2}"
   173             return 1
   174             ;;
   175     esac
   176 }
   177 
   178 # The set_xxx functions will set the corresponding configuration variable
   179 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
   180 set_prefix() {
   181     PREFIX="$( get_optval "$1" "$2" )"
   182 }
   183 set_bindir() {
   184     BINDIR_set=1
   185     BINDIR="$( get_optval "$1" "$2" )"
   186 }
   187 set_libdir() {
   188     LIBDIR_set=1
   189     LIBDIR="$( get_optval "$1" "$2" )"
   190 }
   191 set_docdir() {
   192     DOCDIR_set=1
   193     DOCDIR="$( get_optval "$1" "$2" )"
   194 }
   195 set_mandir() {
   196     MANDIR_set=1
   197     MANDIR="$( get_optval "$1" "$2" )"
   198 }
   199 set_tool() {
   200     local var_name="${1%%=*}"
   201     var_name="${var_name#--with-}"
   202     eval ${var_name}="\$( get_optval "$1" "$2" )"
   203 }
   204 
   205 do_help() {
   206     cat <<__EOF__
   207 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
   208 
   209 USAGE: ./configure [OPTION]...
   210 
   211 Defaults for the options are specified in brackets.
   212 
   213 Configuration:
   214   -h, --help              display this help and exit
   215 
   216 Installation directories:
   217   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
   218   --local                 don't install, and use current directory
   219 
   220 By default, \`make install' will install all the files in
   221 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
   222 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
   223 for instance \`--prefix=\${HOME}'.
   224 
   225 For better control, use the options below.
   226 
   227 Fine tuning of the installation directories:
   228   --bindir=DIR            user executables [PREFIX/bin]
   229   --libdir=DIR            object code libraries [PREFIX/lib]
   230   --docdir=DIR            info documentation [PREFIX/share/doc]
   231   --mandir=DIR            man documentation [PREFIX/share/man]
   232 
   233 Optional Features:
   234   --with-install=PATH     Specify the full PATH to GNU install
   235   --with-make=PATH        Specify the full PATH to GNU make
   236   --with-grep=PATH        Specify the full PATH to GNU grep
   237   --with-sed=PATH         Specify the full PATH to GNU sed
   238   --with-bash=PATH        Specify the full PATH to bash >= 3.0
   239 __EOF__
   240 }
   241 
   242 #---------------------------------------------------------------------
   243 # Set user's options
   244 
   245 while [ $# -ne 0 ]; do
   246     case "$1" in
   247         --local)    LOCAL_set="y"; shift;;
   248         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   249         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   250         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   251         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   252         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   253         --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
   254         --help|-h)  do_help; exit 0;;
   255         *)          echo "Unrecognised option: '${1}'"; do_help; exit 1;;
   256     esac
   257 done
   258 
   259 # Use defaults
   260 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   261 
   262 # Special case when installing locally
   263 if [ "${LOCAL_set}" = "y" ]; then
   264     set_prefix "" "$( pwd )"
   265     set_bindir "" "$( pwd )"
   266     set_libdir "" "$( pwd )"
   267     set_docdir "" "$( pwd )/docs"
   268     set_mandir "" "$( pwd )/docs"
   269 fi
   270 
   271 #---------------------------------------------------------------------
   272 # Some sanity checks, now
   273 
   274 # We check for grep and sed manually, because they are used in has_or_abort
   275 printf "Checking for 'grep'... "
   276 if [ -n "${grep}" ]; then
   277     echo "${grep} (cached)"
   278 else
   279     grep="$( which grep 2>/dev/null )"
   280     if [ -z "${grep}" ]; then
   281         echo "not found"
   282     else
   283         echo "${grep}"
   284         printf "Checking whether '${grep}' supports -E... "
   285         if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
   286             echo "yes"
   287         else
   288             echo "no"
   289             grep=
   290         fi
   291     fi
   292 fi
   293 if [ -z "${grep}" ]; then
   294     echo "Either you are missing entirely the needed tool,"
   295     echo "or the version you have is too old."
   296     echo "You can give the path to this tool using: --with-grep=PATH"
   297     do_error "Bailing out..."
   298 fi
   299 
   300 printf "Checking for 'sed'... "
   301 if [ -n "${sed}" ]; then
   302     echo "${sed} (cached)"
   303 else
   304     sed="$( which sed 2>/dev/null )"
   305     if [ -z "${sed}" ]; then
   306         echo "not found"
   307     else
   308         echo "${sed}"
   309         printf "Checking whether '${sed}' supports -i and -e... "
   310         touch .ct-ng.sed.test
   311         if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
   312             echo "yes"
   313         else
   314             echo "no"
   315             sed=
   316         fi
   317         rm -f .ct-ng.sed.test
   318     fi
   319 fi
   320 if [ -z "${sed}" ]; then
   321     echo "Either you are missing entirely the needed tool,"
   322     echo "or the version you have is too old."
   323     echo "You can give the path to this tool using: --with-sed=PATH"
   324     do_error "Bailing out..."
   325 fi
   326 
   327 # Check the existence of absolutely required tools
   328 save_IFS="${IFS}"
   329 IFS='
   330 '
   331 for tool in ${TOOLS_TO_CHECK}; do
   332     has_or_abort "${tool}"
   333 done
   334 IFS="${save_IFS}"
   335 
   336 #---------------------------------------------------------------------
   337 # Compute the version string
   338 
   339 # If this version is a svn snapshot, try to get the revision number
   340 # If we can't get the revision number, use date
   341 printf "Computing version string... "
   342 case "${VERSION}" in
   343     *+svn|svn)
   344         REVISION="$( LC_ALL=C svnversion )"
   345         case "${REVISION}" in
   346             exported)
   347                 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
   348             *)
   349                 URL="$( LC_ALL=C svn info 2>/dev/null   \
   350                                  |egrep 'URL: '         \
   351                                  |cut -d ' ' -f 2-      \
   352                       )"
   353                 ROOT="$( LC_ALL=C svn info 2>/dev/null      \
   354                          |"${grep}" '^Repository Root: '    \
   355                          |cut -d ' ' -f 3-                  \
   356                        )"
   357                 VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
   358                 ;;
   359         esac
   360         # Arrange to have no / in the directory name, no need to create an
   361         # arbitrarily deep directory structure
   362         VERSION="$( echo "${VERSION}" |"${sed}" -r -e 's|/+|_|g;' )"
   363         ;;
   364 esac
   365 echo "${VERSION}"
   366 
   367 #---------------------------------------------------------------------
   368 # Compute and check install paths
   369 
   370 # Now we have the version string, we can build up the paths
   371 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   372 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   373 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   374 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   375 
   376 # Check that install PATHs are absolute
   377 for p in BIN LIB DOC MAN; do
   378     var="${p}DIR"
   379     eval v='"${'"${var}"'}"'
   380     case "${v}" in
   381         /*) ;;
   382         *)  do_error "'${var}' is not an absolute path: '${v}'"
   383     esac
   384 done
   385 
   386 #---------------------------------------------------------------------
   387 # That's all, folks!
   388 
   389 printf "Building up Makefile... "
   390 var_list="grep
   391           sed
   392           $( printf "${TOOLS_TO_CHECK}"                                 \
   393              |"${sed}" -r -e 's/^(([^=:]+):.+|[^:=]+=.+|[^:=]+)$/\2/;'
   394            )"
   395 var_sed="$( for var_name in ${var_list}; do
   396                 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
   397             done 
   398           )"
   399 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
   400                 s,@@LIBDIR@@,${LIBDIR},g
   401                 s,@@DOCDIR@@,${DOCDIR},g
   402                 s,@@MANDIR@@,${MANDIR},g
   403                 s,@@VERSION@@,${VERSION},g
   404                 s,@@DATE@@,${DATE},g
   405                 ${var_sed}
   406                 s,@@LOCAL@@,${LOCAL_set},g"  Makefile.in >Makefile
   407 echo "done"
   408 
   409 cat <<__EOF__
   410 
   411 crosstool-NG configured as follows:
   412   PREFIX='${PREFIX}'
   413   BINDIR='${BINDIR}'
   414   LIBDIR='${LIBDIR}'
   415   DOCDIR='${DOCDIR}'
   416   MANDIR='${MANDIR}'
   417 
   418 Now run:
   419   make
   420 __EOF__
   421 if [ "${LOCAL_set}" != "y" ]; then
   422     printf "  make install\n"
   423 fi