Refactor how Makefile invokes Bison for reusability (#1259)

Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
This commit is contained in:
Rangi
2023-12-01 13:29:05 -05:00
committed by GitHub
parent 6132b77c1e
commit 1402615bc0
4 changed files with 34 additions and 29 deletions

26
src/bison.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e
BISONFLAGS=-Wall
readonly BISON_VER=$(bison -V)
add_flag () {
if awk <<<"$BISON_VER" -v major="$1" -v minor="$2" '
/^bison.*[0-9]+(\.[0-9]+)(\.[0-9]+)?$/ {
match($0, /[0-9]+(\.[0-9]+)(\.[0-9]+)?$/);
split(substr($0, RSTART), ver, ".");
if (ver[1] == major && ver[2] >= minor) { exit 0 } else { exit 1 }
}'; then
BISONFLAGS="-D$3 $BISONFLAGS"
fi
}
add_flag 3 5 api.token.raw=true
add_flag 3 6 parse.error=detailed
add_flag 3 0 parse.error=verbose
add_flag 3 0 parse.lac=full
add_flag 3 0 lr.type=ielr
echo "BISONFLAGS=$BISONFLAGS"
exec bison $BISONFLAGS -d -o "$1" "$2"

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
bison -V | awk -v major="$1" -v minor="$2" '
/^bison.*[0-9]+(\.[0-9]+)(\.[0-9]+)?$/ {
match($0, /[0-9]+(\.[0-9]+)(\.[0-9]+)?$/);
split(substr($0, RSTART), ver, ".");
if (ver[1] == major && ver[2] >= minor) { exit 0 } else { exit 1 }
}'

View File

@@ -360,7 +360,7 @@ int main(int argc, char *argv[])
break;
case 'l':
if (linkerScriptName)
warnx("Overriding linkerscript %s", musl_optarg);
warnx("Overriding linker script %s", musl_optarg);
linkerScriptName = musl_optarg;
break;
case 'M':
@@ -368,12 +368,12 @@ int main(int argc, char *argv[])
break;
case 'm':
if (mapFileName)
warnx("Overriding mapfile %s", musl_optarg);
warnx("Overriding map file %s", musl_optarg);
mapFileName = musl_optarg;
break;
case 'n':
if (symFileName)
warnx("Overriding symfile %s", musl_optarg);
warnx("Overriding sym file %s", musl_optarg);
symFileName = musl_optarg;
break;
case 'O':
@@ -504,7 +504,6 @@ int main(int argc, char *argv[])
reportErrors();
}
// then process them,
obj_DoSanityChecks();
if (nbErrors != 0)