Newer
Older
matrix4x5 / Makefile
  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.  
  34. # mth 2004/09
  35. # Differences from WinAVR 20040720 sample:
  36. # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
  37. # - F_CPU Define in CFLAGS and AFLAGS
  38.  
  39.  
  40. # MCU name
  41. MCU = atmega8
  42.  
  43. # Main Oscillator Frequency
  44. # This is only used to define F_CPU in all assembler and c-sources.
  45. F_CPU = 8000000
  46.  
  47. # uncomment for no debugging output over uart
  48. DEBUG = -DDEBUG
  49.  
  50. # Output format. (can be srec, ihex, binary)
  51. FORMAT = ihex
  52.  
  53. # Target file name (without extension).
  54. TARGET = main
  55.  
  56.  
  57. # List C source files here. (C dependencies are automatically generated.)
  58. SRC = $(TARGET).c keypad.c uart.c
  59.  
  60.  
  61. # List Assembler source files here.
  62. # Make them always end in a capital .S. Files ending in a lowercase .s
  63. # will not be considered source files but generated files (assembler
  64. # output from the compiler), and will be deleted upon "make clean"!
  65. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  66. # it will preserve the spelling of the filenames, and gcc itself does
  67. # care about how the name is spelled on its command-line.
  68. ASRC =
  69.  
  70.  
  71.  
  72. # Optimization level, can be [0, 1, 2, 3, s].
  73. # 0 = turn off optimization. s = optimize for size.
  74. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  75. OPT = s
  76.  
  77. # List any extra directories to look for include files here.
  78. # Each directory must be seperated by a space.
  79. EXTRAINCDIRS =
  80.  
  81.  
  82. # Compiler flag to set the C Standard level.
  83. # c89 - "ANSI" C
  84. # gnu89 - c89 plus GCC extensions
  85. # c99 - ISO C99 standard (not yet fully implemented)
  86. # gnu99 - c99 plus GCC extensions
  87. CSTANDARD = -std=gnu99
  88.  
  89. # Place -D or -U options here
  90. CDEFS = $(DEBUG)
  91.  
  92. # Place -I options here
  93. CINCS =
  94.  
  95.  
  96. # Compiler flags.
  97. # -g*: generate debugging information
  98. # -O*: optimization level
  99. # -f...: tuning, see GCC manual and avr-libc documentation
  100. # -Wall...: warning level
  101. # -Wa,...: tell GCC to pass this to the assembler.
  102. # -adhlns...: create assembler listing
  103. #CFLAGS = -g$(DEBUG)
  104. CFLAGS = $(CDEFS) $(CINCS)
  105. CFLAGS += -O$(OPT)
  106. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  107. CFLAGS += -Wall -Wstrict-prototypes
  108. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  109. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  110. CFLAGS += $(CSTANDARD)
  111. CFLAGS += -DF_CPU=$(F_CPU)
  112.  
  113.  
  114.  
  115. # Assembler flags.
  116. # -Wa,...: tell GCC to pass this to the assembler.
  117. # -ahlms: create listing
  118. # -gstabs: have the assembler create line number information; note that
  119. # for use in COFF files, additional information about filenames
  120. # and function names needs to be present in the assembler source
  121. # files -- see avr-libc docs [FIXME: not yet described there]
  122. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  123. ASFLAGS += -DF_CPU=$(F_CPU)
  124.  
  125.  
  126. #Additional libraries.
  127.  
  128. # Minimalistic printf version
  129. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  130.  
  131. # Floating point printf version (requires MATH_LIB = -lm below)
  132. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  133.  
  134. PRINTF_LIB =
  135.  
  136. # Minimalistic scanf version
  137. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  138.  
  139. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  140. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  141.  
  142. SCANF_LIB =
  143.  
  144. MATH_LIB = -lm
  145.  
  146. # External memory options
  147.  
  148. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  149. # used for variables (.data/.bss) and heap (malloc()).
  150. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  151.  
  152. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  153. # only used for heap (malloc()).
  154. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  155.  
  156. EXTMEMOPTS =
  157.  
  158. # Linker flags.
  159. # -Wl,...: tell GCC to pass this to linker.
  160. # -Map: create map file
  161. # --cref: add cross reference to map file
  162. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  163. LDFLAGS += $(EXTMEMOPTS)
  164. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  165.  
  166.  
  167.  
  168.  
  169. # Programming support using avrdude. Settings and variables.
  170.  
  171. # Programming hardware: alf avr910 avrisp bascom bsd
  172. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  173. #
  174. # Type: avrdude -c ?
  175. # to get a full listing.
  176. #
  177. AVRDUDE_PROGRAMMER = stk500
  178.  
  179. # com1 = serial port. Use lpt1 to connect to parallel port.
  180. AVRDUDE_PORT = com1 # programmer connected to serial device
  181.  
  182. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  183. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  184.  
  185.  
  186. # Uncomment the following if you want avrdude's erase cycle counter.
  187. # Note that this counter needs to be initialized first using -Yn,
  188. # see avrdude manual.
  189. #AVRDUDE_ERASE_COUNTER = -y
  190.  
  191. # Uncomment the following if you do /not/ wish a verification to be
  192. # performed after programming the device.
  193. #AVRDUDE_NO_VERIFY = -V
  194.  
  195. # Increase verbosity level. Please use this when submitting bug
  196. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  197. # to submit bug reports.
  198. #AVRDUDE_VERBOSE = -v -v
  199.  
  200. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  201. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  202. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  203. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  204.  
  205.  
  206.  
  207. # ---------------------------------------------------------------------------
  208.  
  209. # Define directories, if needed.
  210. DIRAVR = c:/winavr
  211. DIRAVRBIN = $(DIRAVR)/bin
  212. DIRAVRUTILS = $(DIRAVR)/utils/bin
  213. DIRINC = .
  214. DIRLIB = $(DIRAVR)/avr/lib
  215.  
  216.  
  217. # Define programs and commands.
  218. SHELL = sh
  219. CC = avr-gcc
  220. OBJCOPY = avr-objcopy
  221. OBJDUMP = avr-objdump
  222. SIZE = avr-size
  223. NM = avr-nm
  224. AVRDUDE = avrdude
  225. REMOVE = rm -f
  226. COPY = cp
  227.  
  228.  
  229.  
  230.  
  231. # Define Messages
  232. # English
  233. MSG_ERRORS_NONE = Errors: none
  234. MSG_BEGIN = -------- begin --------
  235. MSG_END = -------- end --------
  236. MSG_SIZE_BEFORE = Size before:
  237. MSG_SIZE_AFTER = Size after:
  238. MSG_COFF = Converting to AVR COFF:
  239. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  240. MSG_FLASH = Creating load file for Flash:
  241. MSG_EEPROM = Creating load file for EEPROM:
  242. MSG_EXTENDED_LISTING = Creating Extended Listing:
  243. MSG_SYMBOL_TABLE = Creating Symbol Table:
  244. MSG_LINKING = Linking:
  245. MSG_COMPILING = Compiling:
  246. MSG_ASSEMBLING = Assembling:
  247. MSG_CLEANING = Cleaning project:
  248.  
  249.  
  250.  
  251.  
  252. # Define all object files.
  253. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  254.  
  255. # Define all listing files.
  256. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  257.  
  258.  
  259. # Compiler flags to generate dependency files.
  260. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  261. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  262.  
  263. # Combine all necessary flags and optional flags.
  264. # Add target processor to flags.
  265. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  266. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  267.  
  268.  
  269.  
  270.  
  271.  
  272. # Default target.
  273. all: begin gccversion sizebefore build sizeafter finished end
  274.  
  275. build: elf hex eep lss sym
  276.  
  277. elf: $(TARGET).elf
  278. hex: $(TARGET).hex
  279. eep: $(TARGET).eep
  280. lss: $(TARGET).lss
  281. sym: $(TARGET).sym
  282.  
  283.  
  284.  
  285. # Eye candy.
  286. # AVR Studio 3.x does not check make's exit code but relies on
  287. # the following magic strings to be generated by the compile job.
  288. begin:
  289. @echo
  290. @echo $(MSG_BEGIN)
  291.  
  292. finished:
  293. @echo $(MSG_ERRORS_NONE)
  294.  
  295. end:
  296. @echo $(MSG_END)
  297. @echo
  298.  
  299.  
  300. # Display size of file.
  301. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  302. ELFSIZE = $(SIZE) -A $(TARGET).elf
  303. sizebefore:
  304. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  305.  
  306. sizeafter:
  307. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  308.  
  309.  
  310.  
  311. # Display compiler version information.
  312. gccversion :
  313. @$(CC) --version
  314.  
  315.  
  316.  
  317. # Program the device.
  318. program: $(TARGET).hex $(TARGET).eep
  319. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  320.  
  321.  
  322.  
  323.  
  324. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  325. COFFCONVERT=$(OBJCOPY) --debugging \
  326. --change-section-address .data-0x800000 \
  327. --change-section-address .bss-0x800000 \
  328. --change-section-address .noinit-0x800000 \
  329. --change-section-address .eeprom-0x810000
  330.  
  331.  
  332. coff: $(TARGET).elf
  333. @echo
  334. @echo $(MSG_COFF) $(TARGET).cof
  335. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  336.  
  337.  
  338. extcoff: $(TARGET).elf
  339. @echo
  340. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  341. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  342.  
  343.  
  344.  
  345. # Create final output files (.hex, .eep) from ELF output file.
  346. %.hex: %.elf
  347. @echo
  348. @echo $(MSG_FLASH) $@
  349. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  350.  
  351. %.eep: %.elf
  352. @echo
  353. @echo $(MSG_EEPROM) $@
  354. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  355. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  356.  
  357. # Create extended listing file from ELF output file.
  358. %.lss: %.elf
  359. @echo
  360. @echo $(MSG_EXTENDED_LISTING) $@
  361. $(OBJDUMP) -h -S $< > $@
  362.  
  363. # Create a symbol table from ELF output file.
  364. %.sym: %.elf
  365. @echo
  366. @echo $(MSG_SYMBOL_TABLE) $@
  367. $(NM) -n $< > $@
  368.  
  369.  
  370.  
  371. # Link: create ELF output file from object files.
  372. .SECONDARY : $(TARGET).elf
  373. .PRECIOUS : $(OBJ)
  374. %.elf: $(OBJ)
  375. @echo
  376. @echo $(MSG_LINKING) $@
  377. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  378.  
  379.  
  380. # Compile: create object files from C source files.
  381. %.o : %.c
  382. @echo
  383. @echo $(MSG_COMPILING) $<
  384. $(CC) -c $(ALL_CFLAGS) $< -o $@
  385.  
  386.  
  387. # Compile: create assembler files from C source files.
  388. %.s : %.c
  389. $(CC) -S $(ALL_CFLAGS) $< -o $@
  390.  
  391.  
  392. # Assemble: create object files from assembler source files.
  393. %.o : %.S
  394. @echo
  395. @echo $(MSG_ASSEMBLING) $<
  396. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  397.  
  398.  
  399.  
  400. # Target: clean project.
  401. clean: begin clean_list finished end
  402.  
  403. clean_list :
  404. @echo
  405. @echo $(MSG_CLEANING)
  406. $(REMOVE) $(TARGET).hex
  407. $(REMOVE) $(TARGET).eep
  408. $(REMOVE) $(TARGET).obj
  409. $(REMOVE) $(TARGET).cof
  410. $(REMOVE) $(TARGET).elf
  411. $(REMOVE) $(TARGET).map
  412. $(REMOVE) $(TARGET).obj
  413. $(REMOVE) $(TARGET).a90
  414. $(REMOVE) $(TARGET).sym
  415. $(REMOVE) $(TARGET).lnk
  416. $(REMOVE) $(TARGET).lss
  417. $(REMOVE) $(OBJ)
  418. $(REMOVE) $(LST)
  419. $(REMOVE) $(SRC:.c=.s)
  420. $(REMOVE) $(SRC:.c=.d)
  421. $(REMOVE) .dep/*
  422.  
  423.  
  424.  
  425. # Include the dependency files.
  426. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  427.  
  428.  
  429. # Listing of phony targets.
  430. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  431. build elf hex eep lss sym coff extcoff \
  432. clean clean_list program
  433.