-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
206 lines (168 loc) · 5.08 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
################################################################################
# Company:
#
# Project: GPS frequency standard
#
# Description: makefile
#
# Filename: Makefile
#
# Author: Tobias Plüss <[email protected]>
#
# Creation-Date: 03.03.2020
################################################################################
# uncomment if build is too slow.
#MAKEFLAGS := --jobs=8
#MAKEFLAGS += --output-sync=target
find=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call find,$d/,$2))
MCU = cortex-m4
#
# List all defines here, like -D_DEBUG=1
#
DEFS =
#
# List the user directory to look for the libraries here
#
LIBDIR =
#
# List used libraries here
#
LIBS = -lm
#
# Define Ram/Flash mode here and optionally a project name
#
PROJECT =
RUN_FROM_FLASH = 1
HEAP_SIZE = 4k
STACK_SIZE = 2k
USE_HARD_FPU = 1
#
# manually add c, assembly or c++ source files if necessary.
# for instance: SRC = somefolder/file.c OR $(call find,somefolder/,*.c)
#
SRC = $(call find,3rdparty/freertos/,*.c)
CXXSRC =
ASRC =
#
# List all include directories here (besides src/include)
#
INCDIR = 3rdparty/freertos/include \
3rdparty/freertos/portable/GCC/ARM_CM4F \
3rdparty/cmsis/CMSIS/Core/Include \
3rdparty/cmsis-header-stm32/stm32f4xx/Include
MEMORYMAP = ./prj/stm32f407ve.ld
#
# Define optimisation level here
#
ifeq ($(RUN_FROM_FLASH), 1)
OPT = -O3 -falign-functions=16 -fno-inline -fomit-frame-pointer -flto
else
OPT = -Og -g3 -Wa,-g -fstack-usage
endif
################################################################################
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
CP = arm-none-eabi-objcopy
AS = arm-none-eabi-gcc -x assembler-with-cpp
SZ = arm-none-eabi-size
DUMP = arm-none-eabi-objdump
#
# automatically determine project file name based on directory name if empty
#
ifndef PROJECT
PROJECT = $(notdir $(CURDIR))
endif
#
# Define FPU settings here.
#
ifeq ($(USE_HARD_FPU), 1)
FPU = -mhard-float -mfloat-abi=hard -mfpu=fpv4-sp-d16
else
FPU =
endif
#
# define an additional symbol when code runs from ram
#
ifeq ($(RUN_FROM_FLASH), 1)
DEFS += -DRUN_FROM_FLASH
endif
#
# default directories to look for include files
#
INCDIR += $(sort $(dir $(call find,src/include/,*)))
#
# Define linker script file here depending on the ram/flash mode
#
ifeq ($(RUN_FROM_FLASH), 1)
LDSCRIPT = ./prj/flash.ld
else
LDSCRIPT = ./prj/ram.ld
endif
#
# automatically find all c, assembly and c++ source files
#
SRC += $(call find,src/,*.c)
CXXSRC += $(call find,src/,*.cpp)
ASRC += $(call find,src/,*.s)
ASRC += $(call find,src/,*.S)
INC = $(patsubst %,-I%,$(INCDIR))
LIB = $(patsubst %,-L%,$(LIBDIR))
OBJS = $(addsuffix .o, $(ASRC) $(SRC) $(CXXSRC))
LIST = $(addsuffix .lss, $(ASRC) $(SRC) $(CXXSRC))
DEP = $(addsuffix .d, $(ASRC) $(SRC) $(CXXSRC))
SU = $(addsuffix .su, $(SRC) $(CXXSRC))
MCFLAGS = -mcpu=$(MCU) -mthumb $(FPU)
WARNFLAGS = -Wall -Wextra -Wimplicit-fallthrough -Wshadow -Wunused
WARNFLAGS += -Wmisleading-indentation -Wswitch-default
WARNFLAGS += -Wformat=2 -Wformat-truncation -Wundef -Wpedantic
WARNFLAGS += -Wstack-usage=1000
COMMONFLAGS = -ffunction-sections -fdata-sections -fverbose-asm -fno-common
ASFLAGS = $(MCFLAGS) $(OPT) $(DEFS) $(WARNFLAGS) $(COMMONFLAGS)
CPFLAGS = $(MCFLAGS) $(OPT) $(DEFS) $(WARNFLAGS) $(COMMONFLAGS)
CPFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CPFLAGS += -MD -MP -MF $(@:.o=.d)
CXXFLAGS = $(MCFLAGS) $(OPT) $(DEFS) $(WARNFLAGS) $(COMMONFLAGS)
CXXFLAGS += -std=c++20
CXXFLAGS += -fno-threadsafe-statics -fno-use-cxa-atexit -fno-rtti -fno-exceptions
CXXFLAGS += -MD -MP -MF $(@:.o=.d)
LDFLAGS = $(MCFLAGS) $(OPT) $(DEFS) $(WARNFLAGS) $(COMMONFLAGS)
LDFLAGS += -T$(MEMORYMAP) -T$(LDSCRIPT)
LDFLAGS += -Xlinker --defsym=__HEAP_SIZE=$(HEAP_SIZE)
LDFLAGS += -Xlinker --defsym=__STACK_SIZE=$(STACK_SIZE)
LDFLAGS += -Wl,-Map=lst/$(PROJECT).map,--cref,--gc-sections,--no-warn-mismatch,--no-warn-rwx-segments $(LIB)
.PHONY: all
all: $(OBJS) bin/$(PROJECT).elf \
lst/$(PROJECT).lss $(LDSCRIPT) Makefile
@$(SZ) --format=Berkeley -d bin/$(PROJECT).elf
%.c.o : %.c $(LDSCRIPT) Makefile
@echo "CC $<"
@$(CC) -c $(CPFLAGS) $(INC) $< -o $@
@$(DUMP) -S -d $@ > $(addsuffix .lss, $<)
%.cpp.o : %.cpp $(LDSCRIPT) Makefile
@echo "CXX $<"
@$(CXX) -c $(CXXFLAGS) $(INC) $< -o $@
@$(DUMP) -S -d $@ > $(addsuffix .lss, $<)
%.s.o : %.s $(LDSCRIPT) Makefile
@echo "AS $<"
@$(AS) -c $(ASFLAGS) $< -o $@
@$(DUMP) -S -d $@ > $(addsuffix .lss, $<)
%.S.o : %.S $(LDSCRIPT) Makefile
@echo "AS $<"
@$(AS) -c $(ASFLAGS) $< -o $@
@$(DUMP) -S -d $@ > $(addsuffix .lss, $<)
bin/$(PROJECT).elf: $(OBJS) $(LDSCRIPT) Makefile
@echo "LD $@"
@$(CXX) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
lst/$(PROJECT).lss: bin/$(PROJECT).elf $(LDSCRIPT) Makefile
@echo "OBJDUMP $(PROJECT).elf"
@$(DUMP) -S -d bin/$(PROJECT).elf > $@
.PHONY: doc
doc:
@doxygen
@if [ -e doc/latex ]; then cd doc/latex; $(MAKE); fi;
.PHONY: clean
clean:
@rm -rfv $(OBJS) $(LIST) $(DEP) $(SU)
@rm -rfv bin/$(PROJECT).elf bin/$(PROJECT).hex bin/$(PROJECT).bin bin/$(PROJECT).s19
@rm -rfv lst/$(PROJECT).lss lst/$(PROJECT).map
-include $(DEP)