1 | #=============================================================================#
|
2 | # ARM makefile
|
3 | #
|
4 | # author: Freddie Chopin, http://www.freddiechopin.info/
|
5 | # last change: 2012-03-22
|
6 | #
|
7 | # this makefile is based strongly on many examples found in the network
|
8 | #=============================================================================#
|
9 |
|
10 | #=============================================================================#
|
11 | # toolchain configuration
|
12 | #=============================================================================#
|
13 |
|
14 | ##Zum Testen:
|
15 | $ TOOLCHAIN = C:\ARMtoolchains\arm-none-eabi-gcc\bin\arm-none-eabi-
|
16 | #$ TOOLCHAIN = arm-none-eabi-
|
17 |
|
18 | CXX = $(TOOLCHAIN)g++
|
19 | CC = $(TOOLCHAIN)gcc
|
20 | AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
|
21 | OBJCOPY = $(TOOLCHAIN)objcopy
|
22 | OBJDUMP = $(TOOLCHAIN)objdump
|
23 | SIZE = $(TOOLCHAIN)size
|
24 | RM = rm -f
|
25 |
|
26 | #=============================================================================#
|
27 | # project configuration
|
28 | #=============================================================================#
|
29 |
|
30 | # project name
|
31 | PROJECT = STemWinTest
|
32 |
|
33 | # core type
|
34 | CORE = cortex-m4
|
35 |
|
36 | # linker script
|
37 | LD_SCRIPT = STM32F429G.ld
|
38 |
|
39 | # output folder (absolute or relative path, leave empty for in-tree compilation)
|
40 | OUT_DIR = out
|
41 |
|
42 | # global definitions for C++, C and ASM (e.g. "symbol_with_value=0xDEAD symbol_without_value")
|
43 | GLOBAL_DEFS = STM32F429_439xx
|
44 |
|
45 | # C++ definitions
|
46 | CXX_DEFS =
|
47 |
|
48 | # C definitions
|
49 | C_DEFS =
|
50 |
|
51 | # ASM definitions
|
52 | AS_DEFS =
|
53 |
|
54 | # include directories (absolute or relative paths to additional folders with
|
55 | # headers, current folder is always included)
|
56 | INC_DIRS = inc GUI/Config GUI/Inc
|
57 |
|
58 | # library directories (absolute or relative paths to additional folders with
|
59 | # libraries)
|
60 | LIB_DIRS =
|
61 |
|
62 | # libraries (additional libraries for linking, e.g. "-lm -lsome_name" to link
|
63 | # math library libm.a and libsome_name.a)
|
64 | LIBS = GUI/Lib/STemWin522_CM4_GCC.a
|
65 |
|
66 | # additional directories with source files (absolute or relative paths to
|
67 | # folders with source files, current folder is always included)
|
68 | SRCS_DIRS = GUI/Config
|
69 |
|
70 | # extension of C++ files
|
71 | CXX_EXT = cpp
|
72 |
|
73 | # wildcard for C++ source files (all files with CXX_EXT extension found in
|
74 | # current folder and SRCS_DIRS folders will be compiled and linked)
|
75 | CXX_SRCS = $(wildcard $(patsubst %, %/*.$(CXX_EXT), . $(SRCS_DIRS)))
|
76 |
|
77 | # extension of C files
|
78 | C_EXT = c
|
79 |
|
80 | # wildcard for C source files (all files with C_EXT extension found in current
|
81 | # folder and SRCS_DIRS folders will be compiled and linked)
|
82 | C_SRCS = $(wildcard $(patsubst %, %/*.$(C_EXT), . $(SRCS_DIRS)))
|
83 |
|
84 | # extension of ASM files
|
85 | AS_EXT = S
|
86 |
|
87 | # wildcard for ASM source files (all files with AS_EXT extension found in
|
88 | # current folder and SRCS_DIRS folders will be compiled and linked)
|
89 | AS_SRCS = $(wildcard $(patsubst %, %/*.$(AS_EXT), . $(SRCS_DIRS)))
|
90 |
|
91 | # optimization flags ("-O0" - no optimization, "-O1" - optimize, "-O2" -
|
92 | # optimize even more, "-Os" - optimize for size or "-O3" - optimize yet more)
|
93 | OPTIMIZATION = -O0
|
94 |
|
95 | # set to 1 to optimize size by removing unused code and data during link phase
|
96 | REMOVE_UNUSED = 1
|
97 |
|
98 | # set to 1 to compile and link additional code required for C++
|
99 | USES_CXX = 0
|
100 |
|
101 | # define warning options here
|
102 | CXX_WARNINGS = -Wall -Wextra
|
103 | C_WARNINGS = -Wall -Wstrict-prototypes -Wextra
|
104 |
|
105 | # C++ language standard ("c++98", "gnu++98" - default, "c++0x", "gnu++0x")
|
106 | CXX_STD = gnu++98
|
107 |
|
108 | # C language standard ("c89" / "iso9899:1990", "iso9899:199409",
|
109 | # "c99" / "iso9899:1999", "gnu89" - default, "gnu99")
|
110 | C_STD = gnu89
|
111 |
|
112 | #=============================================================================#
|
113 | # set the VPATH according to SRCS_DIRS
|
114 | #=============================================================================#
|
115 |
|
116 | VPATH = $(SRCS_DIRS)
|
117 |
|
118 | #=============================================================================#
|
119 | # when using output folder, append trailing slash to its name
|
120 | #=============================================================================#
|
121 |
|
122 | ifeq ($(strip $(OUT_DIR)), )
|
123 | OUT_DIR_F =
|
124 | else
|
125 | OUT_DIR_F = $(strip $(OUT_DIR))/
|
126 | endif
|
127 |
|
128 | #=============================================================================#
|
129 | # various compilation flags
|
130 | #=============================================================================#
|
131 |
|
132 | # core flags
|
133 | CORE_FLAGS = -mcpu=$(CORE) -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffast-math
|
134 |
|
135 | # flags for C++ compiler
|
136 | CXX_FLAGS = -std=$(CXX_STD) -g -ggdb3 -fno-rtti -fno-exceptions -fverbose-asm -Wa,-ahlms=$(OUT_DIR_F)$(notdir $(<:.$(CXX_EXT)=.lst))
|
137 |
|
138 | # flags for C compiler
|
139 | C_FLAGS = -std=$(C_STD) -g -ggdb3 -fverbose-asm -Wa,-ahlms=$(OUT_DIR_F)$(notdir $(<:.$(C_EXT)=.lst))
|
140 |
|
141 | # flags for assembler
|
142 | AS_FLAGS = -g -ggdb3 -Wa,-amhls=$(OUT_DIR_F)$(notdir $(<:.$(AS_EXT)=.lst))
|
143 |
|
144 | # flags for linker
|
145 | LD_FLAGS = -T$(LD_SCRIPT) -g -Wl,-Map=$(OUT_DIR_F)$(PROJECT).map,--cref,--no-warn-mismatch
|
146 |
|
147 | # process option for removing unused code
|
148 | ifeq ($(REMOVE_UNUSED), 1)
|
149 | LD_FLAGS += -Wl,--gc-sections
|
150 | OPTIMIZATION += -ffunction-sections -fdata-sections
|
151 | endif
|
152 |
|
153 | # if __USES_CXX is defined for ASM then code for global/static constructors /
|
154 | # destructors is compiled; if -nostartfiles option for linker is added then C++
|
155 | # initialization / finalization code is not linked
|
156 | ifeq ($(USES_CXX), 1)
|
157 | AS_DEFS += __USES_CXX
|
158 | else
|
159 | LD_FLAGS += -nostartfiles
|
160 | endif
|
161 |
|
162 | #=============================================================================#
|
163 | # do some formatting
|
164 | #=============================================================================#
|
165 |
|
166 | CXX_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(CXX_SRCS:.$(CXX_EXT)=.o)))
|
167 | C_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(C_SRCS:.$(C_EXT)=.o)))
|
168 | AS_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(AS_SRCS:.$(AS_EXT)=.o)))
|
169 | OBJS = $(AS_OBJS) $(C_OBJS) $(CXX_OBJS) $(USER_OBJS)
|
170 | DEPS = $(OBJS:.o=.d)
|
171 | INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
|
172 | LIB_DIRS_F = $(patsubst %, -L%, $(LIB_DIRS))
|
173 | GLOBAL_DEFS_F = $(patsubst %, -D%, $(GLOBAL_DEFS))
|
174 | CXX_DEFS_F = $(patsubst %, -D%, $(CXX_DEFS))
|
175 | C_DEFS_F = $(patsubst %, -D%, $(C_DEFS))
|
176 | AS_DEFS_F = $(patsubst %, -D%, $(AS_DEFS))
|
177 |
|
178 | ELF = $(OUT_DIR_F)$(PROJECT).elf
|
179 | HEX = $(OUT_DIR_F)$(PROJECT).hex
|
180 | BIN = $(OUT_DIR_F)$(PROJECT).bin
|
181 | LSS = $(OUT_DIR_F)$(PROJECT).lss
|
182 | DMP = $(OUT_DIR_F)$(PROJECT).dmp
|
183 |
|
184 | # format final flags for tools, request dependancies for C++, C and asm
|
185 | CXX_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(CXX_WARNINGS) $(CXX_FLAGS) $(GLOBAL_DEFS_F) $(CXX_DEFS_F) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
|
186 | C_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(C_WARNINGS) $(C_FLAGS) $(GLOBAL_DEFS_F) $(C_DEFS_F) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
|
187 | AS_FLAGS_F = $(CORE_FLAGS) $(AS_FLAGS) $(GLOBAL_DEFS_F) $(AS_DEFS_F) -MD -MP -MF $(OUT_DIR_F)$(@F:.o=.d) $(INC_DIRS_F)
|
188 | LD_FLAGS_F = $(CORE_FLAGS) $(LD_FLAGS) $(LIB_DIRS_F)
|
189 |
|
190 | #contents of output directory
|
191 | GENERATED = $(wildcard $(patsubst %, $(OUT_DIR_F)*.%, bin d dmp elf hex lss lst map o))
|
192 |
|
193 | #=============================================================================#
|
194 | # make all
|
195 | #=============================================================================#
|
196 |
|
197 | all : make_output_dir $(ELF) $(LSS) $(DMP) $(HEX) $(BIN) print_size
|
198 |
|
199 | # make object files dependent on Makefile
|
200 | $(OBJS) : Makefile
|
201 | # make .elf file dependent on linker script
|
202 | $(ELF) : $(LD_SCRIPT)
|
203 |
|
204 | #-----------------------------------------------------------------------------#
|
205 | # linking - objects -> elf
|
206 | #-----------------------------------------------------------------------------#
|
207 |
|
208 | $(ELF) : $(OBJS)
|
209 | @echo 'Linking target: $(ELF)'
|
210 | $(CXX) $(LD_FLAGS_F) $(OBJS) $(LIBS) -o $@
|
211 | @echo ' '
|
212 |
|
213 | #-----------------------------------------------------------------------------#
|
214 | # compiling - C++ source -> objects
|
215 | #-----------------------------------------------------------------------------#
|
216 |
|
217 | $(OUT_DIR_F)%.o : %.$(CXX_EXT)
|
218 | @echo 'Compiling file: $<'
|
219 | $(CXX) -c $(CXX_FLAGS_F) $< -o $@
|
220 | @echo ' '
|
221 |
|
222 | #-----------------------------------------------------------------------------#
|
223 | # compiling - C source -> objects
|
224 | #-----------------------------------------------------------------------------#
|
225 |
|
226 | $(OUT_DIR_F)%.o : %.$(C_EXT)
|
227 | @echo 'Compiling file: $<'
|
228 | $(CC) -c $(C_FLAGS_F) $< -o $@
|
229 | @echo ' '
|
230 |
|
231 | #-----------------------------------------------------------------------------#
|
232 | # assembling - ASM source -> objects
|
233 | #-----------------------------------------------------------------------------#
|
234 |
|
235 | $(OUT_DIR_F)%.o : %.$(AS_EXT)
|
236 | @echo 'Assembling file: $<'
|
237 | $(AS) -c $(AS_FLAGS_F) $< -o $@
|
238 | @echo ' '
|
239 |
|
240 | #-----------------------------------------------------------------------------#
|
241 | # memory images - elf -> hex, elf -> bin
|
242 | #-----------------------------------------------------------------------------#
|
243 |
|
244 | $(HEX) : $(ELF)
|
245 | @echo 'Creating IHEX image: $(HEX)'
|
246 | $(OBJCOPY) -O ihex $< $@
|
247 | @echo ' '
|
248 |
|
249 | $(BIN) : $(ELF)
|
250 | @echo 'Creating binary image: $(BIN)'
|
251 | $(OBJCOPY) -O binary $< $@
|
252 | @echo ' '
|
253 |
|
254 | #-----------------------------------------------------------------------------#
|
255 | # memory dump - elf -> dmp
|
256 | #-----------------------------------------------------------------------------#
|
257 |
|
258 | $(DMP) : $(ELF)
|
259 | @echo 'Creating memory dump: $(DMP)'
|
260 | $(OBJDUMP) -x --syms $< > $@
|
261 | @echo ' '
|
262 |
|
263 | #-----------------------------------------------------------------------------#
|
264 | # extended listing - elf -> lss
|
265 | #-----------------------------------------------------------------------------#
|
266 |
|
267 | $(LSS) : $(ELF)
|
268 | @echo 'Creating extended listing: $(LSS)'
|
269 | $(OBJDUMP) -S $< > $@
|
270 | @echo ' '
|
271 |
|
272 | #-----------------------------------------------------------------------------#
|
273 | # print the size of the objects and the .elf file
|
274 | #-----------------------------------------------------------------------------#
|
275 |
|
276 | print_size : $(ELF)
|
277 | @echo 'Size of modules:'
|
278 | $(SIZE) -B -t --common $(OBJS) $(USER_OBJS)
|
279 | @echo ' '
|
280 | @echo 'Size of target .elf file:'
|
281 | $(SIZE) -B $(ELF)
|
282 | @echo ' '
|
283 |
|
284 | #-----------------------------------------------------------------------------#
|
285 | # create the desired output directory
|
286 | #-----------------------------------------------------------------------------#
|
287 |
|
288 | make_output_dir :
|
289 | $(shell mkdir $(OUT_DIR_F) 2>/dev/null)
|
290 |
|
291 | #=============================================================================#
|
292 | # make clean
|
293 | #=============================================================================#
|
294 |
|
295 | clean:
|
296 | ifeq ($(strip $(OUT_DIR_F)), )
|
297 | @echo 'Removing all generated output files'
|
298 | else
|
299 | @echo 'Removing all generated output files from output directory: $(OUT_DIR_F)'
|
300 | endif
|
301 | ifneq ($(strip $(GENERATED)), )
|
302 | $(RM) $(GENERATED)
|
303 | else
|
304 | @echo 'Nothing to remove...'
|
305 | endif
|
306 |
|
307 | #=============================================================================#
|
308 | # global exports
|
309 | #=============================================================================#
|
310 |
|
311 | .PHONY: all clean dependents
|
312 |
|
313 | .SECONDARY:
|
314 |
|
315 | # include dependancy files
|
316 | -include $(DEPS)
|