From 649b160292cd316a252c4d6c6999de020035ee8a Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 12 Apr 2016 04:48:35 +0200 Subject: [PATCH] Use better makefiles for loader and the screen init stub --- loader/Makefile | 134 +++++++++--------------------- loader/{stub.ld => linker.ld} | 1 - loader/stub.specs | 5 -- screeninit/Makefile | 125 +++++++--------------------- screeninit/{stub.ld => linker.ld} | 0 screeninit/stub.specs | 5 -- 6 files changed, 65 insertions(+), 205 deletions(-) rename loader/{stub.ld => linker.ld} (99%) delete mode 100644 loader/stub.specs rename screeninit/{stub.ld => linker.ld} (100%) delete mode 100755 screeninit/stub.specs diff --git a/loader/Makefile b/loader/Makefile index 8f9c035e..c8b41bc8 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -1,6 +1,4 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- +rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) ifeq ($(strip $(DEVKITARM)),) $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") @@ -8,108 +6,50 @@ endif include $(DEVKITARM)/3ds_rules -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# SPECS is the directory containing the important build and link files -#--------------------------------------------------------------------------------- -export TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source source/fatfs source/fatfs/sdmmc source/fatfs/option +CC := arm-none-eabi-gcc +AS := arm-none-eabi-as +LD := arm-none-eabi-ld +OC := arm-none-eabi-objcopy -#--------------------------------------------------------------------------------- -# Setup some defines -#--------------------------------------------------------------------------------- +name := $(shell basename $(CURDIR)) -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork +dir_source := source +dir_build := build -CFLAGS := -g -Wall -O2 -flto\ - -march=armv5te -mtune=arm946e-s\ - -ffast-math -Wno-main -std=c99\ - $(ARCH) +ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te +CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork -CFLAGS += $(INCLUDE) -DARM9 +objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ + $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ + $(call rwildcard, $(dir_source), *.s *.c))) -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions +.PHONY: all +all: $(name).bin -ASFLAGS := -g $(ARCH) -LDFLAGS = -nostartfiles -g --specs=../stub.specs $(ARCH) -Wl,-Map,$(TARGET).map - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- +.PHONY: clean clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).bin : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) + @rm -rf $(dir_build) +$(name).bin: $(dir_build)/$(name).elf + $(OC) -S -O binary $< $@ -#--------------------------------------------------------------------------------- -%.bin: %.elf - @$(OBJCOPY) -O binary $< $@ - @echo built ... $(notdir $@) - +$(dir_build)/$(name).elf: $(objects) + # FatFs requires libgcc for __aeabi_uidiv + $(CC) -nostartfiles -T linker.ld $(OUTPUT_OPTION) $^ --include $(DEPENDS) +$(dir_build)/%.o: $(dir_source)/%.c + @mkdir -p "$(@D)" + $(COMPILE.c) $(OUTPUT_OPTION) $< - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- +$(dir_build)/%.o: $(dir_source)/%.s + @mkdir -p "$(@D)" + $(COMPILE.s) $(OUTPUT_OPTION) $< + +$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c + @mkdir -p "$(@D)" + $(COMPILE.c) $(OUTPUT_OPTION) $< + +$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s + @mkdir -p "$(@D)" + $(COMPILE.s) $(OUTPUT_OPTION) $< +include $(call rwildcard, $(dir_build), *.d) diff --git a/loader/stub.ld b/loader/linker.ld similarity index 99% rename from loader/stub.ld rename to loader/linker.ld index 8ad4b141..a7775c8b 100644 --- a/loader/stub.ld +++ b/loader/linker.ld @@ -9,4 +9,3 @@ SECTIONS .rodata : { *(.rodata) } . = ALIGN(4); } - diff --git a/loader/stub.specs b/loader/stub.specs deleted file mode 100644 index b6c2098c..00000000 --- a/loader/stub.specs +++ /dev/null @@ -1,5 +0,0 @@ -%rename link old_link - -*link: -%(old_link) -T ../stub.ld%s - diff --git a/screeninit/Makefile b/screeninit/Makefile index 21ec57fc..a6e3e42e 100755 --- a/screeninit/Makefile +++ b/screeninit/Makefile @@ -1,6 +1,4 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- +rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) ifeq ($(strip $(DEVKITARM)),) $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") @@ -8,108 +6,41 @@ endif include $(DEVKITARM)/3ds_rules -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# SPECS is the directory containing the important build and link files -#--------------------------------------------------------------------------------- -export TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := source +CC := arm-none-eabi-gcc +AS := arm-none-eabi-as +LD := arm-none-eabi-ld +OC := arm-none-eabi-objcopy -#--------------------------------------------------------------------------------- -# Setup some defines -#--------------------------------------------------------------------------------- +name := $(shell basename $(CURDIR)) -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork +dir_source := source +dir_build := build -CFLAGS := -g -Wall -O2 -flto\ - -mcpu=mpcore -mlittle-endian\ - -ffast-math -Wno-main -std=c99\ - $(ARCH) +ASFLAGS := -mlittle-endian -mcpu=mpcore +CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork -CFLAGS += $(INCLUDE) -DARM11 +objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ + $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ + $(call rwildcard, $(dir_source), *.s *.c))) -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions +.PHONY: all +all: $(name).bin -ASFLAGS := -g $(ARCH) -LDFLAGS = -nostartfiles -g --specs=../stub.specs $(ARCH) -Wl,-Map,$(TARGET).map - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- +.PHONY: clean clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).bin : $(OUTPUT).elf -$(OUTPUT).elf : $(OFILES) + @rm -rf $(dir_build) +$(name).bin: $(dir_build)/$(name).elf + $(OC) -S -O binary $< $@ -#--------------------------------------------------------------------------------- -%.bin: %.elf - @$(OBJCOPY) -O binary $< $@ - @echo built ... $(notdir $@) - +$(dir_build)/$(name).elf: $(objects) + $(CC) -nostartfiles -T linker.ld $(OUTPUT_OPTION) $^ --include $(DEPENDS) +$(dir_build)/%.o: $(dir_source)/%.c + @mkdir -p "$(@D)" + $(COMPILE.c) $(OUTPUT_OPTION) $< - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- +$(dir_build)/%.o: $(dir_source)/%.s + @mkdir -p "$(@D)" + $(COMPILE.s) $(OUTPUT_OPTION) $< +include $(call rwildcard, $(dir_build), *.d) diff --git a/screeninit/stub.ld b/screeninit/linker.ld similarity index 100% rename from screeninit/stub.ld rename to screeninit/linker.ld diff --git a/screeninit/stub.specs b/screeninit/stub.specs deleted file mode 100755 index b6c2098c..00000000 --- a/screeninit/stub.specs +++ /dev/null @@ -1,5 +0,0 @@ -%rename link old_link - -*link: -%(old_link) -T ../stub.ld%s -