rules.mk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. BUILD_DIR = .build
  59. # Object files directory
  60. # To put object files in current directory, use a dot (.), do NOT make
  61. # this an empty or blank macro!
  62. OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
  63. # Optimization level, can be [0, 1, 2, 3, s].
  64. # 0 = turn off optimization. s = optimize for size.
  65. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  66. OPT = s
  67. # Debugging format.
  68. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  69. # AVR Studio 4.10 requires dwarf-2.
  70. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  71. DEBUG = dwarf-2
  72. COLOR?=true
  73. ifeq ($(COLOR),true)
  74. NO_COLOR=\033[0m
  75. OK_COLOR=\033[32;01m
  76. ERROR_COLOR=\033[31;01m
  77. WARN_COLOR=\033[33;01m
  78. BLUE=\033[0;34m
  79. BOLD=\033[1m
  80. endif
  81. ifneq ($(shell awk --version 2>/dev/null),)
  82. AWK=awk
  83. else
  84. AWK=cat && test
  85. endif
  86. OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
  87. ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
  88. WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
  89. ifndef $(SILENT)
  90. SILENT = false
  91. endif
  92. TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
  93. TAB_LOG_PLAIN = printf "$$LOG\n"
  94. AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
  95. AWK_CMD = $(AWK) '{ printf "%-69s", $$0; }'
  96. PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && false
  97. PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
  98. PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && false
  99. PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
  100. PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
  101. BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
  102. # List any extra directories to look for include files here.
  103. # Each directory must be seperated by a space.
  104. # Use forward slashes for directory separators.
  105. # For a directory that has spaces, enclose it in quotes.
  106. EXTRAINCDIRS = $(subst :, ,$(VPATH))
  107. # Compiler flag to set the C Standard level.
  108. # c89 = "ANSI" C
  109. # gnu89 = c89 plus GCC extensions
  110. # c99 = ISO C99 standard (not yet fully implemented)
  111. # gnu99 = c99 plus GCC extensions
  112. CSTANDARD = -std=gnu99
  113. # Place -D or -U options here for C sources
  114. CDEFS = -DF_CPU=$(F_CPU)UL
  115. CDEFS += $(OPT_DEFS)
  116. # Place -D or -U options here for ASM sources
  117. ADEFS = -DF_CPU=$(F_CPU)
  118. ADEFS += $(OPT_DEFS)
  119. # Place -D or -U options here for C++ sources
  120. CPPDEFS = -DF_CPU=$(F_CPU)UL
  121. #CPPDEFS += -D__STDC_LIMIT_MACROS
  122. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  123. CPPDEFS += $(OPT_DEFS)
  124. #---------------- Compiler Options C ----------------
  125. # -g*: generate debugging information
  126. # -O*: optimization level
  127. # -f...: tuning, see GCC manual and avr-libc documentation
  128. # -Wall...: warning level
  129. # -Wa,...: tell GCC to pass this to the assembler.
  130. # -adhlns...: create assembler listing
  131. CFLAGS = -g$(DEBUG)
  132. CFLAGS += $(CDEFS)
  133. CFLAGS += -O$(OPT)
  134. CFLAGS += -funsigned-char
  135. CFLAGS += -funsigned-bitfields
  136. CFLAGS += -ffunction-sections
  137. CFLAGS += -fdata-sections
  138. CFLAGS += -fno-inline-small-functions
  139. CFLAGS += -fpack-struct
  140. CFLAGS += -fshort-enums
  141. CFLAGS += -fno-strict-aliasing
  142. # add color
  143. ifeq ($(COLOR),true)
  144. ifeq ("$(echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
  145. CFLAGS+= -fdiagnostics-color
  146. else ifeq ("$(echo "int main(){}" | $(CC) -fcolor-diagnostics -x c - -o /dev/null 2>&1)", "")
  147. CFLAGS+= -fcolor-diagnostics
  148. endif
  149. endif
  150. CFLAGS += -Wall
  151. CFLAGS += -Wstrict-prototypes
  152. #CFLAGS += -mshort-calls
  153. #CFLAGS += -fno-unit-at-a-time
  154. #CFLAGS += -Wundef
  155. #CFLAGS += -Wunreachable-code
  156. #CFLAGS += -Wsign-compare
  157. CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  158. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  159. CFLAGS += $(CSTANDARD)
  160. ifdef CONFIG_H
  161. CFLAGS += -include $(CONFIG_H)
  162. endif
  163. #---------------- Compiler Options C++ ----------------
  164. # -g*: generate debugging information
  165. # -O*: optimization level
  166. # -f...: tuning, see GCC manual and avr-libc documentation
  167. # -Wall...: warning level
  168. # -Wa,...: tell GCC to pass this to the assembler.
  169. # -adhlns...: create assembler listing
  170. CPPFLAGS = -g$(DEBUG)
  171. CPPFLAGS += $(CPPDEFS)
  172. CPPFLAGS += -O$(OPT)
  173. CPPFLAGS += -funsigned-char
  174. CPPFLAGS += -funsigned-bitfields
  175. CPPFLAGS += -fpack-struct
  176. CPPFLAGS += -fshort-enums
  177. CPPFLAGS += -fno-exceptions
  178. CPPFLAGS += -ffunction-sections
  179. CPPFLAGS += -fdata-sections
  180. # to supress "warning: only initialized variables can be placed into program memory area"
  181. CPPFLAGS += -w
  182. CPPFLAGS += -Wall
  183. CPPFLAGS += -Wundef
  184. #CPPFLAGS += -mshort-calls
  185. #CPPFLAGS += -fno-unit-at-a-time
  186. #CPPFLAGS += -Wstrict-prototypes
  187. #CPPFLAGS += -Wunreachable-code
  188. #CPPFLAGS += -Wsign-compare
  189. CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  190. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  191. #CPPFLAGS += $(CSTANDARD)
  192. ifdef CONFIG_H
  193. CPPFLAGS += -include $(CONFIG_H)
  194. endif
  195. #---------------- Assembler Options ----------------
  196. # -Wa,...: tell GCC to pass this to the assembler.
  197. # -adhlns: create listing
  198. # -gstabs: have the assembler create line number information; note that
  199. # for use in COFF files, additional information about filenames
  200. # and function names needs to be present in the assembler source
  201. # files -- see avr-libc docs [FIXME: not yet described there]
  202. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  203. # dump that will be displayed for a given single line of source input.
  204. ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
  205. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  206. ifdef CONFIG_H
  207. ASFLAGS += -include $(CONFIG_H)
  208. endif
  209. #---------------- Library Options ----------------
  210. # Minimalistic printf version
  211. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  212. # Floating point printf version (requires MATH_LIB = -lm below)
  213. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  214. # If this is left blank, then it will use the Standard printf version.
  215. PRINTF_LIB =
  216. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  217. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  218. # Minimalistic scanf version
  219. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  220. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  221. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  222. # If this is left blank, then it will use the Standard scanf version.
  223. SCANF_LIB =
  224. #SCANF_LIB = $(SCANF_LIB_MIN)
  225. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  226. MATH_LIB = -lm
  227. # List any extra directories to look for libraries here.
  228. # Each directory must be seperated by a space.
  229. # Use forward slashes for directory separators.
  230. # For a directory that has spaces, enclose it in quotes.
  231. EXTRALIBDIRS =
  232. #---------------- External Memory Options ----------------
  233. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  234. # used for variables (.data/.bss) and heap (malloc()).
  235. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  236. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  237. # only used for heap (malloc()).
  238. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  239. EXTMEMOPTS =
  240. #---------------- Linker Options ----------------
  241. # -Wl,...: tell GCC to pass this to linker.
  242. # -Map: create map file
  243. # --cref: add cross reference to map file
  244. #
  245. # Comennt out "--relax" option to avoid a error such:
  246. # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
  247. #
  248. LDFLAGS = -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
  249. #LDFLAGS += -Wl,--relax
  250. LDFLAGS += -Wl,--gc-sections
  251. LDFLAGS += $(EXTMEMOPTS)
  252. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  253. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  254. #LDFLAGS += -T linker_script.x
  255. # You can give EXTRALDFLAGS at 'make' command line.
  256. LDFLAGS += $(EXTRALDFLAGS)
  257. #---------------- Debugging Options ----------------
  258. # For simulavr only - target MCU frequency.
  259. DEBUG_MFREQ = $(F_CPU)
  260. # Set the DEBUG_UI to either gdb or insight.
  261. # DEBUG_UI = gdb
  262. DEBUG_UI = insight
  263. # Set the debugging back-end to either avarice, simulavr.
  264. DEBUG_BACKEND = avarice
  265. #DEBUG_BACKEND = simulavr
  266. # GDB Init Filename.
  267. GDBINIT_FILE = __avr_gdbinit
  268. # When using avarice settings for the JTAG
  269. JTAG_DEV = /dev/com1
  270. # Debugging port used to communicate between GDB / avarice / simulavr.
  271. DEBUG_PORT = 4242
  272. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  273. # just set to localhost unless doing some sort of crazy debugging when
  274. # avarice is running on a different computer.
  275. DEBUG_HOST = localhost
  276. #============================================================================
  277. # Define programs and commands.
  278. SHELL = sh
  279. CC = avr-gcc
  280. OBJCOPY = avr-objcopy
  281. OBJDUMP = avr-objdump
  282. SIZE = avr-size
  283. AR = avr-ar rcs
  284. NM = avr-nm
  285. REMOVE = rm -f
  286. REMOVEDIR = rmdir
  287. COPY = cp
  288. WINSHELL = cmd
  289. SECHO = $(SILENT) || echo
  290. # Autodecct teensy loader
  291. ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
  292. TEENSY_LOADER_CLI = teensy-loader-cli
  293. else
  294. TEENSY_LOADER_CLI = teensy_loader_cli
  295. endif
  296. # Define Messages
  297. # English
  298. MSG_ERRORS_NONE = Errors: none
  299. MSG_BEGIN = -------- begin --------
  300. MSG_END = -------- end --------
  301. MSG_SIZE_BEFORE = Size before:
  302. MSG_SIZE_AFTER = Size after:
  303. MSG_COFF = Converting to AVR COFF:
  304. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  305. MSG_FLASH = Creating load file for Flash:
  306. MSG_EEPROM = Creating load file for EEPROM:
  307. MSG_EXTENDED_LISTING = Creating Extended Listing:
  308. MSG_SYMBOL_TABLE = Creating Symbol Table:
  309. MSG_LINKING = Linking:
  310. MSG_COMPILING = Compiling:
  311. MSG_COMPILING_CPP = Compiling:
  312. MSG_ASSEMBLING = Assembling:
  313. MSG_CLEANING = Cleaning project:
  314. MSG_CREATING_LIBRARY = Creating library:
  315. # Define all object files.
  316. OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
  317. # Define all listing files.
  318. LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
  319. # Compiler flags to generate dependency files.
  320. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  321. GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d
  322. # Combine all necessary flags and optional flags.
  323. # Add target processor to flags.
  324. # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
  325. ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  326. ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  327. ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
  328. # Default target.
  329. all:
  330. @$(MAKE) begin
  331. @$(MAKE) gccversion
  332. @$(MAKE) sizebefore
  333. @$(MAKE) clean_list # force clean each time
  334. @$(MAKE) build
  335. @$(MAKE) sizeafter
  336. @$(MAKE) end
  337. # Quick make that doesn't clean
  338. quick:
  339. @$(MAKE) begin
  340. @$(MAKE) gccversion
  341. @$(MAKE) sizebefore
  342. @$(MAKE) build
  343. @$(MAKE) sizeafter
  344. @$(MAKE) end
  345. # Change the build target to build a HEX file or a library.
  346. build: elf hex
  347. #build: elf hex eep lss sym
  348. #build: lib
  349. elf: $(BUILD_DIR)/$(TARGET).elf
  350. hex: $(BUILD_DIR)/$(TARGET).hex
  351. eep: $(BUILD_DIR)/$(TARGET).eep
  352. lss: $(BUILD_DIR)/$(TARGET).lss
  353. sym: $(BUILD_DIR)/$(TARGET).sym
  354. LIBNAME=lib$(TARGET).a
  355. lib: $(LIBNAME)
  356. # Eye candy.
  357. # AVR Studio 3.x does not check make's exit code but relies on
  358. # the following magic strings to be generated by the compile job.
  359. begin:
  360. @$(SECHO) $(MSG_BEGIN)
  361. end:
  362. @$(SECHO) $(MSG_END)
  363. # Display size of file.
  364. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  365. #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  366. ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
  367. sizebefore:
  368. @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
  369. 2>/dev/null; $(SECHO); fi
  370. sizeafter:
  371. @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
  372. 2>/dev/null; $(SECHO); fi
  373. # test file sizes eventually
  374. # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
  375. # Display compiler version information.
  376. gccversion :
  377. @$(SILENT) || $(CC) --version
  378. # Program the device.
  379. program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  380. $(PROGRAM_CMD)
  381. teensy: $(BUILD_DIR)/$(TARGET).hex
  382. $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
  383. flip: $(BUILD_DIR)/$(TARGET).hex
  384. batchisp -hardware usb -device $(MCU) -operation erase f
  385. batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
  386. batchisp -hardware usb -device $(MCU) -operation start reset 0
  387. dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
  388. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  389. dfu-programmer $(MCU) erase --force
  390. else
  391. dfu-programmer $(MCU) erase
  392. endif
  393. dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
  394. dfu-programmer $(MCU) reset
  395. dfu-no-build:
  396. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  397. dfu-programmer $(MCU) erase --force
  398. else
  399. dfu-programmer $(MCU) erase
  400. endif
  401. dfu-programmer $(MCU) flash $(KEYMAP_PATH)/compiled.hex
  402. dfu-programmer $(MCU) reset
  403. dfu-start:
  404. dfu-programmer $(MCU) reset
  405. dfu-programmer $(MCU) start
  406. flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  407. $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
  408. batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
  409. batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
  410. batchisp -hardware usb -device $(MCU) -operation start reset 0
  411. $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
  412. dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  413. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  414. dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
  415. else
  416. dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
  417. endif
  418. dfu-programmer $(MCU) reset
  419. # Generate avr-gdb config/init file which does the following:
  420. # define the reset signal, load the target file, connect to target, and set
  421. # a breakpoint at main().
  422. gdb-config:
  423. @$(REMOVE) $(GDBINIT_FILE)
  424. @echo define reset >> $(GDBINIT_FILE)
  425. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  426. @echo end >> $(GDBINIT_FILE)
  427. @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
  428. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  429. ifeq ($(DEBUG_BACKEND),simulavr)
  430. @echo load >> $(GDBINIT_FILE)
  431. endif
  432. @echo break main >> $(GDBINIT_FILE)
  433. debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
  434. ifeq ($(DEBUG_BACKEND), avarice)
  435. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  436. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  437. $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  438. @$(WINSHELL) /c pause
  439. else
  440. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  441. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  442. endif
  443. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  444. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  445. COFFCONVERT = $(OBJCOPY) --debugging
  446. COFFCONVERT += --change-section-address .data-0x800000
  447. COFFCONVERT += --change-section-address .bss-0x800000
  448. COFFCONVERT += --change-section-address .noinit-0x800000
  449. COFFCONVERT += --change-section-address .eeprom-0x810000
  450. coff: $(BUILD_DIR)/$(TARGET).elf
  451. @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
  452. $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
  453. extcoff: $(BUILD_DIR)/$(TARGET).elf
  454. @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
  455. $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
  456. # Create final output files (.hex, .eep) from ELF output file.
  457. %.hex: %.elf
  458. @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
  459. $(eval CMD=$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@)
  460. @$(BUILD_CMD)
  461. @$(COPY) $@ $(TARGET).hex
  462. $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/compiled.hex" | $(AWK_CMD)
  463. $(eval CMD=$(COPY) $@ $(KEYMAP_PATH)/compiled.hex)
  464. @$(BUILD_CMD)
  465. %.eep: %.elf
  466. @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
  467. $(eval CMD=$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0)
  468. @$(BUILD_CMD)
  469. # Create extended listing file from ELF output file.
  470. %.lss: %.elf
  471. @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
  472. $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
  473. @$(BUILD_CMD)
  474. # Create a symbol table from ELF output file.
  475. %.sym: %.elf
  476. @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
  477. $(eval CMD=$(NM) -n $< > $@ )
  478. @$(BUILD_CMD)
  479. # Create library from object files.
  480. .SECONDARY : $(BUILD_DIR)/$(TARGET).a
  481. .PRECIOUS : $(OBJ)
  482. %.a: $(OBJ)
  483. @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
  484. $(eval CMD=$(AR) $@ $(OBJ) )
  485. @$(BUILD_CMD)
  486. # Link: create ELF output file from object files.
  487. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
  488. .PRECIOUS : $(OBJ)
  489. %.elf: $(OBJ)
  490. @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
  491. $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS))
  492. @$(BUILD_CMD)
  493. # Compile: create object files from C source files.
  494. $(OBJDIR)/%.o : %.c
  495. @mkdir -p $(@D)
  496. @$(SILENT) || printf "$(MSG_COMPILING) $<" | $(AWK_CMD)
  497. $(eval CMD=$(CC) -c $(ALL_CFLAGS) $< -o $@)
  498. @$(BUILD_CMD)
  499. # Compile: create object files from C++ source files.
  500. $(OBJDIR)/%.o : %.cpp
  501. @mkdir -p $(@D)
  502. @$(SILENT) || printf "$(MSG_COMPILING_CPP) $<" | $(AWK_CMD)
  503. $(CC) -c $(ALL_CPPFLAGS) $< -o $@
  504. @$(BUILD_CMD)
  505. # Compile: create assembler files from C source files.
  506. %.s : %.c
  507. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  508. $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
  509. @$(BUILD_CMD)
  510. # Compile: create assembler files from C++ source files.
  511. %.s : %.cpp
  512. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  513. $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
  514. @$(BUILD_CMD)
  515. # Assemble: create object files from assembler source files.
  516. $(OBJDIR)/%.o : %.S
  517. @mkdir -p $(@D)
  518. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  519. $(eval CMD=$(CC) -c $(ALL_ASFLAGS) $< -o $@)
  520. @$(BUILD_CMD)
  521. # Create preprocessed source for use in sending a bug report.
  522. %.i : %.c
  523. $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
  524. # Target: clean project.
  525. clean: begin clean_list end
  526. clean_list :
  527. $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR)
  528. $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR)
  529. $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR)
  530. show_path:
  531. @echo VPATH=$(VPATH)
  532. @echo SRC=$(SRC)
  533. SUBDIRS := $(sort $(dir $(wildcard $(TOP_DIR)/keyboard/*/.)))
  534. all-keyboards-defaults:
  535. @for x in $(SUBDIRS) ; do \
  536. printf "Compiling with default: $$x" | $(AWK_CMD); \
  537. LOG=$$($(MAKE) -C $$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  538. done
  539. KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboard/%/=/keyboard/%)
  540. all-keyboards: $(KEYBOARDS)
  541. /keyboard/%:
  542. $(eval KEYBOARD=$(patsubst /keyboard/%,%,$@))
  543. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)$@/keymaps/*/.))))
  544. @for x in $(KEYMAPS) ; do \
  545. printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-88s", $$0; }'; \
  546. LOG=$$($(MAKE) -C $(TOP_DIR)$@ keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  547. done
  548. all-keymaps:
  549. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboard/$(KEYBOARD)/keymaps/*/.))))
  550. @for x in $(KEYMAPS) ; do \
  551. printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-88s", $$0; }'; \
  552. LOG=$$($(MAKE) keyboard=$(KEYBOARD) keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  553. done
  554. # Create build directory
  555. $(shell mkdir $(BUILD_DIR) 2>/dev/null)
  556. # Create object files directory
  557. $(shell mkdir $(OBJDIR) 2>/dev/null)
  558. # Include the dependency files.
  559. -include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
  560. # Listing of phony targets.
  561. .PHONY : all quick begin finish end sizebefore sizeafter gccversion \
  562. build elf hex eep lss sym coff extcoff \
  563. clean clean_list debug gdb-config show_path \
  564. program teensy dfu flip dfu-ee flip-ee dfu-start \
  565. all-keyboards-defaults all-keyboards all-keymaps