Skip to content

Commit 40c0483

Browse files
committed
Make shell script tools more portable
1 parent 5284faa commit 40c0483

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

tools/build-ccheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
#
33
# Copyright (c) 2019 Jiri Svoboda
44
# All rights reserved.

tools/cc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/bin/sh
22

33
#
44
# Copyright (c) 2017 Jakub Jermar

tools/ccheck.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
#
33
# Copyright (c) 2018 Jiri Svoboda
44
# All rights reserved.
@@ -32,7 +32,7 @@ if [ ."$CCHECK" != . ]; then
3232
ccheck="$CCHECK"
3333
fi
3434

35-
if [ ."$1" == .--fix ] ; then
35+
if [ ."$1" = .--fix ]; then
3636
opt=--fix
3737
else
3838
opt=
@@ -48,8 +48,7 @@ find abi kernel boot uspace -type f -regex '^.*\.[ch]$' \
4848
while read fname; do
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))
5554
cat "$outfile"
@@ -64,7 +63,7 @@ while read fname; do
6463
rm -f "$outfile"
6564
done
6665

67-
if [ $srepcnt == 0 -a $fcnt == 0 ] ; then
66+
if [ $srepcnt -eq 0 ] && [ $fcnt -eq 0 ]; then
6867
echo "Ccheck passed."
6968
else
7069
echo "Ccheck failed."

tools/toolchain.sh

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/bin/sh
22

33
#
44
# Copyright (c) 2009 Martin Decky
@@ -102,27 +102,27 @@ test_version() {
102102
echo "Start testing the version of the installed software"
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

111111

112112
if [ -z "${CROSS_PREFIX}" ] ; then
113113
CROSS_PREFIX="/usr/local/cross"
114114
fi
115115

116-
for i in "${PLATFORMS[@]}"
116+
for i in $PLATFORMS
117117
do
118118
PLATFORM="$i"
119119
set_target_from_platform "$PLATFORM"
120120
PREFIX="${CROSS_PREFIX}/bin/${HELENOS_TARGET}"
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

128128
exit
@@ -139,27 +139,25 @@ test_app_version() {
139139
if [ ! -e $APP ]; then
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
}
158156

159157

160158

161159
change_title() {
162-
echo -en "\e]0;$1\a"
160+
printf "\e]0;$1\a"
163161
}
164162

165163
show_countdown() {
@@ -170,7 +168,7 @@ show_countdown() {
170168
return 0
171169
fi
172170

173-
echo -n "${TM} "
171+
printf "${TM} "
174172
change_title "${TM}"
175173
sleep 1
176174

@@ -221,30 +219,31 @@ create_dir() {
221219
check_dirs() {
222220
OUTSIDE="$1"
223221
BASE="$2"
224-
ORIGINAL="`pwd`"
225-
226-
mkdir -p "${OUTSIDE}"
227-
228-
cd "${OUTSIDE}"
229-
check_error $? "Unable to change directory to ${OUTSIDE}."
230-
ABS_OUTSIDE="`pwd`"
222+
ORIGINAL="$PWD"
231223

232224
cd "${BASE}"
233225
check_error $? "Unable to change directory to ${BASE}."
234-
ABS_BASE="`pwd`"
235-
226+
ABS_BASE="$PWD"
236227
cd "${ORIGINAL}"
237228
check_error $? "Unable to change directory to ${ORIGINAL}."
238229

239-
BASE_LEN="${#ABS_BASE}"
240-
OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
230+
mkdir -p "${OUTSIDE}"
231+
cd "${OUTSIDE}"
232+
check_error $? "Unable to change directory to ${OUTSIDE}."
241233

242-
if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
234+
while [ "${#PWD}" -gt "${#ABS_BASE}" ]; do
235+
cd ..
236+
done
237+
238+
if [ "$PWD" = "$ABS_BASE" ]; then
243239
echo
244240
echo "CROSS_PREFIX cannot reside within the working directory."
245241

246242
exit 5
247243
fi
244+
245+
cd "${ORIGINAL}"
246+
check_error $? "Unable to change directory to ${ORIGINAL}."
248247
}
249248

250249
prepare() {

0 commit comments

Comments
 (0)