forked from artfulbytes/nsumo_video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
141 lines (119 loc) · 3.28 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Check arguments
ifeq ($(HW),LAUNCHPAD) # HW argument
TARGET_HW=launchpad
else ifeq ($(HW),NSUMO)
TARGET_HW=nsumo
else ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),cppcheck)
else ifeq ($(MAKECMDGOALS),format)
# HW argument not required for this rule
else
$(error "Must pass HW=LAUNCHPAD or HW=NSUMO")
endif
TARGET_NAME=$(TARGET_HW)
ifneq ($(TEST),) # TEST argument
ifeq ($(findstring test_,$(TEST)),)
$(error "TEST=$(TEST) is invalid (test function must start with test_)")
else
TARGET_NAME=$(TEST)
endif
endif
# Directories
TOOLS_DIR = ${TOOLS_PATH}
MSPGCC_ROOT_DIR = $(TOOLS_DIR)/msp430-gcc
MSPGCC_BIN_DIR = $(MSPGCC_ROOT_DIR)/bin
MSPGCC_INCLUDE_DIR = $(MSPGCC_ROOT_DIR)/include
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
TI_CCS_DIR = $(TOOLS_DIR)/ccs1210/ccs
DEBUG_BIN_DIR = $(TI_CCS_DIR)/ccs_base/DebugServer/bin
DEBUG_DRIVERS_DIR = $(TI_CCS_DIR)/ccs_base/DebugServer/drivers
LIB_DIRS = $(MSPGCC_INCLUDE_DIR)
INCLUDE_DIRS = $(MSPGCC_INCLUDE_DIR) \
./src \
./external/ \
./external/printf
# Toolchain
CC = $(MSPGCC_BIN_DIR)/msp430-elf-gcc
RM = rm
DEBUG = LD_LIBRARY_PATH=$(DEBUG_DRIVERS_DIR) $(DEBUG_BIN_DIR)/mspdebug
CPPCHECK = cppcheck
FORMAT = clang-format-12
SIZE = $(MSPGCC_BIN_DIR)/msp430-elf-size
READELF = $(MSPGCC_BIN_DIR)/msp430-elf-readelf
# Files
TARGET = $(BUILD_DIR)/bin/$(TARGET_HW)/$(TARGET_NAME)
SOURCES_WITH_HEADERS = \
src/common/assert_handler.c \
src/common/ring_buffer.c \
src/drivers/mcu_init.c \
src/drivers/io.c \
src/drivers/led.c \
src/drivers/uart.c \
src/app/drive.c \
src/app/enemy.c \
ifndef TEST
SOURCES = \
src/main.c \
$(SOURCES_WITH_HEADERS)
else
SOURCES = \
src/test/test.c \
$(SOURCES_WITH_HEADERS)
# Delete object file to force rebuild when changing test (there is probably a better way...)
$(shell rm -f $(BUILD_DIR)/obj/src/test/test.o)
endif
HEADERS = \
$(SOURCES_WITH_HEADERS:.c=.h) \
src/common/defines.h \
OBJECT_NAMES = $(SOURCES:.c=.o)
OBJECTS = $(patsubst %,$(OBJ_DIR)/%,$(OBJECT_NAMES))
# Defines
HW_DEFINE = $(addprefix -D,$(HW))
TEST_DEFINE = $(addprefix -DTEST=,$(TEST))
DEFINES = \
$(HW_DEFINE) \
$(TEST_DEFINE)
# Static Analysis
## Don't check the msp430 helper headers (they have a LOT of ifdefs)
CPPCHECK_INCLUDES = ./src
CPPCHECK_IGNORE = external/printf
CPPCHECK_FLAGS = \
--quiet --enable=all --error-exitcode=1 \
--inline-suppr \
--suppress=missingIncludeSystem \
--suppress=unmatchedSuppression \
--suppress=unusedFunction \
$(addprefix -I,$(CPPCHECK_INCLUDES)) \
$(addprefix -i,$(CPPCHECK_IGNORE))
# Flags
MCU = msp430g2553
WFLAGS = -Wall -Wextra -Werror -Wshadow
CFLAGS = -mmcu=$(MCU) $(WFLAGS) -fshort-enums $(addprefix -I,$(INCLUDE_DIRS)) $(DEFINES) -Og -g
LDFLAGS = -mmcu=$(MCU) $(DEFINES) $(addprefix -L,$(LIB_DIRS))
# Build
## Linking
$(TARGET): $(OBJECTS) $(HEADERS)
echo $(OBJECTS)
@mkdir -p $(dir $@)
$(CC) $(LDFLAGS) $^ -o $@
## Compiling
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $^
# Phonies
.PHONY: all clean flash cppcheck format
all: $(TARGET)
clean:
@$(RM) -rf $(BUILD_DIR)
flash: $(TARGET)
@$(DEBUG) tilib "prog $(TARGET)"
cppcheck:
@$(CPPCHECK) $(CPPCHECK_FLAGS) $(SOURCES)
format:
@$(FORMAT) -i $(SOURCES) $(HEADERS)
size: $(TARGET)
@$(SIZE) $(TARGET)
symbols: $(TARGET)
# List symbols table sorted by size
@$(READELF) -s $(TARGET) | sort -n -k3