tovis

AVR makefile

May 21st, 2015
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 10.22 KB | None | 0 0
  1. # http://wiki.hacdc.org/index.php/AVR_Makefile
  2.  
  3. # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
  4. # Modified (bringing often-changed options to the top) by Elliot Williams
  5.  
  6. # make all = Make software and program
  7. # make clean = Clean out built project files.
  8. # make program = Download the hex file to the device, using avrdude.  Please
  9. #                customize the avrdude settings below first!
  10.  
  11. # Microcontroller Type
  12. # MCU = attiny13
  13. # MCU = attiny2313
  14. # MCU = atmega8
  15. # MCU = attiny45
  16. MCU = atmega16
  17.  
  18. # Target file name (without extension).
  19. TARGET = timi5
  20.  
  21. # Programming hardware: type avrdude -c ?
  22. # to get a full listing.
  23. # AVRDUDE_PROGRAMMER = dapa
  24. # AVRDUDE_PROGRAMMER = usbtiny      
  25. # AVRDUDE_PROGRAMMER = dt006
  26. AVRDUDE_PROGRAMMER = jtag1
  27.  
  28. # AVRDUDE_PORT = /dev/usb    # not really needed for usb
  29. AVRDUDE_PORT = /dev/ttyUSB0
  30. # AVRDUDE_PORT = /dev/parport0         # linux
  31. # AVRDUDE_PORT = lpt1              # windows
  32.  
  33. ############# Don't need to change below here for most purposes  (Elliot)
  34.  
  35. # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
  36. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  37. OPT = s
  38.  
  39. # Output format. (can be srec, ihex, binary)
  40. FORMAT = ihex
  41.  
  42. # List C source files here. (C dependencies are automatically generated.)
  43. # SRC = $(TARGET).c
  44.  
  45. # If there is more than one source file, append them above, or modify and
  46. # uncomment the following:
  47. #SRC += foo.c bar.c
  48.  
  49. # You can also wrap lines by appending a backslash to the end of the line:
  50. #SRC += baz.c \
  51. #xyzzy.c
  52. SRC = timi5.c
  53.  
  54.  
  55. # List Assembler source files here.
  56. # Make them always end in a capital .S.  Files ending in a lowercase .s
  57. # will not be considered source files but generated files (assembler
  58. # output from the compiler), and will be deleted upon "make clean"!
  59. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  60. # it will preserve the spelling of the filenames, and gcc itself does
  61. # care about how the name is spelled on its command-line.
  62. ASRC = timi5_isr.S
  63.  
  64.  
  65. # List any extra directories to look for include files here.
  66. #     Each directory must be seperated by a space.
  67. EXTRAINCDIRS =
  68.  
  69.  
  70. # Optional compiler flags.
  71. #  -g:        generate debugging information (for GDB, or for COFF conversion)
  72. #  -O*:       optimization level
  73. #  -f...:     tuning, see gcc manual and avr-libc documentation
  74. #  -Wall...:  warning level
  75. #  -Wa,...:   tell GCC to pass this to the assembler.
  76. #    -ahlms:  create assembler listing
  77. CFLAGS = -g -O$(OPT) \
  78. -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
  79. -Wall -Wstrict-prototypes \
  80. -Wa,-adhlns=$(<:.c=.lst) \
  81. $(patsubst %,-I%,$(EXTRAINCDIRS))
  82.  
  83.  
  84. # Set a "language standard" compiler flag.
  85. #   Unremark just one line below to set the language standard to use.
  86. #   gnu99 = C99 + GNU extensions. See GCC manual for more information.
  87. #CFLAGS += -std=c89
  88. #CFLAGS += -std=gnu89
  89. #CFLAGS += -std=c99
  90. CFLAGS += -std=gnu99
  91.  
  92.  
  93.  
  94. # Optional assembler flags.
  95. #  -Wa,...:   tell GCC to pass this to the assembler.
  96. #  -ahlms:    create listing
  97. #  -gstabs:   have the assembler create line number information; note that
  98. #             for use in COFF files, additional information about filenames
  99. #             and function names needs to be present in the assembler source
  100. #             files -- see avr-libc docs [FIXME: not yet described there]
  101. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  102.  
  103.  
  104.  
  105. # Optional linker flags.
  106. #  -Wl,...:   tell GCC to pass this to linker.
  107. #  -Map:      create map file
  108. #  --cref:    add cross reference to  map file
  109. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  110.  
  111.  
  112.  
  113. # Additional libraries
  114.  
  115. # Minimalistic printf version
  116. #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
  117.  
  118. # Floating point printf version (requires -lm below)
  119. #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
  120.  
  121. # -lm = math library
  122. LDFLAGS += -lm
  123.  
  124.  
  125. # Programming support using avrdude. Settings and variables.
  126.  
  127.  
  128. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  129. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  130.  
  131. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  132.  
  133. # Uncomment the following if you want avrdude's erase cycle counter.
  134. # Note that this counter needs to be initialized first using -Yn,
  135. # see avrdude manual.
  136. #AVRDUDE_ERASE += -y
  137.  
  138. # Uncomment the following if you do /not/ wish a verification to be
  139. # performed after programming the device.
  140. #AVRDUDE_FLAGS += -V
  141.  
  142. # Increase verbosity level.  Please use this when submitting bug
  143. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  144. # to submit bug reports.
  145. #AVRDUDE_FLAGS += -v -v
  146.  
  147. #Run while cable attached or don't
  148. AVRDUDE_FLAGS += -E reset #keep chip disabled while cable attached
  149. #AVRDUDE_FLAGS += -E noreset
  150.  
  151. #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock
  152.  
  153. #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode
  154.  
  155. #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time
  156.  
  157. # ---------------------------------------------------------------------------
  158.  
  159. # Define directories, if needed.
  160. DIRAVR = c:/winavr
  161. DIRAVRBIN = $(DIRAVR)/bin
  162. DIRAVRUTILS = $(DIRAVR)/utils/bin
  163. DIRINC = .
  164. DIRLIB = $(DIRAVR)/avr/lib
  165.  
  166.  
  167. # Define programs and commands.
  168. SHELL = sh
  169.  
  170. CC = avr-gcc
  171.  
  172. OBJCOPY = avr-objcopy
  173. OBJDUMP = avr-objdump
  174. SIZE = avr-size
  175.  
  176.  
  177. # Programming support using avrdude.
  178. AVRDUDE = avrdude
  179.  
  180.  
  181. REMOVE = rm -f
  182. COPY = cp
  183.  
  184. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  185. ELFSIZE = $(SIZE) -A $(TARGET).elf
  186.  
  187.  
  188.  
  189. # Define Messages
  190. # English
  191. MSG_ERRORS_NONE = Errors: none
  192. MSG_BEGIN = -------- begin --------
  193. MSG_END = --------  end  --------
  194. MSG_SIZE_BEFORE = Size before:
  195. MSG_SIZE_AFTER = Size after:
  196. MSG_COFF = Converting to AVR COFF:
  197. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  198. MSG_FLASH = Creating load file for Flash:
  199. MSG_EEPROM = Creating load file for EEPROM:
  200. MSG_EXTENDED_LISTING = Creating Extended Listing:
  201. MSG_SYMBOL_TABLE = Creating Symbol Table:
  202. MSG_LINKING = Linking:
  203. MSG_COMPILING = Compiling:
  204. MSG_ASSEMBLING = Assembling:
  205. MSG_CLEANING = Cleaning project:
  206.  
  207.  
  208.  
  209.  
  210. # Define all object files.
  211. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  212.  
  213. # Define all listing files.
  214. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  215.  
  216. # Combine all necessary flags and optional flags.
  217. # Add target processor to flags.
  218. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  219. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  220.  
  221.  
  222.  
  223. # Default target: make program!
  224. all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
  225.     $(TARGET).lss $(TARGET).sym sizeafter finished end
  226. #   $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  227.  
  228. # Eye candy.
  229. # AVR Studio 3.x does not check make's exit code but relies on
  230. # the following magic strings to be generated by the compile job.
  231. begin:
  232.     @echo
  233.     @echo $(MSG_BEGIN)
  234.  
  235. finished:
  236.     @echo $(MSG_ERRORS_NONE)
  237.  
  238. end:
  239.     @echo $(MSG_END)
  240.     @echo
  241.  
  242.  
  243. # Display size of file.
  244. sizebefore:
  245.     @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  246.  
  247. sizeafter:
  248.     @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  249.  
  250.  
  251.  
  252. # Display compiler version information.
  253. gccversion :
  254.     @$(CC) --version
  255.  
  256.  
  257.  
  258.  
  259. # Convert ELF to COFF for use in debugging / simulating in
  260. # AVR Studio or VMLAB.
  261. COFFCONVERT=$(OBJCOPY) --debugging \
  262.     --change-section-address .data-0x800000 \
  263.     --change-section-address .bss-0x800000 \
  264.     --change-section-address .noinit-0x800000 \
  265.     --change-section-address .eeprom-0x810000
  266.  
  267.  
  268. coff: $(TARGET).elf
  269.     @echo
  270.     @echo $(MSG_COFF) $(TARGET).cof
  271.     $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  272.  
  273.  
  274. extcoff: $(TARGET).elf
  275.     @echo
  276.     @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  277.     $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  278.  
  279.  
  280.  
  281.  
  282. # Program the device.  
  283. program: $(TARGET).hex $(TARGET).eep
  284.     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  285.  
  286.  
  287.  
  288.  
  289. # Create final output files (.hex, .eep) from ELF output file.
  290. %.hex: %.elf
  291.     @echo
  292.     @echo $(MSG_FLASH) $@
  293.     $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  294.  
  295. %.eep: %.elf
  296.     @echo
  297.     @echo $(MSG_EEPROM) $@
  298.     -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  299.     --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  300.  
  301. # Create extended listing file from ELF output file.
  302. %.lss: %.elf
  303.     @echo
  304.     @echo $(MSG_EXTENDED_LISTING) $@
  305.     $(OBJDUMP) -h -S $< > $@
  306.  
  307. # Create a symbol table from ELF output file.
  308. %.sym: %.elf
  309.     @echo
  310.     @echo $(MSG_SYMBOL_TABLE) $@
  311.     avr-nm -n $< > $@
  312.  
  313.  
  314.  
  315. # Link: create ELF output file from object files.
  316. .SECONDARY : $(TARGET).elf
  317. .PRECIOUS : $(OBJ)
  318. %.elf: $(OBJ)
  319.     @echo
  320.     @echo $(MSG_LINKING) $@
  321.     $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  322.  
  323.  
  324. # Compile: create object files from C source files.
  325. %.o : %.c
  326.     @echo
  327.     @echo $(MSG_COMPILING) $<
  328.     $(CC) -c $(ALL_CFLAGS) $< -o $@
  329.  
  330.  
  331. # Compile: create assembler files from C source files.
  332. %.s : %.c
  333.     $(CC) -S $(ALL_CFLAGS) $< -o $@
  334.  
  335.  
  336. # Assemble: create object files from assembler source files.
  337. %.o : %.S
  338.     @echo
  339.     @echo $(MSG_ASSEMBLING) $<
  340.     $(CC) -c $(ALL_ASFLAGS) $< -o $@
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347. # Target: clean project.
  348. clean: begin clean_list finished end
  349.  
  350. clean_list :
  351.     @echo
  352.     @echo $(MSG_CLEANING)
  353.     $(REMOVE) $(TARGET).hex
  354.     $(REMOVE) $(TARGET).eep
  355.     $(REMOVE) $(TARGET).obj
  356.     $(REMOVE) $(TARGET).cof
  357.     $(REMOVE) $(TARGET).elf
  358.     $(REMOVE) $(TARGET).map
  359.     $(REMOVE) $(TARGET).obj
  360.     $(REMOVE) $(TARGET).a90
  361.     $(REMOVE) $(TARGET).sym
  362.     $(REMOVE) $(TARGET).lnk
  363.     $(REMOVE) $(TARGET).lss
  364.     $(REMOVE) $(OBJ)
  365.     $(REMOVE) $(LST)
  366.     $(REMOVE) $(SRC:.c=.s)
  367.     $(REMOVE) $(SRC:.c=.d)
  368.     $(REMOVE) *~
  369.  
  370. # Automatically generate C source code dependencies.
  371. # (Code originally taken from the GNU make user manual and modified
  372. # (See README.txt Credits).)
  373. #
  374. # Note that this will work with sh (bash) and sed that is shipped with WinAVR
  375. # (see the SHELL variable defined above).
  376. # This may not work with other shells or other seds.
  377. #
  378. %.d: %.c
  379.     set -e; $(CC) -MM $(ALL_CFLAGS) $< \
  380.     | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
  381.     [ -s $@ ] || rm -f $@
  382.  
  383.  
  384. # Remove the '-' if you want to see the dependency files generated.
  385. -include $(SRC:.c=.d)
  386.  
  387.  
  388.  
  389. # Listing of phony targets.
  390. .PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
  391.     clean clean_list program
Advertisement
Add Comment
Please, Sign In to add comment