configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Sep 12 20:44:15 2007 +0000 (2007-09-12)
changeset 376 8a2c53a1b263
parent 334 49b354cfd34d
child 377 38720321dad0
permissions -rwxr-xr-x
Sanitise ./configure a little bit.
Add a check for bash 3.0 or above.
     1 #!/bin/sh
     2 
     3 VERSION=$(cat .version)
     4 DATE=$(date +%Y%m%d)
     5 
     6 PREFIX_DEFAULT=/usr/local
     7 
     8 BINDIR_set=
     9 LIBDIR_set=
    10 DOCDIR_set=
    11 MANDIR_set=
    12 LOCAL_set=
    13 
    14 get_optval(){
    15     local ret
    16     case "$1" in
    17         --*=?*)
    18             echo "${1}" |cut -d '=' -f 2-
    19             ret=0
    20             ;;
    21         *)
    22             echo "${2}"
    23             ret=1
    24             ;;
    25     esac
    26     return ${ret}
    27 }
    28 
    29 set_prefix() {
    30     PREFIX=$(get_optval "$1" "$2")
    31     return $?
    32 }
    33 
    34 set_bindir() {
    35     BINDIR_set=1
    36     BINDIR=$(get_optval "$1" "$2")
    37     return $?
    38 }
    39 
    40 set_libdir() {
    41     LIBDIR_set=1
    42     LIBDIR=$(get_optval "$1" "$2")
    43     return $?
    44 }
    45 
    46 set_docdir() {
    47     DOCDIR_set=1
    48     DOCDIR=$(get_optval "$1" "$2")
    49     return $?
    50 }
    51 
    52 set_mandir() {
    53     MANDIR_set=1
    54     MANDIR=$(get_optval "$1" "$2")
    55     return $?
    56 }
    57 
    58 do_help() {
    59     cat <<__EOF__
    60 \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
    61 
    62 USAGE: ./configure [OPTION]...
    63 
    64 Defaults for the options are specified in brackets.
    65 
    66 Configuration:
    67   -h, --help              display this help and exit                                                                                                                  
    68   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
    69   --local                 don't install, and use current directory
    70 
    71 By default, \`make install' will install all the files in
    72 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
    73 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
    74 for instance \`--prefix=\${HOME}'.
    75 
    76 For better control, use the options below.
    77 
    78 Fine tuning of the installation directories:
    79   --bindir=DIR           user executables [PREFIX/bin]
    80   --libdir=DIR           object code libraries [PREFIX/lib]
    81   --docdir=DIR           info documentation [PREFIX/share/doc]
    82   --mandir=DIR           man documentation [PREFIX/share/man]
    83 __EOF__
    84 }
    85 
    86 do_error() {
    87     echo "[ERROR] ${@}"
    88     exit 1
    89 }
    90 
    91 #---------------------------------------------------------------------
    92 # Set user's options
    93 
    94 while [ $# -ne 0 ]; do
    95     case "$1" in
    96         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
    97         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
    98         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
    99         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   100         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   101         --local)    LOCAL_set=1; shift;;
   102         --help|-h)  do_help; exit 0;;
   103         *)          do_help; exit 1;;
   104     esac
   105 done
   106 
   107 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   108 if [ "${LOCAL_set}" = "1" ]; then
   109     set_prefix "" $(pwd)
   110     set_bindir "" $(pwd)
   111     set_libdir "" $(pwd)
   112     set_docdir "" $(pwd)/docs
   113     set_mandir "" $(pwd)/docs
   114 fi
   115 
   116 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
   117 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
   118 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
   119 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
   120 
   121 #---------------------------------------------------------------------
   122 # Some sanity checks, now
   123 
   124 # Check bash is present, and at least version 3.0
   125 [ -x /bin/bash ] || do_error "bash 3.0 or above was not found in /bin/bash"
   126 bash_version=$(/bin/bash --version |head -n 1 |cut -d ' ' -f 4)
   127 [ ${bash_version//%.*} -ge 3 ] || do_error "bash 3.0 or above is needed (found ${bash_version})"
   128 
   129 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   130        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   131        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   132        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   133        -e "s,@@VERSION@@,${VERSION},g;" \
   134        -e "s,@@DATE@@,${DATE},g;"       \
   135        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   136        Makefile.in >Makefile
   137 
   138 cat <<__EOF__
   139 crosstool-NG configured as follows:
   140   PREFIX="${PREFIX}"
   141   BINDIR="${BINDIR}"
   142   LIBDIR="${LIBDIR}"
   143   DOCDIR="${DOCDIR}"
   144   MANDIR="${MANDIR}"
   145 __EOF__