From 05e132851016d566629fcfd279eef025a14ddb32 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 19 Mar 2026 19:32:43 +0100 Subject: Shell script changes for portability --- bootstrap.sh | 13 +++++++++---- test/all.sh | 2 +- test/run.sh | 16 ++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index b193bbd..1478e1f 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,4 @@ -#!/bin/env sh +#!/bin/sh set -eo pipefail @@ -14,18 +14,23 @@ if test -n "$V"; then fi src=$(find src/ -name '*.c') X() { - echo "> $@" | (test -n "$V" && cat || sed -s 's/\([^ ]\+\.c \?\)\{10\}$/.../') + echo "> $@" | (test -n "$V" && cat || sed 's/\([^ ]\+\.c \?\)\{10\}$/.../') $@ } +md5=md5sum +if ! $(command -v md5sum > /dev/null); then + md5=md5 +fi + echo "== Stage 0 (compiling with $cc) ==" X $cc $cflags -o antcc0 $src echo echo "== Stage 1 (compiling with stage 0 output) ==" X ./antcc0 $opt $cflags -o antcc1 $src -X md5sum antcc1 +X $md5 antcc1 echo echo "== Stage 2 (compiling with stage 1 output) ==" X ./antcc1 $opt $cflags -o antcc2 $src -X md5sum antcc2 +X $md5 antcc2 (X cmp antcc1 antcc2) && echo ok. || (echo 'bootstrap FAIL!'; exit 1) diff --git a/test/all.sh b/test/all.sh index d80db09..00f3f6c 100755 --- a/test/all.sh +++ b/test/all.sh @@ -1,4 +1,4 @@ -#!/bin/env sh +#!/bin/sh cd $(dirname "$0") ./run.sh diff --git a/test/run.sh b/test/run.sh index 485b0a8..ec40161 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1,4 +1,4 @@ -#!/bin/env sh +#!/bin/sh cd $(dirname "$0") ANTCC="../antcc $CFLAGS" @@ -12,24 +12,24 @@ x() { run() { ntest=$(( ntest + 1 )) f="$(basename "$1")" - expected=build/"$(echo "$f" | sed -s 's/\.c$/.expected/')" + expected=build/"$(echo "$f" | sed 's/\.c$/.expected/')" echo ---- "$f" ---- >> log.txt mkdir -p build/ args=$(awk '/\/\* ARGS:.*$/ {ORS=" ";for (i=3;i "$expected"; then - obj=build/"$(echo "$f" | sed -s 's/\.c$/.o/')" - exe=build/"$(echo "$f" | sed -s 's/\.c$//')" + obj=build/"$(echo "$f" | sed 's/\.c$/.o/')" + exe=build/"$(echo "$f" | sed 's/\.c$//')" if ! ( x $ANTCC $cflags "$f" -c -o "$obj" && x $ANTCC $cflags "$obj" -o "$exe" ); then echo !TEST ERROR "$f" echo !FAILED TO COMPILE echo '-------' else - actual=build/"$(echo "$f" | sed -s 's/\.c$/.actual/')" + actual=build/"$(echo "$f" | sed 's/\.c$/.actual/')" x "$exe" $args > "$actual" - if [ "$(md5sum < "$actual")" != "$(md5sum < "$expected")" ]; then + if ! cmp "$actual" "$expected" > /dev/null; then echo --- !TEST ERROR "$f" - diff --unified=0 --color=auto "$expected" "$actual" + diff --unified=0 "$expected" "$actual" echo '-------' else npass=$(( npass + 1 )) @@ -41,7 +41,7 @@ run() { } : < /dev/null > log.txt -tests=$(find . -regex '\./[0-9]+-.*\.c' | sort) +tests=$(find . | grep -E '\./[0-9]+-.*\.c' | sort) for test in $tests; do run $test done -- cgit v1.2.3