diff --git a/Makefile b/Makefile index 9bee64f..d187d39 100644 --- a/Makefile +++ b/Makefile @@ -38,17 +38,23 @@ GRAPHICS := graphics #--------------------------------------------------------------------------------- ARCH := -mthumb -mthumb-interwork +GIT_DIRTY := $(shell git diff-index --quiet HEAD -- || echo "-dirty") +GIT_HASH := $(shell git rev-parse --short HEAD || echo "undef") +GIT_C_FLAGS := -DGIT_HASH=\"$(GIT_HASH)\" -DGIT_DIRTY=\"$(GIT_DIRTY)\" + CFLAGS := -g -O3 -Wall -Werror\ -mcpu=arm7tdmi -mtune=arm7tdmi \ -ffast-math -fomit-frame-pointer -funroll-loops \ $(ARCH) +CFLAGS += $(GIT_C_FLAGS) + CFLAGS += $(INCLUDE) CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map) +LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map),--undefined=balatro_version #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project diff --git a/scripts/build_bug_report.py b/scripts/build_bug_report.py new file mode 100644 index 0000000..017127a --- /dev/null +++ b/scripts/build_bug_report.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys +import re + +def grep_binary_offsets(path, pattern): + with open(path, "rb") as f: + data = f.read() + + results = [] + for match in re.finditer(rb"[ -~]{4,}", data): + s = match.group() + if re.search(pattern.encode(), s): + results.append((match.start(), s.decode("utf-8", errors="ignore"))) + return results + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python script.py ") + sys.exit(1) + + file_path = sys.argv[1] + pattern = "GBALATRO_VERSION" + + for offset, text in grep_binary_offsets(file_path, pattern): + version = text.split(":")[1] + print(f"git hash: {version}") diff --git a/source/version.c b/source/version.c new file mode 100644 index 0000000..9d850d8 --- /dev/null +++ b/source/version.c @@ -0,0 +1,10 @@ +#ifndef GIT_HASH +#define GIT_HASH "undef" +#endif + +#ifndef GIT_DIRTY +#define GIT_DIRTY "-dirty" +#endif + +__attribute__((section(".version"), used)) +const char balatro_version[] = "GBALATRO_VERSION:" GIT_HASH GIT_DIRTY;