rules.mk 21 KB

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