configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 05 13:27:09 2008 +0000 (2008-08-05)
changeset 760 80098c869f5e
parent 707 54a54765e827
child 774 77d925a3765a
permissions -rwxr-xr-x
Mark "ADA", "ObjC", "ObjC++" and "other languages" as being EXPERIMENTAL.

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