-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathapp_make.gmk
439 lines (366 loc) · 14.2 KB
/
app_make.gmk
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#
# Copyright Christopher Kormanyos 2007 - 2024.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# ------------------------------------------------------------------------------
#
# Makefile
#
# Build file for the reference application using the GNU tools
#
# Based on GNU Make 4.2.1
#
# 07-April-2010
#
# See also a definitive list of GCC command line options
# (for numerous target systems) here:
# https://man7.org/linux/man-pages/man1/gcc.1.html
#
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# operating system
# ------------------------------------------------------------------------------
ifeq ($(TYP_OS),)
ifeq ($(OS),Windows_NT)
TYP_OS := WIN
else
TYP_OS := NIX
endif
endif
# ------------------------------------------------------------------------------
# punctuation
# ------------------------------------------------------------------------------
DQUOTE := \"
$(DQUOTE) := \"
SEMICOLON := ;
$(SEMICOLON) := ;
DOLLAR := $$
$(DOLLAR) := $$
# ------------------------------------------------------------------------------
# null device
# ------------------------------------------------------------------------------
ifeq ($(TYP_OS),WIN)
NULL_DEVICE := NUL
$(NULL_DEVICE) := NUL
else
NULL_DEVICE := /dev/null
$(NULL_DEVICE) := /dev/null
endif
# ------------------------------------------------------------------------------
# paths
# ------------------------------------------------------------------------------
PATH_APP = src
PATH_TGT = target/micros/$(TGT)
PATH_APP_MAKE = target/app/make
PATH_TGT_MAKE = $(PATH_TGT)/make
PATH_BIN = bin
PATH_TMP = tmp
PATH_OBJ = $(PATH_TMP)/obj
PATH_LST = $(PATH_TMP)/lst
PATH_ERR = $(PATH_TMP)/err
# ------------------------------------------------------------------------------
# standard shell tools
# ------------------------------------------------------------------------------
ifeq ($(TYP_OS),WIN)
PATH_TOOLS = tools
PATH_TOOLS_UTIL = $(PATH_TOOLS)\Util
PATH_TOOLS_MINGW = $(PATH_TOOLS_UTIL)\msys64\usr
PATH_TOOLS_MINGW_BIN = $(PATH_TOOLS_MINGW)\bin
PATH_TOOLS_CC = $(PATH_TOOLS_MINGW)\local\gcc-$(GCC_VERSION)-$(GCC_TARGET)\bin
ECHO = $(PATH_TOOLS_MINGW_BIN)\echo.exe
MAKE = $(PATH_TOOLS_MINGW_BIN)\make.exe
MKDIR = $(PATH_TOOLS_MINGW_BIN)\mkdir.exe
RM = $(PATH_TOOLS_MINGW_BIN)\rm.exe
SED = $(PATH_TOOLS_MINGW_BIN)\sed.exe
else
ECHO = echo
MAKE = make
MKDIR = mkdir
RM = rm
SED = sed
ifneq ($(MY_GMAKE),)
MAKE := $(MY_GMAKE)
endif
endif
# ------------------------------------------------------------------------------
# the application
# ------------------------------------------------------------------------------
APP = $(PATH_BIN)/ref_app
IMAGE_FILE = $(APP).bin
RULE_SPECIAL_MAKE_IMAGE_FILE =
RULE_SPECIAL_MAKE_FLASH_BATCH =
WARN_FLAGS :=
# ------------------------------------------------------------------------------
# linker definition file
# ------------------------------------------------------------------------------
LINKER_DEFINITION_FILE := $(PATH_TGT_MAKE)/$(TGT).ld
# ------------------------------------------------------------------------------
# include the target-specific make files
# ------------------------------------------------------------------------------
include $(PATH_APP_MAKE)/app_files.gmk # Application file list
include $(PATH_TGT_MAKE)/$(TGT)_files.gmk # Target filelist
include $(PATH_TGT_MAKE)/$(TGT)_flags.gmk # Target compiler flags
# ------------------------------------------------------------------------------
# object files
# ------------------------------------------------------------------------------
FILES_TMP = $(FILES_CPP) $(FILES_TGT)
FILES_O = $(addprefix $(PATH_OBJ)/, $(notdir $(addsuffix .o, $(FILES_TMP))))
# ------------------------------------------------------------------------------
# VPATH definition
#
# VPATH is required for the maker to find the C/C++/ASM-Source files.
# Extract the directory/module names from the file list with the dir
# command and remove the duplicated directory names with the sort command.
# FILES_PRJ is listed first to make sure that the source files in the project
# directory are searched first.
# ------------------------------------------------------------------------------
VPATH := $(sort $(dir $(FILES_TMP)))
# ------------------------------------------------------------------------------
# Development tools
# ------------------------------------------------------------------------------
ifeq ($(TYP_OS),WIN)
ifeq ($(GCC_PREFIX),)
ifeq ($(AR),)
AR := $(PATH_TOOLS_CC)\ar.exe
endif
ifeq ($(AS),)
AS := $(PATH_TOOLS_CC)\g++.exe
endif
ifeq ($(CC),)
CC := $(PATH_TOOLS_CC)\g++.exe
endif
ifeq ($(CPPFILT),)
CPPFILT := $(PATH_TOOLS_CC)\c++filt.exe
endif
ifeq ($(NM),)
NM := $(PATH_TOOLS_CC)\nm.exe
endif
ifeq ($(OBJDUMP),)
OBJDUMP := $(PATH_TOOLS_CC)\objdump.exe
endif
ifeq ($(OBJCOPY),)
OBJCOPY := $(PATH_TOOLS_CC)\objcopy.exe
endif
ifeq ($(READELF),)
READELF := $(PATH_TOOLS_CC)\readelf.exe
endif
ifeq ($(SIZE),)
SIZE := $(PATH_TOOLS_CC)\size.exe
endif
else
AR := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-ar.exe
AS := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-g++.exe
CC := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-g++.exe
CPPFILT := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-c++filt.exe
NM := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-nm.exe
OBJDUMP := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objdump.exe
OBJCOPY := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objcopy.exe
READELF := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-readelf.exe
SIZE := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-size.exe
endif
else
ifeq ($(GCC_PREFIX),)
AR := ar
AS := g++
CC := g++
CPPFILT := c++filt
NM := nm
OBJDUMP := objdump
OBJCOPY := objcopy
READELF := readelf
SIZE := size
else
AR := $(GCC_PREFIX)-ar
AS := $(GCC_PREFIX)-g++
CC := $(GCC_PREFIX)-g++
CPPFILT := $(GCC_PREFIX)-c++filt
NM := $(GCC_PREFIX)-nm
OBJDUMP := $(GCC_PREFIX)-objdump
OBJCOPY := $(GCC_PREFIX)-objcopy
READELF := $(GCC_PREFIX)-readelf
SIZE := $(GCC_PREFIX)-size
endif
endif
# ------------------------------------------------------------------------------
# Tool parameters
# ------------------------------------------------------------------------------
C_INCLUDES = $(TGT_INCLUDES) \
-I$(PATH_APP) \
-I$(PATH_APP)/mcal/$(TGT)
ifeq ($(WARN_FLAGS),)
WARN_FLAGS = -Wall \
-Wextra \
-Wpedantic \
-Wmain \
-Wundef \
-Wconversion \
-Wsign-conversion \
-Wunused-parameter \
-Wuninitialized \
-Wmissing-declarations \
-Wshadow \
-Wunreachable-code \
-Wswitch-default \
-Wswitch-enum \
-Wcast-align \
-Wmissing-include-dirs \
-Winit-self \
-Wfloat-equal \
-Wdouble-promotion
endif
GCCFLAGS = -g \
$(WARN_FLAGS) \
-Wno-comment \
-gdwarf-2 \
-fno-exceptions \
-fdata-sections \
-ffunction-sections
CFLAGS = $(GCCFLAGS) \
$(TGT_CFLAGS) \
-x c
CXXFLAGS = $(GCCFLAGS) \
$(TGT_CXXFLAGS) \
-x c++ \
-fno-rtti \
-fno-use-cxa-atexit \
-fno-threadsafe-statics \
-ftemplate-depth=128 \
-Wzero-as-null-pointer-constant
AFLAGS = $(GCCFLAGS) \
$(TGT_CXXFLAGS) \
$(TGT_AFLAGS) \
-x assembler
LDFLAGS = $(CXXFLAGS) \
$(TGT_LDFLAGS) \
-x none \
-Wl,--print-memory-usage
# ------------------------------------------------------------------------------
# Main-Dependencies (app: all)
# ------------------------------------------------------------------------------
.PHONY: all
all: clean_prj version $(APP)_flash.hex $(APP)_nm.txt $(APP).$(TGT_SUFFIX)
# ------------------------------------------------------------------------------
# Main-Dependencies (app: rebuild)
# ------------------------------------------------------------------------------
.PHONY: rebuild
rebuild: clean_all all
# ------------------------------------------------------------------------------
# clean project
# ------------------------------------------------------------------------------
.PHONY: clean_prj
clean_prj:
@-$(ECHO) +++ cleaning project
@-$(MKDIR) -p $(PATH_BIN)
@-$(MKDIR) -p $(PATH_OBJ)
@-$(MKDIR) -p $(PATH_ERR)
@-$(MKDIR) -p $(PATH_LST)
@-$(RM) -r $(PATH_BIN) 2>$(NULL_DEVICE)
@-$(MKDIR) -p $(PATH_BIN)
# ------------------------------------------------------------------------------
# clean all
# ------------------------------------------------------------------------------
.PHONY: clean_all
clean_all:
@-$(ECHO) +++ cleaning all
@-$(MKDIR) -p $(PATH_BIN)
@-$(MKDIR) -p $(PATH_OBJ)
@-$(MKDIR) -p $(PATH_ERR)
@-$(MKDIR) -p $(PATH_LST)
@-$(RM) -r $(PATH_OBJ) 2>$(NULL_DEVICE)
@-$(RM) -r $(PATH_ERR) 2>$(NULL_DEVICE)
@-$(RM) -r $(PATH_LST) 2>$(NULL_DEVICE)
@-$(RM) -r $(PATH_BIN) 2>$(NULL_DEVICE)
@-$(MKDIR) -p $(PATH_BIN)
# ------------------------------------------------------------------------------
# print the GNUmake version and the compiler version
# ------------------------------------------------------------------------------
.PHONY: version
version:
# Print the GNU make version and the compiler version
@$(ECHO)
@$(ECHO) +++ Print GNUmake version
@$(MAKE) --version
@$(ECHO)
@$(ECHO) +++ Print compiler version
@$(CC) -v
@$(ECHO)
@$(ECHO) +++ Print compiler include paths
@$(ECHO) $(C_INCLUDES)
@$(ECHO)
ifeq ($(TYP_OS),WIN)
@$(ECHO) +++ Print compiler include paths (for VisualStudio(R) browsing)
@$(ECHO) $(addsuffix $(SEMICOLON),$(subst -I,$$\(ProjectDir\)/, $(C_INCLUDES)))
@$(ECHO)
endif
@$(ECHO) +++ Print compiler definitions
@$(ECHO) $(C_DEFINES)
@$(ECHO)
@$(ECHO) +++ Print compiler CXXFLAGS flags
@$(ECHO) $(CXXFLAGS)
@$(ECHO)
# ------------------------------------------------------------------------------
# link/locate application and generate an assembly list file
# ------------------------------------------------------------------------------
$(APP).$(TGT_SUFFIX) : $(LINKER_DEFINITION_FILE) $(FILES_O)
@-$(ECHO) +++ linking application to generate: $(APP).$(TGT_SUFFIX)
@-$(CC) $(LDFLAGS) $(FILES_O) -o $(APP).$(TGT_SUFFIX)
# ------------------------------------------------------------------------------
# parse the object files to obtain symbol information, and create a size summary
# ------------------------------------------------------------------------------
$(APP)_nm.txt : $(APP).$(TGT_SUFFIX)
@-$(ECHO) +++ parsing symbols with nm to generate: $(APP)_nm.txt
@-$(NM) --numeric-sort --print-size $(APP).$(TGT_SUFFIX) > $(APP)_nm.txt
@-$(ECHO) +++ demangling symbols with c++filt to generate: $(APP)_cppfilt.txt
@-$(NM) --numeric-sort --print-size $(APP).$(TGT_SUFFIX) | $(CPPFILT) > $(APP)_cppfilt.txt
@-$(ECHO) +++ parsing symbols with readelf to generate: $(APP)_readelf.txt
ifeq ($(TGT_SUFFIX),elf)
@-$(READELF) --syms $(APP).$(TGT_SUFFIX) > $(APP)_readelf.txt
else
@-$(ECHO) +++ not available for: $(APP).$(TGT_SUFFIX).
endif
@-$(ECHO) +++ creating size summary table with size to generate: $(APP)_size.txt
@-$(SIZE) -A -t $(APP).$(TGT_SUFFIX) > $(APP)_size.txt
# ------------------------------------------------------------------------------
# create hex mask
# ------------------------------------------------------------------------------
$(APP)_flash.hex : $(APP).$(TGT_SUFFIX)
@-$(ECHO) +++ creating hex module: $(APP).$(TGT_SUFFIX)
ifeq ($(TGT_SUFFIX),elf)
@-$(ECHO) +++ creating hex module: $(APP).hex
@-$(OBJCOPY) $(APP).$(TGT_SUFFIX) -O ihex $(APP).hex
@-$(ECHO) +++ creating srec module: $(APP).s19
@-$(OBJCOPY) $(APP).$(TGT_SUFFIX) -O srec $(APP).s19
@-$(ECHO) +++ creating disassembly listing: $(APP)_disassembly.txt
@-$(OBJDUMP) -D $(APP).$(TGT_SUFFIX) > $(APP)_disassembly.txt
else
@-$(ECHO) +++ creating hex module disabled for non-ELF absolute objet file.
endif
ifeq ($(RULE_SPECIAL_MAKE_IMAGE_FILE),)
@-$(ECHO) +++ creating special image file
@-$(ECHO) +++ disabled because there is no special image file
else
@-$(ECHO) +++ creating special image file
@-$(RULE_SPECIAL_MAKE_IMAGE_FILE)
endif
ifeq ($(RULE_SPECIAL_MAKE_FLASH_BATCH),)
@-$(ECHO) +++ creating special flash batch file
@-$(ECHO) +++ disabled because there is no special flash batch file
else
@-$(ECHO) +++ creating special flash batch file
@-$(RULE_SPECIAL_MAKE_FLASH_BATCH)
endif
# ------------------------------------------------------------------------------
# Dependencyfile include (build)
#
# Include all dependency (*.d) files generated previously from the compiler.
# If the files do not exist then the includes will be ignored.
# ------------------------------------------------------------------------------
ifneq ($(MAKECMDGOALS),rebuild)
-include $(subst .o,.d,$(FILES_O))
endif
# ------------------------------------------------------------------------------
# include the pattern build rules
# ------------------------------------------------------------------------------
include $(PATH_APP_MAKE)/app_rules.gmk