Makefile 22 KB

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