diff --git a/tools/m2ctx/m2ctx.sh b/tools/m2ctx/m2ctx.sh index 24c201165..861de5ee4 100755 --- a/tools/m2ctx/m2ctx.sh +++ b/tools/m2ctx/m2ctx.sh @@ -6,6 +6,7 @@ GCC=gcc FLAGS="-E -P -dD -undef" INCLUDES="-Iinclude -Iinclude/library -Ifiles -Ilib/include -include global.h" DEFINES="-DHEARTGOLD -DGAME_REMASTER=0 -DENGLISH -DPM_KEEP_ASSERTS -DSDK_ARM9 -DSDK_CODE_ARM -DSDK_FINALROM" +SRCS=() if [ "$(uname -s)" == "Darwin" ]; then SED="$(which gsed)" @@ -17,13 +18,7 @@ generate-ctx () { # Remove any line containing a predefined macro. If not removed, mwccarm # generates compiler warnings. - if [ "$OUT_FILE" = "-" ]; then - PIPE_CTX= - else - PIPE_CTX="> $OUT_FILE" - fi - - grep "^#include " "$1" | $GCC $FLAGS $INCLUDES $DEFINES -x c - | ${SED} '/__STDC__\|__STDC_VERSION__\|__STDC_VERSION__\|__STDC_HOSTED__/d' $PIPE_CTX + grep "^#include " "$1" | $GCC $FLAGS $INCLUDES $DEFINES -x c - | ${SED} '/__STDC__\|__STDC_VERSION__\|__STDC_VERSION__\|__STDC_HOSTED__/d' } usage () { @@ -48,8 +43,20 @@ while [[ $# -gt 0 ]]; do OUT_FILE="$2" shift 2 ;; *) - generate-ctx "$1" - exit 0 - ;; + SRCS+=("$1") + shift ;; esac done + +if [ "${#SRCS[@]}" -ne 1 ]; then + echo "error: specify exactly one source file" + exit 255 +else + src="${SRCS[0]}" +fi + +if [ "$OUT_FILE" != "-" ]; then + exec 1>$OUT_FILE +fi + +generate-ctx "$src"