configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jul 22 09:17:40 2008 +0000 (2008-07-22)
changeset 707 54a54765e827
parent 698 2add2b7ae4e8
child 755 c2212f59e1cf
permissions -rwxr-xr-x
Eye-candy in ./configure.

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