Skip to content

Commit

Permalink
explicitly build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeturic committed Mar 13, 2020
1 parent d8030b6 commit e177284
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 48 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions build_tools.sh
Original file line number Diff line number Diff line change
@@ -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
56 changes: 18 additions & 38 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,67 @@ 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

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 "$@" -

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 "$@"
23 changes: 23 additions & 0 deletions project.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e177284

Please sign in to comment.