Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rules.mk 16KB

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