Revised Makefile

This commit is contained in:
Wolfvak 2017-11-09 01:24:46 +01:00 committed by d0k3
parent 463f2881da
commit beeea37d07
190 changed files with 220 additions and 233 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
*.ko *.ko
*.obj *.obj
*.elf *.elf
*.map
# Precompiled Headers # Precompiled Headers
*.gch *.gch

239
Makefile
View File

@ -1,204 +1,73 @@
#---------------------------------------------------------------------------------
.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")
endif endif
include $(DEVKITARM)/ds_rules include $(DEVKITARM)/base_tools
include Makefile.common
#--------------------------------------------------------------------------------- # Base definitions
# TARGET is the name of the output export VERSION := $(shell git describe --tags --abbrev=8)
# BUILD is the directory where object files & intermediate files will be placed export DBUILTS := $(shell date +'%Y%m%d%H%M%S')
# SOURCES is a list of directories containing source code export DBUILTL := $(shell date +'%Y-%m-%d %H:%M:%S')
# 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 := GodMode9
ifeq ($(SAFEMODE),1)
export TARGET := SafeMode9
endif
BUILD := build
SOURCES := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
DATA := data
INCLUDES := common source source/common source/font source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
#--------------------------------------------------------------------------------- export OUTDIR := output
# options for code generation export RELDIR := release
#---------------------------------------------------------------------------------
ARCH := -DARM9 -march=armv5te -mthumb -mthumb-interwork
ASFLAGS := $(ARCH) -g -x assembler-with-cpp $(INCLUDE) # Definitions for initial RAM disk
CFLAGS := $(ARCH) -g -Wall -Wextra -Wpedantic -Wcast-align -Wno-main -O2 \ VRAM_OUT := $(OUTDIR)/vram0.tar
-mtune=arm946e-s -fomit-frame-pointer -ffast-math -std=gnu11 \ VRAM_DIRS := data/
$(INCLUDE) -Wno-unused-function VRAM_FLAGS :=
VERSION := $(shell git describe --tags --abbrev=8) # Definitions for ARM binaries
DBUILTS := $(shell date +'%Y%m%d%H%M%S') export INCLUDE := -I"$(shell pwd)/common"
DBUILTL := $(shell date +'%Y-%m-%d %H:%M:%S')
CFLAGS += -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\""
ifeq ($(FONT),ORIG) export ASFLAGS := -g -x assembler-with-cpp $(INCLUDE)
CFLAGS += -DFONT_ORIGINAL export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\""\
else ifeq ($(FONT),6X10) -g -O2 -Wall -Wextra -Wpedantic -Wcast-align -Wno-main \
CFLAGS += -DFONT_6X10 -fomit-frame-pointer -ffast-math -std=gnu11 \
else ifeq ($(FONT),ACORN) -Wno-unused-function $(INCLUDE)
CFLAGS += -DFONT_ACORN export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=512
else ifeq ($(FONT),GB) ELF := arm9/arm9.elf mpcore/mpcore.elf
CFLAGS += -DFONT_GB
else
CFLAGS += -DFONT_6X10
endif
ifeq ($(SAFEMODE),1) .PHONY: all firm clean
CFLAGS += -DSAFEMODE all: firm
endif
ifeq ($(SALTMODE),1) clean:
CFLAGS += -DSALTMODE @set -e; for elf in $(ELF); do \
endif $(MAKE) --no-print-directory -C $$(dirname $$elf) clean; \
done
ifeq ($(SWITCH_SCREENS),1) @rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_OUT)
CFLAGS += -DSWITCH_SCREENS
endif
ifeq ($(AUTORUN_SCRIPT),1)
CFLAGS += -DAUTORUN_SCRIPT
endif
ifdef FIXED_BRIGHTNESS
CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS)
endif
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
LDFLAGS = -T../link.ld -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map,-z,max-page-size=512
LIBS :=
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
#---------------------------------------------------------------------------------
# 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_D := $(CURDIR)/output
export OUTPUT := $(OUTPUT_D)/$(TARGET)
export RELEASE := $(CURDIR)/release
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(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)))
BINFILES :=
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
export FTCOMMON := -A 0x18000000 -D $(OUTPUT).elf $(OUTPUT_D)/screeninit.elf $(CURDIR)/resources/vram0.tar -C NDMA XDMA memcpy
.PHONY: common clean all firm binary screeninit release
#---------------------------------------------------------------------------------
all: firm ntrboot
common:
@[ -d $(OUTPUT_D) ] || mkdir -p $(OUTPUT_D)
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
screeninit:
@$(MAKE) --no-print-directory dir_out=$(OUTPUT_D) -C screeninit
binary: common
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
firm: binary screeninit
firmtool build $(OUTPUT).firm $(FTCOMMON) -S nand-retail -g
firmtool build $(OUTPUT)_dev.firm $(FTCOMMON) -S nand-dev -g
ntrboot: binary screeninit
firmtool build $(OUTPUT)_ntr.firm $(FTCOMMON) -S spi-retail -g
firmtool build $(OUTPUT)_ntr_dev.firm $(FTCOMMON) -S spi-dev -g
release: release:
@-rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE) @$(MAKE) --no-print-directory clean
@$(MAKE) --no-print-directory firm @$(MAKE) --no-print-directory firm
@$(MAKE) --no-print-directory ntrboot @$(MAKE) --no-print-directory firm NTRBOOT=1
@[ -d $(RELEASE) ] || mkdir -p $(RELEASE)
@[ -d $(RELEASE)/ntrboot ] || mkdir -p $(RELEASE)/ntrboot
@cp $(OUTPUT).firm $(RELEASE)
@cp $(CURDIR)/README.md $(RELEASE)
@cp $(CURDIR)/HelloScript.gm9 $(RELEASE)
@cp $(OUTPUT)_ntr.firm $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr.firm.sha $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr_dev.firm $(RELEASE)/ntrboot
@cp $(OUTPUT)_ntr_dev.firm.sha $(RELEASE)/ntrboot
@cp -R $(CURDIR)/resources/gm9 $(RELEASE)/gm9
@-7z a $(RELEASE)/$(TARGET)-$(VERSION)-$(DBUILTS).zip $(RELEASE)/*
#--------------------------------------------------------------------------------- @mkdir -p $(RELDIR)
clean: @cp $(FIRM) $(RELDIR)
@echo clean ... @[ -d $(RELDIR) ] || mkdir -p $(RELDIR)
@-$(MAKE) clean --no-print-directory -C screeninit @[ -d $(RELDIR)/ntrboot ] || mkdir -p $(RELDIR)/ntrboot
@rm -fr $(BUILD) $(OUTPUT_D) $(RELEASE) @cp $(OUTDIR)/$(FLAVOR)_ntr.firm $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR)_ntr_dev.firm $(RELDIR)/ntrboot/
@cp $(OUTDIR)/$(FLAVOR).firm $(RELDIR)/
@cp $(OUTDIR)/$(FLAVOR)_dev.firm $(RELDIR)/
@cp $(ELF) $(RELDIR)
@cp $(CURDIR)/README.md $(RELDIR)
@cp $(CURDIR)/HelloScript.gm9 $(RELDIR)
@cp -R $(CURDIR)/resources/gm9 $(RELDIR)/gm9
@-7z a $(RELDIR)/$(FLAVOR)-$(VERSION)-$(DBUILTS).zip $(RELDIR)/*
$(VRAM_OUT):
@mkdir -p "$(@D)"
@echo "Creating $@"
@tar $(VRAM_FLAGS) cf $@ $(VRAM_DIRS)
#--------------------------------------------------------------------------------- %.elf:
else @echo "Building $@"
@$(MAKE) --no-print-directory -C $(call dirname,"$@")
DEPENDS := $(OFILES:.o=.d) firm: $(ELF) $(VRAM_OUT)
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
#--------------------------------------------------------------------------------- firmtool build $(FIRM) $(FTFLAGS) -g -A 0x18000000 -D $^ -C NDMA XDMA memcpy
# main targets firmtool build $(FIRMD) $(FTDFLAGS) -g -A 0x18000000 -D $^ -C NDMA XDMA memcpy
#---------------------------------------------------------------------------------
$(OUTPUT).bin : $(OUTPUT).elf
$(OFILES_SOURCES) : $(HFILES)
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
%.bin: %.elf
@$(OBJCOPY) --set-section-flags .bss=alloc,load,contents -O binary $< $@
@echo built ... $(notdir $@)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

53
Makefile.common Normal file
View File

@ -0,0 +1,53 @@
dirname = $(shell dirname $(1))
rwildcard = $(foreach d, $(wildcard $1*), \
$(filter $(subst *, %, $2), $d) \
$(call rwildcard, $d/, $2))
FLAVOR := GodMode9
ifeq ($(FONT),ORIG)
CFLAGS += -DFONT_ORIGINAL
else ifeq ($(FONT),6X10)
CFLAGS += -DFONT_6X10
else ifeq ($(FONT),ACORN)
CFLAGS += -DFONT_ACORN
else ifeq ($(FONT),GB)
CFLAGS += -DFONT_GB
else
CFLAGS += -DFONT_6X10
endif
ifeq ($(SAFEMODE),1)
CFLAGS += -DSAFEMODE
FLAVOR := SafeMode9
endif
ifeq ($(SALTMODE),1)
CFLAGS += -DSALTMODE
endif
ifeq ($(SWITCH_SCREENS),1)
CFLAGS += -DSWITCH_SCREENS
endif
ifeq ($(AUTORUN_SCRIPT),1)
CFLAGS += -DAUTORUN_SCRIPT
endif
ifdef FIXED_BRIGHTNESS
CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS)
endif
ifdef NTRBOOT
FTFLAGS = -S spi-retail
FTDFLAGS = -S spi-dev
FIRM = $(OUTDIR)/$(FLAVOR)_ntr.firm
FIRMD = $(OUTDIR)/$(FLAVOR)_ntr_dev.firm
else
FTFLAGS = -S nand-retail
FTDFLAGS = -S nand-dev
FIRM = $(OUTDIR)/$(FLAVOR).firm
FIRMD = $(OUTDIR)/$(FLAVOR)_dev.firm
endif

37
arm9/Makefile Normal file
View File

@ -0,0 +1,37 @@
TARGET := $(shell basename $(CURDIR))
SOURCE := source
BUILD := build
SUBARCH := -DARM9 -mcpu=arm946e-s -mtune=arm946e-s -mfloat-abi=soft -mthumb
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/quicklz source/qrcodegen source/system source/utils
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")
ASFLAGS += $(SUBARCH) $(INCLUDE)
CFLAGS += $(SUBARCH) $(INCLUDE)
LDFLAGS += $(SUBARCH) -Wl,-Map,$(TARGET).map
include ../Makefile.common
OBJECTS = $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
$(call rwildcard, $(SOURCE), *.s *.c)))
.PHONY: all
all: $(TARGET).elf
.PHONY: clean
clean:
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).map
$(TARGET).elf: $(OBJECTS)
@mkdir -p "$(@D)"
$(CC) $(LDFLAGS) $^ -o $@
$(BUILD)/%.o: $(SOURCE)/%.c
@mkdir -p "$(@D)"
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD)/%.o: $(SOURCE)/%.s
@mkdir -p "$(@D)"
$(CC) -c $(ASFLAGS) -o $@ $<

View File

@ -49,3 +49,40 @@ u32 ValidateAgbHeader(AgbHeader* agb) {
return 0; return 0;
} }
/* u32 ValidateAgbVc(void* data, u32 len) {
const u8 magic[] = { GBAVC_MAGIC };
if (len < sizeof(AgbHeader) + sizeof(AgbVcFooter))
return 1;
AgbHeader* header = (AgbHeader*) data;
AgbVcFooter* footer = (AgbVcFooter*) (((u8*) data) + len - sizeof(AgbVcFooter));
if ((ValidateAgbHeader(header) != 0) || (memcmp(footer->magic, magic, sizeof(magic)) != 0) ||
(footer->rom_size != len - sizeof(AgbVcFooter)))
return 1;
return 0;
} */
// basically reverse ValidateAgbSaveHeader()
/* u32 BuildAgbSaveHeader(AgbSaveHeader* header, u64 title_id, u32 save_size) {
const u8 magic[] = { AGBSAVE_MAGIC };
memset(header, 0x00, sizeof(AgbSaveHeader));
memset(header->reserved0, 0xFF, sizeof(header->reserved0));
memset(header->reserved1, 0xFF, sizeof(header->reserved1));
memset(header->reserved2, 0xFF, sizeof(header->reserved2));
memset(header->reserved3, 0xFF, sizeof(header->reserved3));
memcpy(header->magic, magic, sizeof(magic));
header->unknown0 = 0x01;
header->title_id = title_id;
header->save_start = 0x200;
header->save_size = save_size;
sdmmc_get_cid(0, (u32*) (void*) &(header->sd_cid));
return 0;
} */

Some files were not shown because too many files have changed in this diff Show More