configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Sep 11 09:01:48 2008 +0000 (2008-09-11)
changeset 848 5b3785e0d41d
parent 755 c2212f59e1cf
child 870 76a65d37807f
permissions -rwxr-xr-x
Fix auto-completion for updaetools.

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