Makefile 22 KB

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