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.

481 lines
13 KiB

  1. # Hey Emacs, this is a -*- makefile -*-
  2. #
  3. # WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
  4. # Released to the Public Domain
  5. # Please read the make user manual!
  6. #
  7. # Additional material for this makefile was submitted by:
  8. # Tim Henigan
  9. # Peter Fleury
  10. # Reiner Patommel
  11. # Sander Pool
  12. # Frederik Rouleau
  13. # Markus Pfaff
  14. #
  15. # On command line:
  16. #
  17. # make all = Make software.
  18. #
  19. # make clean = Clean out built project files.
  20. #
  21. # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
  22. #
  23. # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  24. # 4.07 or greater).
  25. #
  26. # make program = Download the hex file to the device, using avrdude. Please
  27. # customize the avrdude settings below first!
  28. #
  29. # make filename.s = Just compile filename.c into the assembler code only
  30. #
  31. # To rebuild project do "make clean" then "make all".
  32. #
  33. # mth 2004/09
  34. # Differences from WinAVR 20040720 sample:
  35. # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
  36. # - F_OSC Define in CFLAGS and AFLAGS
  37. # MCU name
  38. MCU = attiny817
  39. # Main Oscillator Frequency
  40. # This is only used to define F_OSC in all assembler and c-sources.
  41. F_CPU = 20000000
  42. # Output format. (can be srec, ihex, binary)
  43. FORMAT = ihex
  44. # Target file name (without extension).
  45. TARGET = main
  46. # List C source files here. (C dependencies are automatically generated.)
  47. SRC = $(TARGET).c
  48. # List Assembler source files here.
  49. # Make them always end in a capital .S. Files ending in a lowercase .s
  50. # will not be considered source files but generated files (assembler
  51. # output from the compiler), and will be deleted upon "make clean"!
  52. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  53. # it will preserve the spelling of the filenames, and gcc itself does
  54. # care about how the name is spelled on its command-line.
  55. ASRC =
  56. # Optimization level, can be [0, 1, 2, 3, s].
  57. # 0 = turn off optimization. s = optimize for size.
  58. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  59. OPT = s
  60. # Debugging format.
  61. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  62. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  63. #DEBUG = stabs
  64. DEBUG = dwarf-2
  65. # List any extra directories to look for include files here.
  66. # Each directory must be seperated by a space.
  67. EXTRAINCDIRS =
  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
  75. CDEFS =
  76. # Place -I options here
  77. CINCS =
  78. # Compiler flags.
  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) $(CINCS)
  87. CFLAGS += -O$(OPT)
  88. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  89. CFLAGS += -Wall -Wstrict-prototypes
  90. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  91. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  92. CFLAGS += $(CSTANDARD)
  93. CFLAGS += -DF_CPU=$(F_CPU)
  94. #CFLAGS += -B /home/bucde/__avr_gcc/ATtiny_DFP/1.3.172/gcc/dev/attiny817/
  95. #CFLAGS += -I /home/bucde/__avr_gcc/ATtiny_DFP/1.3.172/include/
  96. # Assembler flags.
  97. # -Wa,...: tell GCC to pass this to the assembler.
  98. # -ahlms: create listing
  99. # -gstabs: have the assembler create line number information; note that
  100. # for use in COFF files, additional information about filenames
  101. # and function names needs to be present in the assembler source
  102. # files -- see avr-libc docs [FIXME: not yet described there]
  103. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  104. ASFLAGS += -DF_OSC=$(F_OSC)
  105. #Additional libraries.
  106. # Minimalistic printf version
  107. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  108. # Floating point printf version (requires MATH_LIB = -lm below)
  109. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  110. PRINTF_LIB =
  111. # Minimalistic scanf version
  112. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  113. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  114. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  115. SCANF_LIB =
  116. MATH_LIB = -lm
  117. # External memory options
  118. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  119. # used for variables (.data/.bss) and heap (malloc()).
  120. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  121. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  122. # only used for heap (malloc()).
  123. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  124. EXTMEMOPTS =
  125. # Linker flags.
  126. # -Wl,...: tell GCC to pass this to linker.
  127. # -Map: create map file
  128. # --cref: add cross reference to map file
  129. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  130. LDFLAGS += $(EXTMEMOPTS)
  131. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  132. LDFLAGS += -Ttext=0x0000
  133. # Programming support using avrdude. Settings and variables.
  134. # Programming hardware: alf avr910 avrisp bascom bsd
  135. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  136. #
  137. # Type: avrdude -c ?
  138. # to get a full listing.
  139. #
  140. AVRDUDE_PROGRAMMER = xplainedmini_updi
  141. # com1 = serial port. Use lpt1 to connect to parallel port.
  142. AVRDUDE_PORT = usb
  143. # programmer connected to serial device
  144. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  145. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  146. # Uncomment the following if you want avrdude's erase cycle counter.
  147. # Note that this counter needs to be initialized first using -Yn,
  148. # see avrdude manual.
  149. #AVRDUDE_ERASE_COUNTER = -y
  150. # Uncomment the following if you do /not/ wish a verification to be
  151. # performed after programming the device.
  152. #AVRDUDE_NO_VERIFY = -V
  153. # Increase verbosity level. Please use this when submitting bug
  154. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  155. # to submit bug reports.
  156. #AVRDUDE_VERBOSE = -v -v
  157. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  158. #AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  159. #AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  160. #AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  161. #read fuses
  162. #./avrdude -p atmega4808 -P usb -c xplainedmini_updi -U fuse0:r:fuse_wdtcfg:h -U fuse1:r:fuse_bodcfg:h -U fuse2:r:fuse_osccfg:h -U fuse5:r:fuse_syscfg0:h -U fuse6:r:fuse_syscfg1:h -U fuse7:r:fuse_append:h -U fuse8:r:fuse_bootend:h
  163. AVRDUDE_FUSE0_WDTCFG = 0x00
  164. AVRDUDE_FUSE1_BODCFG = 0x00
  165. AVRDUDE_FUSE2_OSCCFG = 0x02
  166. AVRDUDE_FUSE5_SYSCFG0 = 0b11101101
  167. #AVRDUDE_FUSE5_SYSCFG0[2] must be set to 1
  168. #AVRDUDE_FUSE5_SYSCFG0[5] must be set to 1
  169. AVRDUDE_FUSE6_SYSCFG1 = 0x00
  170. AVRDUDE_FUSE7_APPEND = 0x00
  171. AVRDUDE_FUSE8_BOOTEND = 0x00
  172. AVRDUDE_WRITE_FUSES = -U fuse0:w:$(AVRDUDE_FUSE0_WDTCFG):m
  173. AVRDUDE_WRITE_FUSES += -U fuse1:w:$(AVRDUDE_FUSE1_BODCFG):m
  174. AVRDUDE_WRITE_FUSES += -U fuse2:w:$(AVRDUDE_FUSE2_OSCCFG):m
  175. AVRDUDE_WRITE_FUSES += -U fuse5:w:$(AVRDUDE_FUSE5_SYSCFG0):m
  176. AVRDUDE_WRITE_FUSES += -U fuse6:w:$(AVRDUDE_FUSE6_SYSCFG1):m
  177. AVRDUDE_WRITE_FUSES += -U fuse7:w:$(AVRDUDE_FUSE7_APPEND):m
  178. AVRDUDE_WRITE_FUSES += -U fuse8:w:$(AVRDUDE_FUSE8_BOOTEND):m
  179. AVRDUDE_READ_FUSES = -U fuse0:r:fuse0_wdtcfg:h
  180. AVRDUDE_READ_FUSES += -U fuse1:r:fuse1_bodcfg:h
  181. AVRDUDE_READ_FUSES += -U fuse2:r:fuse2_osccfg:h
  182. AVRDUDE_READ_FUSES += -U fuse5:r:fuse5_syscfg0:h
  183. AVRDUDE_READ_FUSES += -U fuse6:r:fuse6_syscfg1:h
  184. AVRDUDE_READ_FUSES += -U fuse7:r:fuse7_append:h
  185. AVRDUDE_READ_FUSES += -U fuse8:r:fuse8_bootend:h
  186. # ---------------------------------------------------------------------------
  187. # Define directories, if needed.
  188. #DIRAVR = /home/bucde/local/avr
  189. DIRAVR = /home/bucde/documents/hobby/repos/avrgcc
  190. #DIRAVR = ${AVRGCC}
  191. DIRAVRBIN = $(DIRAVR)/bin
  192. #DIRAVRUTILS = $(DIRAVR)/utils/bin
  193. #DIRINC = .
  194. #DIRLIB = $(DIRAVR)/avr/lib
  195. # Define programs and commands.
  196. SHELL = sh
  197. CC = $(DIRAVRBIN)/avr-gcc
  198. OBJCOPY = $(DIRAVRBIN)/avr-objcopy
  199. OBJDUMP = $(DIRAVRBIN)/avr-objdump
  200. SIZE = $(DIRAVRBIN)/avr-size
  201. NM = $(DIRAVRBIN)/avr-nm
  202. AVRDUDE = $(DIRAVRBIN)/avrdude
  203. REMOVE = rm -f
  204. COPY = cp
  205. # Define Messages
  206. # English
  207. MSG_ERRORS_NONE = Errors: none
  208. MSG_INFO = -------- info --------
  209. MSG_BEGIN = -------- begin --------
  210. MSG_END = -------- end --------
  211. MSG_SIZE_BEFORE = Size before:
  212. MSG_SIZE_AFTER = Size after:
  213. MSG_COFF = Converting to AVR COFF:
  214. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  215. MSG_FLASH = Creating load file for Flash:
  216. MSG_EEPROM = Creating load file for EEPROM:
  217. MSG_EXTENDED_LISTING = Creating Extended Listing:
  218. MSG_SYMBOL_TABLE = Creating Symbol Table:
  219. MSG_LINKING = Linking:
  220. MSG_COMPILING = Compiling:
  221. MSG_ASSEMBLING = Assembling:
  222. MSG_CLEANING = Cleaning project:
  223. # Define all object files.
  224. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  225. # Define all listing files.
  226. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  227. # Compiler flags to generate dependency files.
  228. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  229. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  230. # Combine all necessary flags and optional flags.
  231. # Add target processor to flags.
  232. #ALL_CFLAGS = -mmcu=$(MCU) -B /home/bucde/local/packs/Atmel.ATtiny_DFP.1.3.172.atpack_FILES/gcc/dev/attiny817 -I. $(CFLAGS) $(GENDEPFLAGS)
  233. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  234. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  235. # Default target.
  236. all: info begin gccversion sizebefore build sizeafter finished end
  237. build: elf hex eep lss sym
  238. elf: $(TARGET).elf
  239. hex: $(TARGET).hex
  240. eep: $(TARGET).eep
  241. lss: $(TARGET).lss
  242. sym: $(TARGET).sym
  243. # Eye candy.
  244. # AVR Studio 3.x does not check make's exit code but relies on
  245. # the following magic strings to be generated by the compile job.
  246. begin:
  247. @echo
  248. @echo $(MSG_BEGIN)
  249. finished:
  250. @echo $(MSG_ERRORS_NONE)
  251. end:
  252. @echo $(MSG_END)
  253. @echo
  254. # Display size of file.
  255. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  256. ELFSIZE = $(SIZE) -A $(TARGET).elf
  257. sizebefore:
  258. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  259. sizeafter:
  260. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  261. info:
  262. @echo
  263. @echo $(MSG_INFO)
  264. @echo MCU: $(MCU)
  265. @echo F_CPU: $(F_CPU)
  266. # Display compiler version information.
  267. gccversion :
  268. @$(CC) --version
  269. # Program the device.
  270. program: $(TARGET).hex $(TARGET).eep
  271. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  272. flashfuses :
  273. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSES)
  274. readfuses :
  275. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_READ_FUSES)
  276. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  277. COFFCONVERT=$(OBJCOPY) --debugging \
  278. --change-section-address .data-0x800000 \
  279. --change-section-address .bss-0x800000 \
  280. --change-section-address .noinit-0x800000 \
  281. --change-section-address .eeprom-0x810000
  282. coff: $(TARGET).elf
  283. @echo
  284. @echo $(MSG_COFF) $(TARGET).cof
  285. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  286. extcoff: $(TARGET).elf
  287. @echo
  288. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  289. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  290. # Create final output files (.hex, .eep) from ELF output file.
  291. %.hex: %.elf
  292. @echo
  293. @echo $(MSG_FLASH) $@
  294. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  295. %.eep: %.elf
  296. @echo
  297. @echo $(MSG_EEPROM) $@
  298. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  299. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  300. # Create extended listing file from ELF output file.
  301. %.lss: %.elf
  302. @echo
  303. @echo $(MSG_EXTENDED_LISTING) $@
  304. $(OBJDUMP) -h -S $< > $@
  305. # Create a symbol table from ELF output file.
  306. %.sym: %.elf
  307. @echo
  308. @echo $(MSG_SYMBOL_TABLE) $@
  309. $(NM) -n $< > $@
  310. # Link: create ELF output file from object files.
  311. .SECONDARY : $(TARGET).elf
  312. .PRECIOUS : $(OBJ)
  313. %.elf: $(OBJ)
  314. @echo
  315. @echo $(MSG_LINKING) $@
  316. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  317. # Compile: create object files from C source files.
  318. %.o : %.c
  319. @echo
  320. @echo $(MSG_COMPILING) $<
  321. $(CC) -c $(ALL_CFLAGS) $< -o $@
  322. # Compile: create assembler files from C source files.
  323. %.s : %.c
  324. $(CC) -S $(ALL_CFLAGS) $< -o $@
  325. # Assemble: create object files from assembler source files.
  326. %.o : %.S
  327. @echo
  328. @echo $(MSG_ASSEMBLING) $<
  329. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  330. # Target: clean project.
  331. clean: begin clean_list finished end
  332. clean_list :
  333. @echo
  334. @echo $(MSG_CLEANING)
  335. $(REMOVE) $(TARGET).hex
  336. $(REMOVE) $(TARGET).eep
  337. $(REMOVE) $(TARGET).obj
  338. $(REMOVE) $(TARGET).cof
  339. $(REMOVE) $(TARGET).elf
  340. $(REMOVE) $(TARGET).map
  341. $(REMOVE) $(TARGET).obj
  342. $(REMOVE) $(TARGET).a90
  343. $(REMOVE) $(TARGET).sym
  344. $(REMOVE) $(TARGET).lnk
  345. $(REMOVE) $(TARGET).lss
  346. $(REMOVE) $(OBJ)
  347. $(REMOVE) $(LST)
  348. $(REMOVE) $(SRC:.c=.s)
  349. $(REMOVE) $(SRC:.c=.d)
  350. $(REMOVE) .dep/*
  351. # Include the dependency files.
  352. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  353. # Listing of phony targets.
  354. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  355. build elf hex eep lss sym coff extcoff \
  356. clean clean_list program