1 # Hey Emacs, this is a -*- makefile -*-
2 # Time-stamp: "23.12.10 21:21 Makefile klaus?wachtler.de"
4 #############################################################################
6 # WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
7 # Released to the Public Domain
8 # Please read the make user manual!
10 # Additional material for this makefile was submitted by:
18 # This file version is a proposal to be used for the AVR gcc tutorial
19 # found at http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial
20 # (tutorial in german only, sorry).
22 #############################################################################
27 # 1. Before compiling please tune all settings marked with ==> to
28 # match your requirements (up to the following <==).
29 # Settings not marked with ==> ... <== may be left unchanged usually.
33 # make = Make software.
34 # make all = Make software.
36 # make clean = Clean out built project files.
38 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
40 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
43 # make program = Download the hex file to the device, using avrdude. Please
44 # customize the avrdude settings below first!
46 # make filename.s = Just compile filename.c into the assembler code only
48 # To rebuild your project do "make clean" then "make all".
50 #############################################################################
56 # Differences from WinAVR 20040720 sample:
57 # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
58 # - F_OSC Define in CFLAGS and AFLAGS
60 # klaus?wachtler.de 2009/10/07
61 # - Adapted for C++ and C files in one project (separate lists for C-, C++- and
62 # ASM-Sources, modified names of list files)
64 # klaus?wachtler.de 2010/04/26, see discussion
65 # on http://www.mikrocontroller.net/topic/175727 (in german)
67 # - defaults to C source again, but may be used for C++
68 # - settings usually to be customised marked with ==>
70 # klaus@wachtler.de 2010/05/01
71 # - separate flags for C and C++
73 # Not tested on Windows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 # (to be countinued...)
80 #############################################################################
83 # ==> define the name of your project and main source file (without extension)
85 # The gcc tutorial http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial
86 # uses main.c as the main file, so you have to use the name main here.
87 # On unix like systems (linux etc.) all file names are case sensitive!
88 PROJECTNAME
=cerebrum_firmware
96 # ==> Main Oscillator Frequency [Hz]
98 # Note: This setting does NOT change the frequency of the AVR.
99 # You have to ensure that the frequency has the following value.
100 # This setting is used to trim functions like _delay_ms() etc. to
101 # work with your hardware as expected (used in C, C++ and assembler
103 # If you are in doubt how to set the frequency of your controller
104 # please refer to the corresponding data sheet (www.atmel.com).
105 # You have to look for information on something like
106 # "memory programming/fuse settings" and "system clock and clock options".
112 # Output format. (can be srec, ihex, binary)
115 # Target file name (without extension).
116 TARGET
= $(PROJECTNAME
)
119 # ==> If you have more than one source file then list them here.
121 # The source file named like the project may be given as $(PROJECTNAME).c
122 # or $(PROJECTNAME).cpp; list the remaining files with their full names
124 # C and C++ dependencies are automatically generated.
126 # example with one C file:
127 # CSRC = $(PROJECTNAME).c
129 # example with C file and lcd-routines (cut and paste it together with
130 # lcd-routines.h from mikrocontroller.net):
131 # CSRC = $(PROJECTNAME).c lcd-routines.c
133 # example with one C++ file:
134 # CSRC = $(PROJECTNAME).cpp
136 # example with some C++ files (including the main file of the project) and some C files:
137 # CSRC = $(PROJECTNAME).cpp second.cpp third.cpp a.c another.c
139 # List C and C++ files here
140 CSRC
= $(PROJECTNAME
).c uart.c util.c spi.c r0ketbeam.c RF24
/RF24.c
144 # ==> List Assembler source files here (if any).
146 # Make them always end in a capital .S. Files ending in a lowercase .s
147 # will not be considered source files but generated files (assembler
148 # output from the compiler), and will be deleted upon "make clean"!
149 # Even though the DOS/Win* filesystem matches both .s and .S the same,
150 # it will preserve the spelling of the filenames, and gcc itself does
151 # care about how the name is spelled on its command-line.
157 # ==> Optimization level, can be [0, 1, 2, 3, s].
159 # 0 = turn off optimization. s = optimize for size.
160 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
162 # s will be be a good choice for starting.
163 # If you want to debug your code then 0 makes your life easier.
169 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
170 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
171 #DEBUG = # no debug information
175 # ==> add additional directories for searching include files
177 # List any extra directories to look for include files here.
178 # Each directory must be separated with a space.
180 EXTRAINCDIRS
= . RF24
184 # ==> Compiler flag to set the C Standard level.
186 # gnu99 is usually a good choice.
188 # CSTANDARD = -std=c89 # "ANSI" C
189 # CSTANDARD = -std=gnu89 # c89 plus GCC extensions
190 # CSTANDARD = -std=c99 # ISO C99 standard (not yet fully implemented)
191 # CSTANDARD = -std=gnu99 # c99 plus GCC extensions
192 CSTANDARD
= -std
=gnu99
196 # ==> Place preprocessor definitions here if necessary.
198 # You can define preprocessor values as defined with #define
200 # A macro may be defined without a value (by naming it in the EXTRA_CDEFS list)
201 # or with a value following an equal sign (=).
203 # Each value of the list will be appended to a -D option on
204 # calling the compiler.
206 # Example: if you use my fixpoint routines for C++
207 # (see http://mfgkw.dyndns.org/fixpoint_release.zip) you will probably
208 # want to define the values NO_STDSTRING and NO_STDIOSTREAM like:
209 #EXTRA_CDEFS = NO_STDSTRING NO_STDIOSTREAM
211 #EXTRA_CDEFS = DEBUG=1
212 #EXTRA_CDEFS = NDEBUG=1
217 # ==> In the same way you can undef certain macros(rarely used):
219 # Each value of the list will be appended to a -U option on
220 # calling the compile.
222 # With this feature you can switch off predefined preprocessor macros
223 # and previously defined -D values (see above).
224 # Don't ask me why you you should define macros above and undefine them
230 # ==> Additional options for C only
232 EXTRA_COPTIONS
= -Wstrict-prototypes
235 # ==> Additional options for C++ only
242 # -g*: generate debugging information
243 # -O*: optimization level
244 # -f...: tuning, see GCC manual and avr-libc documentation
245 # -Wall...: warning level
246 # -Wa,...: tell GCC to pass this to the assembler.
247 # -adhlns...: create assembler listing
250 CFLAGS
+= $(foreach ICDEF
,$(EXTRA_CDEFS
),-D
"$(ICDEF)")
251 CFLAGS
+= $(foreach ICUNDEF
,$(EXTRA_CUNDEFS
),-U
$(ICUNDEF
))
253 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
255 CFLAGS
+= -Wa
,-adhlns
=$<.lst
256 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
257 CFLAGS
+= $(CSTANDARD
)
258 CFLAGS
+= $(EXTRA_COPTIONS
)
259 CFLAGS
+= -DF_OSC
=$(F_OSC
)
260 CFLAGS
+= -DF_CPU
=$(F_OSC
)
263 # -g*: generate debugging information
264 # -O*: optimization level
265 # -f...: tuning, see GCC manual and avr-libc documentation
266 # -Wall...: warning level
267 # -Wa,...: tell GCC to pass this to the assembler.
268 # -adhlns...: create assembler listing
270 CPPFLAGS
= -g
$(DEBUG
)
271 CPPFLAGS
+= $(foreach ICDEF
,$(EXTRA_CDEFS
),-D
"$(ICDEF)")
272 CPPFLAGS
+= $(foreach ICUNDEF
,$(EXTRA_CUNDEFS
),-U
$(ICUNDEF
))
274 CPPFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
276 CPPFLAGS
+= -Wa
,-adhlns
=$<.lst
277 CPPFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
278 CPPFLAGS
+= $(EXTRA_CPPOPTIONS
)
279 CPPFLAGS
+= -DF_OSC
=$(F_OSC
)
280 CPPFLAGS
+= -DF_CPU
=$(F_OSC
)
284 # -Wa,...: tell GCC to pass this to the assembler.
285 # -ahlms: create listing
286 # -gstabs: have the assembler create line number information; note that
287 # for use in COFF files, additional information about filenames
288 # and function names needs to be present in the assembler source
289 # files -- see avr-libc docs [FIXME: not yet described there]
290 ASFLAGS
= -Wa
,-adhlns
=$<.lst
,-gstabs
291 ASFLAGS
+= -DF_OSC
=$(F_OSC
)
296 # Additional libraries.
300 # Minimalistic printf version
301 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
303 # Floating point printf version (requires MATH_LIB = -lm below)
304 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
307 # ==> choose one of the following options, depending on your needs
309 # - no floating point needed in all printf() like calls
310 # - floating point with non standard simplified printf()
311 # - floating point with full printf() support
313 # See http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga3b98c0d17b35642c0f3e4649092b9f1
315 #PRINTF_LIB = # full functionality except but no floating point
316 PRINTF_LIB
= $(PRINTF_LIB_MIN
) # simplified (only # flag regarded), no floating point
317 #PRINTF_LIB = $(PRINTF_LIB_FLOAT) # full functionality including floating point (requires MATH_LIB = -lm below)
321 # Minimalistic scanf version
322 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
324 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
325 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
328 # ==> choose one of the following options, depending on your needs
330 # - no floating point needed in all scanf() like calls
331 # - floating point with non standard simplified scanf() (no %[...] conversion)
332 # - floating point with full scanf() support
334 # See http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#g67bae1ad3af79809fd770be392f90e21
336 #SCANF_LIB = # full functionality except floating point, max. width 255
337 SCANF_LIB
= $(SCANF_LIB_MIN
) # no floating point, no %[, max. width 255
338 #SCANF_LIB = $(SCANF_LIB_FLOAT) # full, floating point, max. width 65535 (requires MATH_LIB = -lm below)
342 # ==> choose one of the following
344 # If your code contains math functions or floating point, then use the -lm version.
345 # If not, don't use it to save program space.
347 # See options PRINTF_LIB and SCANF_LIB above!
349 # Note: if your code size grows too high then consider using fixed point
350 # arithmetic instead of floating point arithmetic.
351 # You may expect smaller and faster programs.
358 # ==> If your controller uses external memory:
360 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
361 # used for variables (.data/.bss) and heap (malloc()).
362 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
364 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
365 # only used for heap (malloc()).
366 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
374 # -Wl,...: tell GCC to pass this to linker.
375 # -Map: create map file
376 # --cref: add cross reference to map file
377 LDFLAGS
= -Wl
,-Map
=$(TARGET
).map
,--cref
378 LDFLAGS
+= $(EXTMEMOPTS
)
379 LDFLAGS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
383 # ==> Programming support using avrdude. Settings and variables.
384 AVRDUDE_PROGRAMMER
= stk500v2
-b
115200
388 # ==> Choose the port used by the programmer
389 AVRDUDE_PORT
= /dev
/ttyACM0
394 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
395 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
398 # Uncomment the following if you want avrdude's erase cycle counter.
399 # Note that this counter needs to be initialized first using -Yn,
400 # see avrdude manual.
401 #AVRDUDE_ERASE_COUNTER = -y
403 # Uncomment the following if you do /not/ wish a verification to be
404 # performed after programming the device.
405 #AVRDUDE_NO_VERIFY = -V
407 # Increase verbosity level. Please use this when submitting bug
408 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
409 # to submit bug reports.
410 #AVRDUDE_VERBOSE = -v -v
412 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
413 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
414 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
415 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
416 #AVRDUDE_FLAGS += -E noreset
420 # ---------------------------------------------------------------------------
422 # Define directories, if needed.
424 DIRAVRBIN
= $(DIRAVR
)/bin
425 DIRAVRUTILS
= $(DIRAVR
)/utils
/bin
427 DIRLIB
= $(DIRAVR
)/avr
/lib
430 # Define programs and commands.
433 OBJCOPY
= avr-objcopy
434 OBJDUMP
= avr-objdump
446 MSG_ERRORS_NONE
= Errors
: none
447 MSG_BEGIN
= -------- begin
--------
448 MSG_END
= -------- end
--------
449 MSG_SIZE_BEFORE
= Size before
:
450 MSG_SIZE_AFTER
= Size after
:
451 MSG_COFF
= Converting to AVR COFF
:
452 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
453 MSG_FLASH
= Creating load file for Flash
:
454 MSG_EEPROM
= Creating load file for EEPROM
:
455 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
456 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
457 MSG_LINKING
= Linking
:
458 MSG_COMPILING
= Compiling
:
459 MSG_ASSEMBLING
= Assembling
:
460 MSG_CLEANING
= Cleaning project
:
465 # Define all object files.
466 OBJ
= $(CSRC
:.c
=.o
) $(ASRC
:.S
=.o
)
468 # Compiler flags to generate dependency files.
469 ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
470 GENDEPFLAGS
= -MD
-MP
-MF .deppp
/$(@F
).d
472 # Combine all necessary flags and optional flags.
473 # Add target processor to flags.
474 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
) $(GENDEPFLAGS
)
475 ALL_CPPFLAGS
= -mmcu
=$(MCU
) -I.
$(CPPFLAGS
) $(GENDEPFLAGS
)
476 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
481 all: begin gccversion sizebefore build sizeafter finished end
483 build
: elf hex eep lss sym
494 # AVR Studio 3.x does not check make's exit code but relies on
495 # the following magic strings to be generated by the compile job.
501 @echo
$(MSG_ERRORS_NONE
)
508 # Display size of file.
509 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
510 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
512 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); echo
; fi
515 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); echo
; fi
519 # Display compiler version information.
524 # Program the device.
525 program
: $(TARGET
).hex
$(TARGET
).eep
526 sh
-c
'echo>/dev/ttyACM0'
527 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
532 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
533 COFFCONVERT
=$(OBJCOPY
) --debugging \
534 --change-section-address .data-0x800000 \
535 --change-section-address .bss-0x800000 \
536 --change-section-address .noinit-0x800000 \
537 --change-section-address .eeprom-0x810000
542 @echo
$(MSG_COFF
) $(TARGET
).cof
543 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
546 extcoff
: $(TARGET
).elf
548 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
549 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
553 # Create final output files (.hex, .eep) from ELF output file.
556 @echo
$(MSG_FLASH
) $@
557 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
561 @echo
$(MSG_EEPROM
) $@
562 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
563 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
565 # Create extended listing file from ELF output file.
568 @echo
$(MSG_EXTENDED_LISTING
) $@
569 $(OBJDUMP
) -h
-S
$< > $@
571 # Create a symbol table from ELF output file.
574 @echo
$(MSG_SYMBOL_TABLE
) $@
579 # Link: create ELF output file from object files.
580 .SECONDARY
: $(TARGET
).elf
584 @echo
$(MSG_LINKING
) $@
585 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
588 # Compile: create object files from C source files.
591 @echo
$(MSG_COMPILING
) $<
592 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
595 # Compile: create object files from C++ source files.
598 @echo
$(MSG_COMPILING
) $<
599 $(CC
) -c
$(ALL_CPPFLAGS
) $< -o
$@
602 # Compile: create assembler files from C source files.
604 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
607 # Compile: create assembler files from C++ source files.
609 $(CC
) -S
$(ALL_CPPFLAGS
) $< -o
$@
612 # Assemble: create object files from assembler source files.
615 @echo
$(MSG_ASSEMBLING
) $<
616 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
620 # Target: clean project.
621 clean: begin clean_list finished end
625 @echo
$(MSG_CLEANING
)
626 $(REMOVE
) $(TARGET
).hex
627 $(REMOVE
) $(TARGET
).eep
628 $(REMOVE
) $(TARGET
).obj
629 $(REMOVE
) $(TARGET
).cof
630 $(REMOVE
) $(TARGET
).elf
631 $(REMOVE
) $(TARGET
).map
632 $(REMOVE
) $(TARGET
).obj
633 $(REMOVE
) $(TARGET
).a90
634 $(REMOVE
) $(TARGET
).sym
635 $(REMOVE
) $(TARGET
).lnk
636 $(REMOVE
) $(TARGET
).lss
638 $(REMOVE
) *.bak
*.BAK
*~
*.o
*.s
*.lst
639 $(REMOVE
) RF24
/*.o RF24
/*.s RF24
/*.lst
643 # Include the dependency files.
644 -include $(shell mkdir .deppp
2>/dev
/null
) $(wildcard .deppp
/*)
647 # Listing of phony targets.
648 .PHONY
: all begin finish end sizebefore sizeafter gccversion \
649 build elf hex eep lss sym coff extcoff \
650 clean clean_list program