mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Convert bison.sh to posix shell (#1369)
* Convert bison.sh to posix shell * Refactor bison.sh to be more like CMakeLists.txt No current warnings with shellcheck.net.
This commit is contained in:
@@ -9,7 +9,7 @@ set(common_src
|
||||
)
|
||||
|
||||
find_package(BISON 3.0.0 REQUIRED)
|
||||
set(BISON_FLAGS "-Wall")
|
||||
set(BISON_FLAGS "-Wall -Dparse.lac=full -Dlr.type=ielr")
|
||||
# Set some optimization flags on versions that support them
|
||||
if(BISON_VERSION VERSION_GREATER_EQUAL "3.5")
|
||||
set(BISON_FLAGS "${BISON_FLAGS} -Dapi.token.raw=true")
|
||||
@@ -19,8 +19,6 @@ if(BISON_VERSION VERSION_GREATER_EQUAL "3.6")
|
||||
else()
|
||||
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.error=verbose")
|
||||
endif()
|
||||
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.lac=full")
|
||||
set(BISON_FLAGS "${BISON_FLAGS} -Dlr.type=ielr")
|
||||
|
||||
BISON_TARGET(ASM_PARSER "asm/parser.y"
|
||||
"${PROJECT_SOURCE_DIR}/src/asm/parser.cpp"
|
||||
|
||||
39
src/bison.sh
39
src/bison.sh
@@ -1,23 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
BISONFLAGS=-Wall
|
||||
OUTPUT_CPP="${1:?}"
|
||||
INPUT_Y="${2:?}"
|
||||
|
||||
readonly BISON_MAJOR=$(bison -V | sed -E 's/^.+ ([0-9]+)\..*$/\1/g;q')
|
||||
readonly BISON_MINOR=$(bison -V | sed -E 's/^.+ [0-9]+\.([0-9]+)\..*$/\1/g;q')
|
||||
BISON_MAJOR=$(bison -V | sed -E 's/^.+ ([0-9]+)\..*$/\1/g;q')
|
||||
BISON_MINOR=$(bison -V | sed -E 's/^.+ [0-9]+\.([0-9]+)\..*$/\1/g;q')
|
||||
|
||||
add_flag () {
|
||||
if [[ "$BISON_MAJOR" -eq "$1" && "$BISON_MINOR" -ge "$2" ]]; then
|
||||
BISONFLAGS="$BISONFLAGS -D$3"
|
||||
if [ "$BISON_MAJOR" -lt 3 ]; then
|
||||
echo "Bison $BISON_MAJOR.$BISON_MINOR is not supported" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_flag 3 0 parse.error=verbose
|
||||
add_flag 3 0 parse.lac=full
|
||||
add_flag 3 0 lr.type=ielr
|
||||
add_flag 3 5 api.token.raw=true
|
||||
add_flag 3 6 parse.error=detailed
|
||||
BISON_FLAGS="-Wall -Dparse.lac=full -Dlr.type=ielr"
|
||||
|
||||
echo "BISONFLAGS=$BISONFLAGS"
|
||||
# Set some optimization flags on versions that support them
|
||||
if [ "$BISON_MAJOR" -eq 4 ] || [ "$BISON_MAJOR" -eq 3 ] && [ "$BISON_MINOR" -ge 5 ]; then
|
||||
BISON_FLAGS="$BISON_FLAGS -Dapi.token.raw=true"
|
||||
fi
|
||||
if [ "$BISON_MAJOR" -eq 4 ] || [ "$BISON_MAJOR" -eq 3 ] && [ "$BISON_MINOR" -ge 6 ]; then
|
||||
BISON_FLAGS="$BISON_FLAGS -Dparse.error=detailed"
|
||||
else
|
||||
BISON_FLAGS="$BISON_FLAGS -Dparse.error=verbose"
|
||||
fi
|
||||
|
||||
exec bison $BISONFLAGS -d -o "$1" "$2"
|
||||
# Replace the arguments to this script ($@) with the ones in $BISON_FLAGS
|
||||
eval "set -- $BISON_FLAGS"
|
||||
|
||||
exec bison "$@" -d -o "$OUTPUT_CPP" "$INPUT_Y"
|
||||
|
||||
Reference in New Issue
Block a user