Makefile 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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 = atmega644
  39. # Main Oscillator Frequency
  40. # This is only used to define F_OSC in all assembler and c-sources.
  41. F_OSC = 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_OSC=$(F_OSC)
  94. CFLAGS += -DF_CPU=8000000UL
  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) $(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. # Fuse values for particular devices
  140. ##############################################################################
  141. # If your device is not listed here, go to
  142. # http://palmavr.sourceforge.net/cgi-bin/fc.cgi
  143. # and choose options for external crystal clock and no clock divider
  144. #
  145. ################################## ATMega8 ##################################
  146. # ATMega8 FUSE_L (Fuse low byte):
  147. # 0x9f = 1 0 0 1 1 1 1 1
  148. # ^ ^ \ / \--+--/
  149. # | | | +------- CKSEL 3..0 (external >8M crystal)
  150. # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
  151. # | +------------------ BODEN (BrownOut Detector enabled)
  152. # +-------------------- BODLEVEL (2.7V)
  153. # ATMega8 FUSE_H (Fuse high byte):
  154. # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
  155. # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
  156. # | | | | | +-------- BOOTSZ1
  157. # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
  158. # | | | +-------------- CKOPT (full output swing)
  159. # | | +---------------- SPIEN (allow serial programming)
  160. # | +------------------ WDTON (WDT not always on)
  161. # +-------------------- RSTDISBL (reset pin is enabled)
  162. #
  163. ############################## ATMega48/88/168 ##############################
  164. # ATMega*8 FUSE_L (Fuse low byte):
  165. # 0xdf = 1 1 0 1 1 1 1 1
  166. # ^ ^ \ / \--+--/
  167. # | | | +------- CKSEL 3..0 (external >8M crystal)
  168. # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
  169. # | +------------------ CKOUT (if 0: Clock output enabled)
  170. # +-------------------- CKDIV8 (if 0: divide by 8)
  171. # ATMega*8 FUSE_H (Fuse high byte):
  172. # 0xde = 1 1 0 1 1 1 1 0
  173. # ^ ^ ^ ^ ^ \-+-/
  174. # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
  175. # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
  176. # | | | +-------------- WDTON (if 0: watchdog always on)
  177. # | | +---------------- SPIEN (allow serial programming)
  178. # | +------------------ DWEN (debug wire enable)
  179. # +-------------------- RSTDISBL (reset pin is enabled)
  180. #
  181. ############################## ATTiny25/45/85 ###############################
  182. # ATMega*5 FUSE_L (Fuse low byte):
  183. # 0xef = 1 1 1 0 1 1 1 1
  184. # ^ ^ \+/ \--+--/
  185. # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
  186. # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
  187. # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
  188. # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
  189. # ATMega*5 FUSE_H (Fuse high byte):
  190. # 0xdd = 1 1 0 1 1 1 0 1
  191. # ^ ^ ^ ^ ^ \-+-/
  192. # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
  193. # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
  194. # | | | +-------------- WDTON (watchdog timer always on -> disable)
  195. # | | +---------------- SPIEN (enable serial programming -> enabled)
  196. # | +------------------ DWEN (debug wire enable)
  197. # +-------------------- RSTDISBL (disable external reset -> enabled)
  198. #
  199. ################################ ATTiny2313 #################################
  200. # ATTiny2313 FUSE_L (Fuse low byte):
  201. # 0xef = 1 1 1 0 1 1 1 1
  202. # ^ ^ \+/ \--+--/
  203. # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
  204. # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
  205. # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
  206. # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
  207. # ATTiny2313 FUSE_H (Fuse high byte):
  208. # 0xdb = 1 1 0 1 1 0 1 1
  209. # ^ ^ ^ ^ \-+-/ ^
  210. # | | | | | +---- RSTDISBL (disable external reset -> enabled)
  211. # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
  212. # | | | +-------------- WDTON (watchdog timer always on -> disable)
  213. # | | +---------------- SPIEN (enable serial programming -> enabled)
  214. # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
  215. # +-------------------- DWEN (debug wire enable)
  216. #
  217. AVRDUDE_PROGRAMMER = usbasp
  218. # com1 = serial port. Use lpt1 to connect to parallel port.
  219. AVRDUDE_PORT = # programmer connected to serial device
  220. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  221. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  222. # Uncomment the following if you want avrdude's erase cycle counter.
  223. # Note that this counter needs to be initialized first using -Yn,
  224. # see avrdude manual.
  225. #AVRDUDE_ERASE_COUNTER = -y
  226. # Uncomment the following if you do /not/ wish a verification to be
  227. # performed after programming the device.
  228. #AVRDUDE_NO_VERIFY = -V
  229. # Increase verbosity level. Please use this when submitting bug
  230. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  231. # to submit bug reports.
  232. #AVRDUDE_VERBOSE = -v -v
  233. AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
  234. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  235. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  236. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  237. #
  238. # Mega8 set to internal 4mhz
  239. # avrdude -p atmega8 -P /dev/ttyUSB0 -c stk500v2 -U lfuse:w:0xe3:m
  240. #
  241. #flashmac:
  242. # uisp -dprog=avr910 -dpart=ATmega8 -dserial=/dev/cu.PL2303-00002326 --erase -v --upload if=$(TARGET).hex
  243. # ---------------------------------------------------------------------------
  244. # Define directories, if needed.
  245. DIRAVR = c:/winavr
  246. DIRAVRBIN = $(DIRAVR)/bin
  247. DIRAVRUTILS = $(DIRAVR)/utils/bin
  248. DIRINC = .
  249. DIRLIB = $(DIRAVR)/avr/lib
  250. # Define programs and commands.
  251. SHELL = sh
  252. CC = avr-gcc
  253. OBJCOPY = avr-objcopy
  254. OBJDUMP = avr-objdump
  255. SIZE = avr-size
  256. NM = avr-nm
  257. AVRDUDE = avrdude
  258. REMOVE = rm -f
  259. COPY = cp
  260. # Define Messages
  261. # English
  262. MSG_ERRORS_NONE = Errors: none
  263. MSG_BEGIN = -------- begin --------
  264. MSG_END = -------- end --------
  265. MSG_SIZE_BEFORE = Size before:
  266. MSG_SIZE_AFTER = Size after:
  267. MSG_COFF = Converting to AVR COFF:
  268. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  269. MSG_FLASH = Creating load file for Flash:
  270. MSG_EEPROM = Creating load file for EEPROM:
  271. MSG_EXTENDED_LISTING = Creating Extended Listing:
  272. MSG_SYMBOL_TABLE = Creating Symbol Table:
  273. MSG_LINKING = Linking:
  274. MSG_COMPILING = Compiling:
  275. MSG_ASSEMBLING = Assembling:
  276. MSG_CLEANING = Cleaning project:
  277. # Define all object files.
  278. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  279. # Define all listing files.
  280. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  281. # Compiler flags to generate dependency files.
  282. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  283. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  284. # Combine all necessary flags and optional flags.
  285. # Add target processor to flags.
  286. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  287. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  288. # Default target.
  289. all: begin gccversion sizebefore build sizeafter finished end
  290. build: elf hex eep lss sym
  291. elf: $(TARGET).elf
  292. hex: $(TARGET).hex
  293. eep: $(TARGET).eep
  294. lss: $(TARGET).lss
  295. sym: $(TARGET).sym
  296. # Eye candy.
  297. # AVR Studio 3.x does not check make's exit code but relies on
  298. # the following magic strings to be generated by the compile job.
  299. begin:
  300. @echo
  301. @echo $(MSG_BEGIN)
  302. finished:
  303. @echo $(MSG_ERRORS_NONE)
  304. end:
  305. @echo $(MSG_END)
  306. @echo
  307. # Display size of file.
  308. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  309. ELFSIZE = $(SIZE) -A $(TARGET).elf
  310. sizebefore:
  311. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  312. sizeafter:
  313. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  314. # Display compiler version information.
  315. gccversion :
  316. @$(CC) --version
  317. # Program the device.
  318. flash_avrdude: flash
  319. flash: $(TARGET).hex $(TARGET).eep
  320. sudo $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  321. flash_uisp:
  322. sudo uisp -dprog=avr910 -dpart=ATmega8 -dserial=/dev/ttyUSB0 --verify --erase -v --upload if=$(TARGET).hex
  323. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  324. COFFCONVERT=$(OBJCOPY) --debugging \
  325. --change-section-address .data-0x800000 \
  326. --change-section-address .bss-0x800000 \
  327. --change-section-address .noinit-0x800000 \
  328. --change-section-address .eeprom-0x810000
  329. coff: $(TARGET).elf
  330. @echo
  331. @echo $(MSG_COFF) $(TARGET).cof
  332. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  333. extcoff: $(TARGET).elf
  334. @echo
  335. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  336. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  337. # Create final output files (.hex, .eep) from ELF output file.
  338. %.hex: %.elf
  339. @echo
  340. @echo $(MSG_FLASH) $@
  341. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  342. %.eep: %.elf
  343. @echo
  344. @echo $(MSG_EEPROM) $@
  345. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  346. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  347. # Create extended listing file from ELF output file.
  348. %.lss: %.elf
  349. @echo
  350. @echo $(MSG_EXTENDED_LISTING) $@
  351. $(OBJDUMP) -h -S $< > $@
  352. # Create a symbol table from ELF output file.
  353. %.sym: %.elf
  354. @echo
  355. @echo $(MSG_SYMBOL_TABLE) $@
  356. $(NM) -n $< > $@
  357. # Link: create ELF output file from object files.
  358. .SECONDARY : $(TARGET).elf
  359. .PRECIOUS : $(OBJ)
  360. %.elf: $(OBJ)
  361. @echo
  362. @echo $(MSG_LINKING) $@
  363. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  364. # Compile: create object files from C source files.
  365. %.o : %.c
  366. @echo
  367. @echo $(MSG_COMPILING) $<
  368. $(CC) -c $(ALL_CFLAGS) $< -o $@
  369. # Compile: create assembler files from C source files.
  370. %.s : %.c
  371. $(CC) -S $(ALL_CFLAGS) $< -o $@
  372. # Assemble: create object files from assembler source files.
  373. %.o : %.S
  374. @echo
  375. @echo $(MSG_ASSEMBLING) $<
  376. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  377. # Target: clean project.
  378. clean: begin clean_list finished end
  379. clean_list :
  380. @echo
  381. @echo $(MSG_CLEANING)
  382. $(REMOVE) $(TARGET).hex
  383. $(REMOVE) $(TARGET).eep
  384. $(REMOVE) $(TARGET).obj
  385. $(REMOVE) $(TARGET).cof
  386. $(REMOVE) $(TARGET).elf
  387. $(REMOVE) $(TARGET).map
  388. $(REMOVE) $(TARGET).obj
  389. $(REMOVE) $(TARGET).a90
  390. $(REMOVE) $(TARGET).sym
  391. $(REMOVE) $(TARGET).lnk
  392. $(REMOVE) $(TARGET).lss
  393. $(REMOVE) $(OBJ)
  394. $(REMOVE) $(LST)
  395. $(REMOVE) $(SRC:.c=.s)
  396. $(REMOVE) $(SRC:.c=.d)
  397. $(REMOVE) .dep/*
  398. # Include the dependency files.
  399. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  400. # Listing of phony targets.
  401. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  402. build elf hex eep lss sym coff extcoff \
  403. clean clean_list program