upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

rules.mk 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. # Hey Emacs, this is a -*- makefile -*-
  2. #----------------------------------------------------------------------------
  3. # WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al.
  4. #
  5. # Released to the Public Domain
  6. #
  7. # Additional material for this makefile was written by:
  8. # Peter Fleury
  9. # Tim Henigan
  10. # Colin O'Flynn
  11. # Reiner Patommel
  12. # Markus Pfaff
  13. # Sander Pool
  14. # Frederik Rouleau
  15. # Carlos Lamas
  16. #
  17. #----------------------------------------------------------------------------
  18. # On command line:
  19. #
  20. # make all = Make software.
  21. #
  22. # make clean = Clean out built project files.
  23. #
  24. # make coff = Convert ELF to AVR COFF.
  25. #
  26. # make extcoff = Convert ELF to AVR Extended COFF.
  27. #
  28. # make program = Download the hex file to the device.
  29. # Please customize your programmer settings(PROGRAM_CMD)
  30. #
  31. # make teensy = Download the hex file to the device, using teensy_loader_cli.
  32. # (must have teensy_loader_cli installed).
  33. #
  34. # make dfu = Download the hex file to the device, using dfu-programmer (must
  35. # have dfu-programmer installed).
  36. #
  37. # make flip = Download the hex file to the device, using Atmel FLIP (must
  38. # have Atmel FLIP installed).
  39. #
  40. # make dfu-ee = Download the eeprom file to the device, using dfu-programmer
  41. # (must have dfu-programmer installed).
  42. #
  43. # make flip-ee = Download the eeprom file to the device, using Atmel FLIP
  44. # (must have Atmel FLIP installed).
  45. #
  46. # make debug = Start either simulavr or avarice as specified for debugging,
  47. # with avr-gdb or avr-insight as the front end for debugging.
  48. #
  49. # make filename.s = Just compile filename.c into the assembler code only.
  50. #
  51. # make filename.i = Create a preprocessed source file for use in submitting
  52. # bug reports to the GCC project.
  53. #
  54. # To rebuild project do "make clean" then "make all".
  55. #----------------------------------------------------------------------------
  56. # Output format. (can be srec, ihex, binary)
  57. FORMAT = ihex
  58. # Object files directory
  59. # To put object files in current directory, use a dot (.), do NOT make
  60. # this an empty or blank macro!
  61. OBJDIR = obj_$(TARGET)
  62. # Optimization level, can be [0, 1, 2, 3, s].
  63. # 0 = turn off optimization. s = optimize for size.
  64. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  65. OPT = s
  66. # Debugging format.
  67. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  68. # AVR Studio 4.10 requires dwarf-2.
  69. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  70. DEBUG = dwarf-2
  71. # List any extra directories to look for include files here.
  72. # Each directory must be seperated by a space.
  73. # Use forward slashes for directory separators.
  74. # For a directory that has spaces, enclose it in quotes.
  75. EXTRAINCDIRS = $(subst :, ,$(VPATH))
  76. # Compiler flag to set the C Standard level.
  77. # c89 = "ANSI" C
  78. # gnu89 = c89 plus GCC extensions
  79. # c99 = ISO C99 standard (not yet fully implemented)
  80. # gnu99 = c99 plus GCC extensions
  81. CSTANDARD = -std=gnu99
  82. # Place -D or -U options here for C sources
  83. CDEFS = -DF_CPU=$(F_CPU)UL
  84. CDEFS += $(OPT_DEFS)
  85. # Place -D or -U options here for ASM sources
  86. ADEFS = -DF_CPU=$(F_CPU)
  87. ADEFS += $(OPT_DEFS)
  88. # Place -D or -U options here for C++ sources
  89. CPPDEFS = -DF_CPU=$(F_CPU)UL
  90. #CPPDEFS += -D__STDC_LIMIT_MACROS
  91. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  92. CPPDEFS += $(OPT_DEFS)
  93. #---------------- Compiler Options C ----------------
  94. # -g*: generate debugging information
  95. # -O*: optimization level
  96. # -f...: tuning, see GCC manual and avr-libc documentation
  97. # -Wall...: warning level
  98. # -Wa,...: tell GCC to pass this to the assembler.
  99. # -adhlns...: create assembler listing
  100. CFLAGS = -g$(DEBUG)
  101. CFLAGS += $(CDEFS)
  102. CFLAGS += -O$(OPT)
  103. CFLAGS += -funsigned-char
  104. CFLAGS += -funsigned-bitfields
  105. CFLAGS += -ffunction-sections
  106. CFLAGS += -fdata-sections
  107. CFLAGS += -fno-inline-small-functions
  108. CFLAGS += -fpack-struct
  109. CFLAGS += -fshort-enums
  110. CFLAGS += -fno-strict-aliasing
  111. CFLAGS += -Wall
  112. CFLAGS += -Wstrict-prototypes
  113. #CFLAGS += -mshort-calls
  114. #CFLAGS += -fno-unit-at-a-time
  115. #CFLAGS += -Wundef
  116. #CFLAGS += -Wunreachable-code
  117. #CFLAGS += -Wsign-compare
  118. CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  119. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  120. CFLAGS += $(CSTANDARD)
  121. ifdef CONFIG_H
  122. CFLAGS += -include $(CONFIG_H)
  123. endif
  124. ifdef CONFIG_USER_H
  125. CFLAGS += -include $(CONFIG_USER_H)
  126. endif
  127. #---------------- Compiler Options C++ ----------------
  128. # -g*: generate debugging information
  129. # -O*: optimization level
  130. # -f...: tuning, see GCC manual and avr-libc documentation
  131. # -Wall...: warning level
  132. # -Wa,...: tell GCC to pass this to the assembler.
  133. # -adhlns...: create assembler listing
  134. CPPFLAGS = -g$(DEBUG)
  135. CPPFLAGS += $(CPPDEFS)
  136. CPPFLAGS += -O$(OPT)
  137. CPPFLAGS += -funsigned-char
  138. CPPFLAGS += -funsigned-bitfields
  139. CPPFLAGS += -fpack-struct
  140. CPPFLAGS += -fshort-enums
  141. CPPFLAGS += -fno-exceptions
  142. CPPFLAGS += -ffunction-sections
  143. CPPFLAGS += -fdata-sections
  144. # to supress "warning: only initialized variables can be placed into program memory area"
  145. CPPFLAGS += -w
  146. CPPFLAGS += -Wall
  147. CPPFLAGS += -Wundef
  148. #CPPFLAGS += -mshort-calls
  149. #CPPFLAGS += -fno-unit-at-a-time
  150. #CPPFLAGS += -Wstrict-prototypes
  151. #CPPFLAGS += -Wunreachable-code
  152. #CPPFLAGS += -Wsign-compare
  153. CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  154. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  155. #CPPFLAGS += $(CSTANDARD)
  156. ifdef CONFIG_H
  157. CPPFLAGS += -include $(CONFIG_H)
  158. endif
  159. ifdef CONFIG_USER_H
  160. CPPFLAGS += -include $(CONFIG_USER_H)
  161. endif
  162. #---------------- Assembler Options ----------------
  163. # -Wa,...: tell GCC to pass this to the assembler.
  164. # -adhlns: create listing
  165. # -gstabs: have the assembler create line number information; note that
  166. # for use in COFF files, additional information about filenames
  167. # and function names needs to be present in the assembler source
  168. # files -- see avr-libc docs [FIXME: not yet described there]
  169. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  170. # dump that will be displayed for a given single line of source input.
  171. ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
  172. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  173. ifdef CONFIG_H
  174. ASFLAGS += -include $(CONFIG_H)
  175. endif
  176. ifdef CONFIG_USER_H
  177. ASFLAGS += -include $(CONFIG_USER_H)
  178. endif
  179. #---------------- Library Options ----------------
  180. # Minimalistic printf version
  181. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  182. # Floating point printf version (requires MATH_LIB = -lm below)
  183. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  184. # If this is left blank, then it will use the Standard printf version.
  185. PRINTF_LIB =
  186. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  187. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  188. # Minimalistic scanf version
  189. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  190. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  191. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  192. # If this is left blank, then it will use the Standard scanf version.
  193. SCANF_LIB =
  194. #SCANF_LIB = $(SCANF_LIB_MIN)
  195. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  196. MATH_LIB = -lm
  197. # List any extra directories to look for libraries here.
  198. # Each directory must be seperated by a space.
  199. # Use forward slashes for directory separators.
  200. # For a directory that has spaces, enclose it in quotes.
  201. EXTRALIBDIRS =
  202. #---------------- External Memory Options ----------------
  203. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  204. # used for variables (.data/.bss) and heap (malloc()).
  205. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  206. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  207. # only used for heap (malloc()).
  208. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  209. EXTMEMOPTS =
  210. #---------------- Linker Options ----------------
  211. # -Wl,...: tell GCC to pass this to linker.
  212. # -Map: create map file
  213. # --cref: add cross reference to map file
  214. #
  215. # Comennt out "--relax" option to avoid a error such:
  216. # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
  217. #
  218. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  219. #LDFLAGS += -Wl,--relax
  220. LDFLAGS += -Wl,--gc-sections
  221. LDFLAGS += $(EXTMEMOPTS)
  222. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  223. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  224. #LDFLAGS += -T linker_script.x
  225. # You can give EXTRALDFLAGS at 'make' command line.
  226. LDFLAGS += $(EXTRALDFLAGS)
  227. #---------------- Debugging Options ----------------
  228. # For simulavr only - target MCU frequency.
  229. DEBUG_MFREQ = $(F_CPU)
  230. # Set the DEBUG_UI to either gdb or insight.
  231. # DEBUG_UI = gdb
  232. DEBUG_UI = insight
  233. # Set the debugging back-end to either avarice, simulavr.
  234. DEBUG_BACKEND = avarice
  235. #DEBUG_BACKEND = simulavr
  236. # GDB Init Filename.
  237. GDBINIT_FILE = __avr_gdbinit
  238. # When using avarice settings for the JTAG
  239. JTAG_DEV = /dev/com1
  240. # Debugging port used to communicate between GDB / avarice / simulavr.
  241. DEBUG_PORT = 4242
  242. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  243. # just set to localhost unless doing some sort of crazy debugging when
  244. # avarice is running on a different computer.
  245. DEBUG_HOST = localhost
  246. #============================================================================
  247. # Define programs and commands.
  248. SHELL = sh
  249. CC = avr-gcc
  250. OBJCOPY = avr-objcopy
  251. OBJDUMP = avr-objdump
  252. SIZE = avr-size
  253. AR = avr-ar rcs
  254. NM = avr-nm
  255. REMOVE = rm -f
  256. REMOVEDIR = rmdir
  257. COPY = cp
  258. WINSHELL = cmd
  259. # Autodecct teensy loader
  260. ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
  261. TEENSY_LOADER_CLI = teensy-loader-cli
  262. else
  263. TEENSY_LOADER_CLI = teensy_loader_cli
  264. endif
  265. # Define Messages
  266. # English
  267. MSG_ERRORS_NONE = Errors: none
  268. MSG_BEGIN = -------- begin --------
  269. MSG_END = -------- end --------
  270. MSG_SIZE_BEFORE = Size before:
  271. MSG_SIZE_AFTER = Size after:
  272. MSG_COFF = Converting to AVR COFF:
  273. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  274. MSG_FLASH = Creating load file for Flash:
  275. MSG_EEPROM = Creating load file for EEPROM:
  276. MSG_EXTENDED_LISTING = Creating Extended Listing:
  277. MSG_SYMBOL_TABLE = Creating Symbol Table:
  278. MSG_LINKING = Linking:
  279. MSG_COMPILING = Compiling C:
  280. MSG_COMPILING_CPP = Compiling C++:
  281. MSG_ASSEMBLING = Assembling:
  282. MSG_CLEANING = Cleaning project:
  283. MSG_CREATING_LIBRARY = Creating library:
  284. # Define all object files.
  285. OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
  286. # Define all listing files.
  287. LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
  288. # Compiler flags to generate dependency files.
  289. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  290. GENDEPFLAGS = -MMD -MP -MF .dep/$(subst /,_,$@).d
  291. # Combine all necessary flags and optional flags.
  292. # Add target processor to flags.
  293. # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
  294. ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  295. ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  296. ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
  297. # Default target.
  298. all:
  299. $(MAKE) begin
  300. $(MAKE) gccversion
  301. $(MAKE) sizebefore
  302. $(MAKE) build
  303. $(MAKE) sizeafter
  304. $(MAKE) end
  305. # Change the build target to build a HEX file or a library.
  306. build: elf hex eep lss sym
  307. #build: lib
  308. elf: $(TARGET).elf
  309. hex: $(TARGET).hex
  310. eep: $(TARGET).eep
  311. lss: $(TARGET).lss
  312. sym: $(TARGET).sym
  313. LIBNAME=lib$(TARGET).a
  314. lib: $(LIBNAME)
  315. # Eye candy.
  316. # AVR Studio 3.x does not check make's exit code but relies on
  317. # the following magic strings to be generated by the compile job.
  318. begin:
  319. @echo $(MSG_BEGIN)
  320. end:
  321. @echo $(MSG_END)
  322. # Display size of file.
  323. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  324. #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  325. ELFSIZE = $(SIZE) $(TARGET).elf
  326. sizebefore:
  327. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
  328. 2>/dev/null; echo; fi
  329. sizeafter:
  330. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
  331. 2>/dev/null; echo; fi
  332. # Display compiler version information.
  333. gccversion :
  334. @$(CC) --version
  335. # Program the device.
  336. program: $(TARGET).hex $(TARGET).eep
  337. $(PROGRAM_CMD)
  338. teensy: $(TARGET).hex
  339. $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(TARGET).hex
  340. flip: $(TARGET).hex
  341. batchisp -hardware usb -device $(MCU) -operation erase f
  342. batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
  343. batchisp -hardware usb -device $(MCU) -operation start reset 0
  344. dfu: $(TARGET).hex sizeafter
  345. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  346. dfu-programmer $(MCU) erase --force
  347. else
  348. dfu-programmer $(MCU) erase
  349. endif
  350. dfu-programmer $(MCU) erase
  351. dfu-programmer $(MCU) flash $(TARGET).hex
  352. dfu-programmer $(MCU) reset
  353. dfu-start:
  354. dfu-programmer $(MCU) reset
  355. dfu-programmer $(MCU) start
  356. flip-ee: $(TARGET).hex $(TARGET).eep
  357. $(COPY) $(TARGET).eep $(TARGET)eep.hex
  358. batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
  359. batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
  360. batchisp -hardware usb -device $(MCU) -operation start reset 0
  361. $(REMOVE) $(TARGET)eep.hex
  362. dfu-ee: $(TARGET).hex $(TARGET).eep
  363. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  364. dfu-programmer $(MCU) flash --eeprom $(TARGET).eep
  365. else
  366. dfu-programmer $(MCU) flash-eeprom $(TARGET).eep
  367. endif
  368. dfu-programmer $(MCU) reset
  369. # Generate avr-gdb config/init file which does the following:
  370. # define the reset signal, load the target file, connect to target, and set
  371. # a breakpoint at main().
  372. gdb-config:
  373. @$(REMOVE) $(GDBINIT_FILE)
  374. @echo define reset >> $(GDBINIT_FILE)
  375. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  376. @echo end >> $(GDBINIT_FILE)
  377. @echo file $(TARGET).elf >> $(GDBINIT_FILE)
  378. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  379. ifeq ($(DEBUG_BACKEND),simulavr)
  380. @echo load >> $(GDBINIT_FILE)
  381. endif
  382. @echo break main >> $(GDBINIT_FILE)
  383. debug: gdb-config $(TARGET).elf
  384. ifeq ($(DEBUG_BACKEND), avarice)
  385. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  386. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  387. $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  388. @$(WINSHELL) /c pause
  389. else
  390. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  391. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  392. endif
  393. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  394. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  395. COFFCONVERT = $(OBJCOPY) --debugging
  396. COFFCONVERT += --change-section-address .data-0x800000
  397. COFFCONVERT += --change-section-address .bss-0x800000
  398. COFFCONVERT += --change-section-address .noinit-0x800000
  399. COFFCONVERT += --change-section-address .eeprom-0x810000
  400. coff: $(TARGET).elf
  401. @echo $(MSG_COFF) $(TARGET).cof
  402. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  403. extcoff: $(TARGET).elf
  404. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  405. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  406. # Create final output files (.hex, .eep) from ELF output file.
  407. %.hex: %.elf
  408. @echo $(MSG_FLASH) $@
  409. $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
  410. %.eep: %.elf
  411. @echo $(MSG_EEPROM) $@
  412. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  413. --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
  414. # Create extended listing file from ELF output file.
  415. %.lss: %.elf
  416. @echo $(MSG_EXTENDED_LISTING) $@
  417. $(OBJDUMP) -h -S -z $< > $@
  418. # Create a symbol table from ELF output file.
  419. %.sym: %.elf
  420. @echo $(MSG_SYMBOL_TABLE) $@
  421. $(NM) -n $< > $@
  422. # Create library from object files.
  423. .SECONDARY : $(TARGET).a
  424. .PRECIOUS : $(OBJ)
  425. %.a: $(OBJ)
  426. @echo $(MSG_CREATING_LIBRARY) $@
  427. $(AR) $@ $(OBJ)
  428. # Link: create ELF output file from object files.
  429. .SECONDARY : $(TARGET).elf
  430. .PRECIOUS : $(OBJ)
  431. %.elf: $(OBJ)
  432. @echo $(MSG_LINKING) $@
  433. $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  434. # Compile: create object files from C source files.
  435. $(OBJDIR)/%.o : %.c
  436. mkdir -p $(@D)
  437. @echo $(MSG_COMPILING) $<
  438. $(CC) -c $(ALL_CFLAGS) $< -o $@
  439. # Compile: create object files from C++ source files.
  440. $(OBJDIR)/%.o : %.cpp
  441. mkdir -p $(@D)
  442. @echo $(MSG_COMPILING_CPP) $<
  443. $(CC) -c $(ALL_CPPFLAGS) $< -o $@
  444. # Compile: create assembler files from C source files.
  445. %.s : %.c
  446. $(CC) -S $(ALL_CFLAGS) $< -o $@
  447. # Compile: create assembler files from C++ source files.
  448. %.s : %.cpp
  449. $(CC) -S $(ALL_CPPFLAGS) $< -o $@
  450. # Assemble: create object files from assembler source files.
  451. $(OBJDIR)/%.o : %.S
  452. mkdir -p $(@D)
  453. @echo $(MSG_ASSEMBLING) $<
  454. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  455. # Create preprocessed source for use in sending a bug report.
  456. %.i : %.c
  457. $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
  458. # Target: clean project.
  459. clean: begin clean_list end
  460. clean_list :
  461. $(REMOVE) $(TARGET).hex
  462. $(REMOVE) $(TARGET).eep
  463. $(REMOVE) $(TARGET).cof
  464. $(REMOVE) $(TARGET).elf
  465. $(REMOVE) $(TARGET).map
  466. $(REMOVE) $(TARGET).sym
  467. $(REMOVE) $(TARGET).lss
  468. $(REMOVE) $(OBJ)
  469. $(REMOVE) $(LST)
  470. $(REMOVE) $(OBJ:.o=.s)
  471. $(REMOVE) $(OBJ:.o=.i)
  472. $(REMOVE) -r .dep
  473. $(REMOVE) -r $(OBJDIR)
  474. show_path:
  475. @echo VPATH=$(VPATH)
  476. @echo SRC=$(SRC)
  477. # Create object files directory
  478. $(shell mkdir $(OBJDIR) 2>/dev/null)
  479. # Include the dependency files.
  480. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  481. # Listing of phony targets.
  482. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  483. build elf hex eep lss sym coff extcoff \
  484. clean clean_list debug gdb-config show_path \
  485. program teensy dfu flip dfu-ee flip-ee dfu-start