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