forked from aegean-odyssey/mpmd_marlin_1.1.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
290 lines (214 loc) · 7.84 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
### simple(-ish) makefile to build Marlin images
PROJECT = mpmd_marlin_1.1.x
VERSION = 119
RELEASE = 16
STM32CUBE = STM32Cube-1.10.1
MARLIN11X = Marlin-1.1.x
MARLINCHG = marlin_changes
DEFINES += -DMAKE_PROJECT='"${PROJECT}"'
DEFINES += -DMAKE_VERSION='"${VERSION}"'
DEFINES += -DMAKE_RELEASE='"${RELEASE}"'
PRJ = ${PROJECT}-${VERSION}r${RELEASE}
### BUILD VARIANTS
SM0000 = -DMAKE_STEPPERS_0000
SM0001 = -DMAKE_STEPPERS_0001
SM1110 = -DMAKE_STEPPERS_1110
SM1111 = -DMAKE_STEPPERS_1111
AC_FAN = -DMAKE_AC_FAN
PC_FAN = -DMAKE_PC_FAN
L05AMP = -DMAKE_05ALIMIT
L10AMP = -DMAKE_10ALIMIT
${PRJ}-SM0000-ACfan-05Alimit~ : DEFINES += ${SM0000} ${AC_FAN} ${L05AMP}
${PRJ}-SM0000-ACfan-10Alimit~ : DEFINES += ${SM0000} ${AC_FAN} ${L10AMP}
${PRJ}-SM0000-PCfan-05Alimit~ : DEFINES += ${SM0000} ${PC_FAN} ${L05AMP}
${PRJ}-SM0000-PCfan-10Alimit~ : DEFINES += ${SM0000} ${PC_FAN} ${L10AMP}
${PRJ}-SM0001-ACfan-05Alimit~ : DEFINES += ${SM0001} ${AC_FAN} ${L05AMP}
${PRJ}-SM0001-ACfan-10Alimit~ : DEFINES += ${SM0001} ${AC_FAN} ${L10AMP}
${PRJ}-SM0001-PCfan-05Alimit~ : DEFINES += ${SM0001} ${PC_FAN} ${L05AMP}
${PRJ}-SM0001-PCfan-10Alimit~ : DEFINES += ${SM0001} ${PC_FAN} ${L10AMP}
${PRJ}-SM1110-ACfan-05Alimit~ : DEFINES += ${SM1110} ${AC_FAN} ${L05AMP}
${PRJ}-SM1110-ACfan-10Alimit~ : DEFINES += ${SM1110} ${AC_FAN} ${L10AMP}
${PRJ}-SM1110-PCfan-05Alimit~ : DEFINES += ${SM1110} ${PC_FAN} ${L05AMP}
${PRJ}-SM1110-PCfan-10Alimit~ : DEFINES += ${SM1110} ${PC_FAN} ${L10AMP}
${PRJ}-SM1111-ACfan-05Alimit~ : DEFINES += ${SM1111} ${AC_FAN} ${L05AMP}
${PRJ}-SM1111-ACfan-10Alimit~ : DEFINES += ${SM1111} ${AC_FAN} ${L10AMP}
${PRJ}-SM1111-PCfan-05Alimit~ : DEFINES += ${SM1111} ${PC_FAN} ${L05AMP}
${PRJ}-SM1111-PCfan-10Alimit~ : DEFINES += ${SM1111} ${PC_FAN} ${L10AMP}
VARIANTS := \
${PRJ}-SM0000-ACfan-05Alimit~ \
${PRJ}-SM0000-ACfan-10Alimit~ \
${PRJ}-SM0000-PCfan-05Alimit~ \
${PRJ}-SM0000-PCfan-10Alimit~ \
${PRJ}-SM0001-ACfan-05Alimit~ \
${PRJ}-SM0001-ACfan-10Alimit~ \
${PRJ}-SM0001-PCfan-05Alimit~ \
${PRJ}-SM0001-PCfan-10Alimit~ \
${PRJ}-SM1110-ACfan-05Alimit~ \
${PRJ}-SM1110-ACfan-10Alimit~ \
${PRJ}-SM1110-PCfan-05Alimit~ \
${PRJ}-SM1110-PCfan-10Alimit~ \
${PRJ}-SM1111-ACfan-05Alimit~ \
${PRJ}-SM1111-ACfan-10Alimit~ \
${PRJ}-SM1111-PCfan-05Alimit~ \
${PRJ}-SM1111-PCfan-10Alimit~
### testing variants
T1 : DEFINES += -DMAKE_05ALIMIT -DMAKE_AC_FAN
T1 = ${PROJECT}-${VERSION}r${RELEASE}-ACfan
T2 : DEFINES += -DMAKE_05ALIMIT -DMAKE_PC_FAN
T2 = ${PROJECT}-${VERSION}r${RELEASE}-PCfan
### DIRECTORY ABBREVIATIONS
# use the path to the Makefile as root
ZD := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD = ${ZD}build
CMSIS = ${ZD}${STM32CUBE}/Drivers/CMSIS
DEVICE = ${ZD}${STM32CUBE}/Drivers/CMSIS/Device/ST/STM32F0xx
HAL_SRC = ${ZD}${STM32CUBE}/Drivers/STM32F0xx_HAL_Driver/Src
USBDEVICE = Middlewares/ST/STM32_USB_Device_Library
CDC_SRC = ${ZD}${STM32CUBE}/${USBDEVICE}/Class/CDC/Src
USB_SRC = ${ZD}${STM32CUBE}/${USBDEVICE}/Core/Src
STM32F0 = ${ZD}stm32f0xx
MARLIN = ${ZD}Marlin
MARLIN_ = ${ZD}${MARLINCHG}
ARDUINO = ${ZD}${MARLINCHG}/arduino_fakes
### SOURCE FILES
LINKER_LD = ${STM32F0}/LinkerScript.ld
PRJ_INCLUDE_H = ${MARLIN}/HAL_stm32.h
BSP_INCLUDE_H = ${STM32F0}/stm32f0xx_hal_conf.h
PRJ_SOURCES = \
$(wildcard ${MARLIN}/*.c) \
$(wildcard ${MARLIN}/*.cpp)
PRJ_EXCLUDE = \
${MARLIN}/configuration_store.cpp \
${MARLIN}/MarlinSerial.cpp \
${MARLIN}/Sd2Card.cpp \
${MARLIN}/watchdog.cpp \
${MARLIN}/malyanlcd.cpp
BSP_SOURCES = \
$(wildcard ${STM32F0}/*.s) \
$(wildcard ${HAL_SRC}/*.c) \
$(wildcard ${USB_SRC}/*.c) \
$(wildcard ${CDC_SRC}/*.c) \
$(wildcard ${STM32F0}/*.c)
BSP_EXCLUDE = \
${CDC_SRC}/usbd_cdc.c \
${HAL_SRC}/stm32f0xx_hal_pcd.c \
$(wildcard ${HAL_SRC}/*_template.c) \
$(wildcard ${USB_SRC}/*_template.c) \
$(wildcard ${CDC_SRC}/*_template.c)
### TARGET LISTS
PRJ_SRCS = $(filter-out $(PRJ_EXCLUDE),$(PRJ_SOURCES))
PRJ_OBJS = $(addsuffix .o,$(basename $(notdir $(PRJ_SRCS))))
PRJ_DEPS = $(PRJ_OBJS:.o=.d)
BSP_SRCS = $(filter-out $(BSP_EXCLUDE),$(BSP_SOURCES))
BSP_OBJS = $(addsuffix .o,$(basename $(notdir $(BSP_SRCS))))
BSP_DEPS = $(BSP_OBJS:.o=.d)
# number of dependency (.d) files to expect
D_COUNT = $(words $(PRJ_DEPS) $(BSP_DEPS))
### SOURCE FILE SEARCH PATHS
VPATH = $(sort $(dir $(PRJ_SRCS) $(BSP_SRCS)))
### INCLUDE FILE SEARCH PATHS
INCLUDE = \
-isystem ${DEVICE}/Include \
-isystem ${CMSIS}/Include \
-isystem ${CMSIS}/DSP/Include \
-isystem ${HAL_SRC}/../Inc \
-isystem ${USB_SRC}/../Inc \
-isystem ${CDC_SRC}/../Inc \
-isystem ${ARDUINO} \
-I${STM32F0} \
-I${MARLIN}
### BUILD FLAGS
$(BSP_OBJS) $(BSP_DEPS) : CFLAGS += -include ${BSP_INCLUDE_H}
$(PRJ_OBJS) $(PRJ_DEPS) : CFLAGS += -include ${PRJ_INCLUDE_H}
LDFLAGS += -L${CMSIS}/Lib/GCC
LDLIBS += -larm_cortexM0l_math
CFLAGS += --specs=nano.specs ${DEFINES} $(foreach i,$(select),${${i}})
CPPFLAGS += -fsingle-precision-constant -fmerge-all-constants
CFLAGS += -Os -fdata-sections -ffunction-sections -flto $(INCLUDE)
CXXFLAGS += $(CFLAGS) -fno-exceptions -fno-rtti
LDFLAGS += --specs=nano.specs -u _printf_float -Wl,--gc-sections -flto
ASFLAGS += -I${DEVICE}/Include
### BUILD TOOLS
CXX = arm-none-eabi-g++ -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
CC = arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
AS = arm-none-eabi-as -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
AR = arm-none-eabi-ar
OBJCOPY = arm-none-eabi-objcopy
BINSIZE = arm-none-eabi-size
### MAKE RULES
.PHONY : any one all clean realclean distclean depends PRJ T1 T2 ALL
.PRECIOUS : %.elf
any : distclean realclean ${MARLIN} ${BUILD}
$(call variant,PRJ)
one : ${MARLIN} ${BUILD}
ifneq (${D_COUNT},$(words $(wildcard ${BUILD}/*.d)))
# # something's missing, re-create dependencies
$(MAKE) -C ${BUILD} -f ${ZD}Makefile depends
endif
$(MAKE) -C ${BUILD} -f ${ZD}Makefile PRJ
all : distclean realclean ${MARLIN} ${BUILD}
$(foreach i, T1 T2 ,$(call variant,${i}))
ALL : distclean realclean ${MARLIN} ${BUILD}
$(foreach i,$(VARIANTS),$(call variant,${i}))
define variant =
####### # BUILDING VARIANT $(1)
@echo "##########"
@echo "##BUILDING $(1)"
$(MAKE) -C ${BUILD} -f ${ZD}Makefile realclean
$(MAKE) -C ${BUILD} -f ${ZD}Makefile depends
$(MAKE) -C ${BUILD} -f ${ZD}Makefile $(1)
endef
$(VARIANTS) : %~ : %.otx %.bin # %.map %.elf
@cp -u $^ ${ZD} && cat $<
@touch $@
${MARLIN} :
mkdir -p $@
cd $@ && cp -sf ../${MARLIN11X}/Marlin/*.* .
cd $@ && cp -sf ../${MARLINCHG}/*.* .
${BUILD} :
mkdir -p $@
distclean : clean
$(MAKE) -C ${MARLIN_} -f ${ZD}Makefile realclean
$(MAKE) -C ${STM32F0} -f ${ZD}Makefile realclean
rm -fR ${BUILD}
# # safely (conditionally) remove the Marlin directory
-find -P ${MARLIN} -type l -delete
-rmdir ${MARLIN}
depends : $(BSP_DEPS) $(PRJ_DEPS)
PRJ : ${PRJ}.otx ${PRJ}.bin ${PRJ}.map ${PRJ}.elf
@cp -u $^ ${ZD} && cat $<
T1 : ${T1}.otx ${T1}.bin ${T1}.map ${T1}.elf
@cp -u $^ ${ZD} && cat $<
T2 : ${T2}.otx ${T2}.bin ${T2}.map ${T2}.elf
@cp -u $^ ${ZD} && cat $<
%.elf : ${LINKER_LD} $(BSP_OBJS) $(PRJ_OBJS)
$(CXX) $(LDFLAGS) -Wl,-Map=$(@:.elf=.map) -o $@ -T$^ $(LDLIBS)
%.otx : %.elf
$(BINSIZE) -A -B $< >$@
%.bin : %.elf
$(OBJCOPY) -O binary $< $@
%.map : %.elf
realclean : clean
rm -f *.elf *.otx *.map *.bin
clean :
rm -f .*~ *~ *.o *.d *.a
### AUTOMATIC PREREQUISITES
# ignore this stuff if our target is clean, realclean, or distclean
ifeq (,$(findstring ${MAKECMDGOALS},clean realclean distclean))
%.d : %.s
echo "$(@:.d=.o) $@: $<" >$@
%.d : %.c
$(CC) -MM -MF $@ -MT '$(@:.d=.o) $@' $(CPPFLAGS) $(CFLAGS) $<
%.d : %.cpp
$(CXX) -MM -MF $@ -MT '$(@:.d=.o) $@' $(CPPFLAGS) $(CXXFLAGS) $<
ifeq (${MAKECMDGOALS},depends)
define depends_rule =
$(basename $(notdir $(1))).d : $(1)
endef
# for depends, automatically create a rule for each source file
$(foreach f,$(BSP_SRCS) $(PRJ_SRCS),$(eval $(call depends_rule,$(f))))
else
# otherwise, include our rule for each source file (if it exists)
include $(notdir $(realpath $(BSP_DEPS) $(PRJ_DEPS)))
endif
endif