scripts/addToolVersion.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun May 08 11:02:18 2011 +0200 (2011-05-08)
changeset 2441 4cd9cda2265c
parent 2412 20edcd78cf67
child 2485 288f1261964f
permissions -rwxr-xr-x
scripts/addToolVersion: fix gcc complibs dependency

Since the gcc configuration changes, the way to select the
dependent companion libraries has changed.

Update the addToolVersion script to match.

Reported-by: Xun Li <lxfind@gmail.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.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.mk (we can't use  ". paths.mk", as POSIX states that
    11 # $PATH should be searched for, and $PATH most probably doe
    12 # not include "."), hence the "./".
    13 . "./paths.mk"
    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 # Effectively add a version to the specified tool
    50 # $cat          : tool category
    51 # $tool         : tool name
    52 # $tool_prefix  : tool directory prefix
    53 # $EXP          : set to non empty if experimental, to empty otherwise
    54 # #OBS          : set to non empty if obsolete, to empty otherwise
    55 # $1            : version string to add
    56 addToolVersion() {
    57     local version="$1"
    58     local file="$2"
    59     local config_ver_option
    60     local exp_obs_prompt
    61     local deps v ver_M ver_m ver_p
    62     local SedExpr1 SedExpr2
    63 
    64     [ -f "${file}" ] || return 0
    65 
    66     v=$(echo "${version}" |"${sed}" -r -e 's/-/_/g; s/\./_/g;')
    67 
    68     config_ver_option="${cat}_V_${v}"
    69 
    70     # Check for existing version: it can be legitimitate for an end-user
    71     # to try adding a new version if the one he/she wants is not listed.
    72     # But it can be the case where the version is hidden behind either one
    73     # of EXPERIMENTAL or OBSOLETE, so warn if the version is already listed.
    74     if grep -E "^config ${config_ver_option}$" "${file}" >/dev/null 2>&1; then
    75         echo "'${tool}': version '${version}' already present:"
    76         grep -A1 -B0 -n                                                     \
    77              -E "^(config ${config_ver_option}| {4}prompt \"${version}\")$" \
    78              "${file}" /dev/null
    79         return 0
    80     fi
    81 
    82     SedExpr1="${SedExpr1}config ${config_ver_option}\n"
    83     SedExpr1="${SedExpr1}    bool\n"
    84     SedExpr1="${SedExpr1}    prompt \"${version}"
    85     case "${EXP},${OBS}" in
    86         ,)  ;;
    87         ,*) exp_obs_prompt=" (OBSOLETE)"
    88             deps="    depends on OBSOLETE"
    89             ;;
    90         *,) exp_obs_prompt=" (EXPERIMENTAL)"
    91             deps="    depends on EXPERIMENTAL"
    92             ;;
    93         *)  exp_obs_prompt=" (EXPERIMENTAL, OBSOLETE)"
    94             deps="    depends on EXPERIMENTAL \\&\\& OBSOLETE"
    95             ;;
    96     esac
    97     [ -n "${exp_obs_prompt}" ] && SedExpr1="${SedExpr1}${exp_obs_prompt}"
    98     SedExpr1="${SedExpr1}\""
    99     [ -n "${deps}" ] && SedExpr1="${SedExpr1}\n${deps}"
   100     case "${tool}" in
   101         gcc)
   102             # Extract 'M'ajor and 'm'inor from version string
   103             ver_M=$(echo "${version}...." |cut -d . -f 1)
   104             ver_m=$(echo "${version}...." |cut -d . -f 2)
   105             if [   \( ${ver_M} -eq 4 -a ${ver_m} -eq 6 \)  ]; then
   106                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_6"
   107             elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 5 \)  ]; then
   108                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_5"
   109             elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 4 \)  ]; then
   110                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_4"
   111             elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 3 \)  ]; then
   112                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_3"
   113             elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 2 \)  ]; then
   114                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_2"
   115             fi
   116             ;;
   117         uClibc)
   118             # uClibc-0.9.30 and above need some love
   119             ver_M=$(echo "${version}...." |cut -d . -f 1)
   120             ver_m=$(echo "${version}...." |cut -d . -f 2)
   121             ver_p=$(echo "${version}...." |cut -d . -f 3)
   122             if [    ${ver_M} -ge 1                                      \
   123                  -o ${ver_M} -eq 0 -a ${ver_m} -ge 10                   \
   124                  -o ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -ge 30 ]; then
   125                 SedExpr1="${SedExpr1}\n    select LIBC_UCLIBC_0_9_30_or_later"
   126             fi
   127             ;;
   128         gdb)
   129             # gdb-7.0 and above have special handling
   130             ver_M=$(echo "${version}...." |cut -d . -f 1)
   131             if [ ${ver_M} -ge 7 ]; then
   132                 SedExpr1="${SedExpr1}\n    select GDB_7_0_or_later"
   133             fi
   134             ;;
   135     esac
   136     SedExpr2="    default \"${version}\" if ${config_ver_option}"
   137     "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_BELOW)$/\1\n\n'"${SedExpr1}"'/;' "${file}"
   138     "${sed}" -r -i -e 's/^(# CT_INSERT_VERSION_STRING_BELOW)$/\1\n'"${SedExpr2}"'/;' "${file}"
   139 }
   140 
   141 cat=
   142 tool=
   143 tool_prefix=
   144 VERSION=
   145 EXP=
   146 OBS=
   147 
   148 if [ $# -eq 0 ]; then
   149     doHelp
   150     exit 1
   151 fi
   152 
   153 while [ $# -gt 0 ]; do
   154     case "$1" in
   155         # Tools:
   156         --gcc)      EXP=; OBS=; cat=CC;             tool=gcc;       tool_prefix=cc;;
   157         --binutils) EXP=; OBS=; cat=BINUTILS;       tool=binutils;  tool_prefix=binutils;;
   158         --glibc)    EXP=; OBS=; cat=LIBC_GLIBC;     tool=glibc;     tool_prefix=libc;;
   159         --eglibc)   EXP=; OBS=; cat=LIBC_EGLIBC;    tool=eglibc;    tool_prefix=libc;;
   160         --uClibc)   EXP=; OBS=; cat=LIBC_UCLIBC;    tool=uClibc;    tool_prefix=libc;;
   161         --newlib)   EXP=; OBS=; cat=LIBC_NEWLIB;    tool=newlib;    tool_prefix=libc;;
   162         --linux)    EXP=; OBS=; cat=KERNEL;         tool=linux;     tool_prefix=kernel;;
   163         --gdb)      EXP=; OBS=; cat=GDB;            tool=gdb;       tool_prefix=debug;;
   164         --dmalloc)  EXP=; OBS=; cat=DMALLOC;        tool=dmalloc;   tool_prefix=debug;;
   165         --duma)     EXP=; OBS=; cat=DUMA;           tool=duma;      tool_prefix=debug;;
   166         --strace)   EXP=; OBS=; cat=STRACE;         tool=strace;    tool_prefix=debug;;
   167         --ltrace)   EXP=; OBS=; cat=LTRACE;         tool=ltrace;    tool_prefix=debug;;
   168         --gmp)      EXP=; OBS=; cat=GMP;            tool=gmp;       tool_prefix=companion_libs;;
   169         --mpfr)     EXP=; OBS=; cat=MPFR;           tool=mpfr;      tool_prefix=companion_libs;;
   170         --ppl)      EXP=; OBS=; cat=PPL;            tool=ppl;       tool_prefix=companion_libs;;
   171         --cloog)    EXP=; OBS=; cat=CLOOG;          tool=cloog;     tool_prefix=companion_libs;;
   172         --mpc)      EXP=; OBS=; cat=MPC;            tool=mpc;       tool_prefix=companion_libs;;
   173         --libelf)   EXP=; OBS=; cat=LIBELF;         tool=libelf;    tool_prefix=companion_libs;;
   174 
   175         # Tools options:
   176         -x|--experimental|+s)   EXP=1;;
   177         -s|--stable|+x)         EXP=;;
   178         -o|--obsolete|+c)       OBS=1;;
   179         -c|--current|+o)        OBS=;;
   180 
   181         # Misc:
   182         -h|--help)  doHelp; exit 0;;
   183         -*)         echo "Unknown option: '$1' (use -h/--help for help)."; exit 1;;
   184 
   185         # Version string:
   186         *)  [ -n "${tool}" ] || { doHelp; exit 1; }
   187             file_base="config/${tool_prefix}/${tool}.in"
   188             # Components have their version selection either
   189             # in the .in or the .in.2 file. Handle both.
   190             addToolVersion "$1" "${file_base}"
   191             addToolVersion "$1" "${file_base}.2"
   192             ;;
   193     esac
   194     shift
   195 done