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