Use better makefiles for loader and the screen init stub

This commit is contained in:
Aurora 2016-04-12 04:48:35 +02:00
parent 697bc74535
commit 649b160292
6 changed files with 65 additions and 205 deletions

View File

@ -1,6 +1,4 @@
#--------------------------------------------------------------------------------- rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),) ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
@ -8,108 +6,50 @@ endif
include $(DEVKITARM)/3ds_rules include $(DEVKITARM)/3ds_rules
#--------------------------------------------------------------------------------- CC := arm-none-eabi-gcc
# TARGET is the name of the output AS := arm-none-eabi-as
# BUILD is the directory where object files & intermediate files will be placed LD := arm-none-eabi-ld
# SOURCES is a list of directories containing source code OC := arm-none-eabi-objcopy
# 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
#--------------------------------------------------------------------------------- name := $(shell basename $(CURDIR))
# Setup some defines
#---------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- dir_source := source
# options for code generation dir_build := build
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2 -flto\ ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
-march=armv5te -mtune=arm946e-s\ CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork
-ffast-math -Wno-main -std=c99\
$(ARCH)
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) .PHONY: clean
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
#---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @rm -rf $(dir_build)
@rm -fr $(BUILD) $(OUTPUT).elf
$(name).bin: $(dir_build)/$(name).elf
$(OC) -S -O binary $< $@
#--------------------------------------------------------------------------------- $(dir_build)/$(name).elf: $(objects)
else # FatFs requires libgcc for __aeabi_uidiv
$(CC) -nostartfiles -T linker.ld $(OUTPUT_OPTION) $^
DEPENDS := $(OFILES:.o=.d) $(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)"
$(COMPILE.c) $(OUTPUT_OPTION) $<
#--------------------------------------------------------------------------------- $(dir_build)/%.o: $(dir_source)/%.s
# main targets @mkdir -p "$(@D)"
#--------------------------------------------------------------------------------- $(COMPILE.s) $(OUTPUT_OPTION) $<
$(OUTPUT).bin : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c
@mkdir -p "$(@D)"
$(COMPILE.c) $(OUTPUT_OPTION) $<
#--------------------------------------------------------------------------------- $(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
%.bin: %.elf @mkdir -p "$(@D)"
@$(OBJCOPY) -O binary $< $@ $(COMPILE.s) $(OUTPUT_OPTION) $<
@echo built ... $(notdir $@) include $(call rwildcard, $(dir_build), *.d)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -9,4 +9,3 @@ SECTIONS
.rodata : { *(.rodata) } .rodata : { *(.rodata) }
. = ALIGN(4); . = ALIGN(4);
} }

View File

@ -1,5 +0,0 @@
%rename link old_link
*link:
%(old_link) -T ../stub.ld%s

View File

@ -1,6 +1,4 @@
#--------------------------------------------------------------------------------- rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),) ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
@ -8,108 +6,41 @@ endif
include $(DEVKITARM)/3ds_rules include $(DEVKITARM)/3ds_rules
#--------------------------------------------------------------------------------- CC := arm-none-eabi-gcc
# TARGET is the name of the output AS := arm-none-eabi-as
# BUILD is the directory where object files & intermediate files will be placed LD := arm-none-eabi-ld
# SOURCES is a list of directories containing source code OC := arm-none-eabi-objcopy
# 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
#--------------------------------------------------------------------------------- name := $(shell basename $(CURDIR))
# Setup some defines
#---------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- dir_source := source
# options for code generation dir_build := build
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2 -flto\ ASFLAGS := -mlittle-endian -mcpu=mpcore
-mcpu=mpcore -mlittle-endian\ CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork
-ffast-math -Wno-main -std=c99\
$(ARCH)
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) .PHONY: clean
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
#---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @rm -rf $(dir_build)
@rm -fr $(BUILD) $(OUTPUT).elf
$(name).bin: $(dir_build)/$(name).elf
$(OC) -S -O binary $< $@
#--------------------------------------------------------------------------------- $(dir_build)/$(name).elf: $(objects)
else $(CC) -nostartfiles -T linker.ld $(OUTPUT_OPTION) $^
DEPENDS := $(OFILES:.o=.d) $(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)"
$(COMPILE.c) $(OUTPUT_OPTION) $<
#--------------------------------------------------------------------------------- $(dir_build)/%.o: $(dir_source)/%.s
# main targets @mkdir -p "$(@D)"
#--------------------------------------------------------------------------------- $(COMPILE.s) $(OUTPUT_OPTION) $<
$(OUTPUT).bin : $(OUTPUT).elf include $(call rwildcard, $(dir_build), *.d)
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
%.bin: %.elf
@$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -1,5 +0,0 @@
%rename link old_link
*link:
%(old_link) -T ../stub.ld%s