configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 04 00:04:23 2011 +0200 (2011-05-04)
changeset 2608 aa09a36c3d36
parent 2606 b6bf20def07f
child 2619 628192dbf847
permissions -rwxr-xr-x
scripts/functions: test for decompressors before use

./configure does check for the presence of gz and bzip2, so we can
safely use them in the build scripts.

On the other hand, more recent formats (eg. XZ) are not yet widely
available, and we do not want, and can't, force the user to install
them as a pre-requisite.

So, build up a list of allowed tarball formats based on the available
decompressors. For no, this is a static list, but the upcoming XZ
support will conditionnaly add to this list.

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@2597
   351
        --program-prefix=*)                                                          shift;;
yann@2597
   352
        --program-prefix)                                                            shift 2;;
yann@1333
   353
        *)          printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
yann@182
   354
    esac
yann@182
   355
done
yann@182
   356
yann@641
   357
# Use defaults
yann@185
   358
[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
yann@641
   359
yann@641
   360
# Special case when installing locally
yann@1297
   361
if [ "${LOCAL_set}" = "y" ]; then
yann@1105
   362
    set_prefix "" "$( pwd )"
yann@1105
   363
    set_bindir "" "$( pwd )"
yann@1105
   364
    set_libdir "" "$( pwd )"
yann@1105
   365
    set_docdir "" "$( pwd )/docs"
yann@1105
   366
    set_mandir "" "$( pwd )/docs"
yann@285
   367
fi
yann@183
   368
yann@376
   369
#---------------------------------------------------------------------
yann@1140
   370
# Some sanity checks, now
yann@1106
   371
yann@1560
   372
# We check for grep and sed manually, because they are used in check_for()
yann@1140
   373
printf "Checking for 'grep'... "
yann@1140
   374
if [ -n "${grep}" ]; then
yann@1333
   375
    printf "${grep} (cached)\n"
yann@1140
   376
else
yann@1140
   377
    grep="$( which grep 2>/dev/null )"
yann@1187
   378
    if [ -z "${grep}" ]; then
yann@1333
   379
        printf "not found\n"
yann@1187
   380
    else
yann@1333
   381
        printf "${grep}\n"
yann@1187
   382
        printf "Checking whether '${grep}' supports -E... "
yann@1187
   383
        if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
yann@1333
   384
            printf "yes\n"
yann@1187
   385
        else
yann@1333
   386
            printf "no\n"
yann@1187
   387
            grep=
yann@1187
   388
        fi
yann@1187
   389
    fi
yann@1106
   390
fi
yann@1187
   391
if [ -z "${grep}" ]; then
yann@1333
   392
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   393
    printf "or the version you have is too old.\n"
yann@1333
   394
    printf "You can give the path to this tool using: --with-grep=PATH\n"
yann@1187
   395
    do_error "Bailing out..."
yann@1140
   396
fi
yann@1311
   397
add_to_var_list grep
yann@1140
   398
yann@1140
   399
printf "Checking for 'sed'... "
yann@1140
   400
if [ -n "${sed}" ]; then
yann@1333
   401
    printf "${sed} (cached)\n"
yann@1140
   402
else
yann@1140
   403
    sed="$( which sed 2>/dev/null )"
yann@1187
   404
    if [ -z "${sed}" ]; then
yann@1333
   405
        printf "not found\n"
yann@1187
   406
    else
yann@1333
   407
        printf "${sed}\n"
rpjday@1288
   408
        printf "Checking whether '${sed}' supports -i and -e... "
yann@1187
   409
        touch .ct-ng.sed.test
yann@1187
   410
        if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
yann@1333
   411
            printf "yes\n"
yann@1187
   412
        else
yann@1333
   413
            printf "no\n"
yann@1187
   414
            sed=
yann@1187
   415
        fi
yann@1187
   416
        rm -f .ct-ng.sed.test
yann@1187
   417
    fi
yann@1140
   418
fi
yann@1187
   419
if [ -z "${sed}" ]; then
yann@1333
   420
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   421
    printf "or the version you have is too old.\n"
yann@1333
   422
    printf "You can give the path to this tool using: --with-sed=PATH\n"
yann@1187
   423
    do_error "Bailing out..."
yann@1140
   424
fi
yann@1311
   425
add_to_var_list sed
yann@1140
   426
yann@1311
   427
# The regular list of tools we can now easily check for
yann@1311
   428
has_or_abort prog=bash                              \
yann@1311
   429
             var=bash                               \
yann@1477
   430
             ver='^GNU bash, version (3\.[1-9]|4)'  \
yann@1477
   431
             err="'bash' 3.1 or above was not found"
yann@1311
   432
has_or_abort prog=cut
yann@1311
   433
has_or_abort prog=install var=install
yann@1311
   434
has_or_abort prog=make                                  \
yann@1311
   435
             var=make                                   \
yann@1311
   436
             ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
yann@1311
   437
             err="GNU 'make' 3.80 or above was not found"
yann@1311
   438
has_or_abort prog=gcc
yann@1431
   439
has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
yann@1311
   440
has_or_abort prog=bison
yann@1311
   441
has_or_abort prog=flex
yann@1311
   442
has_or_abort prog=makeinfo
yann@1311
   443
has_or_abort prog=automake                                                      \
oron@1432
   444
             ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)'    \
yann@1311
   445
             err="'automake' 1.10 or above was not found"
yann@1311
   446
has_or_abort prog=libtool                                                                           \
titus@1969
   447
             var=libtool                                                                            \
yann@1311
   448
             ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
yann@1311
   449
             err="'libtool' 1.5.26 or above was not found"
titus@1957
   450
has_or_abort prog=stat
yann@2203
   451
has_or_abort prog="curl wget"
yann@1311
   452
has_or_abort prog=patch
yann@1311
   453
has_or_abort prog=tar
yann@1311
   454
has_or_abort prog=gzip
yann@1311
   455
has_or_abort prog=bzip2
yann@2607
   456
has_or_warn  prog=xz                                        \
yann@2607
   457
             kconfig=has_xzutils                            \
yann@2607
   458
             err="xz-comoressed tarballs will not be used"
yann@1313
   459
has_or_abort prog=readlink
titus@1962
   460
has_or_abort prog=objcopy var=objcopy
titus@1962
   461
has_or_abort prog=objdump var=objdump
titus@1962
   462
has_or_abort prog=readelf var=readelf
titus@1962
   463
has_or_abort prog=patch var=patch
yann@2535
   464
has_or_warn  prog=cvs                                                   \
yann@2535
   465
             kconfig=has_cvs                                            \
yann@2535
   466
             err="it will not be possible to use newlib cvs snapshots"
yann@2591
   467
has_or_warn  prog=svn                               \
yann@2540
   468
             kconfig=has_svn                        \
yann@2540
   469
             err="subversion is required to download eglibc"
yann@1311
   470
yann@2525
   471
# Host system checks
yann@2525
   472
yann@2525
   473
printf "Checking for host system... "
yann@2525
   474
host="$( uname -s )"
yann@2525
   475
printf "%s\n" "${host}"
yann@2525
   476
case "${host}" in
yann@2525
   477
    Linux)  ;;
yann@2525
   478
    Cygwin) ;;
yann@2525
   479
    *)
yann@2525
   480
        printf " * Runing under %s is not fully tested\n" "${host}"
yann@2525
   481
        printf " * You may encounter some weird behavior\n"
yann@2525
   482
        ;;
yann@2525
   483
esac
yann@2525
   484
yann@2526
   485
printf "Checking if static linking is possible... "
yann@2526
   486
static_link_ok=""
yann@2526
   487
case "${host}" in
yann@2526
   488
    Darwin) ;;
yann@2526
   489
    *)  tmp=.static.tmp
yann@2534
   490
        if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
yann@2526
   491
				int main() { return 0; }
yann@2526
   492
			_EOF_
yann@2526
   493
        then
yann@2526
   494
            static_link_ok="y"
yann@2526
   495
        fi
yann@2526
   496
        rm -f "${tmp}"
yann@2526
   497
        ;;
yann@2526
   498
esac
yann@2526
   499
if [ "${static_link_ok}" = "y" ]; then
yann@2528
   500
    static_link_ko=""
yann@2526
   501
    printf "yes\n"
yann@2526
   502
else
yann@2528
   503
    static_link_ko="y"
yann@2526
   504
    printf "no\n"
yann@2526
   505
    printf " * An optional host feature is missing, some features will be disabled:\n"
yann@2526
   506
    printf " * - It will not be possible to statically link toolchain's binaries\n"
yann@2526
   507
fi
yann@2526
   508
add_to_kconfig_list static_link_ok
yann@2526
   509
yann@2526
   510
# Library checks
yann@2528
   511
libs_exts="so dylib"
yann@2528
   512
if [ "${static_link_ok}" = "y" ]; then
yann@2534
   513
    libs_exts="${libs_exts} a"
yann@2528
   514
fi
yann@2527
   515
yann@2509
   516
ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
yann@2527
   517
ncurses_libs="libncursesw libncurses libcurses"
yann@2509
   518
has_or_abort lib="${ncurses_libs}"                                          \
yann@2527
   519
             lib_exts="${libs_exts}"                                        \
yann@2509
   520
             inc="${ncurses_hdrs}"                                          \
yann@2506
   521
             err="The 'ncurses' library is needed fo the menuconfig frontend"
yann@1106
   522
yann@2527
   523
has_or_abort lib="libstdc++"            \
yann@2527
   524
             lib_exts="${libs_exts}"    \
yann@2506
   525
             err="The 'libstdc++' library is needed to build gcc"
yann@2499
   526
yann@2500
   527
# Yes, we may be checking twice for libstdc++.a
yann@2500
   528
# The first is because we need one instance of libstdc++ (shared or static)
yann@2500
   529
# because it is needed for PPL; the second is because the static version is
yann@2500
   530
# required for static-linking, and if missing, the option is removed.
yann@2528
   531
has_or_warn  lib="libstdc++"                \
yann@2528
   532
             lib_exts="a"                   \
yann@2500
   533
             err="static 'libstdc++' is needed to statically link the toolchain's executables" \
yann@2528
   534
             kconfig=has_static_libstdcxx   \
yann@2528
   535
             skip="${static_link_ko}"
yann@2500
   536
yann@2527
   537
has_or_warn  inc="expat.h"              \
yann@2527
   538
             lib="libexpat"             \
yann@2527
   539
             lib_exts="${libs_exts}"    \
benoit@2508
   540
             err="The 'expat' header file and library are needed to link cross-gdb's executables" \
benoit@2508
   541
             kconfig=has_expat
benoit@2508
   542
benoit@2508
   543
# Yes, we may be checking twice for libexpat.a
benoit@2508
   544
# The first is because we need one instance of libexpat (shared or static)
benoit@2508
   545
# because it is needed for cross-gdb; the second is because the static version
benoit@2508
   546
# is required for static-linking, and if missing, the option is removed.
yann@2528
   547
has_or_warn  lib="libexpat"             \
yann@2528
   548
             lib_exts="a"               \
benoit@2508
   549
             err="static 'expat' is needed to statically link cross-gdb's executables" \
yann@2528
   550
             kconfig=has_static_expat   \
yann@2528
   551
             skip="${static_link_ko}"
benoit@2508
   552
benoit@2508
   553
for v in 7 6 5 4; do
yann@2527
   554
    python_incs="${python_incs} python2.${v}/Python.h"
yann@2527
   555
    python_libs="${python_libs} libpython2.${v}"
benoit@2508
   556
done
yann@2527
   557
has_or_warn  inc="${python_incs}"       \
yann@2527
   558
             lib="${python_libs}"       \
yann@2527
   559
             lib_exts="${libs_exts}"    \
benoit@2508
   560
             err="The 'python' header file and library are needed for some features of cross-gdb"
benoit@2508
   561
yann@1106
   562
#---------------------------------------------------------------------
yann@1106
   563
# Compute the version string
yann@376
   564
yann@1576
   565
# If this version is n hg clone, try to get the revision number
yann@435
   566
# If we can't get the revision number, use date
yann@2498
   567
printf "\nComputing version string... "
yann@435
   568
case "${VERSION}" in
Yann@1409
   569
    *+hg|hg)
yann@1740
   570
        REVISION="$( hg id -n 2>/dev/null || true )"
yann@1105
   571
        case "${REVISION}" in
Yann@1409
   572
            "")
yann@1105
   573
                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
yann@1105
   574
            *)
yann@1430
   575
                VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
yann@1105
   576
                ;;
yann@1105
   577
        esac
yann@1105
   578
        # Arrange to have no / in the directory name, no need to create an
yann@1105
   579
        # arbitrarily deep directory structure
yann@1333
   580
        VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
yann@444
   581
        ;;
yann@435
   582
esac
yann@1740
   583
printf "${VERSION}\n"
yann@435
   584
yann@1106
   585
#---------------------------------------------------------------------
yann@1106
   586
# Compute and check install paths
yann@1106
   587
yann@614
   588
# Now we have the version string, we can build up the paths
yann@554
   589
[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
yann@1660
   590
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
yann@1660
   591
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
yann@2026
   592
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
yann@554
   593
yann@1660
   594
# Install support files in our own sub-dir, so as not to mangle (system)
yann@1660
   595
# files and dirs, but only if not --local
yann@1660
   596
if [ -z "${LOCAL_set}" ]; then
yann@1660
   597
    LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
yann@1660
   598
    DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
yann@1660
   599
fi
yann@1660
   600
yann@1047
   601
# Check that install PATHs are absolute
yann@1047
   602
for p in BIN LIB DOC MAN; do
yann@1105
   603
    var="${p}DIR"
yann@1105
   604
    eval v='"${'"${var}"'}"'
yann@1105
   605
    case "${v}" in
yann@1105
   606
        /*) ;;
yann@1105
   607
        *)  do_error "'${var}' is not an absolute path: '${v}'"
yann@1105
   608
    esac
yann@1047
   609
done
yann@1047
   610
yann@1106
   611
#---------------------------------------------------------------------
yann@1106
   612
# That's all, folks!
yann@614
   613
yann@641
   614
printf "Building up Makefile... "
yann@1140
   615
var_sed="$( for var_name in ${var_list}; do
yann@1140
   616
                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
yann@2481
   617
            done
yann@1140
   618
          )"
yann@2481
   619
kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
yann@2481
   620
                                  eval printf \"${k_name}=\${${k_name}} \"
yann@2481
   621
                              done
yann@2481
   622
                            )/"
yann@2481
   623
"${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g"       \
yann@2481
   624
            -e "s,@@LIBDIR@@,${LIBDIR},g"       \
yann@2481
   625
            -e "s,@@DOCDIR@@,${DOCDIR},g"       \
yann@2481
   626
            -e "s,@@MANDIR@@,${MANDIR},g"       \
yann@2481
   627
            -e "s,@@VERSION@@,${VERSION},g"     \
yann@2481
   628
            -e "s,@@DATE@@,${DATE},g"           \
yann@2481
   629
            -e "s,@@LOCAL@@,${LOCAL_set},g"     \
yann@2481
   630
            -e "${var_sed}"                     \
yann@2481
   631
            -e "${kconfig_sed}"                 \
yann@2481
   632
         Makefile.in                            \
yann@2481
   633
         >Makefile
yann@673
   634
echo "done"
yann@185
   635
yann@185
   636
cat <<__EOF__
yann@673
   637
yann@197
   638
crosstool-NG configured as follows:
yann@554
   639
  PREFIX='${PREFIX}'
yann@554
   640
  BINDIR='${BINDIR}'
yann@554
   641
  LIBDIR='${LIBDIR}'
yann@554
   642
  DOCDIR='${DOCDIR}'
yann@554
   643
  MANDIR='${MANDIR}'
yann@1106
   644
yann@1106
   645
Now run:
yann@1106
   646
  make
yann@185
   647
__EOF__
yann@1298
   648
if [ "${LOCAL_set}" != "y" ]; then
yann@1297
   649
    printf "  make install\n"
yann@1297
   650
fi