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