daily pastebin goal
56%
SHARE
TWEET

Makefile

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