Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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 = atmega16
  39. # Main Oscillator Frequency
  40. # This is only used to define F_OSC in all assembler and c-sources.
  41. F_OSC = 16000000
  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 uart.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_OSC=$(F_OSC)
  94. CFLAGS += -DF_CPU=16000000UL
  95. #CFLAGS += -DF_CPU=3686400UL
  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_MIN) $(SCANF_LIB) $(MATH_LIB)
  132. # Programming support using avrdude. Settings and variables.
  133. # Programming hardware: alf avr910 avrisp bascom bsd
  134. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  135. #
  136. # Type: avrdude -c ?
  137. # to get a full listing.
  138. #
  139. AVRDUDE_PROGRAMMER = stk500v2
  140. # com1 = serial port. Use lpt1 to connect to parallel port.
  141. AVRDUDE_PORT = /dev/tty.PL2303-00002126
  142. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  143. # Uncomment the following if you want avrdude's erase cycle counter.
  144. # Note that this counter needs to be initialized first using -Yn,
  145. # see avrdude manual.
  146. #AVRDUDE_ERASE_COUNTER = -y
  147. # Uncomment the following if you do /not/ wish a verification to be
  148. # performed after programming the device.
  149. AVRDUDE_NO_VERIFY = -V
  150. # Increase verbosity level. Please use this when submitting bug
  151. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  152. # to submit bug reports.
  153. AVRDUDE_VERBOSE = -v -v
  154. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  155. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  156. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  157. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  158. #flash_fuse:
  159. # avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U lfuse:w:0xfe:m
  160. # avrdude -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -U hfuse:w:0xd9:m
  161. # ---------------------------------------------------------------------------
  162. # Define directories, if needed.
  163. DIRAVR = c:/winavr
  164. DIRAVRBIN = $(DIRAVR)/bin
  165. DIRAVRUTILS = $(DIRAVR)/utils/bin
  166. DIRINC = .
  167. DIRLIB = $(DIRAVR)/avr/lib
  168. # Define programs and commands.
  169. SHELL = sh
  170. CC = avr-gcc
  171. OBJCOPY = avr-objcopy
  172. OBJDUMP = avr-objdump
  173. SIZE = avr-size
  174. NM = avr-nm
  175. AVRDUDE = avrdude
  176. REMOVE = rm -f
  177. COPY = cp
  178. # Define Messages
  179. # English
  180. MSG_ERRORS_NONE = Errors: none
  181. MSG_BEGIN = -------- begin --------
  182. MSG_END = -------- end --------
  183. MSG_SIZE_BEFORE = Size before:
  184. MSG_SIZE_AFTER = Size after:
  185. MSG_COFF = Converting to AVR COFF:
  186. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  187. MSG_FLASH = Creating load file for Flash:
  188. MSG_EEPROM = Creating load file for EEPROM:
  189. MSG_EXTENDED_LISTING = Creating Extended Listing:
  190. MSG_SYMBOL_TABLE = Creating Symbol Table:
  191. MSG_LINKING = Linking:
  192. MSG_COMPILING = Compiling:
  193. MSG_ASSEMBLING = Assembling:
  194. MSG_CLEANING = Cleaning project:
  195. # Define all object files.
  196. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  197. # Define all listing files.
  198. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  199. # Compiler flags to generate dependency files.
  200. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  201. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  202. # Combine all necessary flags and optional flags.
  203. # Add target processor to flags.
  204. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  205. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  206. # Default target.
  207. all: begin gccversion sizebefore build sizeafter finished end
  208. build: elf hex eep lss sym
  209. elf: $(TARGET).elf
  210. hex: $(TARGET).hex
  211. eep: $(TARGET).eep
  212. lss: $(TARGET).lss
  213. sym: $(TARGET).sym
  214. # Eye candy.
  215. # AVR Studio 3.x does not check make's exit code but relies on
  216. # the following magic strings to be generated by the compile job.
  217. begin:
  218. @echo
  219. @echo $(MSG_BEGIN)
  220. finished:
  221. @echo $(MSG_ERRORS_NONE)
  222. end:
  223. @echo $(MSG_END)
  224. @echo
  225. # Display size of file.
  226. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  227. ELFSIZE = $(SIZE) -A $(TARGET).elf
  228. sizebefore:
  229. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  230. sizeafter:
  231. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  232. # Display compiler version information.
  233. gccversion :
  234. @$(CC) --version
  235. # Program the device.
  236. flash: $(TARGET).hex $(TARGET).eep
  237. sudo $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  238. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  239. COFFCONVERT=$(OBJCOPY) --debugging \
  240. --change-section-address .data-0x800000 \
  241. --change-section-address .bss-0x800000 \
  242. --change-section-address .noinit-0x800000 \
  243. --change-section-address .eeprom-0x810000
  244. coff: $(TARGET).elf
  245. @echo
  246. @echo $(MSG_COFF) $(TARGET).cof
  247. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  248. extcoff: $(TARGET).elf
  249. @echo
  250. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  251. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  252. # Create final output files (.hex, .eep) from ELF output file.
  253. %.hex: %.elf
  254. @echo
  255. @echo $(MSG_FLASH) $@
  256. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  257. %.eep: %.elf
  258. @echo
  259. @echo $(MSG_EEPROM) $@
  260. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  261. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  262. # Create extended listing file from ELF output file.
  263. %.lss: %.elf
  264. @echo
  265. @echo $(MSG_EXTENDED_LISTING) $@
  266. $(OBJDUMP) -h -S $< > $@
  267. # Create a symbol table from ELF output file.
  268. %.sym: %.elf
  269. @echo
  270. @echo $(MSG_SYMBOL_TABLE) $@
  271. $(NM) -n $< > $@
  272. # Link: create ELF output file from object files.
  273. .SECONDARY : $(TARGET).elf
  274. .PRECIOUS : $(OBJ)
  275. %.elf: $(OBJ)
  276. @echo
  277. @echo $(MSG_LINKING) $@
  278. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  279. # Compile: create object files from C source files.
  280. %.o : %.c
  281. @echo
  282. @echo $(MSG_COMPILING) $<
  283. $(CC) -c $(ALL_CFLAGS) $< -o $@
  284. # Compile: create assembler files from C source files.
  285. %.s : %.c
  286. $(CC) -S $(ALL_CFLAGS) $< -o $@
  287. # Assemble: create object files from assembler source files.
  288. %.o : %.S
  289. @echo
  290. @echo $(MSG_ASSEMBLING) $<
  291. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  292. # Target: clean project.
  293. clean: begin clean_list finished end
  294. clean_list :
  295. @echo
  296. @echo $(MSG_CLEANING)
  297. $(REMOVE) $(TARGET).hex
  298. $(REMOVE) $(TARGET).eep
  299. $(REMOVE) $(TARGET).obj
  300. $(REMOVE) $(TARGET).cof
  301. $(REMOVE) $(TARGET).elf
  302. $(REMOVE) $(TARGET).map
  303. $(REMOVE) $(TARGET).obj
  304. $(REMOVE) $(TARGET).a90
  305. $(REMOVE) $(TARGET).sym
  306. $(REMOVE) $(TARGET).lnk
  307. $(REMOVE) $(TARGET).lss
  308. $(REMOVE) $(OBJ)
  309. $(REMOVE) $(LST)
  310. $(REMOVE) $(SRC:.c=.s)
  311. $(REMOVE) $(SRC:.c=.d)
  312. $(REMOVE) .dep/*
  313. # Include the dependency files.
  314. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  315. # Listing of phony targets.
  316. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  317. build elf hex eep lss sym coff extcoff \
  318. clean clean_list program