diff --git a/Makefile b/Makefile index 07143e4ad..d39b9fb2d 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,28 @@ TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 -ifeq ($(CC),) -HOSTCC := gcc -else -HOSTCC := $(CC) -endif - -ifeq ($(CXX),) -HOSTCXX := g++ -else -HOSTCXX := $(CXX) -endif - +# check if dkP's base_tools makefile exists ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) -include $(TOOLCHAIN)/base_tools + include $(TOOLCHAIN)/base_tools +# otherwise, either use the bin files or the +# arm-none-eabi binaries on the system else -export PATH := $(TOOLCHAIN)/bin:$(PATH) -PREFIX := arm-none-eabi- -OBJCOPY := $(PREFIX)objcopy -export CC := $(PREFIX)gcc -export AS := $(PREFIX)as + ifneq ($(TOOLCHAIN),) + export PATH := $(TOOLCHAIN)/bin:$(PATH) + endif + PREFIX := arm-none-eabi- + OBJCOPY := $(PREFIX)objcopy + # note: the makefile must be set up so MODERNCC is never called + # if MODERN=0 + export MODERNCC := $(PREFIX)gcc + export AS := $(PREFIX)as endif + +ifneq ($(TOOLCHAIN),) export CPP := $(PREFIX)cpp +else +export CPP := $(CC) -E +endif export LD := $(PREFIX)ld ifeq ($(OS),Windows_NT) @@ -37,6 +37,16 @@ MAKER_CODE := 01 REVISION := 0 MODERN ?= 0 +ROM_NAME := pokeemerald.gba +ELF_NAME := $(ROM_NAME:.gba=.elf) +MAP_NAME := $(ROM_NAME:.gba=.map) +OBJ_DIR_NAME := build/emerald + +MODERN_ROM_NAME := pokeemerald_modern.gba +MODERN_ELF_NAME := $(MODERN_ROM_NAME:.gba=.elf) +MODERN_MAP_NAME := $(MODERN_ROM_NAME:.gba=.map) +MODERN_OBJ_DIR_NAME := build/modern + SHELL := /bin/bash -o pipefail ELF = $(ROM:.gba=.elf) @@ -64,18 +74,18 @@ ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN) ifeq ($(MODERN),0) CC1 := tools/agbcc/bin/agbcc$(EXE) override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm -ROM := pokeemerald.gba -OBJ_DIR := build/emerald +ROM := $(ROM_NAME) +OBJ_DIR := $(OBJ_DIR_NAME) LIBPATH := -L ../../tools/agbcc/lib else -CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet +CC1 = $(shell $(MODERNCC) --print-prog-name=cc1) -quiet override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -ROM := pokeemerald_modern.gba -OBJ_DIR := build/modern -LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" +ROM := $(MODERN_ROM_NAME) +OBJ_DIR := $(MODERN_OBJ_DIR_NAME) +LIBPATH := -L "$(dir $(shell $(MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(MODERNCC) -mthumb -print-file-name=libc.a))" endif -CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=$(MODERN) +CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=$(MODERN) -nostdinc -undef ifeq ($(MODERN),0) CPPFLAGS += -I tools/agbcc/include -I tools/agbcc endif @@ -111,7 +121,7 @@ MAKEFLAGS += --no-print-directory # Secondary expansion is required for dependency variables in object rules. .SECONDEXPANSION: -.PHONY: all rom clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern +.PHONY: all rom clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern tidymodern tidynonmodern infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line)))) @@ -162,7 +172,7 @@ all: rom tools: $(TOOLDIRS) $(TOOLDIRS): - @$(MAKE) -C $@ CC=$(HOSTCC) CXX=$(HOSTCXX) + @$(MAKE) -C $@ rom: $(ROM) ifeq ($(COMPARE),1) @@ -177,7 +187,7 @@ clean: mostlyclean clean-tools clean-tools: @$(foreach tooldir,$(TOOLDIRS),$(MAKE) clean -C $(tooldir);) -mostlyclean: tidy +mostlyclean: tidynonmodern tidymodern rm -f $(SAMPLE_SUBDIR)/*.bin rm -f $(CRY_SUBDIR)/*.bin rm -f $(MID_SUBDIR)/*.s @@ -192,10 +202,15 @@ mostlyclean: tidy tidy: rm -f $(ROM) $(ELF) $(MAP) rm -r $(OBJ_DIR) -ifeq ($(MODERN),0) - @$(MAKE) tidy MODERN=1 -endif +tidynonmodern: + rm -f $(ROM_NAME) $(ELF_NAME) $(MAP_NAME) + rm -rf $(OBJ_DIR_NAME) + +tidymodern: + rm -f $(MODERN_ROM_NAME) $(MODERN_ELF_NAME) $(MODERN_MAP_NAME) + rm -rf $(MODERN_OBJ_DIR_NAME) + ifneq ($(MODERN),0) $(C_BUILDDIR)/berry_crush.o: override CFLAGS += -Wno-address-of-packed-member endif @@ -296,11 +311,11 @@ endif ifeq ($(NODEP),1) $(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s - $(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@ + $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ else define DATA_ASM_DEP $1: $2 $$(shell $(SCANINC) -I include -I "" $2) - $$(PREPROC) $$< charmap.txt | $$(CPP) -I include | $$(AS) $$(ASFLAGS) -o $$@ + $$(PREPROC) $$< charmap.txt | $$(CPP) -I include - | $$(AS) $$(ASFLAGS) -o $$@ endef $(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) endif diff --git a/berry_fix/Makefile b/berry_fix/Makefile index 0ead3804f..dd52792ec 100644 --- a/berry_fix/Makefile +++ b/berry_fix/Makefile @@ -1,28 +1,26 @@ TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 -ifeq ($(CC),) -HOSTCC := gcc -else -HOSTCC := $(CC) -endif - -ifeq ($(CXX),) -HOSTCXX := g++ -else -HOSTCXX := $(CXX) -endif - +# check if dkP's base_tools makefile exists ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) -include $(TOOLCHAIN)/base_tools + include $(TOOLCHAIN)/base_tools +# otherwise, either use the bin files or the +# arm-none-eabi binaries on the system else -export PATH := $(TOOLCHAIN)/bin:$(PATH) -PREFIX := arm-none-eabi- -OBJCOPY := $(PREFIX)objcopy -export CC := $(PREFIX)gcc -export AS := $(PREFIX)as + ifneq ($(TOOLCHAIN),) + export PATH := $(TOOLCHAIN)/bin:$(PATH) + endif + PREFIX := arm-none-eabi- + OBJCOPY := $(PREFIX)objcopy + export MODERNCC := $(PREFIX)gcc + export AS := $(PREFIX)as endif + +ifneq ($(TOOLCHAIN),) export CPP := $(PREFIX)cpp +else +export CPP := $(CC) -E +endif export LD := $(PREFIX)ld ifeq ($(OS),Windows_NT) diff --git a/berry_fix/payload/Makefile b/berry_fix/payload/Makefile index a121fda93..20d3d60c8 100644 --- a/berry_fix/payload/Makefile +++ b/berry_fix/payload/Makefile @@ -1,28 +1,26 @@ TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 -ifeq ($(CC),) -HOSTCC := gcc -else -HOSTCC := $(CC) -endif - -ifeq ($(CXX),) -HOSTCXX := g++ -else -HOSTCXX := $(CXX) -endif - +# check if dkP's base_tools makefile exists ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) -include $(TOOLCHAIN)/base_tools + include $(TOOLCHAIN)/base_tools +# otherwise, either use the bin files or the +# arm-none-eabi binaries on the system else -export PATH := $(TOOLCHAIN)/bin:$(PATH) -PREFIX := arm-none-eabi- -OBJCOPY := $(PREFIX)objcopy -export CC := $(PREFIX)gcc -export AS := $(PREFIX)as + ifneq ($(TOOLCHAIN),) + export PATH := $(TOOLCHAIN)/bin:$(PATH) + endif + PREFIX := arm-none-eabi- + OBJCOPY := $(PREFIX)objcopy + export MODERNCC := $(PREFIX)gcc + export AS := $(PREFIX)as endif + +ifneq ($(TOOLCHAIN),) export CPP := $(PREFIX)cpp +else +export CPP := $(CC) -E +endif export LD := $(PREFIX)ld ifeq ($(OS),Windows_NT) diff --git a/libagbsyscall/Makefile b/libagbsyscall/Makefile index 911cdb237..6c0ba681e 100644 --- a/libagbsyscall/Makefile +++ b/libagbsyscall/Makefile @@ -1,30 +1,27 @@ TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 -ifeq ($(CC),) -HOSTCC := gcc -else -HOSTCC := $(CC) -endif - -ifeq ($(CXX),) -HOSTCXX := g++ -else -HOSTCXX := $(CXX) -endif - +# check if dkP's base_tools makefile exists ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) -include $(TOOLCHAIN)/base_tools + include $(TOOLCHAIN)/base_tools +# otherwise, either use the bin files or the +# arm-none-eabi binaries on the system else -export PATH := $(TOOLCHAIN)/bin:$(PATH) -PREFIX := arm-none-eabi- -OBJCOPY := $(PREFIX)objcopy -export CC := $(PREFIX)gcc -export AS := $(PREFIX)as + ifneq ($(TOOLCHAIN),) + export PATH := $(TOOLCHAIN)/bin:$(PATH) + endif + PREFIX := arm-none-eabi- + OBJCOPY := $(PREFIX)objcopy + export MODERNCC := $(PREFIX)gcc + export AS := $(PREFIX)as endif -export CPP := $(PREFIX)cpp -export LD := $(PREFIX)ld +ifneq ($(TOOLCHAIN),) +export CPP := $(PREFIX)cpp +else +export CPP := $(CC) -E +endif +export LD := $(PREFIX)ld ifeq ($(OS),Windows_NT) EXE := .exe else diff --git a/map_data_rules.mk b/map_data_rules.mk index 0203b383d..626cd4724 100755 --- a/map_data_rules.mk +++ b/map_data_rules.mk @@ -9,9 +9,9 @@ MAP_EVENTS := $(patsubst $(MAPS_DIR)/%/,$(MAPS_DIR)/%/events.inc,$(MAP_DIRS)) MAP_HEADERS := $(patsubst $(MAPS_DIR)/%/,$(MAPS_DIR)/%/header.inc,$(MAP_DIRS)) $(DATA_ASM_BUILDDIR)/maps.o: $(DATA_ASM_SUBDIR)/maps.s $(LAYOUTS_DIR)/layouts.inc $(LAYOUTS_DIR)/layouts_table.inc $(MAPS_DIR)/headers.inc $(MAPS_DIR)/groups.inc $(MAPS_DIR)/connections.inc $(MAP_CONNECTIONS) $(MAP_HEADERS) - $(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@ + $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ $(DATA_ASM_BUILDDIR)/map_events.o: $(DATA_ASM_SUBDIR)/map_events.s $(MAPS_DIR)/events.inc $(MAP_EVENTS) - $(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@ + $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ $(MAPS_DIR)/%/header.inc: $(MAPS_DIR)/%/map.json $(MAPJSON) map emerald $< $(LAYOUTS_DIR)/layouts.json