# SPDX-License-Identifier: CC0-1.0 # # SPDX-FileContributor: Antonio Niño Díaz, 2023 export BLOCKSDS ?= /opt/wonderful/thirdparty/blocksds/core export BLOCKSDSEXT ?= /opt/wonderful/thirdparty/blocksds/external export WONDERFUL_TOOLCHAIN ?= /opt/wonderful ARM_NONE_EABI_PATH ?= $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-arm-none-eabi/bin/ SOURCEDIRS := src INCLUDEDIRS := DEFINES := -DPLAT_NDS LIBS := -ldswifi9 -lnds9 -lc LIBDIRS := $(BLOCKSDS)/libs/dswifi $(BLOCKSDS)/libs/libnds NAME := cc-arm9 BUILDDIR := build-nds ELF := build-nds/$(NAME).elf DUMP := build-nds/$(NAME).dump MAP := build-nds/$(NAME).map # Tools # ----- PREFIX := $(ARM_NONE_EABI_PATH)arm-none-eabi- CC := $(PREFIX)gcc CXX := $(PREFIX)g++ LD := $(PREFIX)gcc # Source files # ------------ SOURCES_S := $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.s)) SOURCES_C := $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c)) # Compiler and linker flags # ------------------------- ARCH := -mthumb -mcpu=arm946e-s+nofp SPECS := $(BLOCKSDS)/sys/crts/ds_arm9.specs WARNFLAGS := -Wall INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \ $(foreach path,$(LIBDIRS),-I$(path)/include) LIBDIRSFLAGS := $(foreach path,$(LIBDIRS),-L$(path)/lib) ASFLAGS += -x assembler-with-cpp $(DEFINES) $(INCLUDEFLAGS) \ $(ARCH) -ffunction-sections -fdata-sections \ -specs=$(SPECS) CFLAGS += -std=gnu17 $(WARNFLAGS) $(DEFINES) $(INCLUDEFLAGS) \ $(ARCH) -O2 -ffunction-sections -fdata-sections \ -specs=$(SPECS) LDFLAGS := $(ARCH) $(LIBDIRSFLAGS) -Wl,-Map,$(MAP) $(DEFINES) \ -Wl,--start-group $(LIBS) -Wl,--end-group -specs=$(SPECS) # Intermediate build files # ------------------------ OBJS := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_S))) \ $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_C))) DEPS := $(OBJS:.o=.d) # Targets # ------- .PHONY: all all: $(ELF) $(ELF): $(OBJS) $(LD) -o $@ $(OBJS) $(LDFLAGS) # Rules # ----- $(BUILDDIR)/%.s.o : %.s @mkdir -p $(@D) $(CC) $(ASFLAGS) -MMD -MP -c -o $@ $< $(BUILDDIR)/%.c.o : %.c @mkdir -p $(@D) $(CC) $(CFLAGS) -MMD -MP -c -o $@ $< $(BUILDDIR)/%.arm.c.o : %.arm.c @mkdir -p $(@D) $(CC) $(CFLAGS) -MMD -MP -marm -mlong-calls -c -o $@ $< # Include dependency files if they exist # -------------------------------------- -include $(DEPS)