mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Refactor how Makefile invokes Bison for reusability (#1259)
Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
This commit is contained in:
22
Makefile
22
Makefile
@@ -39,9 +39,9 @@ LDFLAGS ?=
|
|||||||
REALLDFLAGS := ${LDFLAGS} ${WARNFLAGS} \
|
REALLDFLAGS := ${LDFLAGS} ${WARNFLAGS} \
|
||||||
-DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
|
-DBUILD_VERSION_STRING=\"${VERSION_STRING}\"
|
||||||
|
|
||||||
YFLAGS ?= -Wall
|
# Wrapper around bison that passes flags depending on what the version supports
|
||||||
|
BISON := src/bison.sh
|
||||||
|
|
||||||
BISON := bison
|
|
||||||
RM := rm -rf
|
RM := rm -rf
|
||||||
|
|
||||||
# Used for checking pull requests
|
# Used for checking pull requests
|
||||||
@@ -138,19 +138,7 @@ src/asm/parser.hpp: src/asm/parser.cpp
|
|||||||
$Qtouch $@
|
$Qtouch $@
|
||||||
|
|
||||||
src/asm/parser.cpp: src/asm/parser.y
|
src/asm/parser.cpp: src/asm/parser.y
|
||||||
$QDEFS=; \
|
$Q${BISON} $@ $<
|
||||||
add_flag(){ \
|
|
||||||
if src/check_bison_ver.sh $$1 $$2; then \
|
|
||||||
DEFS="-D$$3 $$DEFS"; \
|
|
||||||
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 "DEFS=$$DEFS"; \
|
|
||||||
${BISON} $$DEFS -d ${YFLAGS} -o $@ $<
|
|
||||||
|
|
||||||
# Only RGBGFX uses libpng (POSIX make doesn't support pattern rules to cover all these)
|
# Only RGBGFX uses libpng (POSIX make doesn't support pattern rules to cover all these)
|
||||||
src/gfx/main.o: src/gfx/main.cpp
|
src/gfx/main.o: src/gfx/main.cpp
|
||||||
@@ -244,12 +232,12 @@ mingw32:
|
|||||||
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
||||||
CXX=i686-w64-mingw32-g++ \
|
CXX=i686-w64-mingw32-g++ \
|
||||||
CXXFLAGS="-O3 -flto -DNDEBUG -static-libgcc" \
|
CXXFLAGS="-O3 -flto -DNDEBUG -static-libgcc" \
|
||||||
BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config"
|
PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config"
|
||||||
|
|
||||||
mingw64:
|
mingw64:
|
||||||
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
|
||||||
CXX=x86_64-w64-mingw32-g++ \
|
CXX=x86_64-w64-mingw32-g++ \
|
||||||
BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config"
|
PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config"
|
||||||
|
|
||||||
wine-shim:
|
wine-shim:
|
||||||
$Qecho '#!/usr/bin/env bash' > rgbshim.sh
|
$Qecho '#!/usr/bin/env bash' > rgbshim.sh
|
||||||
|
|||||||
26
src/bison.sh
Executable file
26
src/bison.sh
Executable 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"
|
||||||
@@ -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 }
|
|
||||||
}'
|
|
||||||
@@ -360,7 +360,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (linkerScriptName)
|
if (linkerScriptName)
|
||||||
warnx("Overriding linkerscript %s", musl_optarg);
|
warnx("Overriding linker script %s", musl_optarg);
|
||||||
linkerScriptName = musl_optarg;
|
linkerScriptName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
@@ -368,12 +368,12 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if (mapFileName)
|
if (mapFileName)
|
||||||
warnx("Overriding mapfile %s", musl_optarg);
|
warnx("Overriding map file %s", musl_optarg);
|
||||||
mapFileName = musl_optarg;
|
mapFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (symFileName)
|
if (symFileName)
|
||||||
warnx("Overriding symfile %s", musl_optarg);
|
warnx("Overriding sym file %s", musl_optarg);
|
||||||
symFileName = musl_optarg;
|
symFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
@@ -504,7 +504,6 @@ int main(int argc, char *argv[])
|
|||||||
reportErrors();
|
reportErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// then process them,
|
// then process them,
|
||||||
obj_DoSanityChecks();
|
obj_DoSanityChecks();
|
||||||
if (nbErrors != 0)
|
if (nbErrors != 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user