scripts/addToolVersion.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 18 23:00:46 2011 +0200 (2011-05-18)
changeset 2467 200836977ce6
parent 2412 20edcd78cf67
child 2485 288f1261964f
permissions -rwxr-xr-x
config: rename variables that are arrays

Make it explicit that a variable is an array bu the name of the variable.
It will be used later when .config gets munged to allow both multiple
arguments and arguments with spaces at the same time to be passed from the
configuration down to the build scripts.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@1173
     1
#!/bin/sh
yann@1174
     2
set -e
yann@1
     3
yann@1
     4
# Adds a new version to one of the toolchain component
yann@1
     5
myname="$0"
yann@1
     6
yann@1174
     7
# Parse the tools' paths configuration
yann@1623
     8
# It is expected that this script is only to be run from the
yann@1623
     9
# source directory of crosstool-NG, so it is trivial to find
yann@1623
    10
# paths.mk (we can't use  ". paths.mk", as POSIX states that
yann@1623
    11
# $PATH should be searched for, and $PATH most probably doe
yann@1623
    12
# not include "."), hence the "./".
yann@1623
    13
. "./paths.mk"
yann@1174
    14
yann@1
    15
doHelp() {
yann@1
    16
    cat <<-EOF
yann@1722
    17
		Usage: ${myname} <--tool> <[options] version [...]> ...
yann@1722
    18
		  'tool' in one of:
yann@1723
    19
		    gcc, binutils, glibc, eglibc, uClibc, newlib, linux, gdb, dmalloc,
yann@1723
    20
		    duma, strace, ltrace, libelf, gmp, mpfr, ppl, cloog, mpc
yann@1722
    21
		
yann@1722
    22
		  Valid options for all tools:
yann@1722
    23
		    --stable, -s, +x   (default)
yann@1722
    24
		      mark the version as being stable (as opposed to experimental, below)
yann@1722
    25
		
yann@1722
    26
		    --experimental, -x, +s
yann@1722
    27
		      mark the version as being experimental (as opposed to stable, above)
yann@1722
    28
		
yann@1722
    29
		    --current, -c, +o   (default)
yann@1722
    30
		      mark the version as being cuurent (as opposed to obsolete, below)
yann@1722
    31
		
yann@1722
    32
		    --obsolete, -o, +c
yann@1722
    33
		      mark the version as being obsolete (as opposed to current, above)
yann@1722
    34
		
yann@1722
    35
		  Note: setting a new tool resets to the defaults: 'stable' and 'current'.
yann@1722
    36
		
yann@1722
    37
		  'version' is a valid version for the specified tool.
yann@1722
    38
		
yann@1722
    39
		  Examples:
yann@1722
    40
		    add stable current version 2.6.19.2 to linux kernel:
yann@1722
    41
		      ${myname} --linux 2.6.19.2
yann@1722
    42
		
yann@1722
    43
		    add experimental obsolete version 2.3.5 and stable current versions 2.6.1
yann@1722
    44
		    and 2.6.2 to glibc, add stable obsolete version 3.3.3 to gcc:
yann@1722
    45
		      ${myname} --glibc -x -o 2.3.5 -s -c 2.6.1 2.6.2 --gcc -o 3.3.3
yann@1722
    46
		EOF
yann@1
    47
}
yann@1
    48
yann@1173
    49
# Effectively add a version to the specified tool
yann@1173
    50
# $cat          : tool category
yann@1173
    51
# $tool         : tool name
yann@1173
    52
# $tool_prefix  : tool directory prefix
yann@1173
    53
# $EXP          : set to non empty if experimental, to empty otherwise
yann@1173
    54
# #OBS          : set to non empty if obsolete, to empty otherwise
yann@1173
    55
# $1            : version string to add
yann@1173
    56
addToolVersion() {
yann@1173
    57
    local version="$1"
yann@2412
    58
    local file="$2"
yann@1200
    59
    local config_ver_option
yann@1173
    60
    local exp_obs_prompt
yann@1734
    61
    local deps v ver_M ver_m ver_p
yann@1173
    62
    local SedExpr1 SedExpr2
yann@1173
    63
yann@2412
    64
    [ -f "${file}" ] || return 0
yann@2412
    65
yann@1174
    66
    v=$(echo "${version}" |"${sed}" -r -e 's/-/_/g; s/\./_/g;')
yann@1173
    67
yann@1200
    68
    config_ver_option="${cat}_V_${v}"
yann@1200
    69
yann@1200
    70
    # Check for existing version: it can be legitimitate for an end-user
yann@1200
    71
    # to try adding a new version if the one he/she wants is not listed.
yann@1200
    72
    # But it can be the case where the version is hidden behind either one
yann@1200
    73
    # of EXPERIMENTAL or OBSOLETE, so warn if the version is already listed.
yann@2412
    74
    if grep -E "^config ${config_ver_option}$" "${file}" >/dev/null 2>&1; then
yann@1200
    75
        echo "'${tool}': version '${version}' already present:"
yann@2412
    76
        grep -A1 -B0 -n                                                     \
yann@2412
    77
             -E "^(config ${config_ver_option}| {4}prompt \"${version}\")$" \
yann@2412
    78
             "${file}" /dev/null
yann@1200
    79
        return 0
yann@1200
    80
    fi
yann@1200
    81
yann@1200
    82
    SedExpr1="${SedExpr1}config ${config_ver_option}\n"
yann@1173
    83
    SedExpr1="${SedExpr1}    bool\n"
yann@1173
    84
    SedExpr1="${SedExpr1}    prompt \"${version}"
yann@1173
    85
    case "${EXP},${OBS}" in
yann@1173
    86
        ,)  ;;
yann@1536
    87
        ,*) exp_obs_prompt=" (OBSOLETE)"
yann@1535
    88
            deps="    depends on OBSOLETE"
yann@1173
    89
            ;;
yann@1536
    90
        *,) exp_obs_prompt=" (EXPERIMENTAL)"
yann@1535
    91
            deps="    depends on EXPERIMENTAL"
yann@1173
    92
            ;;
yann@1536
    93
        *)  exp_obs_prompt=" (EXPERIMENTAL, OBSOLETE)"
yann@1535
    94
            deps="    depends on EXPERIMENTAL \\&\\& OBSOLETE"
yann@1173
    95
            ;;
yann@1173
    96
    esac
yann@1173
    97
    [ -n "${exp_obs_prompt}" ] && SedExpr1="${SedExpr1}${exp_obs_prompt}"
yann@1535
    98
    SedExpr1="${SedExpr1}\""
yann@1535
    99
    [ -n "${deps}" ] && SedExpr1="${SedExpr1}\n${deps}"
yann@1692
   100
    case "${tool}" in
yann@1692
   101
        gcc)
yann@1692
   102
            # Extract 'M'ajor and 'm'inor from version string
yann@1692
   103
            ver_M=$(echo "${version}...." |cut -d . -f 1)
yann@1692
   104
            ver_m=$(echo "${version}...." |cut -d . -f 2)
yann@2441
   105
            if [   \( ${ver_M} -eq 4 -a ${ver_m} -eq 6 \)  ]; then
yann@2441
   106
                SedExpr1="${SedExpr1}\n    select CC_GCC_4_6"
yann@2441
   107
            elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 5 \)  ]; then
yann@2441
   108
                SedExpr1="${SedExpr1}\n    select CC_GCC_4_5"
yann@2441
   109
            elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 4 \)  ]; then
yann@2441
   110
                SedExpr1="${SedExpr1}\n    select CC_GCC_4_4"
yann@2441
   111
            elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 3 \)  ]; then
yann@2441
   112
                SedExpr1="${SedExpr1}\n    select CC_GCC_4_3"
yann@2441
   113
            elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 2 \)  ]; then
yann@2441
   114
                SedExpr1="${SedExpr1}\n    select CC_GCC_4_2"
yann@1692
   115
            fi
yann@1692
   116
            ;;
yann@1734
   117
        uClibc)
yann@1734
   118
            # uClibc-0.9.30 and above need some love
yann@1734
   119
            ver_M=$(echo "${version}...." |cut -d . -f 1)
yann@1734
   120
            ver_m=$(echo "${version}...." |cut -d . -f 2)
yann@1734
   121
            ver_p=$(echo "${version}...." |cut -d . -f 3)
yann@1734
   122
            if [    ${ver_M} -ge 1                                      \
yann@1734
   123
                 -o ${ver_M} -eq 0 -a ${ver_m} -ge 10                   \
yann@1734
   124
                 -o ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -ge 30 ]; then
yann@1734
   125
                SedExpr1="${SedExpr1}\n    select LIBC_UCLIBC_0_9_30_or_later"
yann@1734
   126
            fi
yann@1734
   127
            ;;
yann@1852
   128
        gdb)
yann@1852
   129
            # gdb-7.0 and above have special handling
yann@1852
   130
            ver_M=$(echo "${version}...." |cut -d . -f 1)
yann@1852
   131
            if [ ${ver_M} -ge 7 ]; then
yann@1852
   132
                SedExpr1="${SedExpr1}\n    select GDB_7_0_or_later"
yann@1852
   133
            fi
yann@1852
   134
            ;;
yann@1692
   135
    esac
yann@1721
   136
    SedExpr2="    default \"${version}\" if ${config_ver_option}"
yann@1542
   137
    "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_BELOW)$/\1\n\n'"${SedExpr1}"'/;' "${file}"
yann@1535
   138
    "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_STRING_BELOW)$/\1\n'"${SedExpr2}"'/;' "${file}"
yann@1173
   139
}
yann@1173
   140
yann@96
   141
cat=
yann@1
   142
tool=
yann@1
   143
tool_prefix=
yann@1
   144
VERSION=
yann@43
   145
EXP=
yann@96
   146
OBS=
yann@1
   147
yann@1173
   148
if [ $# -eq 0 ]; then
yann@1173
   149
    doHelp
yann@1173
   150
    exit 1
yann@1173
   151
fi
yann@1173
   152
yann@1173
   153
while [ $# -gt 0 ]; do
yann@1173
   154
    case "$1" in
yann@96
   155
        # Tools:
yann@1722
   156
        --gcc)      EXP=; OBS=; cat=CC;             tool=gcc;       tool_prefix=cc;;
yann@1722
   157
        --binutils) EXP=; OBS=; cat=BINUTILS;       tool=binutils;  tool_prefix=binutils;;
yann@1722
   158
        --glibc)    EXP=; OBS=; cat=LIBC_GLIBC;     tool=glibc;     tool_prefix=libc;;
yann@1722
   159
        --eglibc)   EXP=; OBS=; cat=LIBC_EGLIBC;    tool=eglibc;    tool_prefix=libc;;
yann@1722
   160
        --uClibc)   EXP=; OBS=; cat=LIBC_UCLIBC;    tool=uClibc;    tool_prefix=libc;;
yann@1723
   161
        --newlib)   EXP=; OBS=; cat=LIBC_NEWLIB;    tool=newlib;    tool_prefix=libc;;
yann@1722
   162
        --linux)    EXP=; OBS=; cat=KERNEL;         tool=linux;     tool_prefix=kernel;;
yann@1722
   163
        --gdb)      EXP=; OBS=; cat=GDB;            tool=gdb;       tool_prefix=debug;;
yann@1722
   164
        --dmalloc)  EXP=; OBS=; cat=DMALLOC;        tool=dmalloc;   tool_prefix=debug;;
yann@1722
   165
        --duma)     EXP=; OBS=; cat=DUMA;           tool=duma;      tool_prefix=debug;;
yann@1722
   166
        --strace)   EXP=; OBS=; cat=STRACE;         tool=strace;    tool_prefix=debug;;
yann@1722
   167
        --ltrace)   EXP=; OBS=; cat=LTRACE;         tool=ltrace;    tool_prefix=debug;;
yann@1722
   168
        --gmp)      EXP=; OBS=; cat=GMP;            tool=gmp;       tool_prefix=companion_libs;;
yann@1722
   169
        --mpfr)     EXP=; OBS=; cat=MPFR;           tool=mpfr;      tool_prefix=companion_libs;;
yann@1722
   170
        --ppl)      EXP=; OBS=; cat=PPL;            tool=ppl;       tool_prefix=companion_libs;;
yann@1722
   171
        --cloog)    EXP=; OBS=; cat=CLOOG;          tool=cloog;     tool_prefix=companion_libs;;
yann@1722
   172
        --mpc)      EXP=; OBS=; cat=MPC;            tool=mpc;       tool_prefix=companion_libs;;
yann@1872
   173
        --libelf)   EXP=; OBS=; cat=LIBELF;         tool=libelf;    tool_prefix=companion_libs;;
yann@1173
   174
yann@96
   175
        # Tools options:
yann@1173
   176
        -x|--experimental|+s)   EXP=1;;
yann@1173
   177
        -s|--stable|+x)         EXP=;;
yann@1173
   178
        -o|--obsolete|+c)       OBS=1;;
yann@1173
   179
        -c|--current|+o)        OBS=;;
yann@1173
   180
yann@96
   181
        # Misc:
yann@1173
   182
        -h|--help)  doHelp; exit 0;;
yann@1173
   183
        -*)         echo "Unknown option: '$1' (use -h/--help for help)."; exit 1;;
yann@1173
   184
yann@1173
   185
        # Version string:
yann@1173
   186
        *)  [ -n "${tool}" ] || { doHelp; exit 1; }
yann@2412
   187
            file_base="config/${tool_prefix}/${tool}.in"
yann@2412
   188
            # Components have their version selection either
yann@2412
   189
            # in the .in or the .in.2 file. Handle both.
yann@2412
   190
            addToolVersion "$1" "${file_base}"
yann@2412
   191
            addToolVersion "$1" "${file_base}.2"
yann@1173
   192
            ;;
yann@1
   193
    esac
yann@1173
   194
    shift
yann@1
   195
done