]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_XPlained/RTOSDemo/src/ASF/sam0/utils/make/Makefile.sam.in
Starting point for the SAMD20 demo.
[freertos] / FreeRTOS / Demo / CORTEX_M0+_Atmel_SAMD20_XPlained / RTOSDemo / src / ASF / sam0 / utils / make / Makefile.sam.in
1 # List of available make goals:\r
2 #\r
3 # all                     Default target, builds the project\r
4 # clean                   Clean up the project\r
5 # rebuild                 Rebuild the project\r
6 # debug_flash             Builds the project and debug in flash\r
7 # debug_sram              Builds the project and debug in sram\r
8 #\r
9 # doc                     Build the documentation\r
10 # cleandoc                Clean up the documentation\r
11 # rebuilddoc              Rebuild the documentation\r
12 #\r
13 # \file\r
14 #\r
15 # Copyright (c) 2011 - 2013 Atmel Corporation. All rights reserved.\r
16 #\r
17 # \asf_license_start\r
18 #\r
19 # \page License\r
20 #\r
21 # Redistribution and use in source and binary forms, with or without\r
22 # modification, are permitted provided that the following conditions are met:\r
23 #\r
24 # 1. Redistributions of source code must retain the above copyright notice,\r
25 #    this list of conditions and the following disclaimer.\r
26 #\r
27 # 2. Redistributions in binary form must reproduce the above copyright notice,\r
28 #    this list of conditions and the following disclaimer in the documentation\r
29 #    and/or other materials provided with the distribution.\r
30 #\r
31 # 3. The name of Atmel may not be used to endorse or promote products derived\r
32 #    from this software without specific prior written permission.\r
33 #\r
34 # 4. This software may only be redistributed and used in connection with an\r
35 #    Atmel microcontroller product.\r
36 #\r
37 # THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED\r
38 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
39 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
40 # EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR\r
41 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
42 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
43 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
44 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
45 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
46 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
47 # POSSIBILITY OF SUCH DAMAGE.\r
48 #\r
49 # \asf_license_stop\r
50 #\r
51 \r
52 # Include the config.mk file from the current working path, e.g., where the\r
53 # user called make.\r
54 include config.mk\r
55 \r
56 # Tool to use to generate documentation from the source code\r
57 DOCGEN          ?= doxygen\r
58 \r
59 # Look for source files relative to the top-level source directory\r
60 VPATH           := $(PRJ_PATH)\r
61 \r
62 # Output target file\r
63 project_type    := $(PROJECT_TYPE)\r
64 \r
65 # Output target file\r
66 ifeq ($(project_type),flash)\r
67 target          := $(TARGET_FLASH)\r
68 linker_script   := $(PRJ_PATH)/$(LINKER_SCRIPT_FLASH)\r
69 debug_script    := $(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)\r
70 else\r
71 target          := $(TARGET_SRAM)\r
72 linker_script   := $(PRJ_PATH)/$(LINKER_SCRIPT_SRAM)\r
73 debug_script    := $(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)\r
74 endif\r
75 \r
76 # Output project name (target name minus suffix)\r
77 project         := $(basename $(target))\r
78 \r
79 # Output target file (typically ELF or static library)\r
80 ifeq ($(suffix $(target)),.a)\r
81 target_type     := lib\r
82 else\r
83 ifeq ($(suffix $(target)),.elf)\r
84 target_type     := elf\r
85 else\r
86 $(error "Target type $(target_type) is not supported")\r
87 endif\r
88 endif\r
89 \r
90 # Allow override of operating system detection. The user can add OS=Linux or\r
91 # OS=Windows on the command line to explicit set the host OS.\r
92 #\r
93 # This allows to work around broken uname utility on certain systems.\r
94 ifdef OS\r
95   ifeq ($(strip $(OS)), Linux)\r
96     os_type     := Linux\r
97   endif\r
98   ifeq ($(strip $(OS)), Windows)\r
99     os_type     := windows32_64\r
100   endif\r
101 endif\r
102 \r
103 os_type         ?= $(strip $(shell uname))\r
104 \r
105 ifeq ($(os_type),windows32)\r
106 os              := Windows\r
107 else\r
108 ifeq ($(os_type),windows64)\r
109 os              := Windows\r
110 else\r
111 ifeq ($(os_type),windows32_64)\r
112 os              ?= Windows\r
113 else\r
114 ifeq ($(os_type),)\r
115 os              := Windows\r
116 else\r
117 # Default to Linux style operating system. Both Cygwin and mingw are fully\r
118 # compatible (for this Makefile) with Linux.\r
119 os              := Linux\r
120 endif\r
121 endif\r
122 endif\r
123 endif\r
124 \r
125 # Output documentation directory and configuration file.\r
126 docdir          := ../doxygen/html\r
127 doccfg          := ../doxygen/doxyfile.doxygen\r
128 \r
129 CROSS           ?= arm-none-eabi-\r
130 AR              := $(CROSS)ar\r
131 AS              := $(CROSS)as\r
132 CC              := $(CROSS)gcc\r
133 CPP             := $(CROSS)gcc -E\r
134 CXX             := $(CROSS)g++\r
135 LD              := $(CROSS)g++\r
136 NM              := $(CROSS)nm\r
137 OBJCOPY         := $(CROSS)objcopy\r
138 OBJDUMP         := $(CROSS)objdump\r
139 SIZE            := $(CROSS)size\r
140 GDB             := $(CROSS)gdb\r
141 \r
142 RM              := rm\r
143 ifeq ($(os),Windows)\r
144 RMDIR           := rmdir /S /Q\r
145 else\r
146 RMDIR           := rmdir -p --ignore-fail-on-non-empty\r
147 endif\r
148 \r
149 # On Windows, we need to override the shell to force the use of cmd.exe\r
150 ifeq ($(os),Windows)\r
151 SHELL           := cmd\r
152 endif\r
153 \r
154 # Strings for beautifying output\r
155 MSG_CLEAN_FILES         = "RM      *.o *.d"\r
156 MSG_CLEAN_DIRS          = "RMDIR   $(strip $(clean-dirs))"\r
157 MSG_CLEAN_DOC           = "RMDIR   $(docdir)"\r
158 MSG_MKDIR               = "MKDIR   $(dir $@)"\r
159 \r
160 MSG_INFO                = "INFO    "\r
161 \r
162 MSG_ARCHIVING           = "AR      $@"\r
163 MSG_ASSEMBLING          = "AS      $@"\r
164 MSG_BINARY_IMAGE        = "OBJCOPY $@"\r
165 MSG_COMPILING           = "CC      $@"\r
166 MSG_COMPILING_CXX       = "CXX     $@"\r
167 MSG_EXTENDED_LISTING    = "OBJDUMP $@"\r
168 MSG_IHEX_IMAGE          = "OBJCOPY $@"\r
169 MSG_LINKING             = "LN      $@"\r
170 MSG_PREPROCESSING       = "CPP     $@"\r
171 MSG_SIZE                = "SIZE    $@"\r
172 MSG_SYMBOL_TABLE        = "NM      $@"\r
173 \r
174 MSG_GENERATING_DOC      = "DOXYGEN $(docdir)"\r
175 \r
176 # Don't use make's built-in rules and variables\r
177 MAKEFLAGS       += -rR\r
178 \r
179 # Don't print 'Entering directory ...'\r
180 MAKEFLAGS       += --no-print-directory\r
181 \r
182 # Function for reversing the order of a list\r
183 reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))\r
184 \r
185 # Hide command output by default, but allow the user to override this\r
186 # by adding V=1 on the command line.\r
187 #\r
188 # This is inspired by the Kbuild system used by the Linux kernel.\r
189 ifdef V\r
190   ifeq ("$(origin V)", "command line")\r
191     VERBOSE = $(V)\r
192   endif\r
193 endif\r
194 ifndef VERBOSE\r
195   VERBOSE = 0\r
196 endif\r
197 \r
198 ifeq ($(VERBOSE), 1)\r
199   Q =\r
200 else\r
201   Q = @\r
202 endif\r
203 \r
204 arflags-gnu-y           := $(ARFLAGS)\r
205 asflags-gnu-y           := $(ASFLAGS)\r
206 cflags-gnu-y            := $(CFLAGS)\r
207 cxxflags-gnu-y          := $(CXXFLAGS)\r
208 cppflags-gnu-y          := $(CPPFLAGS)\r
209 cpuflags-gnu-y          :=\r
210 dbgflags-gnu-y          := $(DBGFLAGS)\r
211 libflags-gnu-y          := $(foreach LIB,$(LIBS),-l$(LIB))\r
212 ldflags-gnu-y           := $(LDFLAGS)\r
213 flashflags-gnu-y        :=\r
214 clean-files             :=\r
215 clean-dirs              :=\r
216 \r
217 clean-files             += $(wildcard $(target) $(project).map)\r
218 clean-files             += $(wildcard $(project).hex $(project).bin)\r
219 clean-files             += $(wildcard $(project).lss $(project).sym)\r
220 clean-files             += $(wildcard $(build))\r
221 \r
222 # Use pipes instead of temporary files for communication between processes\r
223 cflags-gnu-y    += -pipe\r
224 asflags-gnu-y   += -pipe\r
225 ldflags-gnu-y   += -pipe\r
226 \r
227 # Archiver flags.\r
228 arflags-gnu-y   += rcs\r
229 \r
230 # Always enable warnings. And be very careful about implicit\r
231 # declarations.\r
232 cflags-gnu-y    += -Wall -Wstrict-prototypes -Wmissing-prototypes\r
233 cflags-gnu-y    += -Werror-implicit-function-declaration\r
234 cxxflags-gnu-y  += -Wall\r
235 # IAR doesn't allow arithmetic on void pointers, so warn about that.\r
236 cflags-gnu-y    += -Wpointer-arith\r
237 cxxflags-gnu-y  += -Wpointer-arith\r
238 \r
239 # Preprocessor flags.\r
240 cppflags-gnu-y  += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),-I$(INC))\r
241 asflags-gnu-y   += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),'-Wa,-I$(INC)')\r
242 \r
243 # CPU specific flags.\r
244 cpuflags-gnu-y  += -mcpu=$(ARCH) -mthumb -D=__$(PART)__\r
245 \r
246 # Dependency file flags.\r
247 depflags        = -MD -MP -MQ $@\r
248 \r
249 # Debug specific flags.\r
250 ifdef BUILD_DEBUG_LEVEL\r
251 dbgflags-gnu-y  += -g$(BUILD_DEBUG_LEVEL)\r
252 else\r
253 dbgflags-gnu-y  += -g3\r
254 endif\r
255 \r
256 # Optimization specific flags.\r
257 ifdef BUILD_OPTIMIZATION\r
258 optflags-gnu-y  = -O$(BUILD_OPTIMIZATION)\r
259 else\r
260 optflags-gnu-y  = $(OPTIMIZATION)\r
261 endif\r
262 \r
263 # Always preprocess assembler files.\r
264 asflags-gnu-y   += -x assembler-with-cpp\r
265 # Compile C files using the GNU99 standard.\r
266 cflags-gnu-y    += -std=gnu99\r
267 # Compile C++ files using the GNU++98 standard.\r
268 cxxflags-gnu-y  += -std=gnu++98\r
269 \r
270 # Don't use strict aliasing (very common in embedded applications).\r
271 cflags-gnu-y    += -fno-strict-aliasing\r
272 cxxflags-gnu-y  += -fno-strict-aliasing\r
273 \r
274 # Separate each function and data into its own separate section to allow\r
275 # garbage collection of unused sections.\r
276 cflags-gnu-y    += -ffunction-sections -fdata-sections\r
277 cxxflags-gnu-y  += -ffunction-sections -fdata-sections\r
278 \r
279 # Various cflags.\r
280 cflags-gnu-y += -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int\r
281 cflags-gnu-y += -Wmain -Wparentheses\r
282 cflags-gnu-y += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused\r
283 cflags-gnu-y += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef\r
284 cflags-gnu-y += -Wshadow -Wbad-function-cast -Wwrite-strings\r
285 cflags-gnu-y += -Wsign-compare -Waggregate-return\r
286 cflags-gnu-y += -Wmissing-declarations\r
287 cflags-gnu-y += -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations\r
288 cflags-gnu-y += -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long\r
289 cflags-gnu-y += -Wunreachable-code\r
290 cflags-gnu-y += -Wcast-align\r
291 cflags-gnu-y += --param max-inline-insns-single=500\r
292 \r
293 # To reduce application size use only integer printf function.\r
294 cflags-gnu-y += -Dprintf=iprintf\r
295 \r
296 # Garbage collect unreferred sections when linking.\r
297 ldflags-gnu-y   += -Wl,--gc-sections\r
298 \r
299 # Use the linker script if provided by the project.\r
300 ifneq ($(strip $(linker_script)),)\r
301 ldflags-gnu-y   += -Wl,-T $(linker_script)\r
302 endif\r
303 \r
304 # Output a link map file and a cross reference table\r
305 ldflags-gnu-y   += -Wl,-Map=$(project).map,--cref\r
306 \r
307 # Add library search paths relative to the top level directory.\r
308 ldflags-gnu-y   += $(foreach _LIB_PATH,$(addprefix $(PRJ_PATH)/,$(LIB_PATH)),-L$(_LIB_PATH))\r
309 \r
310 a_flags  = $(cpuflags-gnu-y) $(depflags) $(cppflags-gnu-y) $(asflags-gnu-y) -D__ASSEMBLY__\r
311 c_flags  = $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cflags-gnu-y)\r
312 cxx_flags= $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cxxflags-gnu-y)\r
313 l_flags  = -Wl,--entry=Reset_Handler -Wl,--cref $(cpuflags-gnu-y) $(optflags-gnu-y) $(ldflags-gnu-y)\r
314 ar_flags = $(arflags-gnu-y)\r
315 \r
316 # Source files list and part informations must already be included before\r
317 # running this makefile\r
318 \r
319 # If a custom build directory is specified, use it -- force trailing / in directory name.\r
320 ifdef BUILD_DIR\r
321         build-dir       := $(dir $(BUILD_DIR))$(if $(notdir $(BUILD_DIR)),$(notdir $(BUILD_DIR))/)\r
322 else\r
323         build-dir        =\r
324 endif\r
325 \r
326 # Create object files list from source files list.\r
327 obj-y                   := $(addprefix $(build-dir), $(addsuffix .o,$(basename $(CSRCS) $(ASSRCS))))\r
328 # Create dependency files list from source files list.\r
329 dep-files               := $(wildcard $(foreach f,$(obj-y),$(basename $(f)).d))\r
330 \r
331 clean-files             += $(wildcard $(obj-y))\r
332 clean-files             += $(dep-files)\r
333 \r
334 clean-dirs              += $(call reverse,$(sort $(wildcard $(dir $(obj-y)))))\r
335 \r
336 # Default target.\r
337 .PHONY: all\r
338 ifeq ($(project_type),all)\r
339 all:\r
340         $(MAKE) all PROJECT_TYPE=flash\r
341         $(MAKE) all PROJECT_TYPE=sram\r
342 else\r
343 ifeq ($(target_type),lib)\r
344 all: $(target) $(project).lss $(project).sym\r
345 else\r
346 ifeq ($(target_type),elf)\r
347 all: $(target) $(project).lss $(project).sym $(project).hex $(project).bin\r
348 endif\r
349 endif\r
350 endif\r
351 \r
352 # Clean up the project.\r
353 .PHONY: clean\r
354 clean:\r
355         @$(if $(strip $(clean-files)),echo $(MSG_CLEAN_FILES))\r
356         $(if $(strip $(clean-files)),$(Q)$(RM) $(clean-files),)\r
357         @$(if $(strip $(clean-dirs)),echo $(MSG_CLEAN_DIRS))\r
358 # Remove created directories, and make sure we only remove existing\r
359 # directories, since recursive rmdir might help us a bit on the way.\r
360 ifeq ($(os),Windows)\r
361         $(Q)$(if $(strip $(clean-dirs)),                        \\r
362                         $(RMDIR) $(strip $(subst /,\,$(clean-dirs))))\r
363 else\r
364         $(Q)$(if $(strip $(clean-dirs)),                        \\r
365                 for directory in $(strip $(clean-dirs)); do     \\r
366                         if [ -d "$$directory" ]; then           \\r
367                                 $(RMDIR) $$directory;           \\r
368                         fi                                      \\r
369                 done                                            \\r
370         )\r
371 endif\r
372 \r
373 # Rebuild the project.\r
374 .PHONY: rebuild\r
375 rebuild: clean all\r
376 \r
377 # Debug the project in flash.\r
378 .PHONY: debug_flash\r
379 debug_flash: all\r
380         $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)" -ex "reset" -readnow -se $(TARGET_FLASH)\r
381 \r
382 # Debug the project in sram.\r
383 .PHONY: debug_sram\r
384 debug_sram: all\r
385         $(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)" -ex "reset" -readnow -se $(TARGET_SRAM)\r
386 \r
387 .PHONY: objfiles\r
388 objfiles: $(obj-y)\r
389 \r
390 # Create object files from C source files.\r
391 $(build-dir)%.o: %.c $(MAKEFILE_PATH) config.mk\r
392         $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)\r
393 ifeq ($(os),Windows)\r
394         $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))\r
395 else\r
396         $(Q)test -d $(dir $@) || mkdir -p $(dir $@)\r
397 endif\r
398         @echo $(MSG_COMPILING)\r
399         $(Q)$(CC) $(c_flags) -c $< -o $@\r
400 \r
401 # Create object files from C++ source files.\r
402 $(build-dir)%.o: %.cpp $(MAKEFILE_PATH) config.mk\r
403         $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)\r
404 ifeq ($(os),Windows)\r
405         $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))\r
406 else\r
407         $(Q)test -d $(dir $@) || mkdir -p $(dir $@)\r
408 endif\r
409         @echo $(MSG_COMPILING_CXX)\r
410         $(Q)$(CXX) $(cxx_flags) -c $< -o $@\r
411 \r
412 # Preprocess and assemble: create object files from assembler source files.\r
413 $(build-dir)%.o: %.S $(MAKEFILE_PATH) config.mk\r
414         $(Q)test -d $(dir $@) || echo $(MSG_MKDIR)\r
415 ifeq ($(os),Windows)\r
416         $(Q)test -d $(patsubst %/,%,$(dir $@)) || mkdir $(subst /,\,$(dir $@))\r
417 else\r
418         $(Q)test -d $(dir $@) || mkdir -p $(dir $@)\r
419 endif\r
420         @echo $(MSG_ASSEMBLING)\r
421         $(Q)$(CC) $(a_flags) -c $< -o $@\r
422 \r
423 # Include all dependency files to add depedency to all header files in use.\r
424 include $(dep-files)\r
425 \r
426 ifeq ($(target_type),lib)\r
427 # Archive object files into an archive\r
428 $(target): $(MAKEFILE_PATH) config.mk $(obj-y)\r
429         @echo $(MSG_ARCHIVING)\r
430         $(Q)$(AR) $(ar_flags) $@ $(obj-y)\r
431         @echo $(MSG_SIZE)\r
432         $(Q)$(SIZE) -Bxt $@\r
433 else\r
434 ifeq ($(target_type),elf)\r
435 # Link the object files into an ELF file. Also make sure the target is rebuilt\r
436 # if the common Makefile.sam.in or project config.mk is changed.\r
437 $(target): $(linker_script) $(MAKEFILE_PATH) config.mk $(obj-y)\r
438         @echo $(MSG_LINKING)\r
439         $(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $@\r
440         @echo $(MSG_SIZE)\r
441         $(Q)$(SIZE) -Ax $@\r
442         $(Q)$(SIZE) -Bx $@\r
443 endif\r
444 endif\r
445 \r
446 # Create extended function listing from target output file.\r
447 %.lss: $(target)\r
448         @echo $(MSG_EXTENDED_LISTING)\r
449         $(Q)$(OBJDUMP) -h -S $< > $@\r
450 \r
451 # Create symbol table from target output file.\r
452 %.sym: $(target)\r
453         @echo $(MSG_SYMBOL_TABLE)\r
454         $(Q)$(NM) -n $< > $@\r
455 \r
456 # Create Intel HEX image from ELF output file.\r
457 %.hex: $(target)\r
458         @echo $(MSG_IHEX_IMAGE)\r
459         $(Q)$(OBJCOPY) -O ihex $(flashflags-gnu-y)  $< $@\r
460 \r
461 # Create binary image from ELF output file.\r
462 %.bin: $(target)\r
463         @echo $(MSG_BINARY_IMAGE)\r
464         $(Q)$(OBJCOPY) -O binary $< $@\r
465 \r
466 # Provide information about the detected host operating system.\r
467 .SECONDARY: info-os\r
468 info-os:\r
469         @echo $(MSG_INFO)$(os) build host detected\r
470 \r
471 # Build Doxygen generated documentation.\r
472 .PHONY: doc\r
473 doc:\r
474         @echo $(MSG_GENERATING_DOC)\r
475         $(Q)cd $(dir $(doccfg)) && $(DOCGEN) $(notdir $(doccfg))\r
476 \r
477 # Clean Doxygen generated documentation.\r
478 .PHONY: cleandoc\r
479 cleandoc:\r
480         @$(if $(wildcard $(docdir)),echo $(MSG_CLEAN_DOC))\r
481         $(Q)$(if $(wildcard $(docdir)),$(RM) --recursive $(docdir))\r
482 \r
483 # Rebuild the Doxygen generated documentation.\r
484 .PHONY: rebuilddoc\r
485 rebuilddoc: cleandoc doc\r