This is the mail archive of the crossgcc@sourceware.org mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2 of 8] scripts/addToolVersion.sh: add a function to extract fields from versions


# HG changeset patch
# User "BenoÃt THÃBAUDEAU" <benoit.thebaudeau@advansee.com>
# Date 1306855252 -7200
# Node ID e9712058fd48182b4039e6f066fa36514279ee3b
# Parent  d124516c60a2f0559020400a8dfd1dbf339359a5
scripts/addToolVersion.sh: add a function to extract fields from versions

This patch adds a function to extract major, minor, revision, etc. from version
numbers.

Signed-off-by: "BenoÃt THÃBAUDEAU" <benoit.thebaudeau@advansee.com>

diff --git a/scripts/addToolVersion.sh b/scripts/addToolVersion.sh
--- a/scripts/addToolVersion.sh
+++ b/scripts/addToolVersion.sh
@@ -18,34 +18,43 @@
 		  'tool' in one of:
 		    gcc, binutils, glibc, eglibc, uClibc, newlib, linux, gdb, dmalloc,
 		    duma, strace, ltrace, libelf, gmp, mpfr, ppl, cloog, mpc
-		
+
 		  Valid options for all tools:
 		    --stable, -s, +x   (default)
 		      mark the version as being stable (as opposed to experimental, below)
-		
+
 		    --experimental, -x, +s
 		      mark the version as being experimental (as opposed to stable, above)
-		
+
 		    --current, -c, +o   (default)
 		      mark the version as being cuurent (as opposed to obsolete, below)
-		
+
 		    --obsolete, -o, +c
 		      mark the version as being obsolete (as opposed to current, above)
-		
+
 		  Note: setting a new tool resets to the defaults: 'stable' and 'current'.
-		
+
 		  'version' is a valid version for the specified tool.
-		
+
 		  Examples:
 		    add stable current version 2.6.19.2 to linux kernel:
 		      ${myname} --linux 2.6.19.2
-		
+
 		    add experimental obsolete version 2.3.5 and stable current versions 2.6.1
 		    and 2.6.2 to glibc, add stable obsolete version 3.3.3 to gcc:
 		      ${myname} --glibc -x -o 2.3.5 -s -c 2.6.1 2.6.2 --gcc -o 3.3.3
 		EOF
 }
 
+# Extract field $3 from version $1 with separator $2
+getVersionField() {
+    local version="$1"
+    local sep="$2"
+    local field="$3"
+
+    echo "${version}${sep}${sep}${sep}${sep}" |cut -d ${sep} -f ${field}
+}
+
 # Effectively add a version to the specified tool
 # $cat          : tool category
 # $tool         : tool name
@@ -100,8 +109,8 @@
     case "${tool}" in
         gcc)
             # Extract 'M'ajor and 'm'inor from version string
-            ver_M=$(echo "${version}...." |cut -d . -f 1)
-            ver_m=$(echo "${version}...." |cut -d . -f 2)
+            ver_M=$(getVersionField "${version}" . 1)
+            ver_m=$(getVersionField "${version}" . 2)
             if [   \( ${ver_M} -eq 4 -a ${ver_m} -eq 6 \)  ]; then
                 SedExpr1="${SedExpr1}\n    select CC_GCC_4_6"
             elif [ \( ${ver_M} -eq 4 -a ${ver_m} -eq 5 \)  ]; then
@@ -116,9 +125,9 @@
             ;;
         uClibc)
             # uClibc-0.9.30 and above need some love
-            ver_M=$(echo "${version}...." |cut -d . -f 1)
-            ver_m=$(echo "${version}...." |cut -d . -f 2)
-            ver_p=$(echo "${version}...." |cut -d . -f 3)
+            ver_M=$(getVersionField "${version}" . 1)
+            ver_m=$(getVersionField "${version}" . 2)
+            ver_p=$(getVersionField "${version}" . 3)
             if [    ${ver_M} -ge 1                                      \
                  -o ${ver_M} -eq 0 -a ${ver_m} -ge 10                   \
                  -o ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -ge 30 ]; then
@@ -127,7 +136,7 @@
             ;;
         gdb)
             # gdb-7.0 and above have special handling
-            ver_M=$(echo "${version}...." |cut -d . -f 1)
+            ver_M=$(getVersionField "${version}" . 1)
             if [ ${ver_M} -ge 7 ]; then
                 SedExpr1="${SedExpr1}\n    select GDB_7_0_or_later"
             fi

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]