configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Aug 02 18:26:53 2011 +0200 (2011-08-02)
changeset 2592 4908eb2b6f17
parent 2551 9409fe04bb7c
child 2597 d28b764334b8
permissions -rwxr-xr-x
scripts/functions: cvs retrieval first tries the mirror for tarballs

The cvs download helper looks for the local tarballs dir to see if it
can find a pre-downloaded tarball, and if it does not find it, does
the actual fetch to upstream via cvs.

In the process, it does not even try to get a tarball from the local
mirror, which can be useful if the mirror has been pre-populated
manually (or with a previously downloaded tree).

Fake a tarball get with the standard tarball-download helper, but
without specifying any upstream URL, which makes the helper directly
try the LAN mirror.

Of course, if no mirror is specified, no URL wil be available, and
the standard cvs retrieval will kick in.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@182
     1
#!/bin/sh
yann@182
     2
yann@1311
     3
myname="${0##*/}"
yann@1311
     4
yann@1105
     5
VERSION=$( cat .version )
yann@1105
     6
DATE=$( date +%Y%m%d )
yann@182
     7
yann@183
     8
PREFIX_DEFAULT=/usr/local
yann@182
     9
yann@182
    10
BINDIR_set=
yann@182
    11
LIBDIR_set=
yann@182
    12
DOCDIR_set=
yann@182
    13
MANDIR_set=
yann@285
    14
LOCAL_set=
yann@1311
    15
FORCE=
yann@182
    16
yann@641
    17
do_quit=
yann@614
    18
yann@673
    19
# Simply print the error message, and exit. Obvious, he?
yann@673
    20
do_error() {
yann@1333
    21
    printf "${myname}: ${@}\n"
yann@673
    22
    exit 1
yann@673
    23
}
yann@673
    24
yann@641
    25
# Given an option string and the following argument,
yann@641
    26
# echoes the value of the option.
yann@641
    27
# If --var=val => echoes val and returns 0, meaning second arg was not consumed
yann@641
    28
# If --var val => echoes val and returns non null, meaning second arg was used
yann@182
    29
get_optval(){
yann@182
    30
    case "$1" in
yann@182
    31
        --*=?*)
yann@1333
    32
            printf "${1#*=}"
yann@1105
    33
            return 0
yann@182
    34
            ;;
yann@182
    35
        *)
yann@1333
    36
            printf "${2}"
yann@1105
    37
            return 1
yann@182
    38
            ;;
yann@182
    39
    esac
yann@182
    40
}
yann@182
    41
yann@641
    42
# The set_xxx functions will set the corresponding configuration variable
yann@641
    43
# They return 0 if second arg was not consumed, and non-zero if it was consumed.
yann@182
    44
set_prefix() {
yann@1105
    45
    PREFIX="$( get_optval "$1" "$2" )"
yann@182
    46
}
yann@182
    47
set_bindir() {
yann@376
    48
    BINDIR_set=1
yann@1105
    49
    BINDIR="$( get_optval "$1" "$2" )"
yann@182
    50
}
yann@182
    51
set_libdir() {
yann@376
    52
    LIBDIR_set=1
yann@1105
    53
    LIBDIR="$( get_optval "$1" "$2" )"
yann@182
    54
}
yann@182
    55
set_docdir() {
yann@376
    56
    DOCDIR_set=1
yann@1105
    57
    DOCDIR="$( get_optval "$1" "$2" )"
yann@182
    58
}
yann@182
    59
set_mandir() {
yann@376
    60
    MANDIR_set=1
yann@1105
    61
    MANDIR="$( get_optval "$1" "$2" )"
yann@182
    62
}
yann@1140
    63
set_tool() {
yann@1140
    64
    local var_name="${1%%=*}"
yann@1140
    65
    var_name="${var_name#--with-}"
yann@1140
    66
    eval ${var_name}="\$( get_optval "$1" "$2" )"
yann@614
    67
}
yann@614
    68
yann@1311
    69
# var_list is a list of variables, each one holding a path to a
yann@1311
    70
# tool, either detected by ./configure, or specified by the user.
yann@1311
    71
var_list=""
yann@2481
    72
kconfig_list=""
yann@1311
    73
yann@1311
    74
# This function adds a variable name to the above list of variable names.
yann@1311
    75
# $1: the name of the variable to add to the list
yann@1311
    76
add_to_var_list() {
yann@2481
    77
    local v
yann@2481
    78
    for v in ${var_list}; do
yann@2481
    79
        [ "${v}" = "${1}" ] && return 0
yann@2481
    80
    done
yann@1311
    81
    var_list="${var_list} ${1}"
yann@1311
    82
}
yann@2481
    83
add_to_kconfig_list() {
yann@2481
    84
    local k
yann@2481
    85
    for k in ${kconfig_list}; do
yann@2481
    86
        [ "${k}" = "${1}" ] && return 0
yann@2481
    87
    done
yann@2481
    88
    kconfig_list="${kconfig_list} ${1}"
yann@2481
    89
}
yann@1311
    90
yann@1311
    91
# A function to test for required tools/headers/libraries
yann@1560
    92
# Return 0 (true) if found, !0 (false) if not found
yann@1560
    93
#
yann@1311
    94
# $*: [prog|inc|lib]=<name[ name...]>
yann@1311
    95
#     the name(s) of tool(s) to test for
yann@1311
    96
#     mandatory
yann@1311
    97
#       eg: prog=bash   prog="curl wget"
yann@1311
    98
# $*: var=<var_name>
yann@1311
    99
#     the name of the variable to test and set
yann@1311
   100
#     optional
yann@1311
   101
#       eg: var=bash    if ${bash} is set and non-null, use that,
yann@1311
   102
#                       else check for bash and set bash=$(which bash)
yann@1311
   103
# $*: ver=<regexp>
yann@1311
   104
#     for each 'prog', test if $(prog --version) matches 'regexp'
yann@1311
   105
#     optional
yann@1311
   106
#       eg: ver='^GNU bash, version [34]\.'
yann@2527
   107
# $*: lib_exts=<extension[ extension...]>
yann@2527
   108
#     the list of allowed library extension
yann@2527
   109
#     mandatory
yann@2527
   110
#       eg: lib_exts="so dylib"     lib_exts="so dylib a"
yann@1311
   111
# $*: err=<error_message>
yann@1311
   112
#     the error message to print if tool is missing
yann@1311
   113
#     optional, defaults to: '${prog}: none found'
yann@1311
   114
#       eg: err="'bash' 3.x or above was not found"
yann@2480
   115
#     Note: err may be printed by caller, not us
yann@2481
   116
# $*: kconfig=<var_name>
yann@2481
   117
#     the name of a variable to pass down to kconfig if
yann@2481
   118
#     the prog/inc/lib was found
yann@2481
   119
#     optional, defaults to none
yann@2481
   120
#       eg: kconfig=has_libncurses
yann@2528
   121
# $*: skip=[y|n|]
yann@2528
   122
#     if set to 'y', skip the test, but still register the
yann@2528
   123
#     kconfig and var variables; if 'n' or empty, do the
yann@2528
   124
#     test.
yann@2528
   125
#     optional, default to 'n'
yann@2528
   126
#       eg: skip="${static_link_ko}"
yann@1560
   127
check_for() {
yann@2527
   128
    local lib_exts
yann@2528
   129
    local skip
yann@1311
   130
    local val
yann@1311
   131
    local item
yann@1311
   132
    local where
yann@1312
   133
    local status
yann@2527
   134
    local ext
yann@1311
   135
yann@2481
   136
    # Note: prog/inc/lib and var/kconfig/ver/err are set here,
yann@2479
   137
    # but declared by the caller (because it needs it)
yann@1311
   138
    for item in "${@}"; do
yann@1311
   139
        case "${item}" in
yann@2528
   140
            prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*|skip=*)
yann@2497
   141
                eval ${item%%=*}=\"${item#*=}\"
yann@1311
   142
                ;;
yann@2527
   143
            *)  do_error "check_for: incorrect parameters: '${item}'";;
yann@1311
   144
        esac
yann@1311
   145
    done
yann@1311
   146
benoit@2507
   147
    case "${prog}:${inc}:${lib}" in
benoit@2507
   148
        ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
benoit@2507
   149
            if [ -n "${var}" ]; then
benoit@2507
   150
                do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
benoit@2507
   151
            fi
benoit@2507
   152
            ;;
benoit@2507
   153
        ::) do_error "check_for: [prog|inc|lib] is mandatory";;
benoit@2507
   154
    esac
benoit@2507
   155
yann@2528
   156
    if [ -n "${var}" ]; then
yann@2528
   157
        add_to_var_list "${var}"
yann@2528
   158
    fi
yann@2481
   159
    if [ -n "${kconfig}" ]; then
yann@2481
   160
        add_to_kconfig_list "${kconfig}"
yann@2481
   161
    fi
yann@2481
   162
yann@2528
   163
    if [ "${skip}" = "y" ]; then
yann@2528
   164
        return 0
yann@2528
   165
    fi
yann@2528
   166
benoit@2507
   167
    if [ -n "${prog}" ]; then
benoit@2507
   168
        for item in ${prog}; do
benoit@2507
   169
            printf "Checking for '${item}'... "
benoit@2507
   170
            if [ -n "${var}" ]; then
benoit@2507
   171
                eval val="\${${var}}"
benoit@2507
   172
                if [ -n "${val}" ]; then
yann@2528
   173
                    status="${val} (cached)\n"
yann@2528
   174
                    break
yann@1311
   175
                fi
benoit@2507
   176
            fi
benoit@2507
   177
            where="$( which "${item}" 2>/dev/null )"
benoit@2507
   178
            if [ -z "${where}" ]; then
benoit@2507
   179
                printf "no\n"
benoit@2507
   180
                continue
benoit@2507
   181
            elif [ -n "${ver}" ]; then
benoit@2507
   182
                str=$( LC_ALL=C "${where}" --version 2>&1   \
benoit@2507
   183
                       |grep -E "${ver}"                    \
benoit@2507
   184
                       |head -n 1
benoit@2507
   185
                     )
benoit@2507
   186
                if [ -z "${str}" ]; then
yann@1312
   187
                    printf "no\n"
benoit@2507
   188
                    unset where
yann@1311
   189
                    continue
yann@1311
   190
                fi
benoit@2507
   191
            fi
benoit@2507
   192
            status="${where}"
benoit@2507
   193
            break
benoit@2507
   194
        done
benoit@2507
   195
        if [ -z "${status}" ]; then
benoit@2507
   196
            return 1
benoit@2507
   197
        fi
benoit@2507
   198
        printf "${status}\n"
benoit@2507
   199
        unset status
yann@1560
   200
    fi
yann@1560
   201
benoit@2507
   202
    if [ -n "${inc}" ]; then
benoit@2507
   203
        for item in ${inc}; do
benoit@2507
   204
            printf "Checking for '${item}'... "
benoit@2507
   205
            if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
benoit@2507
   206
                where="${item}"
benoit@2507
   207
                status=yes
benoit@2507
   208
                break;
benoit@2507
   209
            fi
benoit@2507
   210
            printf "no\n"
benoit@2507
   211
        done
benoit@2507
   212
        if [ -z "${status}" ]; then
benoit@2507
   213
            return 1
benoit@2507
   214
        fi
benoit@2507
   215
        printf "${status}\n"
benoit@2507
   216
        unset status
benoit@2507
   217
    fi
benoit@2507
   218
benoit@2507
   219
    if [ -n "${lib}" ]; then
yann@2527
   220
        if [ -z "${lib_exts}" ]; then
yann@2527
   221
            do_error "check_for: no library extension specified for '${lib}'"
yann@2527
   222
        fi
benoit@2507
   223
        for item in ${lib}; do
yann@2527
   224
            for ext in ${lib_exts}; do
yann@2527
   225
                printf "Checking for '${item}.${ext}'... "
yann@2527
   226
                where="$( gcc -print-file-name="${item}.${ext}" )"
yann@2527
   227
                if [ "${where}" != "${item}.${ext}" ]; then
yann@2527
   228
                    where="$( readlink "${where}" )"
yann@2527
   229
                    status=yes
yann@2527
   230
                    break 2;
yann@2527
   231
                fi
yann@2527
   232
                printf "no\n"
yann@2527
   233
            done
benoit@2507
   234
        done
benoit@2507
   235
        if [ -z "${status}" ]; then
benoit@2507
   236
            return 1
benoit@2507
   237
        fi
benoit@2507
   238
        printf "${status}\n"
benoit@2507
   239
        unset status
benoit@2507
   240
    fi
benoit@2507
   241
yann@1560
   242
    if [ -n "${var}" ]; then
yann@1560
   243
        eval ${var}='"'"${where}"'"'
yann@1560
   244
    fi
yann@2481
   245
    if [ -n "${kconfig}" ]; then
yann@2481
   246
        eval ${kconfig}=y
yann@2481
   247
    fi
yann@1560
   248
}
yann@1560
   249
yann@1560
   250
# This function checks for a tool, and aborts if not found
yann@1560
   251
# See check_for(), above, for how to call has_or_abort
yann@1560
   252
has_or_abort() {
yann@2479
   253
    # We declare these 6 variables here, although they are
yann@2479
   254
    # set in check_for(), called below
yann@2479
   255
    local prog inc lib
yann@2481
   256
    local var ver err kconfig
yann@2479
   257
yann@1560
   258
    if ! check_for "$@"; then
yann@2524
   259
        printf " * A mandatory dependency is missing, or version mis-match:\n"
yann@2524
   260
        printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
yann@2479
   261
        if [ -n "${var}" ]; then
yann@2498
   262
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2479
   263
        fi
yann@2479
   264
        printf "\n"
yann@2479
   265
        # Bail out if --force is not specified
yann@1312
   266
        [ -z "${FORCE}" ] && do_error "Bailing out..."
yann@1312
   267
        printf "<*                                          *>\n"
yann@1312
   268
        printf "<*            FORCE in action:              *>\n"
yann@1312
   269
        printf "<* Continuing despite missing pre-requisite *>\n"
yann@1312
   270
        printf "<*          Prepare for breakage            *>\n"
yann@1312
   271
        printf "<*                                          *>\n"
yann@1312
   272
        printf "\n"
yann@1312
   273
    fi
yann@1311
   274
}
yann@1311
   275
yann@2480
   276
# This function checks for a tool, and warns if not found
yann@2480
   277
# See check_for(), above, for how to call has_or_abort
yann@2480
   278
# Note: if err is not set, then no error message is printed
yann@2480
   279
has_or_warn() {
yann@2480
   280
    # We declare these 6 variables here, although they are
yann@2480
   281
    # set in check_for(), called below
yann@2480
   282
    local prog inc lib
yann@2481
   283
    local var ver err kconfig
yann@2480
   284
yann@2480
   285
    if ! check_for "$@"; then
yann@2524
   286
        printf " * An optional dependency is missing, some features will be disabled"
yann@2524
   287
        printf "${err:+:\n * - ${err}}\n"
yann@2480
   288
        if [ -n "${var}" ]; then
yann@2498
   289
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2480
   290
        fi
yann@2480
   291
    fi
yann@2480
   292
}
yann@2480
   293
yann@183
   294
do_help() {
yann@183
   295
    cat <<__EOF__
yann@1140
   296
\`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
yann@183
   297
yann@183
   298
USAGE: ./configure [OPTION]...
yann@183
   299
yann@183
   300
Defaults for the options are specified in brackets.
yann@183
   301
yann@183
   302
Configuration:
yann@1105
   303
  -h, --help              display this help and exit
yann@1311
   304
      --force             force configure to continue, even in case
yann@1311
   305
                          some pre-requisites are missing
yann@615
   306
yann@615
   307
Installation directories:
yann@185
   308
  --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
yann@285
   309
  --local                 don't install, and use current directory
yann@183
   310
yann@183
   311
By default, \`make install' will install all the files in
yann@183
   312
\`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
yann@183
   313
an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
yann@183
   314
for instance \`--prefix=\${HOME}'.
yann@183
   315
yann@183
   316
For better control, use the options below.
yann@183
   317
yann@183
   318
Fine tuning of the installation directories:
yann@683
   319
  --bindir=DIR            user executables [PREFIX/bin]
yann@683
   320
  --libdir=DIR            object code libraries [PREFIX/lib]
yann@683
   321
  --docdir=DIR            info documentation [PREFIX/share/doc]
yann@683
   322
  --mandir=DIR            man documentation [PREFIX/share/man]
yann@614
   323
yann@614
   324
Optional Features:
yann@1140
   325
  --with-install=PATH     Specify the full PATH to GNU install
yann@1311
   326
  --with-make=PATH        Specify the full PATH to GNU make >= 3.80
yann@1140
   327
  --with-grep=PATH        Specify the full PATH to GNU grep
yann@1140
   328
  --with-sed=PATH         Specify the full PATH to GNU sed
yann@1140
   329
  --with-bash=PATH        Specify the full PATH to bash >= 3.0
yann@183
   330
__EOF__
yann@183
   331
}
yann@183
   332
yann@376
   333
#---------------------------------------------------------------------
yann@376
   334
# Set user's options
yann@376
   335
yann@182
   336
while [ $# -ne 0 ]; do
yann@182
   337
    case "$1" in
yann@1297
   338
        --local)    LOCAL_set="y"; shift;;
yann@182
   339
        --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
yann@182
   340
        --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
yann@182
   341
        --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
yann@182
   342
        --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
yann@182
   343
        --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
yann@1140
   344
        --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
yann@1311
   345
        --force)    FORCE=1; shift;;
yann@183
   346
        --help|-h)  do_help; exit 0;;
blueness@1739
   347
        # Skip, auto-stuff compatibility
blueness@1739
   348
        --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
blueness@1739
   349
        --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir)             shift 2;;
yann@2551
   350
        --enable-shared|--disable-shared|--enable-static|--disable-static)           shift;;
yann@1333
   351
        *)          printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
yann@182
   352
    esac
yann@182
   353
done
yann@182
   354
yann@641
   355
# Use defaults
yann@185
   356
[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
yann@641
   357
yann@641
   358
# Special case when installing locally
yann@1297
   359
if [ "${LOCAL_set}" = "y" ]; then
yann@1105
   360
    set_prefix "" "$( pwd )"
yann@1105
   361
    set_bindir "" "$( pwd )"
yann@1105
   362
    set_libdir "" "$( pwd )"
yann@1105
   363
    set_docdir "" "$( pwd )/docs"
yann@1105
   364
    set_mandir "" "$( pwd )/docs"
yann@285
   365
fi
yann@183
   366
yann@376
   367
#---------------------------------------------------------------------
yann@1140
   368
# Some sanity checks, now
yann@1106
   369
yann@1560
   370
# We check for grep and sed manually, because they are used in check_for()
yann@1140
   371
printf "Checking for 'grep'... "
yann@1140
   372
if [ -n "${grep}" ]; then
yann@1333
   373
    printf "${grep} (cached)\n"
yann@1140
   374
else
yann@1140
   375
    grep="$( which grep 2>/dev/null )"
yann@1187
   376
    if [ -z "${grep}" ]; then
yann@1333
   377
        printf "not found\n"
yann@1187
   378
    else
yann@1333
   379
        printf "${grep}\n"
yann@1187
   380
        printf "Checking whether '${grep}' supports -E... "
yann@1187
   381
        if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
yann@1333
   382
            printf "yes\n"
yann@1187
   383
        else
yann@1333
   384
            printf "no\n"
yann@1187
   385
            grep=
yann@1187
   386
        fi
yann@1187
   387
    fi
yann@1106
   388
fi
yann@1187
   389
if [ -z "${grep}" ]; then
yann@1333
   390
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   391
    printf "or the version you have is too old.\n"
yann@1333
   392
    printf "You can give the path to this tool using: --with-grep=PATH\n"
yann@1187
   393
    do_error "Bailing out..."
yann@1140
   394
fi
yann@1311
   395
add_to_var_list grep
yann@1140
   396
yann@1140
   397
printf "Checking for 'sed'... "
yann@1140
   398
if [ -n "${sed}" ]; then
yann@1333
   399
    printf "${sed} (cached)\n"
yann@1140
   400
else
yann@1140
   401
    sed="$( which sed 2>/dev/null )"
yann@1187
   402
    if [ -z "${sed}" ]; then
yann@1333
   403
        printf "not found\n"
yann@1187
   404
    else
yann@1333
   405
        printf "${sed}\n"
rpjday@1288
   406
        printf "Checking whether '${sed}' supports -i and -e... "
yann@1187
   407
        touch .ct-ng.sed.test
yann@1187
   408
        if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
yann@1333
   409
            printf "yes\n"
yann@1187
   410
        else
yann@1333
   411
            printf "no\n"
yann@1187
   412
            sed=
yann@1187
   413
        fi
yann@1187
   414
        rm -f .ct-ng.sed.test
yann@1187
   415
    fi
yann@1140
   416
fi
yann@1187
   417
if [ -z "${sed}" ]; then
yann@1333
   418
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   419
    printf "or the version you have is too old.\n"
yann@1333
   420
    printf "You can give the path to this tool using: --with-sed=PATH\n"
yann@1187
   421
    do_error "Bailing out..."
yann@1140
   422
fi
yann@1311
   423
add_to_var_list sed
yann@1140
   424
yann@1311
   425
# The regular list of tools we can now easily check for
yann@1311
   426
has_or_abort prog=bash                              \
yann@1311
   427
             var=bash                               \
yann@1477
   428
             ver='^GNU bash, version (3\.[1-9]|4)'  \
yann@1477
   429
             err="'bash' 3.1 or above was not found"
yann@1311
   430
has_or_abort prog=cut
yann@1311
   431
has_or_abort prog=install var=install
yann@1311
   432
has_or_abort prog=make                                  \
yann@1311
   433
             var=make                                   \
yann@1311
   434
             ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
yann@1311
   435
             err="GNU 'make' 3.80 or above was not found"
yann@1311
   436
has_or_abort prog=gcc
yann@1431
   437
has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
yann@1311
   438
has_or_abort prog=bison
yann@1311
   439
has_or_abort prog=flex
yann@1311
   440
has_or_abort prog=makeinfo
yann@1311
   441
has_or_abort prog=automake                                                      \
oron@1432
   442
             ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)'    \
yann@1311
   443
             err="'automake' 1.10 or above was not found"
yann@1311
   444
has_or_abort prog=libtool                                                                           \
titus@1969
   445
             var=libtool                                                                            \
yann@1311
   446
             ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
yann@1311
   447
             err="'libtool' 1.5.26 or above was not found"
titus@1957
   448
has_or_abort prog=stat
yann@2203
   449
has_or_abort prog="curl wget"
yann@1311
   450
has_or_abort prog=patch
yann@1311
   451
has_or_abort prog=tar
yann@1311
   452
has_or_abort prog=gzip
yann@1311
   453
has_or_abort prog=bzip2
yann@1311
   454
has_or_abort prog=lzma
yann@1313
   455
has_or_abort prog=readlink
titus@1962
   456
has_or_abort prog=objcopy var=objcopy
titus@1962
   457
has_or_abort prog=objdump var=objdump
titus@1962
   458
has_or_abort prog=readelf var=readelf
titus@1962
   459
has_or_abort prog=patch var=patch
yann@2535
   460
has_or_warn  prog=cvs                                                   \
yann@2535
   461
             kconfig=has_cvs                                            \
yann@2535
   462
             err="it will not be possible to use newlib cvs snapshots"
yann@2591
   463
has_or_warn  prog=svn                               \
yann@2540
   464
             kconfig=has_svn                        \
yann@2540
   465
             err="subversion is required to download eglibc"
yann@1311
   466
yann@2525
   467
# Host system checks
yann@2525
   468
yann@2525
   469
printf "Checking for host system... "
yann@2525
   470
host="$( uname -s )"
yann@2525
   471
printf "%s\n" "${host}"
yann@2525
   472
case "${host}" in
yann@2525
   473
    Linux)  ;;
yann@2525
   474
    Cygwin) ;;
yann@2525
   475
    *)
yann@2525
   476
        printf " * Runing under %s is not fully tested\n" "${host}"
yann@2525
   477
        printf " * You may encounter some weird behavior\n"
yann@2525
   478
        ;;
yann@2525
   479
esac
yann@2525
   480
yann@2526
   481
printf "Checking if static linking is possible... "
yann@2526
   482
static_link_ok=""
yann@2526
   483
case "${host}" in
yann@2526
   484
    Darwin) ;;
yann@2526
   485
    *)  tmp=.static.tmp
yann@2534
   486
        if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
yann@2526
   487
				int main() { return 0; }
yann@2526
   488
			_EOF_
yann@2526
   489
        then
yann@2526
   490
            static_link_ok="y"
yann@2526
   491
        fi
yann@2526
   492
        rm -f "${tmp}"
yann@2526
   493
        ;;
yann@2526
   494
esac
yann@2526
   495
if [ "${static_link_ok}" = "y" ]; then
yann@2528
   496
    static_link_ko=""
yann@2526
   497
    printf "yes\n"
yann@2526
   498
else
yann@2528
   499
    static_link_ko="y"
yann@2526
   500
    printf "no\n"
yann@2526
   501
    printf " * An optional host feature is missing, some features will be disabled:\n"
yann@2526
   502
    printf " * - It will not be possible to statically link toolchain's binaries\n"
yann@2526
   503
fi
yann@2526
   504
add_to_kconfig_list static_link_ok
yann@2526
   505
yann@2526
   506
# Library checks
yann@2528
   507
libs_exts="so dylib"
yann@2528
   508
if [ "${static_link_ok}" = "y" ]; then
yann@2534
   509
    libs_exts="${libs_exts} a"
yann@2528
   510
fi
yann@2527
   511
yann@2509
   512
ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
yann@2527
   513
ncurses_libs="libncursesw libncurses libcurses"
yann@2509
   514
has_or_abort lib="${ncurses_libs}"                                          \
yann@2527
   515
             lib_exts="${libs_exts}"                                        \
yann@2509
   516
             inc="${ncurses_hdrs}"                                          \
yann@2506
   517
             err="The 'ncurses' library is needed fo the menuconfig frontend"
yann@1106
   518
yann@2527
   519
has_or_abort lib="libstdc++"            \
yann@2527
   520
             lib_exts="${libs_exts}"    \
yann@2506
   521
             err="The 'libstdc++' library is needed to build gcc"
yann@2499
   522
yann@2500
   523
# Yes, we may be checking twice for libstdc++.a
yann@2500
   524
# The first is because we need one instance of libstdc++ (shared or static)
yann@2500
   525
# because it is needed for PPL; the second is because the static version is
yann@2500
   526
# required for static-linking, and if missing, the option is removed.
yann@2528
   527
has_or_warn  lib="libstdc++"                \
yann@2528
   528
             lib_exts="a"                   \
yann@2500
   529
             err="static 'libstdc++' is needed to statically link the toolchain's executables" \
yann@2528
   530
             kconfig=has_static_libstdcxx   \
yann@2528
   531
             skip="${static_link_ko}"
yann@2500
   532
yann@2527
   533
has_or_warn  inc="expat.h"              \
yann@2527
   534
             lib="libexpat"             \
yann@2527
   535
             lib_exts="${libs_exts}"    \
benoit@2508
   536
             err="The 'expat' header file and library are needed to link cross-gdb's executables" \
benoit@2508
   537
             kconfig=has_expat
benoit@2508
   538
benoit@2508
   539
# Yes, we may be checking twice for libexpat.a
benoit@2508
   540
# The first is because we need one instance of libexpat (shared or static)
benoit@2508
   541
# because it is needed for cross-gdb; the second is because the static version
benoit@2508
   542
# is required for static-linking, and if missing, the option is removed.
yann@2528
   543
has_or_warn  lib="libexpat"             \
yann@2528
   544
             lib_exts="a"               \
benoit@2508
   545
             err="static 'expat' is needed to statically link cross-gdb's executables" \
yann@2528
   546
             kconfig=has_static_expat   \
yann@2528
   547
             skip="${static_link_ko}"
benoit@2508
   548
benoit@2508
   549
for v in 7 6 5 4; do
yann@2527
   550
    python_incs="${python_incs} python2.${v}/Python.h"
yann@2527
   551
    python_libs="${python_libs} libpython2.${v}"
benoit@2508
   552
done
yann@2527
   553
has_or_warn  inc="${python_incs}"       \
yann@2527
   554
             lib="${python_libs}"       \
yann@2527
   555
             lib_exts="${libs_exts}"    \
benoit@2508
   556
             err="The 'python' header file and library are needed for some features of cross-gdb"
benoit@2508
   557
yann@1106
   558
#---------------------------------------------------------------------
yann@1106
   559
# Compute the version string
yann@376
   560
yann@1576
   561
# If this version is n hg clone, try to get the revision number
yann@435
   562
# If we can't get the revision number, use date
yann@2498
   563
printf "\nComputing version string... "
yann@435
   564
case "${VERSION}" in
Yann@1409
   565
    *+hg|hg)
yann@1740
   566
        REVISION="$( hg id -n 2>/dev/null || true )"
yann@1105
   567
        case "${REVISION}" in
Yann@1409
   568
            "")
yann@1105
   569
                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
yann@1105
   570
            *)
yann@1430
   571
                VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
yann@1105
   572
                ;;
yann@1105
   573
        esac
yann@1105
   574
        # Arrange to have no / in the directory name, no need to create an
yann@1105
   575
        # arbitrarily deep directory structure
yann@1333
   576
        VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
yann@444
   577
        ;;
yann@435
   578
esac
yann@1740
   579
printf "${VERSION}\n"
yann@435
   580
yann@1106
   581
#---------------------------------------------------------------------
yann@1106
   582
# Compute and check install paths
yann@1106
   583
yann@614
   584
# Now we have the version string, we can build up the paths
yann@554
   585
[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
yann@1660
   586
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
yann@1660
   587
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
yann@2026
   588
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
yann@554
   589
yann@1660
   590
# Install support files in our own sub-dir, so as not to mangle (system)
yann@1660
   591
# files and dirs, but only if not --local
yann@1660
   592
if [ -z "${LOCAL_set}" ]; then
yann@1660
   593
    LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
yann@1660
   594
    DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
yann@1660
   595
fi
yann@1660
   596
yann@1047
   597
# Check that install PATHs are absolute
yann@1047
   598
for p in BIN LIB DOC MAN; do
yann@1105
   599
    var="${p}DIR"
yann@1105
   600
    eval v='"${'"${var}"'}"'
yann@1105
   601
    case "${v}" in
yann@1105
   602
        /*) ;;
yann@1105
   603
        *)  do_error "'${var}' is not an absolute path: '${v}'"
yann@1105
   604
    esac
yann@1047
   605
done
yann@1047
   606
yann@1106
   607
#---------------------------------------------------------------------
yann@1106
   608
# That's all, folks!
yann@614
   609
yann@641
   610
printf "Building up Makefile... "
yann@1140
   611
var_sed="$( for var_name in ${var_list}; do
yann@1140
   612
                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
yann@2481
   613
            done
yann@1140
   614
          )"
yann@2481
   615
kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
yann@2481
   616
                                  eval printf \"${k_name}=\${${k_name}} \"
yann@2481
   617
                              done
yann@2481
   618
                            )/"
yann@2481
   619
"${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g"       \
yann@2481
   620
            -e "s,@@LIBDIR@@,${LIBDIR},g"       \
yann@2481
   621
            -e "s,@@DOCDIR@@,${DOCDIR},g"       \
yann@2481
   622
            -e "s,@@MANDIR@@,${MANDIR},g"       \
yann@2481
   623
            -e "s,@@VERSION@@,${VERSION},g"     \
yann@2481
   624
            -e "s,@@DATE@@,${DATE},g"           \
yann@2481
   625
            -e "s,@@LOCAL@@,${LOCAL_set},g"     \
yann@2481
   626
            -e "${var_sed}"                     \
yann@2481
   627
            -e "${kconfig_sed}"                 \
yann@2481
   628
         Makefile.in                            \
yann@2481
   629
         >Makefile
yann@673
   630
echo "done"
yann@185
   631
yann@185
   632
cat <<__EOF__
yann@673
   633
yann@197
   634
crosstool-NG configured as follows:
yann@554
   635
  PREFIX='${PREFIX}'
yann@554
   636
  BINDIR='${BINDIR}'
yann@554
   637
  LIBDIR='${LIBDIR}'
yann@554
   638
  DOCDIR='${DOCDIR}'
yann@554
   639
  MANDIR='${MANDIR}'
yann@1106
   640
yann@1106
   641
Now run:
yann@1106
   642
  make
yann@185
   643
__EOF__
yann@1298
   644
if [ "${LOCAL_set}" != "y" ]; then
yann@1297
   645
    printf "  make install\n"
yann@1297
   646
fi