Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use $(PRET) tools install #813

Closed
wants to merge 10 commits into from
Closed
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ install:
- pushd $HOME
- travis_retry wget https://github.com/devkitPro/buildscripts/releases/download/devkitARM_r50/devkitARM_r50-linux.tar.xz
- tar xJf devkitARM*.tar.xz
- travis_retry git clone https://github.com/pret/agbcc.git
- cd agbcc && ./build.sh && ./install.sh $TRAVIS_BUILD_DIR
- popd
- ./install-tools.sh
matrix:
include:
- os: linux
Expand Down
24 changes: 10 additions & 14 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,36 @@
[wsl2]: https://docs.microsoft.com/windows/wsl/wsl2-install
[wsl]: https://docs.microsoft.com/windows/wsl/install-win10


The [prerelease version of the Linux subsystem](https://docs.microsoft.com/windows/wsl/install-legacy) available in the 1607 and 1703 releases of Windows 10 is obsolete so consider uninstalling it.

Make sure that the `build-essential`, `git`, and `libpng-dev` packages are installed. The `build-essential` package includes the `make`, `gcc-core`, and `g++` packages so they do not have to be obtained separately. MSYS2 does not include `libpng-dev` so it must be built from source.
Make sure that the <code>build-essential</code><sup>Debian</sup>/<code>base-devel</code><sup>Arch</sup> package group and `git` are installed.

Install the **devkitARM** toolchain of [devkitPro](https://devkitpro.org/wiki/Getting_Started) and add its environment variables. For Windows versions without the Linux subsystem, the devkitPro [graphical installer](https://github.com/devkitPro/installer/releases) includes a preconfigured MSYS2 environment, thus the steps below are not required.

export DEVKITPRO=/opt/devkitpro
echo "export DEVKITPRO=$DEVKITPRO" >> ~/.bashrc
export DEVKITARM=$DEVKITPRO/devkitARM
echo "export DEVKITARM=$DEVKITARM" >> ~/.bashrc

Place the above code in your `~/.bash_profile` and restart your shell for changes to take effect.

Install the pret tools using the `./install-tools.sh` script in the repository root. This automatically downloads & installs precompiled binaries for your current platform of all the tools used to compile pokeemerald, including `agbcc`. Alternatively, you can easily build, package and/or install them from source using the [`grups` tool](https://code.caveoforig.in/fhtk/grups).

# Installation

To set up the repository:

git clone https://github.com/pret/pokeemerald
git clone https://github.com/pret/agbcc

cd ./agbcc
./build.sh
./install.sh ../pokeemerald

cd ../pokeemerald
cd pokeemerald
make

To build **pokeemerald.gba** and confirm it matches the official ROM image:

make compare

## Notes

* If the base tools are not found on macOS in new Terminal sessions after the first successful build, run `echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile` once to prevent the issue from occurring again. Verify that the `devkitarm-rules` package is installed as well; if not, install it by running `sudo dkp-pacman -S devkitarm-rules`.

* If the repository was previously set up using Cygwin, delete the `.exe` files in the subfolders of the `tools` folder except for `agbcc` and try building again. [Learn the differences between MSYS2 and Cygwin.](https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-from-Cygwin)
- Verify that the `devkitarm-rules` package is installed as well; if not, install it by running `sudo dkp-pacman -S devkitarm-rules`.
- If the repository was previously set up using Cygwin, delete the `.exe` files in the subfolders of the `tools` folder except for `agbcc` and try building again. [Learn the differences between MSYS2 and Cygwin.](https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-from-Cygwin)

# Guidance

Expand All @@ -57,7 +53,7 @@ To speed up building, run:

make -j$(nproc)

`nproc` is not available on macOS. The alternative is `sysctl -n hw.ncpu` ([relevant Stack Overflow thread](https://stackoverflow.com/questions/1715580)).
To use `nproc` on macOS, install GNU coreutils with homebrew by running `brew install coreutils`. Alternatively, use `sysctl -n hw.ncpu` instead. ([source](https://stackoverflow.com/questions/1715580)).

## Building without dependency scanning

Expand Down
83 changes: 44 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ COMPARE ?= 0

ifeq ($(CC),)
HOSTCC := gcc
# use system clang on macOS; GCC is wonky w/ homebrew sometimes
ifneq ($(OS),Windows_NT)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
HOSTCC := /usr/bin/clang
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Just no.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, yes. the gcc command is ambiguous asf on macOS. we should stick to the system compiler unless otherwise specified

endif
endif
else
HOSTCC := $(CC)
endif

ifeq ($(CXX),)
HOSTCXX := g++
# use system clang++ on macOS; see above
ifneq ($(OS),Windows_NT)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
HOSTCC := /usr/bin/clang++
endif
endif
else
HOSTCXX := $(CXX)
endif
Expand All @@ -31,6 +45,19 @@ else
EXE :=
endif

# system-friendly install of tools
export PRET := /opt/pret

export GFX := $(PRET)/bin/gbagfx$(EXE)
export AIF := $(PRET)/bin/aif2pcm$(EXE)
export MID := $(PRET)/bin/mid2agb$(EXE)
export SCANINC := $(PRET)/bin/scaninc$(EXE)
export PREPROC := $(PRET)/bin/preproc$(EXE)
export RAMSCRGEN := $(PRET)/bin/ramscrgen$(EXE)
export FIX := $(PRET)/bin/gbafix$(EXE)
export MAPJSON := $(PRET)/bin/mapjson$(EXE)
export JSONPROC := $(PRET)/bin/jsonproc$(EXE)

TITLE := POKEMON EMER
GAME_CODE := BPEE
MAKER_CODE := 01
Expand Down Expand Up @@ -60,11 +87,11 @@ ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN)
GCC_VER = $(shell $(CC) -dumpversion)

ifeq ($(MODERN),0)
CC1 := tools/agbcc/bin/agbcc$(EXE)
CC1 := $(PRET)/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm
ROM := pokeemerald.gba
OBJ_DIR := build/emerald
LIBPATH := -L ../../tools/agbcc/lib
LIBPATH := -L $(PRET)/lib
else
CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet
override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast
Expand All @@ -75,49 +102,33 @@ endif

CPPFLAGS := -iquote include -Wno-trigraphs -DMODERN=$(MODERN)
ifeq ($(MODERN),0)
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc
CPPFLAGS += -I $(PRET)/include -I $(PRET)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add -nostdinc -undef here

endif

LDFLAGS = -Map ../../$(MAP)

LIB := $(LIBPATH) -lgcc -lc

SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
GFX := tools/gbagfx/gbagfx$(EXE)
AIF := tools/aif2pcm/aif2pcm$(EXE)
MID := tools/mid2agb/mid2agb$(EXE)
SCANINC := tools/scaninc/scaninc$(EXE)
PREPROC := tools/preproc/preproc$(EXE)
RAMSCRGEN := tools/ramscrgen/ramscrgen$(EXE)
FIX := tools/gbafix/gbafix$(EXE)
MAPJSON := tools/mapjson/mapjson$(EXE)
JSONPROC := tools/jsonproc/jsonproc$(EXE)

TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*))
TOOLBASE = $(TOOLDIRS:tools/%=%)
TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))

MAKEFLAGS += --no-print-directory

# Clear the default suffixes
.SUFFIXES:
# Don't delete intermediate files
# Dont delete intermediate files
.SECONDARY:
# Delete files that weren't built properly
# Delete files that werent built properly
.DELETE_ON_ERROR:

# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:

.PHONY: all rom clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix
.PHONY: all rom clean compare tidy berry_fix

infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))

# Build tools when building the rom
# Disable dependency scanning for clean/tidy/tools
ifeq (,$(filter-out all compare,$(MAKECMDGOALS)))
$(call infoshell, $(MAKE) tools)
else
# Disable dependency scanning for clean/tidy
ifneq (,$(filter-out all compare,$(MAKECMDGOALS)))
NODEP := 1
endif

Expand Down Expand Up @@ -161,15 +172,10 @@ ifeq ($(COMPARE),1)
@$(SHA1) rom.sha1
endif

# For contributors to make sure a change didn't affect the contents of the ROM.
# For contributors to make sure a change didnt affect the contents of the ROM.
compare: ; @$(MAKE) COMPARE=1

clean: mostlyclean clean-tools

clean-tools:
@$(foreach tooldir,$(TOOLDIRS),$(MAKE) clean -C $(tooldir);)

mostlyclean: tidy
clean: tidy
rm -f sound/direct_sound_samples/*.bin
rm -f $(MID_SUBDIR)/*.s
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
Expand Down Expand Up @@ -211,9 +217,8 @@ include songs.mk
sound/direct_sound_samples/cry_%.bin: sound/direct_sound_samples/cry_%.aif ; $(AIF) $< $@ --compress
sound/%.bin: sound/%.aif ; $(AIF) $< $@


ifeq ($(MODERN),0)
$(C_BUILDDIR)/libc.o: CC1 := tools/agbcc/bin/old_agbcc
$(C_BUILDDIR)/libc.o: CC1 := $(PRET)/bin/old_agbcc
$(C_BUILDDIR)/libc.o: CFLAGS := -O2

$(C_BUILDDIR)/siirtc.o: CFLAGS := -mthumb-interwork
Expand All @@ -222,15 +227,15 @@ $(C_BUILDDIR)/agb_flash.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork

$(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc
$(C_BUILDDIR)/m4a.o: CC1 := $(PRET)/bin/old_agbcc

$(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding
endif

ifeq ($(NODEP),1)
$(C_BUILDDIR)/%.o: c_dep :=
else
$(C_BUILDDIR)/%.o: c_dep = $(shell [[ -f $(C_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I tools/agbcc/include $(C_SUBDIR)/$*.c)
$(C_BUILDDIR)/%.o: c_dep = $(shell [[ -f $(C_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I $(PRET)/include $(C_SUBDIR)/$*.c)
endif

ifeq ($(DINFO),1)
Expand All @@ -246,7 +251,7 @@ $(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep)
ifeq ($(NODEP),1)
$(C_BUILDDIR)/%.o: c_asm_dep :=
else
$(C_BUILDDIR)/%.o: c_asm_dep = $(shell [[ -f $(C_SUBDIR)/$*.s ]] && $(SCANINC) -I "" $(C_SUBDIR)/$*.s)
$(C_BUILDDIR)/%.o: c_asm_dep = $(shell [[ -f $(C_SUBDIR)/$*.s ]] && $(SCANINC) -I $(PRET)/include -I "" $(C_SUBDIR)/$*.s)
endif

$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $$(c_asm_dep)
Expand All @@ -255,7 +260,7 @@ $(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $$(c_asm_dep)
ifeq ($(NODEP),1)
$(ASM_BUILDDIR)/%.o: asm_dep :=
else
$(ASM_BUILDDIR)/%.o: asm_dep = $(shell $(SCANINC) -I "" $(ASM_SUBDIR)/$*.s)
$(ASM_BUILDDIR)/%.o: asm_dep = $(shell $(SCANINC) -I $(PRET)/include -I "" $(ASM_SUBDIR)/$*.s)
endif

$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(asm_dep)
Expand All @@ -264,7 +269,7 @@ $(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(asm_dep)
ifeq ($(NODEP),1)
$(DATA_ASM_BUILDDIR)/%.o: data_dep :=
else
$(DATA_ASM_BUILDDIR)/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $(DATA_ASM_SUBDIR)/$*.s)
$(DATA_ASM_BUILDDIR)/%.o: data_dep = $(shell $(SCANINC) -I $(PRET)/include -I include -I "" $(DATA_ASM_SUBDIR)/$*.s)
endif

$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s $$(data_dep)
Expand All @@ -287,7 +292,7 @@ LD_SCRIPT := ld_script.txt
LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
else
LD_SCRIPT := ld_script_modern.txt
LD_SCRIPT_DEPS :=
LD_SCRIPT_DEPS :=
endif

$(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ It builds the following ROM:

To set up the repository, see [INSTALL.md](INSTALL.md).


## See also

Other disassembly and/or decompilation projects:
Expand All @@ -30,7 +29,6 @@ Other disassembly and/or decompilation projects:
* [**Pokémon FireRed and LeafGreen**](https://github.com/pret/pokefirered)
* [**Pokémon Mystery Dungeon: Red Rescue Team**](https://github.com/pret/pmd-red)


## Contacts

You can find us on [Discord](https://discord.gg/6EuWgX9) and [IRC](https://kiwiirc.com/client/irc.freenode.net/?#pret).
23 changes: 12 additions & 11 deletions berry_fix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ REVISION := 0

SHELL := /bin/bash -o pipefail

CPPFLAGS := -I ../tools/agbcc/include -I ../tools/agbcc -iquote include -nostdinc -undef
PRET := /opt/pret

CPPFLAGS := -I $(PRET)/include -I $(PRET)/bin/agbcc -iquote include -nostdinc -undef

ROM := berry_fix.gba
OBJ_DIR := build
CC1 := ../tools/agbcc/bin/agbcc$(EXE)
CC1 := $(PRET)/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm


Expand All @@ -39,13 +41,13 @@ ASFLAGS := -mcpu=arm7tdmi
LDFLAGS = -Map ../$(MAP)

SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
GFX := ../tools/gbagfx/gbagfx$(EXE)
AIF := ../tools/aif2pcm/aif2pcm$(EXE)
MID := ../tools/mid2agb/mid2agb$(EXE)
SCANINC := ../tools/scaninc/scaninc$(EXE)
PREPROC := ../tools/preproc/preproc$(EXE)
RAMSCRGEN := ../tools/ramscrgen/ramscrgen$(EXE)
FIX := ../tools/gbafix/gbafix$(EXE)
GFX := $(PRET)/bin/gbagfx$(EXE)
AIF := $(PRET)/bin/aif2pcm$(EXE)
MID := $(PRET)/bin/mid2agb$(EXE)
SCANINC := $(PRET)/bin/scaninc$(EXE)
PREPROC := $(PRET)/bin/preproc$(EXE)
RAMSCRGEN := $(PRET)/bin/ramscrgen$(EXE)
FIX := $(PRET)/bin/gbafix$(EXE)

# Clear the default suffixes
.SUFFIXES:
Expand Down Expand Up @@ -120,7 +122,7 @@ tidy:
ifeq ($(NODEP),1)
$(C_BUILDDIR)/%.o: c_dep :=
else
$(C_BUILDDIR)/%.o: c_dep = $(shell $(SCANINC) -I include $(C_SUBDIR)/$*.c)
$(C_BUILDDIR)/%.o: c_dep = $(shell $(SCANINC) -I $(PRET)/include -I include $(C_SUBDIR)/$*.c)
endif

$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep)
Expand Down Expand Up @@ -163,4 +165,3 @@ $(ELF): ld_script.txt $(OBJS)
$(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@
$(FIX) $@ -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent

26 changes: 15 additions & 11 deletions berry_fix/payload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ endif

SHELL := /bin/bash -o pipefail

CPPFLAGS := -I ../../tools/agbcc/include -I ../../tools/agbcc -iquote include -nostdinc -undef
PRET := /opt/pret

CPPFLAGS := -I $(PRET)/include -I $(PRET) -iquote include -nostdinc -undef

ROM := payload.gba
OBJ_DIR := build
CC1 := ../../tools/agbcc/bin/agbcc$(EXE)
CC1 := $(PRET)/bin/agbcc$(EXE)
override CC1FLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm


Expand All @@ -34,16 +36,19 @@ ASFLAGS := -mcpu=arm7tdmi

LDFLAGS = -Map ../$(MAP)

LIB := -L ../../../tools/agbcc/lib -lgcc
LIB := -L $(PRET)/lib -lgcc

SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
GFX := ../../tools/gbagfx/gbagfx$(EXE)
AIF := ../../tools/aif2pcm/aif2pcm$(EXE)
MID := ../../tools/mid2agb/mid2agb$(EXE)
SCANINC := ../../tools/scaninc/scaninc$(EXE)
PREPROC := ../../tools/preproc/preproc$(EXE)
RAMSCRGEN := ../../tools/ramscrgen/ramscrgen$(EXE)
FIX := ../../tools/gbafix/gbafix$(EXE)

export GFX := $(PRET)/bin/gbagfx$(EXE)
export AIF := $(PRET)/bin/aif2pcm$(EXE)
export MID := $(PRET)/bin/mid2agb$(EXE)
export SCANINC := $(PRET)/bin/scaninc$(EXE)
export PREPROC := $(PRET)/bin/preproc$(EXE)
export RAMSCRGEN := $(PRET)/bin/ramscrgen$(EXE)
export FIX := $(PRET)/bin/gbafix$(EXE)
export MAPJSON := $(PRET)/bin/mapjson$(EXE)
export JSONPROC := $(PRET)/bin/jsonproc$(EXE)

# Clear the default suffixes
.SUFFIXES:
Expand Down Expand Up @@ -169,4 +174,3 @@ $(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS)

$(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@

Loading