Simple single-color 8x8x8 LED Cube with AVRs
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

makefile 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. # Makefile
  2. #
  3. # On command line:
  4. #
  5. # make all = Make software.
  6. #
  7. # make clean = Clean out built project files.
  8. #
  9. # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
  10. #
  11. # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  12. # 4.07 or greater).
  13. #
  14. # make program = Download the hex file to the device, using avrdude. Please
  15. # customize the avrdude settings below first!
  16. #
  17. # make filename.s = Just compile filename.c into the assembler code only
  18. #
  19. # To rebuild project do "make clean" then "make all".
  20. #
  21. # MCU name
  22. MCU = atmega8
  23. # Main Oscillator Frequency
  24. # This is only used to define F_OSC in all assembler and c-sources.
  25. F_CPU = 16000000
  26. # Output format. (can be srec, ihex, binary)
  27. FORMAT = ihex
  28. # Target file name (without extension).
  29. TARGET = main
  30. # List C source files here. (C dependencies are automatically generated.)
  31. SRC = $(TARGET).c
  32. #SRC += uart.c # Additional Source-File
  33. # List Assembler source files here.
  34. # Make them always end in a capital .S. Files ending in a lowercase .s
  35. # will not be considered source files but generated files (assembler
  36. # output from the compiler), and will be deleted upon "make clean"!
  37. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  38. # it will preserve the spelling of the filenames, and gcc itself does
  39. # care about how the name is spelled on its command-line.
  40. ASRC =
  41. # Optimization level, can be [0, 1, 2, 3, s].
  42. # 0 = turn off optimization. s = optimize for size.
  43. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  44. OPT = s
  45. # Debugging format.
  46. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  47. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  48. #DEBUG = stabs
  49. DEBUG = dwarf-2
  50. # List any extra directories to look for include files here.
  51. # Each directory must be seperated by a space.
  52. EXTRAINCDIRS =
  53. # Compiler flag to set the C Standard level.
  54. # c89 - "ANSI" C
  55. # gnu89 - c89 plus GCC extensions
  56. # c99 - ISO C99 standard (not yet fully implemented)
  57. # gnu99 - c99 plus GCC extensions
  58. CSTANDARD = -std=gnu99
  59. # Place -D or -U options here
  60. CDEFS =
  61. # Place -I options here
  62. CINCS =
  63. # Compiler flags.
  64. # -g*: generate debugging information
  65. # -O*: optimization level
  66. # -f...: tuning, see GCC manual and avr-libc documentation
  67. # -Wall...: warning level
  68. # -Wa,...: tell GCC to pass this to the assembler.
  69. # -adhlns...: create assembler listing
  70. CFLAGS = -g$(DEBUG)
  71. CFLAGS += $(CDEFS) $(CINCS)
  72. CFLAGS += -O$(OPT)
  73. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  74. CFLAGS += -Wall -Wstrict-prototypes
  75. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  76. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  77. CFLAGS += $(CSTANDARD)
  78. CFLAGS += -DF_CPU=$(F_CPU)
  79. # 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. ASFLAGS += -DF_CPU=$(F_CPU)
  88. #Additional libraries.
  89. # Minimalistic printf version
  90. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  91. # Floating point printf version (requires MATH_LIB = -lm below)
  92. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  93. PRINTF_LIB =
  94. # Minimalistic scanf version
  95. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  96. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  97. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  98. SCANF_LIB =
  99. MATH_LIB = -lm
  100. # External memory options
  101. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  102. # used for variables (.data/.bss) and heap (malloc()).
  103. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  104. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  105. # only used for heap (malloc()).
  106. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  107. EXTMEMOPTS =
  108. # Linker flags.
  109. # -Wl,...: tell GCC to pass this to linker.
  110. # -Map: create map file
  111. # --cref: add cross reference to map file
  112. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  113. LDFLAGS += $(EXTMEMOPTS)
  114. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  115. # Programming support using avrdude. Settings and variables.
  116. # Programming hardware: alf avr910 avrisp bascom bsd
  117. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  118. #
  119. # Type: avrdude -c ?
  120. # to get a full listing.
  121. #
  122. AVRDUDE_PROGRAMMER = stk500
  123. # com1 = serial port. Use lpt1 to connect to parallel port.
  124. AVRDUDE_PORT = com1 # programmer connected to serial device
  125. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  126. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  127. # Uncomment the following if you want avrdude's erase cycle counter.
  128. # Note that this counter needs to be initialized first using -Yn,
  129. # see avrdude manual.
  130. #AVRDUDE_ERASE_COUNTER = -y
  131. # Uncomment the following if you do /not/ wish a verification to be
  132. # performed after programming the device.
  133. #AVRDUDE_NO_VERIFY = -V
  134. # Increase verbosity level. Please use this when submitting bug
  135. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  136. # to submit bug reports.
  137. #AVRDUDE_VERBOSE = -v -v
  138. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  139. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  140. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  141. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  142. # ---------------------------------------------------------------------------
  143. # Define directories, if needed.
  144. DIRAVR = /usr/local/CrossPack-AVR
  145. DIRAVRBIN = $(DIRAVR)/bin
  146. DIRAVRUTILS = $(DIRAVR)/bin
  147. DIRINC = .
  148. DIRLIB = $(DIRAVR)/lib
  149. # Define programs and commands.
  150. SHELL = bash
  151. CC = avr-gcc
  152. OBJCOPY = avr-objcopy
  153. OBJDUMP = avr-objdump
  154. SIZE = avr-size
  155. NM = avr-nm
  156. AVRDUDE = avrdude
  157. REMOVE = rm -f
  158. COPY = cp
  159. # Define Messages
  160. # English
  161. MSG_ERRORS_NONE = Errors: none
  162. MSG_BEGIN = -------- begin --------
  163. MSG_END = -------- end --------
  164. MSG_SIZE_BEFORE = Size before:
  165. MSG_SIZE_AFTER = Size after:
  166. MSG_COFF = Converting to AVR COFF:
  167. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  168. MSG_FLASH = Creating load file for Flash:
  169. MSG_EEPROM = Creating load file for EEPROM:
  170. MSG_EXTENDED_LISTING = Creating Extended Listing:
  171. MSG_SYMBOL_TABLE = Creating Symbol Table:
  172. MSG_LINKING = Linking:
  173. MSG_COMPILING = Compiling:
  174. MSG_ASSEMBLING = Assembling:
  175. MSG_CLEANING = Cleaning project:
  176. # Define all object files.
  177. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  178. # Define all listing files.
  179. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  180. # Compiler flags to generate dependency files.
  181. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  182. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  183. # Combine all necessary flags and optional flags.
  184. # Add target processor to flags.
  185. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  186. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  187. # Default target.
  188. all: begin gccversion sizebefore build sizeafter finished end
  189. build: elf hex eep lss sym
  190. elf: $(TARGET).elf
  191. hex: $(TARGET).hex
  192. eep: $(TARGET).eep
  193. lss: $(TARGET).lss
  194. sym: $(TARGET).sym
  195. # Eye candy.
  196. # AVR Studio 3.x does not check make's exit code but relies on
  197. # the following magic strings to be generated by the compile job.
  198. begin:
  199. @echo
  200. @echo $(MSG_BEGIN)
  201. finished:
  202. @echo $(MSG_ERRORS_NONE)
  203. end:
  204. @echo $(MSG_END)
  205. @echo
  206. # Display size of file.
  207. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  208. ELFSIZE = $(SIZE) -A $(TARGET).elf
  209. sizebefore:
  210. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  211. sizeafter:
  212. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  213. # Display compiler version information.
  214. gccversion :
  215. @$(CC) --version
  216. # Program the device.
  217. program: $(TARGET).hex $(TARGET).eep
  218. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  219. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  220. COFFCONVERT=$(OBJCOPY) --debugging \
  221. --change-section-address .data-0x800000 \
  222. --change-section-address .bss-0x800000 \
  223. --change-section-address .noinit-0x800000 \
  224. --change-section-address .eeprom-0x810000
  225. coff: $(TARGET).elf
  226. @echo
  227. @echo $(MSG_COFF) $(TARGET).cof
  228. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  229. extcoff: $(TARGET).elf
  230. @echo
  231. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  232. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  233. # Create final output files (.hex, .eep) from ELF output file.
  234. %.hex: %.elf
  235. @echo
  236. @echo $(MSG_FLASH) $@
  237. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  238. %.eep: %.elf
  239. @echo
  240. @echo $(MSG_EEPROM) $@
  241. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  242. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  243. # Create extended listing file from ELF output file.
  244. %.lss: %.elf
  245. @echo
  246. @echo $(MSG_EXTENDED_LISTING) $@
  247. $(OBJDUMP) -h -S $< > $@
  248. # Create a symbol table from ELF output file.
  249. %.sym: %.elf
  250. @echo
  251. @echo $(MSG_SYMBOL_TABLE) $@
  252. $(NM) -n $< > $@
  253. # Link: create ELF output file from object files.
  254. .SECONDARY : $(TARGET).elf
  255. .PRECIOUS : $(OBJ)
  256. %.elf: $(OBJ)
  257. @echo
  258. @echo $(MSG_LINKING) $@
  259. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  260. # Compile: create object files from C source files.
  261. %.o : %.c
  262. @echo
  263. @echo $(MSG_COMPILING) $<
  264. $(CC) -c $(ALL_CFLAGS) $< -o $@
  265. # Compile: create assembler files from C source files.
  266. %.s : %.c
  267. $(CC) -S $(ALL_CFLAGS) $< -o $@
  268. # Assemble: create object files from assembler source files.
  269. %.o : %.S
  270. @echo
  271. @echo $(MSG_ASSEMBLING) $<
  272. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  273. # Target: clean project.
  274. clean: begin clean_list finished end
  275. clean_list :
  276. @echo
  277. @echo $(MSG_CLEANING)
  278. $(REMOVE) $(TARGET).hex
  279. $(REMOVE) $(TARGET).eep
  280. $(REMOVE) $(TARGET).obj
  281. $(REMOVE) $(TARGET).cof
  282. $(REMOVE) $(TARGET).elf
  283. $(REMOVE) $(TARGET).map
  284. $(REMOVE) $(TARGET).obj
  285. $(REMOVE) $(TARGET).a90
  286. $(REMOVE) $(TARGET).sym
  287. $(REMOVE) $(TARGET).lnk
  288. $(REMOVE) $(TARGET).lss
  289. $(REMOVE) $(OBJ)
  290. $(REMOVE) $(LST)
  291. $(REMOVE) $(SRC:.c=.s)
  292. $(REMOVE) $(SRC:.c=.d)
  293. $(REMOVE) .dep/*
  294. # Include the dependency files.
  295. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  296. # Listing of phony targets.
  297. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  298. build elf hex eep lss sym coff extcoff \
  299. clean clean_list program