m2ctx.sh bugfixes

This commit is contained in:
PikalaxALT 2024-08-22 22:05:02 -04:00
parent 0599b15eaa
commit 184b5734a7
No known key found for this signature in database
GPG Key ID: 7774E96AA69E5B61

View File

@ -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"