Changeset 40c0483 in mainline


Ignore:
Timestamp:
2019-08-16T20:58:02Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d3db35b
Parents:
5284faa
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-07-21 14:03:59)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-08-16 20:58:02)
Message:

Make shell script tools more portable

Location:
tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tools/build-ccheck.sh

    r5284faa r40c0483  
    1 #!/bin/bash
     1#!/bin/sh
    22#
    33# Copyright (c) 2019 Jiri Svoboda
  • tools/cc.sh

    r5284faa r40c0483  
    1 #! /bin/bash
     1#!/bin/sh
    22
    33#
  • tools/ccheck.sh

    r5284faa r40c0483  
    1 #!/bin/bash
     1#!/bin/sh
    22#
    33# Copyright (c) 2018 Jiri Svoboda
     
    3333fi
    3434
    35 if [ ."$1" == .--fix ] ; then
     35if [ ."$1" = .--fix ]; then
    3636        opt=--fix
    3737else
     
    4949        outfile="$(mktemp)"
    5050        "$ccheck" $opt $fname >"$outfile" 2>&1
    51         rc=$?
    52         if [ .$rc == .0 ]; then
     51        if [ $? -eq 0 ]; then
    5352                if [ -s "$outfile" ] ; then
    5453                        srepcnt=$((srepcnt + 1))
     
    6564done
    6665
    67 if [ $srepcnt == 0 -a $fcnt == 0 ] ; then
     66if [ $srepcnt -eq 0 ] && [ $fcnt -eq 0 ]; then
    6867        echo "Ccheck passed."
    6968else
  • tools/toolchain.sh

    r5284faa r40c0483  
    1 #! /bin/bash
     1#!/bin/sh
    22
    33#
     
    103103        echo
    104104       
    105         if [ -z "$1" ] || [ "$1" == "all" ] ; then
    106                 PLATFORMS=("amd64" "arm32" "arm64" "ia32" "ia64" "mips32" "mips32eb" "ppc32" "riscv64" "sparc64")
     105        if [ -z "$1" ] || [ "$1" = "all" ] ; then
     106                PLATFORMS='amd64 arm32 arm64 ia32 ia64 mips32 mips32eb ppc32 riscv64 sparc64'
    107107        else
    108                 PLATFORMS=("$1")
     108                PLATFORMS="$1"
    109109        fi
    110110       
     
    114114        fi
    115115
    116         for i in "${PLATFORMS[@]}"
     116        for i in $PLATFORMS
    117117        do
    118118                PLATFORM="$i"
     
    121121
    122122                echo "== $PLATFORM =="
    123                 test_app_version "Binutils" "ld" "GNU\ ld\ \(GNU\ Binutils\)\ ((\.|[0-9])+)" "$BINUTILS_VERSION"
    124                 test_app_version "GCC" "gcc" "gcc\ version\ ((\.|[0-9])+)" "$GCC_VERSION"
    125                 test_app_version "GDB" "gdb" "GNU\ gdb\ \(GDB\)\s+((\.|[0-9])+)" "$GDB_VERSION"
     123                test_app_version "Binutils" "ld" "GNU ld (.*) \([.0-9]*\)" "$BINUTILS_VERSION"
     124                test_app_version "GCC" "gcc" "gcc version \([.0-9]*\)" "$GCC_VERSION"
     125                test_app_version "GDB" "gdb" "GNU gdb (.*)[[:space:]]\+\([.0-9]*\)" "$GDB_VERSION"
    126126        done
    127127
     
    140140                echo "- $PKGNAME is missing"
    141141        else
    142                 {
    143                         OUT=$(${APP} -v 2>&1)
    144                 } &> /dev/null
    145 
    146                 if [[ "$OUT" =~ $REGEX ]]; then
    147                 VERSION="${BASH_REMATCH[1]}"
    148                 if [ "$INS_VERSION" = "$VERSION" ]; then
    149                         echo "+ $PKGNAME is uptodate ($INS_VERSION)"
    150                 else
    151                         echo "- $PKGNAME ($VERSION) is outdated ($INS_VERSION)"
    152                 fi
    153             else
    154                 echo "- $PKGNAME Unexpected output"
    155             fi
     142                VERSION=`${APP} -v 2>&1 | sed -n "s:^${REGEX}.*:\1:p"`
     143
     144                if [ -z "$VERSION" ]; then
     145                        echo "- $PKGNAME Unexpected output"
     146                        return 1
     147                fi
     148
     149                if [ "$INS_VERSION" = "$VERSION" ]; then
     150                        echo "+ $PKGNAME is uptodate ($INS_VERSION)"
     151                else
     152                        echo "- $PKGNAME ($VERSION) is outdated ($INS_VERSION)"
     153                fi
    156154        fi
    157155}
     
    160158
    161159change_title() {
    162         echo -en "\e]0;$1\a"
     160        printf "\e]0;$1\a"
    163161}
    164162
     
    171169        fi
    172170
    173         echo -n "${TM} "
     171        printf "${TM} "
    174172        change_title "${TM}"
    175173        sleep 1
     
    222220        OUTSIDE="$1"
    223221        BASE="$2"
    224         ORIGINAL="`pwd`"
     222        ORIGINAL="$PWD"
     223
     224        cd "${BASE}"
     225        check_error $? "Unable to change directory to ${BASE}."
     226        ABS_BASE="$PWD"
     227        cd "${ORIGINAL}"
     228        check_error $? "Unable to change directory to ${ORIGINAL}."
    225229
    226230        mkdir -p "${OUTSIDE}"
    227 
    228231        cd "${OUTSIDE}"
    229232        check_error $? "Unable to change directory to ${OUTSIDE}."
    230         ABS_OUTSIDE="`pwd`"
    231 
    232         cd "${BASE}"
    233         check_error $? "Unable to change directory to ${BASE}."
    234         ABS_BASE="`pwd`"
     233
     234        while [ "${#PWD}" -gt "${#ABS_BASE}" ]; do
     235                cd ..
     236        done
     237
     238        if [ "$PWD" = "$ABS_BASE" ]; then
     239                echo
     240                echo "CROSS_PREFIX cannot reside within the working directory."
     241
     242                exit 5
     243        fi
    235244
    236245        cd "${ORIGINAL}"
    237246        check_error $? "Unable to change directory to ${ORIGINAL}."
    238 
    239         BASE_LEN="${#ABS_BASE}"
    240         OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
    241 
    242         if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
    243                 echo
    244                 echo "CROSS_PREFIX cannot reside within the working directory."
    245 
    246                 exit 5
    247         fi
    248247}
    249248
Note: See TracChangeset for help on using the changeset viewer.