-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (63 loc) · 1.91 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
# Toolchain
CC = arm-none-eabi-gcc
SIZE = arm-none-eabi-size
OBJCOPY = arm-none-eabi-objcopy
STFLASH = st-flash
CPPCHECK = cppcheck
# Directories
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
INCLUDE_DIRS = ./src \
./external/ \
./
# Files
TARGET_NAME = program.elf
TARGET = $(BIN_DIR)/$(TARGET_NAME)
MAIN_FILE = src/main.c
SOURCES_WITH_HEADERS := $(shell find . \( -path ./src/test -o -name "main.c" \) -prune -o -name "*.c" -print)
SOURCES = $(MAIN_FILE) \
$(SOURCES_WITH_HEADERS)
HEADERS = $(SOURCES_WITH_HEADERS:.c=.h) \
./src/common/stm32g0b1re.h
INCLUDES = $(addprefix -I, $(INCLUDE_DIRS))
OBJ_NAMES = $(SOURCES:.c=.o)
OBJECTS := $(addprefix $(OBJ_DIR)/, $(OBJ_NAMES))
LINKER_SCRIPT = src/STM32G0B1RE.ld
# Static Analysis
CPPCHECK_INCLUDES = ./src
IGNORE_FILES := $(shell find ./external -name "*.c")
SOURCES_FORMAT_CHECK := $(filter-out $(IGNORE_FILES), $(SOURCES))
CPPCHECK_FLAGS = \
--quiet --enable=all --error-exitcode=1 \
--inline-suppr \
--suppress=missingIncludeSystem \
--suppress=unmatchedSuppression \
--suppress=unusedFunction \
--checkers-report=cppcheck.report \
$(addprefix -I,$(CPPCHECK_INCLUDES)) \
# Defines
DEFINES = -DPRINTF_INCLUDE_CONFIG_H \
-DDISABLE_ENUM_STRINGS \
-DDISABLE_TRACE
# Flags
WFLAGS = -Wall -Wextra -Werror -Wshadow
CFLAGS = -mcpu=cortex-m0 -mthumb -nostdlib -Og -g $(INCLUDES) $(DEFINES)
LDFLAGS = -Xlinker -Map=$(BUILD_DIR)/bin/program.map -nostartfiles -T $(LINKER_SCRIPT) $(INCLUDES)
# Linking
$(BIN_DIR)/%.elf: $(OBJECTS)
@mkdir -p $(dir $@)
$(CC) $(LDFLAGS) $^ -o $@
$(SIZE) $@
# Compilation
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $^
.PHONY: all clean flash check
all: $(TARGET)
clean:
rm -rf $(BUILD_DIR)
flash: $(TARGET)
@openocd -f interface/stlink.cfg -f target/stm32g0x.cfg -c "program $(TARGET) verify reset exit"
check:
$(CPPCHECK) $(CPPCHECK_FLAGS) $(SOURCES_FORMAT_CHECK)