forked from Reisyukaku/ReiNX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (66 loc) · 2.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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=<path to>devkitARM")
endif
include $(DEVKITARM)/base_tools
LD = $(DEVKITARM)/bin/arm-none-eabi-ld
OBJCOPY = $(DEVKITARM)/bin/arm-none-eabi-objcopy
name := ReiNX
ver_major := 2
ver_minor := 2
dir_source := src
dir_data := data
dir_build := build
dir_out := out
dir_sysmod := NX_Sysmodules
dir_septchainloader := septchainloader
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CFLAGS = $(ARCH) -DVERSION_MAJOR='$(ver_major)' -DVERSION_MINOR='$(ver_minor)' -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -fno-builtin -std=gnu11# -Wall -Werror
LDFLAGS = $(ARCH) -nostartfiles -lgcc -Wl,--nmagic,--gc-sections
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
$(call rwildcard, $(dir_source), *.s *.c)))
define bin2o
bin2s $< | $(AS) -o $(@)
endef
.PHONY: all
all: sysmod reinx
.PHONY: sysmod
sysmod: $(dir_out)/sysmodules
.PHONY: reinx
reinx: $(dir_out)/$(name).bin
.PHONY: clean
clean:
@echo "clean ..."
@rm -rf $(dir_build)
@rm -rf $(dir_out)
@$(MAKE) -C $(dir_sysmod) clean
$(dir_out)/sysmodules: $(dir_sysmod)
@$(MAKE) ver_maj=$(ver_major) ver_min=$(ver_minor) -C $(dir_sysmod)
@mkdir -p "$(dir_out)/ReiNX/sysmodules"
@mkdir -p "$(dir_out)/ReiNX/sysmodules.dis"
@cp $(dir_sysmod)/loader/loader.kip $(dir_out)/ReiNX/sysmodules/
@cp $(dir_sysmod)/sm/sm.kip $(dir_out)/ReiNX/sysmodules/
@cp $(dir_sysmod)/pm/pm.kip $(dir_out)/ReiNX/sysmodules/
@cp $(dir_sysmod)/rnx_mitm/rnx_mitm.kip $(dir_out)/ReiNX/sysmodules/
@mkdir -p "$(dir_out)/ReiNX/titles/0100000000000034"
@mkdir -p "$(dir_out)/ReiNX/titles/0100000000000036"
@mv $(dir_sysmod)/fatal/fatal.nsp $(dir_out)/ReiNX/titles/0100000000000034/exefs.nsp
@cp -a $(dir_sysmod)/creport/0100000000000036/. $(dir_out)/ReiNX/titles/0100000000000036/
$(dir_out)/$(name).bin: $(dir_build)/$(name).elf
@mkdir -p "$(@D)"
@mkdir -p "$(dir_out)/ReiNX/patches"
@mkdir -p "$(dir_out)/sept"
@$(MAKE) -C $(dir_septchainloader)
@cp $(dir_septchainloader)/out/payload.bin $(dir_out)/sept
@cp -R $(dir_data)/*.bin $(dir_out)/ReiNX/
@cp -R $(dir_data)/*.rxp $(dir_out)/ReiNX/patches
$(OBJCOPY) -S -O binary $< $@
$(dir_build)/$(name).elf: $(objects)
$(CC) $(LDFLAGS) -T link.ld $^ -o $@
$(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
$(dir_build)/%.o: $(dir_source)/%.s
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@