rules.mk 22 KB

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