configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Jul 18 21:03:04 2008 +0000 (2008-07-18)
changeset 683 8ac69a34f8f6
parent 680 9f988c983151
child 698 2add2b7ae4e8
permissions -rwxr-xr-x
./configure eye-candy.

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