scripts/addToolVersion.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun Jan 05 19:25:54 2014 +0100 (2014-01-05)
changeset 3274 baa61856643b
parent 3153 f6740f9e42de
child 3315 464128a8fc3f
permissions -rwxr-xr-x
libc/glibc: print name of skipped addon

When trying to extract an already present (aka bundled) addon,
print the name of that addon, for clarity, and to help analyse
the build.log post-mortem.

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