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") endif include $(DEVKITARM)/3ds_rules CC := arm-none-eabi-gcc AS := arm-none-eabi-as LD := arm-none-eabi-ld OC := arm-none-eabi-objcopy name := Luma3DS revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/i') commit := $(shell git rev-parse --short=8 HEAD) dir_source := source dir_patches := patches dir_loader := loader dir_injector := injector dir_exceptions := exceptions dir_arm9_exceptions := $(dir_exceptions)/arm9 dir_arm11_exceptions := $(dir_exceptions)/arm11 dir_cakebrah := CakeBrah dir_diffs := diffs dir_build := build dir_out := out ASFLAGS := -mcpu=arm946e-s CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math LDFLAGS := -nostartfiles FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Aurora Wright/TuxSH" --no-print-directory objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ $(call rwildcard, $(dir_source), *.s *.c))) bundled = $(dir_build)/reboot.bin.o $(dir_build)/emunand.bin.o $(dir_build)/svcGetCFWInfo.bin.o $(dir_build)/injector.bin.o $(dir_build)/loader.bin.o \ $(dir_build)/k11modules.bin.o $(dir_build)/arm9_exceptions.bin.o $(dir_build)/arm11_exceptions.bin.o define bin2o bin2s $< | $(AS) -o $(@) echo "extern const u8" `(echo $(> $(dir_build)/bundled.h echo "extern const u32" `(echo $(> $(dir_build)/bundled.h endef .PHONY: all all: a9lh ninjhax menuhax .PHONY: a9lh a9lh: $(dir_out)/arm9loaderhax.bin .PHONY: ninjhax ninjhax: $(dir_out)/3ds/$(name) .PHONY: menuhax menuhax: $(dir_out)/menuhax/boot.3dsx .PHONY: release release: $(dir_out)/$(name)$(revision).7z .PHONY: clean clean: @$(MAKE) $(FLAGS) -C $(dir_cakebrah) clean @$(MAKE) -C $(dir_loader) clean @$(MAKE) -C $(dir_arm9_exceptions) clean @$(MAKE) -C $(dir_arm11_exceptions) clean @$(MAKE) -C $(dir_injector) clean @rm -rf $(dir_out) $(dir_build) .PRECIOUS: $(dir_build)/%.bin $(dir_out): @mkdir -p "$(dir_out)" $(dir_out)/$(name)$(revision).7z: all @7z a -mx $@ ./$(@D)/* ./$(dir_exceptions)/exception_dump_parser.py $(dir_out)/menuhax/boot.3dsx: $(dir_diffs) $(dir_out) @mkdir -p "$(@D)" @cd $(dir_cakebrah); patch -p1 < ../$(dir_diffs)/1.diff; patch -p1 < ../$(dir_diffs)/2.diff; $(MAKE) $(FLAGS); git reset --hard @mv $(dir_out)/$(name).3dsx $@ @rm $(dir_out)/$(name).smdh $(dir_out)/3ds/$(name): $(dir_diffs) $(dir_out) @mkdir -p "$@" @cd $(dir_cakebrah); patch -p1 < ../$(dir_diffs)/1.diff; $(MAKE) $(FLAGS); git reset --hard @mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@ $(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out) @cp -a $(dir_build)/main.bin $@ $(dir_build)/main.bin: $(dir_build)/main.elf $(OC) -S -O binary $< $@ $(dir_build)/main.elf: $(bundled) $(objects) $(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^ $(dir_build)/%.bin.o: $(dir_build)/%.bin @mkdir -p "$(@D)" @$(bin2o) $(dir_build)/injector.bin: $(dir_injector)/Makefile @mkdir -p "$(@D)" @$(MAKE) -C $(dir_injector) $(dir_build)/loader.bin: $(dir_loader)/Makefile @mkdir -p "$(@D)" @$(MAKE) -C $(dir_loader) $(dir_build)/arm9_exceptions.bin: $(dir_arm9_exceptions)/Makefile @mkdir -p "$(@D)" @$(MAKE) -C $(dir_arm9_exceptions) $(dir_build)/arm11_exceptions.bin: $(dir_arm11_exceptions)/Makefile @mkdir -p "$(@D)" @$(MAKE) -C $(dir_arm11_exceptions) $(dir_build)/%.bin: $(dir_patches)/%.s @mkdir -p "$(@D)" @armips $< $(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3 $(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\"" $(dir_build)/patches.o: CFLAGS += -DREVISION=\"$(revision)\" -DCOMMIT_HASH="0x$(commit)" $(dir_build)/%.o: $(dir_source)/%.c $(bundled) @mkdir -p "$(@D)" $(COMPILE.c) $(OUTPUT_OPTION) $< $(dir_build)/%.o: $(dir_source)/%.s @mkdir -p "$(@D)" $(COMPILE.s) $(OUTPUT_OPTION) $< include $(call rwildcard, $(dir_build), *.d)