configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Jul 16 22:10:28 2008 +0000 (2008-07-16)
changeset 674 ab1fa87c138d
parent 673 a78a4bcc62d6
child 680 9f988c983151
permissions -rwxr-xr-x
Remove debug snippet.

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