From e177284ff53125a698ca9611fa1cc3438c483318 Mon Sep 17 00:00:00 2001 From: Kevin <6500490+Zeturic@users.noreply.github.com> Date: Fri, 6 Mar 2020 15:04:07 -0500 Subject: [PATCH] explicitly build tools --- README.md | 3 ++- build_tools.sh | 9 -------- makefile | 56 ++++++++++++++++---------------------------------- project.mk | 23 +++++++++++++++++++++ 4 files changed, 43 insertions(+), 48 deletions(-) create mode 100644 project.mk diff --git a/README.md b/README.md index 00f08ad..4ad50cf 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ For binary FR. See [here](https://gist.github.com/Zeturic/db1611cc7b17c3140f9b9af32e1b596b) for the prequisites and help in installing them. -#### Cloning the repo +#### Cloning the repo and building the tools Open your terminal to whatever folder you want to download this repo into. Then, do the following to download the repo: ```shell $ git clone https://github.com/Zeturic/bpre-trade-stuff.git $ cd bpre-trade-stuff +$ ./build_tools.sh ``` #### Adding your ROM diff --git a/build_tools.sh b/build_tools.sh index 4eeb7d3..ca31eec 100644 --- a/build_tools.sh +++ b/build_tools.sh @@ -1,13 +1,4 @@ #!/bin/sh -unset CC -unset CXX -unset AS -unset AR -unset OBJCOPY -unset STRIP -unset NM -unset RANLIB - make -C tools/scaninc $BUILD_TOOLS_TARGET make -C tools/preproc $BUILD_TOOLS_TARGET diff --git a/makefile b/makefile index 3ec8397..eb40250 100644 --- a/makefile +++ b/makefile @@ -6,17 +6,20 @@ endif include $(DEVKITARM)/base_tools include config.mk +include project.mk # ------------------------------------------------------------------------------ -SRC_FILES = $(filter-out src/sInGameTrades.c, $(wildcard src/*.c)) -OBJ_FILES = $(SRC_FILES:src/%.c=build/src/%.o) -MAIN_ASM_INCLUDES = $(wildcard *.s) +SRC_FILES ?= $(wildcard src/*.c) +OBJ_FILES ?= $(SRC_FILES:src/%.c=build/src/%.o) +MAIN_ASM_INCLUDES ?= $(wildcard *.s) -CFLAGS = -O2 -mlong-calls -Wall -Wextra -mthumb -mno-thumb-interwork -fno-inline -fno-builtin -std=gnu11 -mabi=apcs-gnu -mcpu=arm7tdmi -march=armv4t -mtune=arm7tdmi -x c -c -I include -I gflib -D NUM_INGAME_TRADES=$(NUM_INGAME_TRADES) -D INSERT_INGAME_TRADE_HACK=$(INSERT_INGAME_TRADE_HACK) +HEADER_DIRS ?= -I include -I gflib + +CFLAGS = -O2 -mlong-calls -Wall -Wextra -mthumb -mno-thumb-interwork -fno-inline -fno-builtin -std=gnu11 -mabi=apcs-gnu -mcpu=arm7tdmi -march=armv4t -mtune=arm7tdmi -x c -c $(HEADER_DIRS) $(EXTRA_CFLAGS) LD = $(PREFIX)ld -LDFLAGS = --relocatable -T rom.ld --defsym sInGameTradesPtr=$(sInGameTradesPtr) +LDFLAGS = --relocatable -T rom.ld $(EXTRA_LDFLAGS) SIZE = $(PREFIX)size SIZEFLAGS = -d -B @@ -24,51 +27,33 @@ SIZEFLAGS = -d -B PREPROC = tools/preproc/preproc SCANINC = tools/scaninc/scaninc -TOOLS = $(PREPROC) $(SCANINC) - ARMIPS ?= armips -ARMIPS_FLAGS = -sym test.sym -equ NUM_INGAME_TRADES $(NUM_INGAME_TRADES) -equ INSERT_INGAME_TRADE_HACK $(INSERT_INGAME_TRADE_HACK) - -PYTHON ?= python3 +ARMIPS_FLAGS = -sym test.sym $(EXTRA_ARMIPS_FLAGS) +PYTHON ?= python FREESIA = $(PYTHON) tools/freesia -FREESIA_FLAGS = --rom rom.gba --start-at $(START_AT) - -TRADESCANTIA = $(PYTHON) tools/tradescantia -TRADESCANTIA_FLAGS = --rom rom.gba --pointer $(sInGameTradesPtr) --num-trades $(NUM_INGAME_TRADES) - -ifneq ($(ABILITYNUM_HAS_ALREADY_BEEN_MOVED),0) -TRADESCANTIA_FLAGS += --modified-format -endif - -sInGameTradesPtr = 0x08053CA4 +FREESIAFLAGS = --rom rom.gba --start-at $(START_AT) # ------------------------------------------------------------------------------ -.PHONY: all spotless clean clean-tools repoint-cursor-options md5 +.PHONY: all spotless clean clean-tools md5 all: test.gba spotless: clean clean-tools clean: - rm -rf build test.gba test.sym src/sInGameTrades.c + rm -rf build test.gba test.sym clean-tools: +BUILD_TOOLS_TARGET=clean ./build_tools.sh -repoint-cursor-options: - $(ARMIPS) repoint-cursor-options.asm - md5: test.gba @md5sum test.gba # ------------------------------------------------------------------------------ -$(TOOLS): - +./build_tools.sh - -build/src/%.o: src/%.c charmap.txt $(PREPROC) +build/src/%.o: src/%.c charmap.txt @mkdir -p build/src (echo '#line 1 "$<"' && $(PREPROC) "$<" charmap.txt) | $(CC) $(CFLAGS) -o "$@" - @@ -76,17 +61,12 @@ build/linked.o: $(OBJ_FILES) rom.ld @mkdir -p build $(LD) $(LDFLAGS) $(OBJ_FILES) -o "$@" -test.gba: rom.gba main.asm build/linked.o $(MAIN_ASM_INCLUDES) build/src/sInGameTrades.o +test.gba: rom.gba main.asm build/linked.o $(MAIN_ASM_INCLUDES) $(eval NEEDED_BYTES = $(shell PATH="$(PATH)" $(SIZE) $(SIZEFLAGS) build/linked.o | awk 'FNR == 2 {print $$4}')) - $(ARMIPS) $(ARMIPS_FLAGS) main.asm -definelabel allocation $(shell $(FREESIA) $(FREESIA_FLAGS) --needed-bytes $(NEEDED_BYTES)) -equ allocation_size $(NEEDED_BYTES) + $(ARMIPS) $(ARMIPS_FLAGS) main.asm -definelabel allocation $(shell $(FREESIA) $(FREESIAFLAGS) --needed-bytes $(NEEDED_BYTES)) -equ allocation_size $(NEEDED_BYTES) -build/dep/src/%.d: src/%.c $(SCANINC) +build/dep/src/%.d: src/%.c @mkdir -p build/dep/src - @$(SCANINC) -I include $< | awk '{print "$(<:src/%.c=build/src/%.o) $@ : "$$0}' > "$@" + @$(SCANINC) $(HEADER_DIRS) $< | awk '{print "$(<:src/%.c=build/src/%.o) $@ : "$$0}' > "$@" include $(SRC_FILES:src/%.c=build/dep/src/%.d) - -# ------------------------------------------------------------------------------ - -src/sInGameTrades.c: rom.gba - $(TRADESCANTIA) $(TRADESCANTIA_FLAGS) --output "$@" diff --git a/project.mk b/project.mk new file mode 100644 index 0000000..ad8d92f --- /dev/null +++ b/project.mk @@ -0,0 +1,23 @@ +SRC_FILES = $(filter-out src/sInGameTrades.c, $(wildcard src/*.c)) + +EXTRA_CFLAGS = -D NUM_INGAME_TRADES=$(NUM_INGAME_TRADES) -D INSERT_INGAME_TRADE_HACK=$(INSERT_INGAME_TRADE_HACK) + +EXTRA_LDFLAGS = --defsym sInGameTradesPtr=$(sInGameTradesPtr) + +EXTRA_ARMIPS_FLAGS = -equ NUM_INGAME_TRADES $(NUM_INGAME_TRADES) -equ INSERT_INGAME_TRADE_HACK $(INSERT_INGAME_TRADE_HACK) + +TRADESCANTIA = $(PYTHON) tools/tradescantia +TRADESCANTIA_FLAGS = --rom rom.gba --pointer $(sInGameTradesPtr) --num-trades $(NUM_INGAME_TRADES) + +ifneq ($(ABILITYNUM_HAS_ALREADY_BEEN_MOVED),0) +TRADESCANTIA_FLAGS += --modified-format +endif + +sInGameTradesPtr = 0x08053CA4 + +# ------------------------------------------------------------------------------ + +src/sInGameTrades.c: rom.gba + $(TRADESCANTIA) $(TRADESCANTIA_FLAGS) --output "$@" + +test.gba: build/src/sInGameTrades.o