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