configure
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jun 04 17:43:49 2011 +0200 (2011-06-04)
changeset 2505 f87f02b00cc7
parent 2499 56b7eab1391a
child 2506 2ab553e37517
permissions -rwxr-xr-x
Makefile: make it work for auto-completion

The latest autocompletion calls 'make -qp' to get all the possible
targets. This currently fails, as our makefile is calling itself
again and again ad-libitum.

Fix it by detecting that the recursion level is not 0, and bail out
if so. It works so well that it has the side effect of showing only
the 'public' target, and hide our internal ones! :-)

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@1311
   107
# $*: err=<error_message>
yann@1311
   108
#     the error message to print if tool is missing
yann@1311
   109
#     optional, defaults to: '${prog}: none found'
yann@1311
   110
#       eg: err="'bash' 3.x or above was not found"
yann@2480
   111
#     Note: err may be printed by caller, not us
yann@2481
   112
# $*: kconfig=<var_name>
yann@2481
   113
#     the name of a variable to pass down to kconfig if
yann@2481
   114
#     the prog/inc/lib was found
yann@2481
   115
#     optional, defaults to none
yann@2481
   116
#       eg: kconfig=has_libncurses
yann@1560
   117
check_for() {
yann@1311
   118
    local val
yann@1311
   119
    local item
yann@1311
   120
    local where
yann@1312
   121
    local status
yann@1311
   122
yann@2481
   123
    # Note: prog/inc/lib and var/kconfig/ver/err are set here,
yann@2479
   124
    # but declared by the caller (because it needs it)
yann@1311
   125
    for item in "${@}"; do
yann@1311
   126
        case "${item}" in
yann@2481
   127
            prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*)
yann@2497
   128
                eval ${item%%=*}=\"${item#*=}\"
yann@1311
   129
                ;;
yann@1311
   130
            *)  do_error "has_or_abort: incorrect parameters: '$@'";;
yann@1311
   131
        esac
yann@1311
   132
    done
yann@1311
   133
yann@2481
   134
    if [ -n "${kconfig}" ]; then
yann@2481
   135
        add_to_kconfig_list "${kconfig}"
yann@2481
   136
    fi
yann@2481
   137
yann@1311
   138
    case "${prog}:${inc}:${lib}" in
yann@1311
   139
        ?*::)
yann@1311
   140
            for item in ${prog}; do
yann@1311
   141
                printf "Checking for '${item}'... "
yann@1311
   142
                if [ -n "${var}" ]; then
yann@1311
   143
                    eval val="\${${var}}"
yann@1311
   144
                    if [ -n "${val}" ]; then
yann@1311
   145
                        printf "${val} (cached)\n"
yann@1570
   146
                        add_to_var_list "${var}"
yann@1311
   147
                        return 0
yann@1311
   148
                    fi
yann@1311
   149
                fi
yann@1311
   150
                where="$( which "${item}" 2>/dev/null )"
yann@1311
   151
                if [ -z "${where}" ]; then
yann@1312
   152
                    printf "no\n"
yann@1311
   153
                    continue
yann@1311
   154
                elif [ -n "${ver}" ]; then
yann@1571
   155
                    str=$( LC_ALL=C "${where}" --version 2>&1   \
yann@1571
   156
                           |grep -E "${ver}"                    \
yann@1571
   157
                           |head -n 1
yann@1571
   158
                         )
yann@1311
   159
                    if [ -z "${str}" ]; then
yann@1312
   160
                        printf "no\n"
yann@1311
   161
                        unset where
yann@1311
   162
                        continue
yann@1311
   163
                    fi
yann@1311
   164
                fi
yann@1312
   165
                status="${where}"
yann@1311
   166
                break
yann@1311
   167
            done
yann@1311
   168
            ;;
yann@1311
   169
        :?*:)
yann@1312
   170
            for item in ${inc}; do
yann@1312
   171
                printf "Checking for '${item}'... "
yann@1312
   172
                if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
yann@1312
   173
                    where="${item}"
yann@1312
   174
                    status=yes
yann@1312
   175
                    break;
yann@1312
   176
                fi
yann@1312
   177
                printf "no\n"
yann@1312
   178
            done
yann@1311
   179
            ;;
yann@1311
   180
        ::?*)
yann@1313
   181
            for item in ${lib}; do
yann@1313
   182
                printf "Checking for '${item}'... "
yann@1313
   183
                where="$( gcc -print-file-name="${item}" )"
yann@1313
   184
                if [ "${where}" != "${item}" ]; then
titus@1959
   185
                    where="$( readlink "${where}" )"
yann@1313
   186
                    status=yes
yann@1313
   187
                    break;
yann@1313
   188
                fi
yann@1313
   189
                printf "no\n"
yann@1313
   190
            done
yann@1311
   191
            ;;
yann@1311
   192
    esac
yann@1560
   193
yann@1312
   194
    if [ -z "${status}" ]; then
yann@1560
   195
        return 1
yann@1560
   196
    fi
yann@1560
   197
yann@1560
   198
    printf "${status}"
yann@1560
   199
    if [ -n "${var}" ]; then
yann@1560
   200
        eval ${var}='"'"${where}"'"'
yann@1560
   201
        add_to_var_list "${var}"
yann@1560
   202
    fi
yann@2481
   203
    if [ -n "${kconfig}" ]; then
yann@2481
   204
        eval ${kconfig}=y
yann@2481
   205
    fi
yann@1560
   206
    printf "\n"
yann@1560
   207
}
yann@1560
   208
yann@1560
   209
# This function checks for a tool, and aborts if not found
yann@1560
   210
# See check_for(), above, for how to call has_or_abort
yann@1560
   211
has_or_abort() {
yann@2479
   212
    # We declare these 6 variables here, although they are
yann@2479
   213
    # set in check_for(), called below
yann@2479
   214
    local prog inc lib
yann@2481
   215
    local var ver err kconfig
yann@2479
   216
yann@1560
   217
    if ! check_for "$@"; then
yann@2498
   218
        printf " * ${err:-${prog}${inc}${lib}: none found}\n"
yann@2498
   219
        printf " * Either you are missing entirely the needed tool,\n"
yann@2498
   220
        printf " * or the version you have is too old.\n"
yann@2479
   221
        if [ -n "${var}" ]; then
yann@2498
   222
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2479
   223
        fi
yann@2479
   224
        printf "\n"
yann@2479
   225
        # Bail out if --force is not specified
yann@1312
   226
        [ -z "${FORCE}" ] && do_error "Bailing out..."
yann@1312
   227
        printf "<*                                          *>\n"
yann@1312
   228
        printf "<*            FORCE in action:              *>\n"
yann@1312
   229
        printf "<* Continuing despite missing pre-requisite *>\n"
yann@1312
   230
        printf "<*          Prepare for breakage            *>\n"
yann@1312
   231
        printf "<*                                          *>\n"
yann@1312
   232
        printf "\n"
yann@1312
   233
    fi
yann@1311
   234
}
yann@1311
   235
yann@2480
   236
# This function checks for a tool, and warns if not found
yann@2480
   237
# See check_for(), above, for how to call has_or_abort
yann@2480
   238
# Note: if err is not set, then no error message is printed
yann@2480
   239
has_or_warn() {
yann@2480
   240
    # We declare these 6 variables here, although they are
yann@2480
   241
    # set in check_for(), called below
yann@2480
   242
    local prog inc lib
yann@2481
   243
    local var ver err kconfig
yann@2480
   244
yann@2480
   245
    if ! check_for "$@"; then
yann@2498
   246
        printf " * optional dependency is missing, some features will be disabled\n"
yann@2498
   247
        printf "${err:+ * ${err}\n}"
yann@2480
   248
        if [ -n "${var}" ]; then
yann@2498
   249
            printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
yann@2480
   250
        fi
yann@2480
   251
    fi
yann@2480
   252
}
yann@2480
   253
yann@183
   254
do_help() {
yann@183
   255
    cat <<__EOF__
yann@1140
   256
\`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
yann@183
   257
yann@183
   258
USAGE: ./configure [OPTION]...
yann@183
   259
yann@183
   260
Defaults for the options are specified in brackets.
yann@183
   261
yann@183
   262
Configuration:
yann@1105
   263
  -h, --help              display this help and exit
yann@1311
   264
      --force             force configure to continue, even in case
yann@1311
   265
                          some pre-requisites are missing
yann@615
   266
yann@615
   267
Installation directories:
yann@185
   268
  --prefix=PREFIX         install files in PREFIX [${PREFIX_DEFAULT}]
yann@285
   269
  --local                 don't install, and use current directory
yann@183
   270
yann@183
   271
By default, \`make install' will install all the files in
yann@183
   272
\`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc.  You can specify
yann@183
   273
an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
yann@183
   274
for instance \`--prefix=\${HOME}'.
yann@183
   275
yann@183
   276
For better control, use the options below.
yann@183
   277
yann@183
   278
Fine tuning of the installation directories:
yann@683
   279
  --bindir=DIR            user executables [PREFIX/bin]
yann@683
   280
  --libdir=DIR            object code libraries [PREFIX/lib]
yann@683
   281
  --docdir=DIR            info documentation [PREFIX/share/doc]
yann@683
   282
  --mandir=DIR            man documentation [PREFIX/share/man]
yann@614
   283
yann@614
   284
Optional Features:
yann@1140
   285
  --with-install=PATH     Specify the full PATH to GNU install
yann@1311
   286
  --with-make=PATH        Specify the full PATH to GNU make >= 3.80
yann@1140
   287
  --with-grep=PATH        Specify the full PATH to GNU grep
yann@1140
   288
  --with-sed=PATH         Specify the full PATH to GNU sed
yann@1140
   289
  --with-bash=PATH        Specify the full PATH to bash >= 3.0
yann@183
   290
__EOF__
yann@183
   291
}
yann@183
   292
yann@376
   293
#---------------------------------------------------------------------
yann@376
   294
# Set user's options
yann@376
   295
yann@182
   296
while [ $# -ne 0 ]; do
yann@182
   297
    case "$1" in
yann@1297
   298
        --local)    LOCAL_set="y"; shift;;
yann@182
   299
        --prefix*)  set_prefix "$1" "$2" && shift || shift 2;;
yann@182
   300
        --bindir*)  set_bindir "$1" "$2" && shift || shift 2;;
yann@182
   301
        --libdir*)  set_libdir "$1" "$2" && shift || shift 2;;
yann@182
   302
        --docdir*)  set_docdir "$1" "$2" && shift || shift 2;;
yann@182
   303
        --mandir*)  set_mandir "$1" "$2" && shift || shift 2;;
yann@1140
   304
        --with-*)   set_tool   "$1" "$2" && shift || shift 2;;
yann@1311
   305
        --force)    FORCE=1; shift;;
yann@183
   306
        --help|-h)  do_help; exit 0;;
blueness@1739
   307
        # Skip, auto-stuff compatibility
blueness@1739
   308
        --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
blueness@1739
   309
        --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir)             shift 2;;
yann@1333
   310
        *)          printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
yann@182
   311
    esac
yann@182
   312
done
yann@182
   313
yann@641
   314
# Use defaults
yann@185
   315
[ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
yann@641
   316
yann@641
   317
# Special case when installing locally
yann@1297
   318
if [ "${LOCAL_set}" = "y" ]; then
yann@1105
   319
    set_prefix "" "$( pwd )"
yann@1105
   320
    set_bindir "" "$( pwd )"
yann@1105
   321
    set_libdir "" "$( pwd )"
yann@1105
   322
    set_docdir "" "$( pwd )/docs"
yann@1105
   323
    set_mandir "" "$( pwd )/docs"
yann@285
   324
fi
yann@183
   325
yann@376
   326
#---------------------------------------------------------------------
yann@1140
   327
# Some sanity checks, now
yann@1106
   328
yann@1560
   329
# We check for grep and sed manually, because they are used in check_for()
yann@1140
   330
printf "Checking for 'grep'... "
yann@1140
   331
if [ -n "${grep}" ]; then
yann@1333
   332
    printf "${grep} (cached)\n"
yann@1140
   333
else
yann@1140
   334
    grep="$( which grep 2>/dev/null )"
yann@1187
   335
    if [ -z "${grep}" ]; then
yann@1333
   336
        printf "not found\n"
yann@1187
   337
    else
yann@1333
   338
        printf "${grep}\n"
yann@1187
   339
        printf "Checking whether '${grep}' supports -E... "
yann@1187
   340
        if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
yann@1333
   341
            printf "yes\n"
yann@1187
   342
        else
yann@1333
   343
            printf "no\n"
yann@1187
   344
            grep=
yann@1187
   345
        fi
yann@1187
   346
    fi
yann@1106
   347
fi
yann@1187
   348
if [ -z "${grep}" ]; then
yann@1333
   349
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   350
    printf "or the version you have is too old.\n"
yann@1333
   351
    printf "You can give the path to this tool using: --with-grep=PATH\n"
yann@1187
   352
    do_error "Bailing out..."
yann@1140
   353
fi
yann@1311
   354
add_to_var_list grep
yann@1140
   355
yann@1140
   356
printf "Checking for 'sed'... "
yann@1140
   357
if [ -n "${sed}" ]; then
yann@1333
   358
    printf "${sed} (cached)\n"
yann@1140
   359
else
yann@1140
   360
    sed="$( which sed 2>/dev/null )"
yann@1187
   361
    if [ -z "${sed}" ]; then
yann@1333
   362
        printf "not found\n"
yann@1187
   363
    else
yann@1333
   364
        printf "${sed}\n"
rpjday@1288
   365
        printf "Checking whether '${sed}' supports -i and -e... "
yann@1187
   366
        touch .ct-ng.sed.test
yann@1187
   367
        if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
yann@1333
   368
            printf "yes\n"
yann@1187
   369
        else
yann@1333
   370
            printf "no\n"
yann@1187
   371
            sed=
yann@1187
   372
        fi
yann@1187
   373
        rm -f .ct-ng.sed.test
yann@1187
   374
    fi
yann@1140
   375
fi
yann@1187
   376
if [ -z "${sed}" ]; then
yann@1333
   377
    printf "Either you are missing entirely the needed tool,\n"
yann@1333
   378
    printf "or the version you have is too old.\n"
yann@1333
   379
    printf "You can give the path to this tool using: --with-sed=PATH\n"
yann@1187
   380
    do_error "Bailing out..."
yann@1140
   381
fi
yann@1311
   382
add_to_var_list sed
yann@1140
   383
yann@1311
   384
# The regular list of tools we can now easily check for
yann@1311
   385
has_or_abort prog=bash                              \
yann@1311
   386
             var=bash                               \
yann@1477
   387
             ver='^GNU bash, version (3\.[1-9]|4)'  \
yann@1477
   388
             err="'bash' 3.1 or above was not found"
yann@1311
   389
has_or_abort prog=cut
yann@1311
   390
has_or_abort prog=install var=install
yann@1311
   391
has_or_abort prog=make                                  \
yann@1311
   392
             var=make                                   \
yann@1311
   393
             ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
yann@1311
   394
             err="GNU 'make' 3.80 or above was not found"
yann@1311
   395
has_or_abort prog=gcc
yann@1431
   396
has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
yann@1311
   397
has_or_abort prog=bison
yann@1311
   398
has_or_abort prog=flex
yann@1311
   399
has_or_abort prog=makeinfo
yann@1311
   400
has_or_abort prog=automake                                                      \
oron@1432
   401
             ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)'    \
yann@1311
   402
             err="'automake' 1.10 or above was not found"
yann@1311
   403
has_or_abort prog=libtool                                                                           \
titus@1969
   404
             var=libtool                                                                            \
yann@1311
   405
             ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
yann@1311
   406
             err="'libtool' 1.5.26 or above was not found"
titus@1957
   407
has_or_abort prog=stat
yann@2203
   408
has_or_abort prog="curl wget"
yann@1347
   409
has_or_abort prog=cvs
yann@1311
   410
has_or_abort prog=patch
yann@1311
   411
has_or_abort prog=tar
yann@1311
   412
has_or_abort prog=gzip
yann@1311
   413
has_or_abort prog=bzip2
yann@1311
   414
has_or_abort prog=lzma
yann@1313
   415
has_or_abort prog=readlink
titus@1962
   416
has_or_abort prog=objcopy var=objcopy
titus@1962
   417
has_or_abort prog=objdump var=objdump
titus@1962
   418
has_or_abort prog=readelf var=readelf
titus@1962
   419
has_or_abort prog=patch var=patch
yann@1311
   420
yann@1312
   421
has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"    \
yann@1312
   422
             err="'ncurses' headers files were not found"
yann@1313
   423
yann@1332
   424
ncurses_libs="$( for l in ncursesw ncurses curses; do   \
yann@1332
   425
                     for x in so a dylib; do            \
yann@1332
   426
                         printf "lib$l.$x ";            \
yann@1332
   427
                     done;                              \
yann@1332
   428
                 done                                   \
yann@1332
   429
               )"
yann@1332
   430
has_or_abort lib="${ncurses_libs}"                  \
yann@1313
   431
             err="'ncurses' library was not found"
yann@1106
   432
yann@2499
   433
stdcxx_libs="$( for x in so dylib a; do \
yann@2499
   434
                   printf "libstdc++.$x "; \
yann@2499
   435
               done \
yann@2499
   436
             )"
yann@2499
   437
has_or_abort lib="${stdcxx_libs}" \
yann@2499
   438
             err="'libstdc++' shared library was not found"
yann@2499
   439
yann@2500
   440
# Yes, we may be checking twice for libstdc++.a
yann@2500
   441
# The first is because we need one instance of libstdc++ (shared or static)
yann@2500
   442
# because it is needed for PPL; the second is because the static version is
yann@2500
   443
# required for static-linking, and if missing, the option is removed.
yann@2500
   444
has_or_warn  lib="libstdc++.a" \
yann@2500
   445
             err="static 'libstdc++' is needed to statically link the toolchain's executables" \
yann@2500
   446
             kconfig=has_static_libstdcxx
yann@2500
   447
yann@1106
   448
#---------------------------------------------------------------------
yann@1106
   449
# Compute the version string
yann@376
   450
yann@1576
   451
# If this version is n hg clone, try to get the revision number
yann@435
   452
# If we can't get the revision number, use date
yann@2498
   453
printf "\nComputing version string... "
yann@435
   454
case "${VERSION}" in
Yann@1409
   455
    *+hg|hg)
yann@1740
   456
        REVISION="$( hg id -n 2>/dev/null || true )"
yann@1105
   457
        case "${REVISION}" in
Yann@1409
   458
            "")
yann@1105
   459
                VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
yann@1105
   460
            *)
yann@1430
   461
                VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
yann@1105
   462
                ;;
yann@1105
   463
        esac
yann@1105
   464
        # Arrange to have no / in the directory name, no need to create an
yann@1105
   465
        # arbitrarily deep directory structure
yann@1333
   466
        VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
yann@444
   467
        ;;
yann@435
   468
esac
yann@1740
   469
printf "${VERSION}\n"
yann@435
   470
yann@1106
   471
#---------------------------------------------------------------------
yann@1106
   472
# Compute and check install paths
yann@1106
   473
yann@614
   474
# Now we have the version string, we can build up the paths
yann@554
   475
[ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
yann@1660
   476
[ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
yann@1660
   477
[ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
yann@2026
   478
[ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
yann@554
   479
yann@1660
   480
# Install support files in our own sub-dir, so as not to mangle (system)
yann@1660
   481
# files and dirs, but only if not --local
yann@1660
   482
if [ -z "${LOCAL_set}" ]; then
yann@1660
   483
    LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
yann@1660
   484
    DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
yann@1660
   485
fi
yann@1660
   486
yann@1047
   487
# Check that install PATHs are absolute
yann@1047
   488
for p in BIN LIB DOC MAN; do
yann@1105
   489
    var="${p}DIR"
yann@1105
   490
    eval v='"${'"${var}"'}"'
yann@1105
   491
    case "${v}" in
yann@1105
   492
        /*) ;;
yann@1105
   493
        *)  do_error "'${var}' is not an absolute path: '${v}'"
yann@1105
   494
    esac
yann@1047
   495
done
yann@1047
   496
yann@1106
   497
#---------------------------------------------------------------------
yann@1106
   498
# That's all, folks!
yann@614
   499
yann@641
   500
printf "Building up Makefile... "
yann@1140
   501
var_sed="$( for var_name in ${var_list}; do
yann@1140
   502
                eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
yann@2481
   503
            done
yann@1140
   504
          )"
yann@2481
   505
kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
yann@2481
   506
                                  eval printf \"${k_name}=\${${k_name}} \"
yann@2481
   507
                              done
yann@2481
   508
                            )/"
yann@2481
   509
"${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g"       \
yann@2481
   510
            -e "s,@@LIBDIR@@,${LIBDIR},g"       \
yann@2481
   511
            -e "s,@@DOCDIR@@,${DOCDIR},g"       \
yann@2481
   512
            -e "s,@@MANDIR@@,${MANDIR},g"       \
yann@2481
   513
            -e "s,@@VERSION@@,${VERSION},g"     \
yann@2481
   514
            -e "s,@@DATE@@,${DATE},g"           \
yann@2481
   515
            -e "s,@@LOCAL@@,${LOCAL_set},g"     \
yann@2481
   516
            -e "${var_sed}"                     \
yann@2481
   517
            -e "${kconfig_sed}"                 \
yann@2481
   518
         Makefile.in                            \
yann@2481
   519
         >Makefile
yann@673
   520
echo "done"
yann@185
   521
yann@185
   522
cat <<__EOF__
yann@673
   523
yann@197
   524
crosstool-NG configured as follows:
yann@554
   525
  PREFIX='${PREFIX}'
yann@554
   526
  BINDIR='${BINDIR}'
yann@554
   527
  LIBDIR='${LIBDIR}'
yann@554
   528
  DOCDIR='${DOCDIR}'
yann@554
   529
  MANDIR='${MANDIR}'
yann@1106
   530
yann@1106
   531
Now run:
yann@1106
   532
  make
yann@185
   533
__EOF__
yann@1298
   534
if [ "${LOCAL_set}" != "y" ]; then
yann@1297
   535
    printf "  make install\n"
yann@1297
   536
fi