configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 31 16:20:03 2007 +0000 (2007-08-31)
changeset 348 9fcb5046b4b5
parent 285 148f0a31e2d8
child 376 8a2c53a1b263
permissions -rwxr-xr-x
Trying to guess how we were called does not work. Don't try to be smart, and take the full path, even if we are in PATH.
     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     local ret
    31     PREFIX=$(get_optval "$1" "$2")
    32     ret=$?
    33     [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
    34     [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
    35     [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
    36     [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
    37     return ${ret}
    38 }
    39 
    40 set_bindir() {
    41     local ret
    42     BINDIR=$(get_optval "$1" "$2")
    43     ret=$?
    44     BINDIR_set=1
    45     return ${ret}
    46 }
    47 
    48 set_libdir() {
    49     local ret
    50     LIBDIR=$(get_optval "$1" "$2")
    51     ret=$?
    52     LIBDIR_set=1
    53     return ${ret}
    54 }
    55 
    56 set_docdir() {
    57     local ret
    58     DOCDIR=$(get_optval "$1" "$2")
    59     ret=$?
    60     DOCDIR_set=1
    61     return ${ret}
    62 }
    63 
    64 set_mandir() {
    65     local ret
    66     MANDIR=$(get_optval "$1" "$2")
    67     ret=$?
    68     MANDIR_set=1
    69     return ${ret}
    70 }
    71 
    72 do_help() {
    73     cat <<__EOF__
    74 \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems.
    75 
    76 USAGE: ./configure [OPTION]...
    77 
    78 Defaults for the options are specified in brackets.
    79 
    80 Configuration:
    81   -h, --help              display this help and exit                                                                                                                  
    82   --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
    83   --local                 don't install, and use current directory
    84 
    85 By default, \`make install' will install all the files in
    86 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
    87 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
    88 for instance \`--prefix=\${HOME}'.
    89 
    90 For better control, use the options below.
    91 
    92 Fine tuning of the installation directories:
    93   --bindir=DIR           user executables [PREFIX/bin]
    94   --libdir=DIR           object code libraries [PREFIX/lib]
    95   --docdir=DIR           info documentation [PREFIX/share/doc]
    96   --mandir=DIR           man documentation [PREFIX/share/man]
    97 __EOF__
    98 }
    99 
   100 while [ $# -ne 0 ]; do
   101     case "$1" in
   102         --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
   103         --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
   104         --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
   105         --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
   106         --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
   107         --local)    LOCAL_set=1; shift;;
   108         --help|-h)  do_help; exit 0;;
   109         *)          do_help; exit 1;;
   110     esac
   111 done
   112 
   113 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
   114 if [ "${LOCAL_set}" = "1" ]; then
   115     set_prefix "" $(pwd)
   116     set_bindir "" $(pwd)
   117     set_libdir "" $(pwd)
   118     set_docdir "" $(pwd)/docs
   119     set_mandir "" $(pwd)/docs
   120 fi
   121 
   122 sed -r -e "s,@@BINDIR@@,${BINDIR},g;"   \
   123        -e "s,@@LIBDIR@@,${LIBDIR},g;"   \
   124        -e "s,@@DOCDIR@@,${DOCDIR},g;"   \
   125        -e "s,@@MANDIR@@,${MANDIR},g;"   \
   126        -e "s,@@VERSION@@,${VERSION},g;" \
   127        -e "s,@@DATE@@,${DATE},g;"       \
   128        -e "s,@@LOCAL@@,${LOCAL_set},g;" \
   129        Makefile.in >Makefile
   130 
   131 cat <<__EOF__
   132 crosstool-NG configured as follows:
   133   PREFIX="${PREFIX}"
   134   BINDIR="${BINDIR}"
   135   LIBDIR="${LIBDIR}"
   136   DOCDIR="${DOCDIR}"
   137   MANDIR="${MANDIR}"
   138 __EOF__