rules.mk 21 KB

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