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
|
RM = rm -f
TARGET = main
# platform is ds (desktop) or stm (stm32)
PLATFORM = ds
ifeq ($(PLATFORM),stm)
STM = true
include stm32.mk
endif
ifeq ($(PLATFORM),ds)
DESKTOP = true
include ds.mk
endif
HOST=$(strip $(shell uname -o))
SHARED_FLAGS += -g
SHARED_FLAGS += -Wall
SHARED_FLAGS += -Wextra
# SHARED_FLAGS += -O1
LFLAGS += -lm
# LFLAGS += -lc
CFLAGS += $(if $(STM), -DHH_TARGET_STM32, )
CFLAGS += $(if $(DESKTOP), -DHH_TARGET_DESKTOP, )
LOCAL_SRCS += main.c
CFLAGS += $(SHARED_FLAGS)
LFLAGS += $(SHARED_FLAGS)
AFLAGS += $(SHARED_FLAGS)
SRCS += $(LOCAL_SRCS)
SRCS += $(if $(STM), $(STM_SRCS), )
SRCS += $(if $(DESKTOP), $(DESKTOP_SRCS), )
ifeq ($(PLATFORM),stm)
OBJS := $(patsubst %.c,%-stm.o, $(patsubst %.s,%-stm.o, $(SRCS)))
all: $(TARGET).bin
endif
ifeq ($(PLATFORM),ds)
OBJS := $(patsubst %.c,%-ds.o, $(SRCS))
all: $(TARGET)
endif
%-stm.o: %.s
$(CC) -c $(AFLAGS) $< -o $@
lib/%-stm.o: lib/%.c
$(CC) -c $(CFLAGS) -w $< -o $@
%-stm.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(TARGET).elf: $(OBJS)
$(LD) $^ $(LFLAGS) -o $@
$(TARGET).bin: $(TARGET).elf
$(OC) -O binary $< $@
$(OS) $<
PHONY += flash
flash: $(TARGET).bin
st-flash --reset write $(TARGET).bin 0x08000000
%-ds.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(TARGET): $(OBJS)
$(LD) $(LFLAGS) $^ -o $@
compile_commands.json:
compiledb make -Bn
../scripts/compiledb-full-path-mingw.sh compile_commands.json
PHONY += format
format:
clang-format -i $(LOCAL_SRCS)
clang-tidy --fix-errors $(LOCAL_SRCS)
PHONY += clean
clean:
$(RM) $(TARGET).bin $(TARGET).elf $(OBJS)
.PHONY: $(PHONY)
|