makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
  2. # Released to the Public Domain
  3. # Please read the make user manual!
  4. #
  5. # Additional material for this makefile was submitted by:
  6. # Tim Henigan
  7. # Peter Fleury
  8. # Reiner Patommel
  9. # Sander Pool
  10. # Frederik Rouleau
  11. # Markus Pfaff
  12. #
  13. # On command line:
  14. #
  15. # make all = Make software.
  16. #
  17. # make clean = Clean out built project files.
  18. #
  19. # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
  20. #
  21. # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  22. # 4.07 or greater).
  23. #
  24. # make program = Download the hex file to the device, using avrdude. Please
  25. # customize the avrdude settings below first!
  26. #
  27. # make filename.s = Just compile filename.c into the assembler code only
  28. #
  29. # To rebuild project do "make clean" then "make all".
  30. #
  31. # MCU name
  32. MCU = atmega32
  33. #MCU = atmega644
  34. # Output format. (can be srec, ihex, binary)
  35. FORMAT = ihex
  36. # Target file name (without extension).
  37. TARGET = main
  38. # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
  39. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  40. OPT = s
  41. # List C source files here. (C dependencies are automatically generated.)
  42. SRC = $(TARGET).c mmc.c fat.c usart.c
  43. # If there is more than one source file, append them above, or modify and
  44. # uncomment the following:
  45. #SRC += foo.c bar.c
  46. # You can also wrap lines by appending a backslash to the end of the line:
  47. #SRC += baz.c \
  48. #xyzzy.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. # List any extra directories to look for include files here.
  58. # Each directory must be seperated by a space.
  59. EXTRAINCDIRS =
  60. # Optional compiler flags.
  61. # -g: generate debugging information (for GDB, or for COFF conversion)
  62. # -O*: optimization level
  63. # -f...: tuning, see gcc manual and avr-libc documentation
  64. # -Wall...: warning level
  65. # -Wa,...: tell GCC to pass this to the assembler.
  66. # -ahlms: create assembler listing
  67. CFLAGS = -g -O$(OPT) \
  68. -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
  69. -Wall -Wstrict-prototypes \
  70. -Wa,-adhlns=$(<:.c=.lst) \
  71. $(patsubst %,-I%,$(EXTRAINCDIRS))
  72. # Set a "language standard" compiler flag.
  73. # Unremark just one line below to set the language standard to use.
  74. # gnu99 = C99 + GNU extensions. See GCC manual for more information.
  75. #CFLAGS += -std=c89
  76. #CFLAGS += -std=gnu89
  77. #CFLAGS += -std=c99
  78. CFLAGS += -std=gnu99
  79. # Optional assembler flags.
  80. # -Wa,...: tell GCC to pass this to the assembler.
  81. # -ahlms: create listing
  82. # -gstabs: have the assembler create line number information; note that
  83. # for use in COFF files, additional information about filenames
  84. # and function names needs to be present in the assembler source
  85. # files -- see avr-libc docs [FIXME: not yet described there]
  86. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  87. # Optional linker flags.
  88. # -Wl,...: tell GCC to pass this to linker.
  89. # -Map: create map file
  90. # --cref: add cross reference to map file
  91. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  92. # Additional libraries
  93. # Minimalistic printf version
  94. #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
  95. # Floating point printf version (requires -lm below)
  96. #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
  97. # -lm = math library
  98. LDFLAGS += -lm
  99. # Programming support using avrdude. Settings and variables.
  100. # Programming hardware: alf avr910 avrisp bascom bsd
  101. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  102. #
  103. # Type: avrdude -c ?
  104. # to get a full listing.
  105. #
  106. AVRDUDE_PROGRAMMER = stk200
  107. #AVRDUDE_PORT = com1 # programmer connected to serial device
  108. AVRDUDE_PORT = lpt1 # programmer connected to parallel port
  109. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  110. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  111. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  112. # Uncomment the following if you want avrdude's erase cycle counter.
  113. # Note that this counter needs to be initialized first using -Yn,
  114. # see avrdude manual.
  115. #AVRDUDE_ERASE += -y
  116. # Uncomment the following if you do /not/ wish a verification to be
  117. # performed after programming the device.
  118. #AVRDUDE_FLAGS += -V
  119. # Increase verbosity level. Please use this when submitting bug
  120. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  121. # to submit bug reports.
  122. #AVRDUDE_FLAGS += -v -v
  123. # ---------------------------------------------------------------------------
  124. # Define directories, if needed.
  125. DIRAVR = c:/winavr
  126. DIRAVRBIN = $(DIRAVR)/bin
  127. DIRAVRUTILS = $(DIRAVR)/utils/bin
  128. DIRINC = .
  129. DIRLIB = $(DIRAVR)/avr/lib
  130. # Define programs and commands.
  131. SHELL = sh
  132. CC = avr-gcc
  133. OBJCOPY = avr-objcopy
  134. OBJDUMP = avr-objdump
  135. SIZE = avr-size
  136. # Programming support using avrdude.
  137. AVRDUDE = avrdude
  138. REMOVE = rm -f
  139. COPY = cp
  140. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  141. ELFSIZE = $(SIZE) -A $(TARGET).elf
  142. # Define Messages
  143. # English
  144. MSG_ERRORS_NONE = Errors: none
  145. MSG_BEGIN = -------- begin --------
  146. MSG_END = -------- end --------
  147. MSG_SIZE_BEFORE = Size before:
  148. MSG_SIZE_AFTER = Size after:
  149. MSG_COFF = Converting to AVR COFF:
  150. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  151. MSG_FLASH = Creating load file for Flash:
  152. MSG_EEPROM = Creating load file for EEPROM:
  153. MSG_EXTENDED_LISTING = Creating Extended Listing:
  154. MSG_SYMBOL_TABLE = Creating Symbol Table:
  155. MSG_LINKING = Linking:
  156. MSG_COMPILING = Compiling:
  157. MSG_ASSEMBLING = Assembling:
  158. MSG_CLEANING = Cleaning project:
  159. # Define all object files.
  160. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  161. # Define all listing files.
  162. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  163. # Combine all necessary flags and optional flags.
  164. # Add target processor to flags.
  165. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  166. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  167. # Default target.
  168. all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
  169. $(TARGET).lss $(TARGET).sym sizeafter finished end
  170. # Eye candy.
  171. # AVR Studio 3.x does not check make's exit code but relies on
  172. # the following magic strings to be generated by the compile job.
  173. begin:
  174. @echo
  175. @echo $(MSG_BEGIN)
  176. finished:
  177. @echo $(MSG_ERRORS_NONE)
  178. end:
  179. @echo $(MSG_END)
  180. @echo
  181. # Display size of file.
  182. sizebefore:
  183. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  184. sizeafter:
  185. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  186. # Display compiler version information.
  187. gccversion :
  188. @$(CC) --version
  189. # Convert ELF to COFF for use in debugging / simulating in
  190. # AVR Studio or VMLAB.
  191. COFFCONVERT=$(OBJCOPY) --debugging \
  192. --change-section-address .data-0x800000 \
  193. --change-section-address .bss-0x800000 \
  194. --change-section-address .noinit-0x800000 \
  195. --change-section-address .eeprom-0x810000
  196. coff: $(TARGET).elf
  197. @echo
  198. @echo $(MSG_COFF) $(TARGET).cof
  199. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  200. extcoff: $(TARGET).elf
  201. @echo
  202. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  203. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  204. # Program the device.
  205. program: $(TARGET).hex $(TARGET).eep
  206. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  207. # Create final output files (.hex, .eep) from ELF output file.
  208. %.hex: %.elf
  209. @echo
  210. @echo $(MSG_FLASH) $@
  211. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  212. %.eep: %.elf
  213. @echo
  214. @echo $(MSG_EEPROM) $@
  215. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  216. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  217. # Create extended listing file from ELF output file.
  218. %.lss: %.elf
  219. @echo
  220. @echo $(MSG_EXTENDED_LISTING) $@
  221. $(OBJDUMP) -h -S $< > $@
  222. # Create a symbol table from ELF output file.
  223. %.sym: %.elf
  224. @echo
  225. @echo $(MSG_SYMBOL_TABLE) $@
  226. avr-nm -n $< > $@
  227. # Link: create ELF output file from object files.
  228. .SECONDARY : $(TARGET).elf
  229. .PRECIOUS : $(OBJ)
  230. %.elf: $(OBJ)
  231. @echo
  232. @echo $(MSG_LINKING) $@
  233. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  234. # Compile: create object files from C source files.
  235. %.o : %.c
  236. @echo
  237. @echo $(MSG_COMPILING) $<
  238. $(CC) -c $(ALL_CFLAGS) $< -o $@
  239. # Compile: create assembler files from C source files.
  240. %.s : %.c
  241. $(CC) -S $(ALL_CFLAGS) $< -o $@
  242. # Assemble: create object files from assembler source files.
  243. %.o : %.S
  244. @echo
  245. @echo $(MSG_ASSEMBLING) $<
  246. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  247. # Target: clean project.
  248. clean: begin clean_list finished end
  249. clean_list :
  250. @echo
  251. @echo $(MSG_CLEANING)
  252. $(REMOVE) $(TARGET).hex
  253. $(REMOVE) $(TARGET).eep
  254. $(REMOVE) $(TARGET).obj
  255. $(REMOVE) $(TARGET).cof
  256. $(REMOVE) $(TARGET).elf
  257. $(REMOVE) $(TARGET).map
  258. $(REMOVE) $(TARGET).obj
  259. $(REMOVE) $(TARGET).a90
  260. $(REMOVE) $(TARGET).sym
  261. $(REMOVE) $(TARGET).lnk
  262. $(REMOVE) $(TARGET).lss
  263. $(REMOVE) $(OBJ)
  264. $(REMOVE) $(LST)
  265. $(REMOVE) $(SRC:.c=.s)
  266. $(REMOVE) $(SRC:.c=.d)
  267. # Automatically generate C source code dependencies.
  268. # (Code originally taken from the GNU make user manual and modified
  269. # (See README.txt Credits).)
  270. #
  271. # Note that this will work with sh (bash) and sed that is shipped with WinAVR
  272. # (see the SHELL variable defined above).
  273. # This may not work with other shells or other seds.
  274. #
  275. %.d: %.c
  276. set -e; $(CC) -MM $(ALL_CFLAGS) $< \
  277. | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
  278. [ -s $@ ] || rm -f $@
  279. # Remove the '-' if you want to see the dependency files generated.
  280. -include $(SRC:.c=.d)
  281. # Listing of phony targets.
  282. .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
  283. clean clean_list program