-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
91 lines (77 loc) · 2.09 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
85
86
87
88
89
90
91
TARGET = main
# Define the linker script location and chip architecture
LD_SCRIPT = link/stm32f412zgtx.ld
MCU_SPEC = cortex-m4
# Toolchain definitions (ARM bare metal defaults)
TOOLCHAIN = /usr
CC = $(TOOLCHAIN)/bin/arm-none-eabi-gcc
AS = $(TOOLCHAIN)/bin/arm-none-eabi-as
LD = $(TOOLCHAIN)/bin/arm-none-eabi-ld
OC = $(TOOLCHAIN)/bin/arm-none-eabi-objcopy
OD = $(TOOLCHAIN)/bin/arm-none-eabi-objdump
OS = $(TOOLCHAIN)/bin/arm-none-eabi-size
# Assembly directives
ASFLAGS += -c
ASFLAGS += -O0
ASFLAGS += -mcpu=$(MCU_SPEC)
ASFLAGS += -mthumb
ASFLAGS += -Wall
# (Set error messages to appear on a single line.)
ASFLAGS += -fmessage-length=0
# C compilation directives
CFLAGS += -mcpu=$(MCU_SPEC)
CFLAGS += -mthumb
CFLAGS += -Wall
CFLAGS += -Werror
CFLAGS += -g3
CFLAGS += -O0
CFLAGS += -std=c17
CFLAGS += -D_FORTIFY_SOURCE=2
CFLAGS += -DSYSTEM_DEBUG__
# (Set error messages to appear on a single line.)
CFLAGS += -fmessage-length=0
# (Set system to ignore semihosted junk)
CFLAGS += --specs=nosys.specs
CFLAGS += -DSTM32H7A3xxQ
CFLAGS += -Wno-main
CFLAGS += -Wno-sequence-point
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wno-unused-variable
# Linker directives.
LSCRIPT = ./$(LD_SCRIPT)
LFLAGS += -mcpu=$(MCU_SPEC)
LFLAGS += -mthumb
LFLAGS += -Wall
LFLAGS += -Wextra
LFLAGS += --specs=nosys.specs
LFLAGS += -lgcc
LFLAGS += -T$(LSCRIPT)
AS_SRC = ./src/startup.S
C_SRC = ./src/main.c
C_SRC += ./src/drivers/ds3231/ds3231.c
C_SRC += ./src/drivers/nixie/nixie.c
C_SRC += ./src/drivers/onboard_led/onboard_led.c
C_SRC += ./src/drivers/rgb_led/rgb_led.c
C_SRC += ./src/drivers/pulse/pulse.c
C_SRC += ./src/drivers/mode_switch/mode_switch.c
C_SRC += ./src/drivers/option_switch/option_switch.c
C_SRC += ./src/util/check_input/check_input.c
INCLUDE = -I.
OBJS = $(AS_SRC:.S=.o)
OBJS += $(C_SRC:.c=.o)
.PHONY: all
all: $(TARGET).bin
%.o: %.S
$(CC) -x assembler-with-cpp $(ASFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@
$(TARGET).elf: $(OBJS)
$(CC) $^ $(LFLAGS) -o $@
$(TARGET).bin: $(TARGET).elf
$(OC) -S -O binary $< $@
$(OS) $<
.PHONY: clean
clean:
rm -f $(OBJS)
rm -f $(TARGET).elf
rm -f $(TARGET).bin