Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 = atmega32
  39. # Main Oscillator Frequency
  40. # This is only used to define F_OSC in all assembler and c-sources.
  41. #F_OSC = 3686400
  42. F_OSC = 16000000
  43. # Output format. (can be srec, ihex, binary)
  44. FORMAT = ihex
  45. # Target file name (without extension).
  46. TARGET = main
  47. # List C source files here. (C dependencies are automatically generated.)
  48. SRC = $(TARGET).c uart.c fifo.c
  49. # List Assembler source files here.
  50. # Make them always end in a capital .S. Files ending in a lowercase .s
  51. # will not be considered source files but generated files (assembler
  52. # output from the compiler), and will be deleted upon "make clean"!
  53. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  54. # it will preserve the spelling of the filenames, and gcc itself does
  55. # care about how the name is spelled on its command-line.
  56. ASRC =
  57. # Optimization level, can be [0, 1, 2, 3, s].
  58. # 0 = turn off optimization. s = optimize for size.
  59. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  60. OPT = s
  61. # Debugging format.
  62. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  63. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  64. #DEBUG = stabs
  65. #DEBUG = dwarf-2
  66. # List any extra directories to look for include files here.
  67. # Each directory must be seperated by a space.
  68. EXTRAINCDIRS =
  69. # Compiler flag to set the C Standard level.
  70. # c89 - "ANSI" C
  71. # gnu89 - c89 plus GCC extensions
  72. # c99 - ISO C99 standard (not yet fully implemented)
  73. # gnu99 - c99 plus GCC extensions
  74. CSTANDARD = -std=gnu99
  75. # Place -D or -U options here
  76. CDEFS =
  77. # Place -I options here
  78. CINCS =
  79. # Compiler flags.
  80. # -g*: generate debugging information
  81. # -O*: optimization level
  82. # -f...: tuning, see GCC manual and avr-libc documentation
  83. # -Wall...: warning level
  84. # -Wa,...: tell GCC to pass this to the assembler.
  85. # -adhlns...: create assembler listing
  86. CFLAGS = -g$(DEBUG)
  87. CFLAGS += $(CDEFS) $(CINCS)
  88. CFLAGS += -O$(OPT)
  89. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  90. CFLAGS += -Wall -Wstrict-prototypes
  91. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  92. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  93. CFLAGS += $(CSTANDARD)
  94. CFLAGS += -DF_OSC=$(F_OSC) -DF_CPU=$(F_OSC)UL
  95. # Assembler flags.
  96. # -Wa,...: tell GCC to pass this to the assembler.
  97. # -ahlms: create listing
  98. # -gstabs: have the assembler create line number information; note that
  99. # for use in COFF files, additional information about filenames
  100. # and function names needs to be present in the assembler source
  101. # files -- see avr-libc docs [FIXME: not yet described there]
  102. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  103. ASFLAGS += -DF_OSC=$(F_OSC)
  104. #Additional libraries.
  105. # Minimalistic printf version
  106. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  107. # Floating point printf version (requires MATH_LIB = -lm below)
  108. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  109. PRINTF_LIB =
  110. # Minimalistic scanf version
  111. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  112. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  113. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  114. SCANF_LIB =
  115. MATH_LIB = -lm
  116. # External memory options
  117. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  118. # used for variables (.data/.bss) and heap (malloc()).
  119. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  120. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  121. # only used for heap (malloc()).
  122. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  123. EXTMEMOPTS =
  124. # Linker flags.
  125. # -Wl,...: tell GCC to pass this to linker.
  126. # -Map: create map file
  127. # --cref: add cross reference to map file
  128. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  129. LDFLAGS += $(EXTMEMOPTS)
  130. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  131. # Programming support using avrdude. Settings and variables.
  132. # Programming hardware: alf avr910 avrisp bascom bsd
  133. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  134. #
  135. # Type: avrdude -c ?
  136. # to get a full listing.
  137. #
  138. AVRDUDE_PROGRAMMER = stk500v2
  139. # com1 = serial port. Use lpt1 to connect to parallel port.
  140. AVRDUDE_PORT = /dev/ttyUSB0 # programmer connected to serial device
  141. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  142. AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  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. # set 4mhz
  159. # avrdude -p atmega8 -P /dev/ttyUSB0 -c stk500v2 -U lfuse:w:0xe3:m
  160. #
  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. fuse_4_int:
  239. sudo $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:0xd3:m -U hfuse:w:0x99:m
  240. fuse_16_ext:
  241. sudo $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:0xdf:m -U hfuse:w:0x99:m
  242. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  243. COFFCONVERT=$(OBJCOPY) --debugging \
  244. --change-section-address .data-0x800000 \
  245. --change-section-address .bss-0x800000 \
  246. --change-section-address .noinit-0x800000 \
  247. --change-section-address .eeprom-0x810000
  248. coff: $(TARGET).elf
  249. @echo
  250. @echo $(MSG_COFF) $(TARGET).cof
  251. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  252. extcoff: $(TARGET).elf
  253. @echo
  254. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  255. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  256. # Create final output files (.hex, .eep) from ELF output file.
  257. %.hex: %.elf
  258. @echo
  259. @echo $(MSG_FLASH) $@
  260. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  261. %.eep: %.elf
  262. @echo
  263. @echo $(MSG_EEPROM) $@
  264. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  265. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  266. # Create extended listing file from ELF output file.
  267. %.lss: %.elf
  268. @echo
  269. @echo $(MSG_EXTENDED_LISTING) $@
  270. $(OBJDUMP) -h -S $< > $@
  271. # Create a symbol table from ELF output file.
  272. %.sym: %.elf
  273. @echo
  274. @echo $(MSG_SYMBOL_TABLE) $@
  275. $(NM) -n $< > $@
  276. # Link: create ELF output file from object files.
  277. .SECONDARY : $(TARGET).elf
  278. .PRECIOUS : $(OBJ)
  279. %.elf: $(OBJ)
  280. @echo
  281. @echo $(MSG_LINKING) $@
  282. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  283. # Compile: create object files from C source files.
  284. %.o : %.c
  285. @echo
  286. @echo $(MSG_COMPILING) $<
  287. $(CC) -c $(ALL_CFLAGS) $< -o $@
  288. # Compile: create assembler files from C source files.
  289. %.s : %.c
  290. $(CC) -S $(ALL_CFLAGS) $< -o $@
  291. # Assemble: create object files from assembler source files.
  292. %.o : %.S
  293. @echo
  294. @echo $(MSG_ASSEMBLING) $<
  295. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  296. # Target: clean project.
  297. clean: begin clean_list finished end
  298. clean_list :
  299. @echo
  300. @echo $(MSG_CLEANING)
  301. $(REMOVE) $(TARGET).hex
  302. $(REMOVE) $(TARGET).eep
  303. $(REMOVE) $(TARGET).obj
  304. $(REMOVE) $(TARGET).cof
  305. $(REMOVE) $(TARGET).elf
  306. $(REMOVE) $(TARGET).map
  307. $(REMOVE) $(TARGET).obj
  308. $(REMOVE) $(TARGET).a90
  309. $(REMOVE) $(TARGET).sym
  310. $(REMOVE) $(TARGET).lnk
  311. $(REMOVE) $(TARGET).lss
  312. $(REMOVE) $(OBJ)
  313. $(REMOVE) $(LST)
  314. $(REMOVE) $(SRC:.c=.s)
  315. $(REMOVE) $(SRC:.c=.d)
  316. $(REMOVE) .dep/*
  317. # Include the dependency files.
  318. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  319. # Listing of phony targets.
  320. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  321. build elf hex eep lss sym coff extcoff \
  322. clean clean_list program