-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
124 lines (92 loc) · 3.89 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
# Define the name of the project
PROJECT = example
# System configuration
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
RM=rm -rf
PROTOC = protoc
# Define where the *.proto files are located.
PROTO_DIR = proto
# Define output directory in which to place the build results.
PROTO_GEN_DIR = build/generated
OBJECT_DIR = build
BIN_DIR = $(OBJECT_DIR)
# Define directories to include.
INC_DIR = -Isrc \
-Isrc/external \
-Isrc/external/CMSIS/Include \
-Isrc/external/CMSIS/Device/ST/STM32F4xx/Include \
-Isrc/external/STM32F4xx_HAL_Driver/Inc \
-I$(PROTO_GEN_DIR) \
-Iembeddedproto/src
# Find all the proto files.
# Extend this for subfolders.
PROTO_FILES = $(wildcard $(PROTO_DIR)/*.proto)
# Convert the names of the proto files to the name of the generated header files.
PROTO_HDR := $(PROTO_FILES:%.proto=$(PROTO_GEN_DIR)/%.h)
# Define source and object files.
SRC := $(wildcard src/*.c) \
$(wildcard src/external/*.c) \
$(wildcard src/external/STM32F4xx_HAL_Driver/Src/*.c) \
$(wildcard src/external/*.s) \
$(wildcard src/*.cpp)
# Create the object file names.
OBJS := $(SRC:%.c=$(OBJECT_DIR)/%.o)
OBJS := $(OBJS:%.cpp=$(OBJECT_DIR)/%.o)
OBJS := $(OBJS:%.s=$(OBJECT_DIR)/%.o)
OBJS := $(OBJS:%.S=$(OBJECT_DIR)/%.o)
# These are the source files from the EmbeddedProto project.
# These are the files that support your messages.
EMBEDDED_PROTO_DIR = $(shell pwd)/embeddedproto
EMBEDDED_PROTO_SRC := $(wildcard ./embeddedproto/src/*.cpp)
EMBEDDED_PROTO_OBJS := $(EMBEDDED_PROTO_SRC:%.cpp=$(OBJECT_DIR)/%.o)
# Assembler, Compiler and Linker flags and linker script settings
LINKER_FLAGS=-lm -mthumb -mhard-float -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -T$(LINK_SCRIPT) -static -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group -specs=nano.specs -specs=nosys.specs -Wl,-cref "-Wl,-Map=$(BIN_DIR)/${PROJECT}.map" -Wl,--defsym=malloc_getpagesize_P=0x1000
LINK_SCRIPT="src/external/stm32_flash.ld"
ASSEMBLER_FLAGS=-c -g -O0 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mhard-float -specs=nano.specs -D"STM32F446xx" -x assembler-with-cpp ${INC_DIR}
COMPILER_FLAGS=-c -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -O0 -Wall -mthumb -mhard-float -specs=nano.specs -D"STM32F446xx" ${INC_DIR}
CXXCOMPILER_FLAGS=-std=c++14 -fno-threadsafe-statics -c -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -O0 -Wall -mthumb -mhard-float -specs=nano.specs -fno-exceptions -fno-rtti -D"STM32F446xx" ${INC_DIR}
###############
# Build project
# Major targets
###############
.PHONY: all generate debug clean
all: generate debug
generate: $(PROTO_HDR)
$(info Done generating source files based on *.proto files.)
debug: buildelf
buildelf: $(EMBEDDED_PROTO_OBJS) $(OBJS)
$(CXX) -o "$(BIN_DIR)/${PROJECT}.elf" $(EMBEDDED_PROTO_OBJS) $(OBJS) $(LINKER_FLAGS)
clean:
$(info sources: $(EMBEDDED_PROTO_OBJS) $(SRC))
$(info end)
$(RM) $(EMBEDDED_PROTO_OBJS) $(OBJS) "$(BIN_DIR)/${PROJECT}.elf" "$(BIN_DIR)/${PROJECT}.map"
$(RM) $(PROTO_GEN_DIR)
##################
# Specific targets
##################
$(OBJECT_DIR)/src/main.o: src/main.cpp
$(shell mkdir -p $(dir $@))
$(CXX) $(CXXCOMPILER_FLAGS) src/main.cpp -o $(OBJECT_DIR)/src/main.o
##################
# Implicit targets
##################
# This rulle is used to generate the message source files based on the *.proto files.
$(PROTO_GEN_DIR)/%.h: %.proto
$(shell mkdir -p $(dir $@))
cd $(EMBEDDED_PROTO_DIR) && $(PROTOC) --plugin=protoc-gen-eams -I../$(PROTO_DIR) --eams_out=../$(PROTO_GEN_DIR) ../$<
$(OBJECT_DIR)/%.o: %.c
$(shell mkdir -p $(dir $@))
$(CC) $(COMPILER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.cpp
$(shell mkdir -p $(dir $@))
$(CXX) $(CXXCOMPILER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: ../%.cpp
$(shell mkdir -p $(dir $@))
$(CXX) $(CXXCOMPILER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.s
$(shell mkdir -p $(dir $@))
$(CC) $(ASSEMBLER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.S
$(shell mkdir -p $(dir $@))
$(CC) $(ASSEMBLER_FLAGS) $< -o $@