-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwizardry.mk
70 lines (52 loc) · 1.87 KB
/
wizardry.mk
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
# ==================
# = OBJECTS & DMPS =
# ==================
LYN_REFERENCE := Tools/CLib/reference/FE8U-20190316.o
# OBJ to event
%.lyn.event: %.o $(LYN_REFERENCE)
$(NOTIFY_PROCESS)
@$(LYN) $< $(LYN_REFERENCE) > $@
# OBJ to DMP rule
%.dmp: %.o
$(NOTIFY_PROCESS)
@$(OBJCOPY) -S $< -O binary $@
# ========================
# = ASSEMBLY/COMPILATION =
# ========================
# Setting C/ASM include directories up (there is none yet)
INCLUDE_DIRS := Tools/CLib/include Wizardry/Include
INCFLAGS := $(foreach dir, $(INCLUDE_DIRS), -I "$(dir)")
# setting up compilation flags
ARCH := -mcpu=arm7tdmi -mthumb -mthumb-interwork
CFLAGS := $(ARCH) $(INCFLAGS) -Wall -Wextra -Wno-unused -O2 -mtune=arm7tdmi -ffreestanding -mlong-calls
ASFLAGS := $(ARCH) $(INCFLAGS)
# defining dependency flags
CDEPFLAGS = -MMD -MT "$*.o" -MT "$*.asm" -MF "$(CACHE_DIR)/$(notdir $*).d" -MP
SDEPFLAGS = --MD "$(CACHE_DIR)/$(notdir $*).d"
# ASM to OBJ rule
%.o: %.s
$(NOTIFY_PROCESS)
@$(AS) $(ASFLAGS) $(SDEPFLAGS) -I $(dir $<) $< -o $@ $(ERROR_FILTER)
# C to ASM rule
# I would be fine with generating an intermediate .s file but this breaks dependencies
%.o: %.c
$(NOTIFY_PROCESS)
@$(CC) $(CFLAGS) $(CDEPFLAGS) -g -c $< -o $@ $(ERROR_FILTER)
# C to ASM rule
%.asm: %.c
$(NOTIFY_PROCESS)
@$(CC) $(CFLAGS) $(CDEPFLAGS) -S $< -o $@ -fverbose-asm $(ERROR_FILTER)
# Avoid make deleting objects it thinks it doesn't need anymore
# Without this make may fail to detect some files as being up to date
.PRECIOUS: %.o;
# ==============
# = MAKE CLEAN =
# ==============
ifeq ($(MAKECMDGOALS),clean)
# ASM/C and generated files
CFILES := $(shell find -type f -name '*.c')
SFILES := $(shell find -type f -name '*.s')
ASM_C_GENERATED := $(CFILES:.c=.o) $(SFILES:.s=.o) $(CFILES:.c=.asm)
ASM_C_GENERATED += $(ASM_C_GENERATED:.o=.dmp) $(ASM_C_GENERATED:.o=.lyn.event)
CLEAN_FILES += $(ASM_C_GENERATED)
endif