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. <<
 
   6 # Released to the Public Domain
 
   8 # Additional material for this makefile was written by:
 
  21 #----------------------------------------------------------------------------
 
  24 # make all = Make software.
 
  26 # make clean = Clean out built project files.
 
  28 # make dfu = Download the hex file to the device, using dfu-programmer (must
 
  29 #            have dfu-programmer installed).
 
  31 # make flip = Download the hex file to the device, using Atmel FLIP (must
 
  32 #             have Atmel FLIP installed).
 
  34 # make doxygen = Generate DoxyGen documentation for the project (must have
 
  37 # make filename.s = Just compile filename.c into the assembler code only.
 
  39 # make filename.i = Create a preprocessed source file for use in submitting
 
  40 #                   bug reports to the GCC project.
 
  42 # To rebuild project do "make clean" then "make all".
 
  43 #----------------------------------------------------------------------------
 
  50 # Targeted chip architecture (see library "Architectures" documentation)
 
  54 # Target board (see library "Board Types" documentation, NONE for projects not requiring
 
  55 # LUFA board drivers). If USER is selected, put custom board drivers in a directory called 
 
  56 # "Board" inside the application directory.
 
  60 # Processor frequency.
 
  61 #     This will define a symbol, F_CPU, in all source code files equal to the
 
  62 #     processor frequency in Hz. You can then use this symbol in your source code to
 
  63 #     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
 
  64 #     automatically to create a 32-bit value in your source code.
 
  66 #     This should be the frequency the system core runs at, after the system clock
 
  67 #     has been set up correctly and started.
 
  71 # USB controller master clock frequency.
 
  72 #     This will define a symbol, F_USB, in all source code files equal to the
 
  73 #     input clock frequency of the USB controller's clock generator in Hz.
 
  75 #     For the UC3 chips, this should be equal to 48MHz or 96MHz.
 
  79 # Output format. (can be srec, ihex, binary)
 
  83 # Target file name (without extension).
 
  87 # Object files directory
 
  88 #     To put object files in current directory, use a dot (.), do NOT make
 
  89 #     this an empty or blank macro!
 
  93 # Path to the LUFA library
 
  97 # LUFA library compile-time options and predefined tokens (add '-D' before each token)
 
 101 # Create the LUFA source path variables by including the LUFA root makefile
 
 102 include $(LUFA_PATH)/LUFA/makefile
 
 105 # List C source files here. (C dependencies are automatically generated.)
 
 111 # List C++ source files here. (C dependencies are automatically generated.)
 
 112 CPPSRC = Test_CPP.cpp
 
 115 # List Assembler source files here.
 
 116 #     Make them always end in a capital .S.  Files ending in a lowercase .s
 
 117 #     will not be considered source files but generated files (assembler
 
 118 #     output from the compiler), and will be deleted upon "make clean"!
 
 119 #     Even though the DOS/Win* filesystem matches both .s and .S the same,
 
 120 #     it will preserve the spelling of the filenames, and gcc itself does
 
 121 #     care about how the name is spelled on its command-line.
 
 123        $(LUFA_PATH)/LUFA/Platform/UC3/Exception.S
 
 126 # Optimization level, can be [0, 1, 2, 3, s]. 
 
 127 #     0 = turn off optimization. s = optimize for size.
 
 128 #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
 
 132 # List any extra directories to look for include files here.
 
 133 #     Each directory must be seperated by a space.
 
 134 #     Use forward slashes for directory separators.
 
 135 #     For a directory that has spaces, enclose it in quotes.
 
 136 EXTRAINCDIRS = $(LUFA_PATH)/
 
 139 # Compiler flag to set the C Standard level.
 
 141 #     gnu89 = c89 plus GCC extensions
 
 142 #     c99   = ISO C99 standard (not yet fully implemented)
 
 143 #     gnu99 = c99 plus GCC extensions
 
 144 CSTANDARD = -std=gnu99
 
 147 # Place -D or -U options here for C sources
 
 148 CDEFS  = -DF_CPU=$(F_CPU)UL
 
 149 CDEFS += -DF_USB=$(F_USB)UL
 
 150 CDEFS += -DBOARD=BOARD_$(BOARD)
 
 151 CDEFS += -DARCH=ARCH_$(ARCH)
 
 152 CDEFS += $(LUFA_OPTS)
 
 155 # Place -D or -U options here for ASM sources
 
 156 ADEFS  = -DF_CPU=$(F_CPU)
 
 157 ADEFS += -DF_USB=$(F_USB)UL
 
 158 ADEFS += -DBOARD=BOARD_$(BOARD)
 
 159 ADEFS += -DARCH=ARCH_$(ARCH)
 
 160 ADEFS += $(LUFA_OPTS)
 
 162 # Place -D or -U options here for C++ sources
 
 163 CPPDEFS  = -DF_CPU=$(F_CPU)UL
 
 164 CPPDEFS += -DF_USB=$(F_USB)UL
 
 165 CPPDEFS += -DBOARD=BOARD_$(BOARD)
 
 166 CPPDEFS += -DARCH=ARCH_$(ARCH)
 
 167 CPPDEFS += $(LUFA_OPTS)
 
 174 #---------------- Compiler Options C ----------------
 
 175 #  -g*:          generate debugging information
 
 176 #  -O*:          optimization level
 
 177 #  -f...:        tuning, see GCC manual and avr-libc documentation
 
 178 #  -Wall...:     warning level
 
 179 #  -Wa,...:      tell GCC to pass this to the assembler.
 
 180 #    -adhlns...: create assembler listing
 
 184 CFLAGS += -funsigned-char
 
 185 CFLAGS += -funsigned-bitfields
 
 186 CFLAGS += -ffunction-sections
 
 187 CFLAGS += -fno-strict-aliasing
 
 188 CFLAGS += -masm-addr-pseudos
 
 189 #CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
 
 190 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 
 191 CFLAGS += $(CSTANDARD)
 
 195 CFLAGS += -Wstrict-prototypes
 
 197 CFLAGS += -Winit-self
 
 198 CFLAGS += -Wswitch-enum
 
 201 CFLAGS += -Wpointer-arith
 
 202 CFLAGS += -Wcast-align
 
 203 CFLAGS += -Wwrite-strings
 
 204 CFLAGS += -Wlogical-op
 
 205 CFLAGS += -Wmissing-parameter-type
 
 206 CFLAGS += -Wmissing-declarations
 
 207 CFLAGS += -Wmissing-field-initializers
 
 208 CFLAGS += -Wmissing-format-attribute
 
 209 #CFLAGS += -Wredundant-decls
 
 210 CFLAGS += -Wnested-externs
 
 211 CFLAGS += -Woverlength-strings
 
 212 #CFLAGS += -Wswitch-default
 
 213 #CFLAGS += -Wc++-compat
 
 214 #CFLAGS += -Wcast-qual
 
 215 #CFLAGS += -Wconversion
 
 216 #CFLAGS += -Wjump-misses-init
 
 220 #---------------- Compiler Options C++ ----------------
 
 221 #  -g*:          generate debugging information
 
 222 #  -O*:          optimization level
 
 223 #  -f...:        tuning, see GCC manual and avr-libc documentation
 
 224 #  -Wall...:     warning level
 
 225 #  -Wa,...:      tell GCC to pass this to the assembler.
 
 226 #    -adhlns...: create assembler listing
 
 227 CPPFLAGS = -g$(DEBUG)
 
 228 CPPFLAGS += $(CPPDEFS)
 
 230 CPPFLAGS += -funsigned-char
 
 231 CPPFLAGS += -funsigned-bitfields
 
 232 CPPFLAGS += -ffunction-sections
 
 233 CPPFLAGS += -fno-strict-aliasing
 
 234 CPPFLAGS += -fno-exceptions
 
 235 CPPFLAGS += -masm-addr-pseudos
 
 238 #CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
 
 239 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 
 240 #CPPFLAGS += $(CSTANDARD)
 
 243 #---------------- Assembler Options ----------------
 
 244 #  -Wa,...:   tell GCC to pass this to the assembler.
 
 245 #  -adhlns:   create listing
 
 246 #  -gstabs:   have the assembler create line number information; note that
 
 247 #             for use in COFF files, additional information about filenames
 
 248 #             and function names needs to be present in the assembler source
 
 249 #             files -- see avr-libc docs [FIXME: not yet described there]
 
 250 #  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
 
 251 #       dump that will be displayed for a given single line of source input.
 
 253 #ASFLAGS += -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
 
 256 #---------------- Linker Options ----------------
 
 257 #  -Wl,...:     tell GCC to pass this to linker.
 
 258 #    -Map:      create map file
 
 259 #    --cref:    add cross reference to  map file
 
 260 LDFLAGS  = -Wl,-Map=$(TARGET).map,--cref
 
 261 LDFLAGS += -Wl,--gc-sections --rodata-writable
 
 262 LDFLAGS += -Wl,--direct-data
 
 263 #LDFLAGS += -T linker_script.x
 
 266 #============================================================================
 
 269 # Define programs and commands.
 
 272 OBJCOPY = avr32-objcopy
 
 273 OBJDUMP = avr32-objdump
 
 285 MSG_ERRORS_NONE = Errors: none
 
 286 MSG_BEGIN = -------- begin --------
 
 287 MSG_END = --------  end  --------
 
 288 MSG_SIZE_BEFORE = Size before: 
 
 289 MSG_SIZE_AFTER = Size after:
 
 290 MSG_COFF = Converting to AVR COFF:
 
 291 MSG_FLASH = Creating load file for Flash:
 
 292 MSG_EEPROM = Creating load file for EEPROM:
 
 293 MSG_EXTENDED_LISTING = Creating Extended Listing:
 
 294 MSG_SYMBOL_TABLE = Creating Symbol Table:
 
 295 MSG_LINKING = Linking:
 
 296 MSG_COMPILING = Compiling C:
 
 297 MSG_COMPILING_CPP = Compiling C++:
 
 298 MSG_ASSEMBLING = Assembling:
 
 299 MSG_CLEANING = Cleaning project:
 
 300 MSG_CREATING_LIBRARY = Creating library:
 
 305 # Define all object files.
 
 306 OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) 
 
 308 # Define all listing files.
 
 309 LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) 
 
 312 # Compiler flags to generate dependency files.
 
 313 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
 
 316 # Combine all necessary flags and optional flags.
 
 317 # Add target processor to flags.
 
 318 ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
 
 319 ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
 
 320 ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 327 all: begin gccversion sizebefore build sizeafter end
 
 329 # Change the build target to build a HEX file or a library.
 
 330 build: elf hex lss sym
 
 338 LIBNAME=lib$(TARGET).a
 
 344 # AVR Studio 3.x does not check make's exit code but relies on
 
 345 # the following magic strings to be generated by the compile job.
 
 355 # Display size of file.
 
 356 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
 
 357 ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
 
 358 MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
 
 359 FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
 
 363         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
 
 364         2>/dev/null; echo; fi
 
 367         @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
 
 368         2>/dev/null; echo; fi
 
 372 # Display compiler version information.
 
 377 # Program the device.  
 
 379         batchisp -hardware usb -device $(MCU) -operation erase f
 
 380         batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
 
 381         batchisp -hardware usb -device $(MCU) -operation start reset 0
 
 384         dfu-programmer $(MCU) erase
 
 385         dfu-programmer $(MCU) flash $(TARGET).hex
 
 386         dfu-programmer $(MCU) reset
 
 389 # Create final output files (.hex, .eep) from ELF output file.
 
 392         @echo $(MSG_FLASH) $@
 
 393         $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
 
 395 # Create extended listing file from ELF output file.
 
 398         @echo $(MSG_EXTENDED_LISTING) $@
 
 399         $(OBJDUMP) -h -S -z $< > $@
 
 401 # Create a symbol table from ELF output file.
 
 404         @echo $(MSG_SYMBOL_TABLE) $@
 
 409 # Create library from object files.
 
 410 .SECONDARY : $(TARGET).a
 
 414         @echo $(MSG_CREATING_LIBRARY) $@
 
 418 # Link: create ELF output file from object files.
 
 419 .SECONDARY : $(TARGET).elf
 
 423         @echo $(MSG_LINKING) $@
 
 424         $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
 
 427 # Compile: create object files from C source files.
 
 430         @echo $(MSG_COMPILING) $<
 
 431         $(CC) -c $(ALL_CFLAGS) $< -o $@ 
 
 434 # Compile: create object files from C++ source files.
 
 435 $(OBJDIR)/%.o : %.cpp
 
 437         @echo $(MSG_COMPILING_CPP) $<
 
 438         $(CC) -c $(ALL_CPPFLAGS) $< -o $@ 
 
 441 # Compile: create assembler files from C source files.
 
 443         $(CC) -S $(ALL_CFLAGS) $< -o $@
 
 446 # Compile: create assembler files from C++ source files.
 
 448         $(CC) -S $(ALL_CPPFLAGS) $< -o $@
 
 451 # Assemble: create object files from assembler source files.
 
 454         @echo $(MSG_ASSEMBLING) $<
 
 455         $(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 458 # Create preprocessed source for use in sending a bug report.
 
 460         $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
 
 463 # Target: clean project.
 
 464 clean: begin clean_list end
 
 468         @echo $(MSG_CLEANING)
 
 469         $(REMOVE) $(TARGET).hex
 
 470         $(REMOVE) $(TARGET).cof
 
 471         $(REMOVE) $(TARGET).elf
 
 472         $(REMOVE) $(TARGET).map
 
 473         $(REMOVE) $(TARGET).sym
 
 474         $(REMOVE) $(TARGET).lss
 
 475         $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
 
 476         $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
 
 477         $(REMOVE) $(SRC:.c=.s)
 
 478         $(REMOVE) $(SRC:.c=.d)
 
 479         $(REMOVE) $(SRC:.c=.i)
 
 483         @echo Generating Project Documentation \($(TARGET)\)...
 
 484         @if ( ( cat Doxygen.conf ; echo "HTML_STYLESHEET=$(LUFA_PATH)/LUFA/DoxygenPages/Style/Style.css" ) | doxygen - 2>&1 | grep -v "warning: ignoring unsupported tag" ;); then \
 
 487         @echo Documentation Generation Complete.
 
 493         @for f in $(SRC) $(CPPSRC) $(ASRC); do \
 
 494                 if [ -f $$f ]; then \
 
 495                         echo "Found Source File: $$f" ; \
 
 497                         echo "Source File Not Found: $$f" ; \
 
 501 # Create object files directory
 
 502 $(shell mkdir $(OBJDIR) 2>/dev/null)
 
 505 # Include the dependency files.
 
 506 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
 
 509 # Listing of phony targets.
 
 510 .PHONY : all begin finish end sizebefore sizeafter gccversion \
 
 511 build elf hex lss sym doxygen clean clean_list clean_doxygen  \