forked from Reisyukaku/ReiNX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (54 loc) · 1.87 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
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 := 1.6
dir_source := src
dir_data := data
dir_build := build
dir_out := out
dir_sysmod := NX_Sysmodules
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CFLAGS = $(ARCH) -DVERSION='"$(ver)"' -Os -nostdlib -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-inline -fno-builtin -std=gnu11# -Wall
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) -C $(dir_sysmod)
$(dir_out)/$(name).bin: $(dir_build)/$(name).elf
@mkdir -p "$(@D)"
@mkdir -p "$(dir_out)/ReiNX/sysmodules"
@mkdir -p "$(dir_out)/ReiNX/patches"
@cp $(dir_sysmod)/loader/loader.kip $(dir_out)/ReiNX/sysmodules/
@cp $(dir_sysmod)/sm/sm.kip $(dir_out)/ReiNX/sysmodules/
@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 $@