From: Taylor R Campbell Date: Sat, 17 Apr 2010 05:28:16 +0000 (-0400) Subject: Make makegen/m4.sh report m4 failure by returning 1. X-Git-Tag: 20100708-Gtk~72 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=08d269fc89eb5962c29772b2fe41ae15a58b11c0;p=mit-scheme.git Make makegen/m4.sh report m4 failure by returning 1. Previously, the return code of m4 was totally ignored, because it was invoked only in a pipeline not at the end. Because of brain damage in shell script, we have to use a temporary file to let the subshell in which we run m4 report the failure to the script so that the script can know to return 1. --- diff --git a/src/microcode/makegen/m4.sh b/src/microcode/makegen/m4.sh index 2411fc79f..bf01c4490 100755 --- a/src/microcode/makegen/m4.sh +++ b/src/microcode/makegen/m4.sh @@ -24,13 +24,29 @@ # Processing to simulate m4 accepting definition arguments. +set -e + +TMP_FILE="m4.tmp" + +clean () +{ + rm -f "${TMP_FILE}" +} + +run_m4 () +{ + m4 && clean +} + +trap clean EXIT INT QUIT TERM +rm -f "${TMP_FILE}" +touch "${TMP_FILE}" + if [ $# = 0 ] then - sed -e '/^#/D' | m4 | sed -e 's/@/$/g' -e 's/^ $//' + sed -e '/^#/D' | run_m4 | sed -e 's/@/$/g' -e 's/^ $//' else - TMP_FILE="m4.tmp" SEEN_INPUT=0 - rm -f "${TMP_FILE}" while [ $# != 0 ]; do if [ "${1}" = "-P" ]; then echo "define(${2})" >> "${TMP_FILE}" @@ -44,6 +60,13 @@ else if [ ${SEEN_INPUT} -eq 0 ]; then sed -e '/^#/D' >> "${TMP_FILE}" fi - m4 < "${TMP_FILE}" | sed -e 's/@/$/g' -e 's/^ $//' - rm -f "${TMP_FILE}" + run_m4 < "${TMP_FILE}" | sed -e 's/@/$/g' -e 's/^ $//' +fi + +# If m4 was successful, run_m4 has deleted the temporary file. If +# not, report the failure; exiting will have the effect of running +# `clean', which will delete the temporary file. + +if [ -f "${TMP_FILE}" ]; then + exit 1 fi