Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
linker.ld.pp
include/**/*.s
tools/*.txt
tools/agbcc
.vscode

err.log
59 changes: 43 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ endif
BASEROM := $(TARGET)_baserom.gba
TARGET := $(TARGET).gba

# Default target
.PHONY: all
all: $(TARGET)

ELF = $(TARGET:.gba=.elf)
MAP = $(TARGET:.gba=.map)
SHA1FILE = $(TARGET:.gba=.sha1)
Expand Down Expand Up @@ -82,10 +86,11 @@ SHA1SUM = sha1sum
TAIL = tail

# Tools
GBAFIX = tools/gbafix/gbafix
include make_tools.mk
GBAFIX = $(TOOLS_DIR)/gbafix/gbafix
PYTHON = python3
EXTRACTOR = tools/extractor.py
PREPROC = tools/preproc/preproc
EXTRACTOR = $(PYTHON) $(TOOLS_DIR)/extractor.py
PREPROC = $(TOOLS_DIR)/preproc/preproc

# Flags
ASFLAGS += -mcpu=arm7tdmi
Expand All @@ -99,10 +104,17 @@ CSRC = $(wildcard src/**.c) $(wildcard src/**/**.c) $(wildcard src/**/**/**.c)
ASMSRC = $(CSRC:.c=.s) $(wildcard asm/*.s) $(wildcard sound/*.s) $(wildcard sound/**/*.s)
OBJ = $(ASMSRC:.s=.o)

# Dynamically find agbcc path and its lib folder
AGBCC_BIN := $(shell which agbcc)
AGBCC_DIR := $(dir $(AGBCC_BIN))/
AGBCC_LIB := $(abspath $(AGBCC_DIR))
# Detect if agbcc was installed into the project
ifneq (,$(wildcard tools/agbcc))
AGBCC_BIN := tools/agbcc/bin/agbcc
AGBCC_LIB := tools/agbcc/lib
CC = $(AGBCC_BIN)
else
# Dynamically find agbcc path and its lib folder
AGBCC_BIN := $(shell which agbcc)
AGBCC_DIR := $(dir $(AGBCC_BIN))/
AGBCC_LIB := $(abspath $(AGBCC_DIR))
endif

LIBS := $(AGBCC_LIB)/libgcc.a $(AGBCC_LIB)/libc.a

Expand All @@ -116,8 +128,24 @@ else
MSG = @echo " "
endif

.PHONY: all
all: $(TARGET)
# Rules that do not require scanning for dependencies
RULES_NO_SCAN += dump diff extract clean tidy

# Generate tools before building anything
SETUP_PREREQS ?= 1
# Disable generating tools for rules that do not build anything
ifneq (,$(MAKECMDGOALS))
ifeq (,$(filter-out $(RULES_NO_SCAN),$(MAKECMDGOALS)))
SETUP_PREREQS := 0
endif
endif
.SHELLSTATUS ?= 0
ifeq ($(SETUP_PREREQS),1)
$(foreach line, $(shell $(MAKE) -f make_tools.mk | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while building tools. See error messages above for more details)
endif
endif

.PHONY: check
check: all
Expand All @@ -135,10 +163,13 @@ diff: $(DUMPS)
.PHONY: extract
extract:
$(MSG) Extracting
$Q python3 tools/extractor.py -r $(REGION)
$Q$(EXTRACTOR) -r $(REGION)

.PHONY: clean
clean:
clean: clean-tools tidy

.PHONY: tidy
tidy:
$(MSG) RM roms
# Delete every gba file that doesn't end with baserom
$Qfind -type f -name "*.gba" -a ! -name "*baserom.gba" -delete
Expand Down Expand Up @@ -181,7 +212,7 @@ help:
@echo ' REGION=<region>: selects the region of the ROM, possible values are "us", "eu", "jp", "cn", and "eu_beta"'
@echo ' DEBUG=1: enables the debug code'

$(TARGET): $(ELF) $(GBAFIX)
$(TARGET): $(ELF)
$(MSG) OBJCOPY $@
$Q$(OBJCOPY) -O binary --gap-fill 0xff --pad-to $(PAD_TO) $< $@
$(MSG) GBAFIX $@
Expand Down Expand Up @@ -213,10 +244,6 @@ src/sram/%.s: src/sram/%.c
src/sprites_AI/%.s: CFLAGS = -O2 -mthumb-interwork -fhex-asm
src/sprites_AI/%.s: src/sram/%.c

tools/%: tools/%.c
$(MSG) HOSTCC $@
$Q$(HOSTCC) $< $(HOSTCFLAGS) $(HOSTCPPFLAGS) -o $@

.PHONY: us
# us_debug eu eu_debug eu_beta jp jp_debug cn cn_debug

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ The default built ROM is mf_us.gba
- Clone [agbcc](https://github.com/pret/agbcc) by running this command: `git clone https://github.com/pret/agbcc`
- Enter the agbcc folder (run `cd agbcc`) and build it (run `./build.sh`)
- Add agbcc to your path (`export PATH="<agbcc_path>:$PATH"`, where `<agbcc_path>` is the full path to the agbcc directory)
- Locate yourself in the decompilation root, and then build preproc (run `cd tools/preproc && make`)
- Either:
- Install agbcc into this project (by using its `./install.sh <path>` script, where `<path>` is the path to the root of this repository), or
- Add agbcc to your path (`export PATH="<agbcc_path>:$PATH"`, where `<agbcc_path>` is the full path to the agbcc directory)

## Build

Expand Down
26 changes: 26 additions & 0 deletions make_tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Make rules to build the tools used for compilation, inside `tools` folder.
ifeq ($(V),1)
Q =
MSG = @:
else
Q = @
MSG = @echo " "
endif

MAKEFLAGS += --no-print-directory

TOOLS_DIR := tools
# Tool executables to build
TOOLS := gbafix preproc

TOOLDIRS := $(TOOLS:%=$(TOOLS_DIR)/%)

.PHONY: tools clean-tools $(TOOLDIRS)

tools: $(TOOLDIRS)

$(TOOLDIRS):
$Q$(MAKE) -C $@

clean-tools:
$Q$(foreach tooldir, $(TOOLDIRS), $(MAKE) clean -C $(tooldir);)
30 changes: 30 additions & 0 deletions tools/gbafix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CC ?= gcc
RM ?= rm -f
ifeq ($(V),1)
Q =
MSG = @:
else
Q = @
MSG = @echo " "
endif

.PHONY: all clean

SRCS = gbafix.c

ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif

all: gbafix$(EXE)
@:

gbafix$(EXE): $(SRCS)
$(MSG) CC $@
$Q$(CC) $(SRCS) -o $@ $(LDFLAGS)

clean:
$(MSG) RM gbafix$(EXE)
$Q$(RM) gbafix gbafix.exe
14 changes: 12 additions & 2 deletions tools/preproc/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
CXX ?= g++
RM ?= rm -f
ifeq ($(V),1)
Q =
MSG = @:
else
Q = @
MSG = @echo " "
endif

CXXFLAGS := -std=c++11 -O2 -Wall -Wno-switch -Werror

Expand All @@ -20,7 +28,9 @@ all: preproc$(EXE)
@:

preproc$(EXE): $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS)
$(MSG) CXX $@
$Q$(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS)

clean:
$(RM) preproc preproc.exe
$(MSG) RM preproc$(EXE)
$Q$(RM) preproc preproc.exe