1# Hey Emacs, this is a -*- makefile -*-
2#----------------------------------------------------------------------------
3# WinAVR Makefile Template written by Eric B. Weddington, J�rg Wunsch, et al.
4#  >> Modified for use with the LUFA project. <<
5#
6# Released to the Public Domain
7#
8# Additional material for this makefile was written by:
9# Peter Fleury
10# Tim Henigan
11# Colin O'Flynn
12# Reiner Patommel
13# Markus Pfaff
14# Sander Pool
15# Frederik Rouleau
16# Carlos Lamas
17# Dean Camera
18# Opendous Inc.
19# Denver Gingerich
20#
21#----------------------------------------------------------------------------
22# On command line:
23#
24# make all = Make software.
25#
26# make clean = Clean out built project files.
27#
28# make coff = Convert ELF to AVR COFF.
29#
30# make extcoff = Convert ELF to AVR Extended COFF.
31#
32# make program = Download the hex file to the device, using avrdude.
33#                Please customize the avrdude settings below first!
34#
35# make doxygen = Generate DoxyGen documentation for the project (must have
36#                DoxyGen installed)
37#
38# make debug = Start either simulavr or avarice as specified for debugging,
39#              with avr-gdb or avr-insight as the front end for debugging.
40#
41# make filename.s = Just compile filename.c into the assembler code only.
42#
43# make filename.i = Create a preprocessed source file for use in submitting
44#                   bug reports to the GCC project.
45#
46# To rebuild project do "make clean" then "make all".
47#----------------------------------------------------------------------------
48
49# USB vendor ID (VID)
50# reuse of this VID by others is forbidden by USB-IF
51# official Arduino LLC VID
52VID = 0x2341
53
54
55# USB product ID (PID)
56# official Leonardo PID
57# PID = 0x0036
58# official Micro PID
59# PID = 0x0037
60# official Arduino Robot Control Board PID
61PID = 0x0038
62# official Arduino Robot Motor Board PID
63# PID = 0x0039
64# official Esplora PID
65# PID = 0x003C
66
67# MCU name
68MCU = atmega32u4
69
70
71# Target architecture (see library "Board Types" documentation).
72ARCH = AVR8
73
74
75# Target board (see library "Board Types" documentation, NONE for projects not requiring
76# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
77# "Board" inside the application directory.
78BOARD = USER
79
80
81# Processor frequency.
82#     This will define a symbol, F_CPU, in all source code files equal to the
83#     processor frequency in Hz. You can then use this symbol in your source code to
84#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
85#     automatically to create a 32-bit value in your source code.
86#
87#     This will be an integer division of F_USB below, as it is sourced by
88#     F_USB after it has run through any CPU prescalers. Note that this value
89#     does not *change* the processor frequency - it should merely be updated to
90#     reflect the processor speed set externally so that the code can use accurate
91#     software delays.
92F_CPU = 16000000
93
94
95# Input clock frequency.
96#     This will define a symbol, F_USB, in all source code files equal to the
97#     input clock frequency (before any prescaling is performed) in Hz. This value may
98#     differ from F_CPU if prescaling is used on the latter, and is required as the
99#     raw input clock is fed directly to the PLL sections of the AVR for high speed
100#     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
101#     at the end, this will be done automatically to create a 32-bit value in your
102#     source code.
103#
104#     If no clock division is performed on the input clock inside the AVR (via the
105#     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
106F_USB = $(F_CPU)
107
108
109# Starting byte address of the bootloader, as a byte address - computed via the formula
110#   BOOT_START = ((FLASH_SIZE_KB - BOOT_SECTION_SIZE_KB) * 1024)
111#
112# Note that the bootloader size and start address given in AVRStudio is in words and not
113# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
114FLASH_SIZE_KB        = 32
115BOOT_SECTION_SIZE_KB = 4
116BOOT_START           = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)
117
118
119# Output format. (can be srec, ihex, binary)
120FORMAT = ihex
121
122
123# Target file name (without extension).
124TARGET = Caterina
125
126
127# Object files directory
128#     To put object files in current directory, use a dot (.), do NOT make
129#     this an empty or blank macro!
130OBJDIR = .
131
132
133# Path to the LUFA library
134LUFA_PATH = LUFA-111009
135
136
137# LUFA library compile-time options and predefined tokens
138LUFA_OPTS  = -D USB_DEVICE_ONLY
139LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
140LUFA_OPTS += -D ORDERED_EP_CONFIG
141LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
142LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
143LUFA_OPTS += -D USE_RAM_DESCRIPTORS
144LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
145LUFA_OPTS += -D NO_INTERNAL_SERIAL
146LUFA_OPTS += -D NO_DEVICE_SELF_POWER
147LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
148LUFA_OPTS += -D NO_SOF_EVENTS
149
150#LUFA_OPTS += -D NO_BLOCK_SUPPORT
151#LUFA_OPTS += -D NO_EEPROM_BYTE_SUPPORT
152#LUFA_OPTS += -D NO_FLASH_BYTE_SUPPORT
153LUFA_OPTS += -D NO_LOCK_BYTE_WRITE_SUPPORT
154
155
156# Create the LUFA source path variables by including the LUFA root makefile
157include $(LUFA_PATH)/LUFA/makefile
158
159
160# List C source files here. (C dependencies are automatically generated.)
161SRC = $(TARGET).c                                                 \
162	  Descriptors.c                                               \
163	  $(LUFA_SRC_USB)                                             \
164
165
166# List C++ source files here. (C dependencies are automatically generated.)
167CPPSRC =
168
169
170# List Assembler source files here.
171#     Make them always end in a capital .S.  Files ending in a lowercase .s
172#     will not be considered source files but generated files (assembler
173#     output from the compiler), and will be deleted upon "make clean"!
174#     Even though the DOS/Win* filesystem matches both .s and .S the same,
175#     it will preserve the spelling of the filenames, and gcc itself does
176#     care about how the name is spelled on its command-line.
177ASRC =
178
179
180# Optimization level, can be [0, 1, 2, 3, s].
181#     0 = turn off optimization. s = optimize for size.
182#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
183OPT = s
184
185
186# Debugging format.
187#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
188#     AVR Studio 4.10 requires dwarf-2.
189#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
190DEBUG = dwarf-2
191
192
193# List any extra directories to look for include files here.
194#     Each directory must be seperated by a space.
195#     Use forward slashes for directory separators.
196#     For a directory that has spaces, enclose it in quotes.
197EXTRAINCDIRS = $(LUFA_PATH)/
198
199
200# Compiler flag to set the C Standard level.
201#     c89   = "ANSI" C
202#     gnu89 = c89 plus GCC extensions
203#     c99   = ISO C99 standard (not yet fully implemented)
204#     gnu99 = c99 plus GCC extensions
205CSTANDARD = -std=c99
206
207
208# Place -D or -U options here for C sources
209CDEFS  = -DF_CPU=$(F_CPU)UL
210CDEFS += -DF_USB=$(F_USB)UL
211CDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)
212CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
213CDEFS += -DDEVICE_VID=$(VID)UL
214CDEFS += -DDEVICE_PID=$(PID)UL
215CDEFS += $(LUFA_OPTS)
216
217
218# Place -D or -U options here for ASM sources
219ADEFS  = -DF_CPU=$(F_CPU)
220ADEFS += -DF_USB=$(F_USB)UL
221ADEFS += -DBOARD=BOARD_$(BOARD)
222ADEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
223ADEFS += $(LUFA_OPTS)
224
225
226# Place -D or -U options here for C++ sources
227CPPDEFS  = -DF_CPU=$(F_CPU)UL
228CPPDEFS += -DF_USB=$(F_USB)UL
229CPPDEFS += -DBOARD=BOARD_$(BOARD)
230CPPDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
231CPPDEFS += $(LUFA_OPTS)
232#CPPDEFS += -D__STDC_LIMIT_MACROS
233#CPPDEFS += -D__STDC_CONSTANT_MACROS
234
235
236
237#---------------- Compiler Options C ----------------
238#  -g*:          generate debugging information
239#  -O*:          optimization level
240#  -f...:        tuning, see GCC manual and avr-libc documentation
241#  -Wall...:     warning level
242#  -Wa,...:      tell GCC to pass this to the assembler.
243#    -adhlns...: create assembler listing
244CFLAGS = -g$(DEBUG)
245CFLAGS += $(CDEFS)
246CFLAGS += -O$(OPT)
247CFLAGS += -funsigned-char
248CFLAGS += -funsigned-bitfields
249CFLAGS += -ffunction-sections
250CFLAGS += -fno-inline-small-functions
251CFLAGS += -fpack-struct
252CFLAGS += -fshort-enums
253CFLAGS += -fno-strict-aliasing
254CFLAGS += -Wall
255CFLAGS += -Wstrict-prototypes
256#CFLAGS += -mshort-calls
257#CFLAGS += -fno-unit-at-a-time
258#CFLAGS += -Wundef
259#CFLAGS += -Wunreachable-code
260#CFLAGS += -Wsign-compare
261CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
262CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
263CFLAGS += $(CSTANDARD)
264
265
266#---------------- Compiler Options C++ ----------------
267#  -g*:          generate debugging information
268#  -O*:          optimization level
269#  -f...:        tuning, see GCC manual and avr-libc documentation
270#  -Wall...:     warning level
271#  -Wa,...:      tell GCC to pass this to the assembler.
272#    -adhlns...: create assembler listing
273CPPFLAGS = -g$(DEBUG)
274CPPFLAGS += $(CPPDEFS)
275CPPFLAGS += -O$(OPT)
276CPPFLAGS += -funsigned-char
277CPPFLAGS += -funsigned-bitfields
278CPPFLAGS += -fpack-struct
279CPPFLAGS += -fshort-enums
280CPPFLAGS += -fno-exceptions
281CPPFLAGS += -Wall
282CPPFLAGS += -Wundef
283#CPPFLAGS += -mshort-calls
284#CPPFLAGS += -fno-unit-at-a-time
285#CPPFLAGS += -Wstrict-prototypes
286#CPPFLAGS += -Wunreachable-code
287#CPPFLAGS += -Wsign-compare
288CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
289CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
290#CPPFLAGS += $(CSTANDARD)
291
292
293#---------------- Assembler Options ----------------
294#  -Wa,...:   tell GCC to pass this to the assembler.
295#  -adhlns:   create listing
296#  -gstabs:   have the assembler create line number information; note that
297#             for use in COFF files, additional information about filenames
298#             and function names needs to be present in the assembler source
299#             files -- see avr-libc docs [FIXME: not yet described there]
300#  -listing-cont-lines: Sets the maximum number of continuation lines of hex
301#       dump that will be displayed for a given single line of source input.
302ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
303
304
305#---------------- Library Options ----------------
306# Minimalistic printf version
307PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
308
309# Floating point printf version (requires MATH_LIB = -lm below)
310PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
311
312# If this is left blank, then it will use the Standard printf version.
313PRINTF_LIB =
314#PRINTF_LIB = $(PRINTF_LIB_MIN)
315#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
316
317
318# Minimalistic scanf version
319SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
320
321# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
322SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
323
324# If this is left blank, then it will use the Standard scanf version.
325SCANF_LIB =
326#SCANF_LIB = $(SCANF_LIB_MIN)
327#SCANF_LIB = $(SCANF_LIB_FLOAT)
328
329
330MATH_LIB = -lm
331
332
333# List any extra directories to look for libraries here.
334#     Each directory must be seperated by a space.
335#     Use forward slashes for directory separators.
336#     For a directory that has spaces, enclose it in quotes.
337EXTRALIBDIRS =
338
339
340
341#---------------- External Memory Options ----------------
342
343# 64 KB of external RAM, starting after internal RAM (ATmega128!),
344# used for variables (.data/.bss) and heap (malloc()).
345#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
346
347# 64 KB of external RAM, starting after internal RAM (ATmega128!),
348# only used for heap (malloc()).
349#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
350
351EXTMEMOPTS =
352
353
354
355#---------------- Linker Options ----------------
356#  -Wl,...:     tell GCC to pass this to linker.
357#    -Map:      create map file
358#    --cref:    add cross reference to  map file
359LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
360LDFLAGS += -Wl,--section-start=.text=$(BOOT_START)
361LDFLAGS += -Wl,--relax
362LDFLAGS += -Wl,--gc-sections
363LDFLAGS += $(EXTMEMOPTS)
364LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
365LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
366#LDFLAGS += -T linker_script.x
367
368
369
370#---------------- Programming Options (avrdude) ----------------
371
372# Programming hardware
373# Type: avrdude -c ?
374# to get a full listing.
375#
376#AVRDUDE_PROGRAMMER = avrispmkII
377AVRDUDE_PROGRAMMER = usbtiny
378
379# com1 = serial port. Use lpt1 to connect to parallel port.
380AVRDUDE_PORT = usb
381
382AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
383#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
384
385
386# Uncomment the following if you want avrdude's erase cycle counter.
387# Note that this counter needs to be initialized first using -Yn,
388# see avrdude manual.
389#AVRDUDE_ERASE_COUNTER = -y
390
391# Uncomment the following if you do /not/ wish a verification to be
392# performed after programming the device.
393#AVRDUDE_NO_VERIFY = -V
394
395# Increase verbosity level.  Please use this when submitting bug
396# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
397# to submit bug reports.
398#AVRDUDE_VERBOSE = -v -v
399
400AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
401AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
402AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
403AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
404
405
406
407#---------------- Debugging Options ----------------
408
409# For simulavr only - target MCU frequency.
410DEBUG_MFREQ = $(F_CPU)
411
412# Set the DEBUG_UI to either gdb or insight.
413# DEBUG_UI = gdb
414DEBUG_UI = insight
415
416# Set the debugging back-end to either avarice, simulavr.
417DEBUG_BACKEND = avarice
418#DEBUG_BACKEND = simulavr
419
420# GDB Init Filename.
421GDBINIT_FILE = __avr_gdbinit
422
423# When using avarice settings for the JTAG
424JTAG_DEV = /dev/com1
425
426# Debugging port used to communicate between GDB / avarice / simulavr.
427DEBUG_PORT = 4242
428
429# Debugging host used to communicate between GDB / avarice / simulavr, normally
430#     just set to localhost unless doing some sort of crazy debugging when
431#     avarice is running on a different computer.
432DEBUG_HOST = localhost
433
434
435
436#============================================================================
437
438
439# Define programs and commands.
440SHELL = sh
441CC = avr-gcc
442OBJCOPY = avr-objcopy
443OBJDUMP = avr-objdump
444SIZE = avr-size
445AR = avr-ar rcs
446NM = avr-nm
447#AVRDUDE = /Applications/avrdude -C /Applications/avrdude.conf -B 1
448AVRDUDE = /home/david/tmp/Arduino-master/build/linux/dist/tools/avrdude -B 1 -C /home/david/tmp/Arduino-master/build/linux/dist/tools/avrdude.conf
449REMOVE = rm -f
450REMOVEDIR = rm -rf
451COPY = cp
452WINSHELL = cmd
453
454
455# Define Messages
456# English
457MSG_ERRORS_NONE = Errors: none
458MSG_BEGIN = -------- begin --------
459MSG_END = --------  end  --------
460MSG_SIZE_BEFORE = Size before:
461MSG_SIZE_AFTER = Size after:
462MSG_COFF = Converting to AVR COFF:
463MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
464MSG_FLASH = Creating load file for Flash:
465MSG_EEPROM = Creating load file for EEPROM:
466MSG_EXTENDED_LISTING = Creating Extended Listing:
467MSG_SYMBOL_TABLE = Creating Symbol Table:
468MSG_LINKING = Linking:
469MSG_COMPILING = Compiling C:
470MSG_COMPILING_CPP = Compiling C++:
471MSG_ASSEMBLING = Assembling:
472MSG_CLEANING = Cleaning project:
473MSG_CREATING_LIBRARY = Creating library:
474
475
476
477
478# Define all object files.
479OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
480
481# Define all listing files.
482LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
483
484
485# Compiler flags to generate dependency files.
486GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
487
488
489# Combine all necessary flags and optional flags.
490# Add target processor to flags.
491ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
492ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
493ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
494
495
496
497
498
499# Default target.
500all: begin gccversion sizebefore build sizeafter end
501
502# Change the build target to build a HEX file or a library.
503build: elf hex eep lss sym
504#build: lib
505
506
507elf: $(TARGET).elf
508hex: $(TARGET).hex
509eep: $(TARGET).eep
510lss: $(TARGET).lss
511sym: $(TARGET).sym
512LIBNAME=lib$(TARGET).a
513lib: $(LIBNAME)
514
515
516
517# Eye candy.
518# AVR Studio 3.x does not check make's exit code but relies on
519# the following magic strings to be generated by the compile job.
520begin:
521	@echo
522	@echo $(MSG_BEGIN)
523
524end:
525	@echo $(MSG_END)
526	@echo
527
528
529# Display size of file.
530HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
531ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
532MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
533FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
534
535
536sizebefore:
537	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
538	2>/dev/null; echo; fi
539
540sizeafter:
541	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
542	2>/dev/null; echo; fi
543
544
545
546# Display compiler version information.
547gccversion :
548	@$(CC) --version
549
550
551# Program the device.
552program: $(TARGET).hex $(TARGET).eep
553	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
554
555
556# Generate avr-gdb config/init file which does the following:
557#     define the reset signal, load the target file, connect to target, and set
558#     a breakpoint at main().
559gdb-config:
560	@$(REMOVE) $(GDBINIT_FILE)
561	@echo define reset >> $(GDBINIT_FILE)
562	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
563	@echo end >> $(GDBINIT_FILE)
564	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
565	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
566ifeq ($(DEBUG_BACKEND),simulavr)
567	@echo load  >> $(GDBINIT_FILE)
568endif
569	@echo break main >> $(GDBINIT_FILE)
570
571debug: gdb-config $(TARGET).elf
572ifeq ($(DEBUG_BACKEND), avarice)
573	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
574	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
575	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
576	@$(WINSHELL) /c pause
577
578else
579	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
580	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
581endif
582	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
583
584
585
586
587# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
588COFFCONVERT = $(OBJCOPY) --debugging
589COFFCONVERT += --change-section-address .data-0x800000
590COFFCONVERT += --change-section-address .bss-0x800000
591COFFCONVERT += --change-section-address .noinit-0x800000
592COFFCONVERT += --change-section-address .eeprom-0x810000
593
594
595
596coff: $(TARGET).elf
597	@echo
598	@echo $(MSG_COFF) $(TARGET).cof
599	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
600
601
602extcoff: $(TARGET).elf
603	@echo
604	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
605	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
606
607
608
609# Create final output files (.hex, .eep) from ELF output file.
610%.hex: %.elf
611	@echo
612	@echo $(MSG_FLASH) $@
613	$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
614
615%.eep: %.elf
616	@echo
617	@echo $(MSG_EEPROM) $@
618	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
619	--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
620
621# Create extended listing file from ELF output file.
622%.lss: %.elf
623	@echo
624	@echo $(MSG_EXTENDED_LISTING) $@
625	$(OBJDUMP) -h -S -z $< > $@
626
627# Create a symbol table from ELF output file.
628%.sym: %.elf
629	@echo
630	@echo $(MSG_SYMBOL_TABLE) $@
631	$(NM) -n $< > $@
632
633
634
635# Create library from object files.
636.SECONDARY : $(TARGET).a
637.PRECIOUS : $(OBJ)
638%.a: $(OBJ)
639	@echo
640	@echo $(MSG_CREATING_LIBRARY) $@
641	$(AR) $@ $(OBJ)
642
643
644# Link: create ELF output file from object files.
645.SECONDARY : $(TARGET).elf
646.PRECIOUS : $(OBJ)
647%.elf: $(OBJ)
648	@echo
649	@echo $(MSG_LINKING) $@
650	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
651
652
653# Compile: create object files from C source files.
654$(OBJDIR)/%.o : %.c
655	@echo
656	@echo $(MSG_COMPILING) $<
657	$(CC) -c $(ALL_CFLAGS) $< -o $@
658
659
660# Compile: create object files from C++ source files.
661$(OBJDIR)/%.o : %.cpp
662	@echo
663	@echo $(MSG_COMPILING_CPP) $<
664	$(CC) -c $(ALL_CPPFLAGS) $< -o $@
665
666
667# Compile: create assembler files from C source files.
668%.s : %.c
669	$(CC) -S $(ALL_CFLAGS) $< -o $@
670
671
672# Compile: create assembler files from C++ source files.
673%.s : %.cpp
674	$(CC) -S $(ALL_CPPFLAGS) $< -o $@
675
676
677# Assemble: create object files from assembler source files.
678$(OBJDIR)/%.o : %.S
679	@echo
680	@echo $(MSG_ASSEMBLING) $<
681	$(CC) -c $(ALL_ASFLAGS) $< -o $@
682
683
684# Create preprocessed source for use in sending a bug report.
685%.i : %.c
686	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
687
688
689# Target: clean project.
690clean: begin clean_list end
691
692clean_list :
693	@echo
694	@echo $(MSG_CLEANING)
695	$(REMOVE) $(TARGET).hex
696	$(REMOVE) $(TARGET).eep
697	$(REMOVE) $(TARGET).cof
698	$(REMOVE) $(TARGET).elf
699	$(REMOVE) $(TARGET).map
700	$(REMOVE) $(TARGET).sym
701	$(REMOVE) $(TARGET).lss
702	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
703	$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
704	$(REMOVE) $(SRC:.c=.s)
705	$(REMOVE) $(SRC:.c=.d)
706	$(REMOVE) $(SRC:.c=.i)
707	$(REMOVEDIR) .dep
708
709doxygen:
710	@echo Generating Project Documentation \($(TARGET)\)...
711	@doxygen Doxygen.conf
712	@echo Documentation Generation Complete.
713
714clean_doxygen:
715	rm -rf Documentation
716
717checksource:
718	@for f in $(SRC) $(CPPSRC) $(ASRC); do \
719		if [ -f $$f ]; then \
720			echo "Found Source File: $$f" ; \
721		else \
722			echo "Source File Not Found: $$f" ; \
723		fi; done
724
725
726# Create object files directory
727$(shell mkdir $(OBJDIR) 2>/dev/null)
728
729
730# Include the dependency files.
731-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
732
733
734# Listing of phony targets.
735.PHONY : all begin finish end sizebefore sizeafter gccversion \
736build elf hex eep lss sym coff extcoff doxygen clean          \
737clean_list clean_doxygen program debug gdb-config checksource
738
739