skrupellos

Ardruino makefile

Aug 21st, 2011
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # http://www.google.com/codesearch/p?hl=de#thaXon_DSGU/trunk/hardware/cores/arduino/Makefile&q=Makefile%20package:http://arduino%5C.googlecode%5C.com&sa=N&cd=8&ct=rc
  2. MCU = atmega1280
  3. F_CPU = 16000000    # 16 MHz
  4. AVRDUDE_PROGRAMMER = arduino
  5. AVRDUDE_PORT = /dev/ttyUSB0 # programmer connected to serial port
  6.  
  7.  
  8.  
  9.  
  10. FORMAT = ihex       # create a .hex file
  11.  
  12. OPT = 3         # assembly-level optimization
  13.  
  14. # Optional compiler flags.
  15. #  -g:        generate debugging information (for GDB, or for COFF conversion)
  16. #  -O*:       optimization level
  17. #  -f...:     tuning, see gcc manual and avr-libc documentation
  18. #  -Wall...:  warning level
  19. #  -Wa,...:   tell GCC to pass this to the assembler.
  20. #    -ahlms:  create assembler listing
  21. CFLAGS = -g -O$(OPT) \
  22. -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
  23. -Wall \
  24. -DF_CPU=$(F_CPU) \
  25. -Wa,-adhlns=$(<:.cpp=.lst) \
  26. $(patsubst %,-I%,$(EXTRAINCDIRS)) \
  27. -mmcu=$(MCU)
  28.  
  29. # Optional assembler flags.
  30. #  -Wa,...:   tell GCC to pass this to the assembler.
  31. #  -ahlms:    create listing
  32. #  -gstabs:   have the assembler create line number information; note that
  33. #             for use in COFF files, additional information about filenames
  34. #             and function names needs to be present in the assembler source
  35. #             files -- see avr-libc docs [FIXME: not yet described there]
  36. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  37.  
  38.  
  39. # Optional linker flags.
  40. #  -Wl,...:   tell GCC to pass this to linker.
  41. #  -Map:      create map file
  42. #  --cref:    add cross reference to  map file
  43. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  44.  
  45.  
  46. # ---------------------------------------------------------------------------
  47. # Programming support using avrdude.
  48. AVRDUDE = /usr/local/bin/avrdude
  49.  
  50. # Programming support using avrdude. Settings and variables.
  51.  
  52. AVRDUDE_WRITE_FLASH = -U flash:w:
  53.  
  54. UPLOAD_RATE = 57600
  55. #AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  56. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
  57.  -b $(UPLOAD_RATE) -q -D
  58.  
  59. # ---------------------------------------------------------------------------
  60.  
  61. # Define directories, if needed.
  62. #DIRAVR = c:/progra~1/winavr
  63. #DIRAVRBIN = $(DIRAVR)/bin
  64. #DIRAVRUTILS = $(DIRAVR)/utils/bin
  65. #DIRINC = .
  66. #DIRLIB = $(DIRAVR)/avr/lib
  67.  
  68.  
  69. # Define programs and commands.
  70. SHELL = sh
  71.  
  72. CC = avr-gcc
  73.  
  74. OBJCOPY = avr-objcopy
  75. OBJDUMP = avr-objdump
  76. SIZE = avr-size
  77.  
  78. REMOVE = rm -f
  79. COPY = cp
  80.  
  81. # Define Messages
  82. # English
  83. MSG_ERRORS_NONE = Errors: none
  84. MSG_BEGIN = -------- begin --------
  85. MSG_END = --------  end  --------
  86. MSG_SIZE_BEFORE = Size before:
  87. MSG_SIZE_AFTER = Size after:
  88. MSG_FLASHING = Flashing:
  89. MSG_PACKING = Creating load file for Flash:
  90. MSG_EXTENDED_LISTING = Creating Extended Listing:
  91. MSG_SYMBOL_TABLE = Creating Symbol Table:
  92. MSG_LINKING = Linking:
  93. MSG_COMPILING = Compiling:
  94. MSG_ASSEMBLING = Assembling:
  95. MSG_ASSEMBLING2 = Create assembler files from C source files for:
  96. MSG_CLEANING = Cleaning project:
  97.  
  98.  
  99. # Define all object files.
  100. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  101.  
  102. # Define all listing files.
  103. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  104.  
  105. # Combine all necessary flags and optional flags.
  106. # Add target processor to flags.
  107. ALL_CFLAGS = -I. $(CFLAGS)
  108. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  109.  
  110.  
  111.  
  112.  
  113. # Eye candy.
  114. # AVR Studio 3.x does not check make's exit code but relies on
  115. # the following magic strings to be generated by the compile job.
  116. begin:
  117.     @echo
  118.     @echo $(MSG_BEGIN)
  119.  
  120. finished:
  121.     @echo $(MSG_ERRORS_NONE)
  122.  
  123. end:
  124.     @echo $(MSG_END)
  125.     @echo
  126.  
  127.  
  128.  
  129. # Display compiler version information.
  130. gccversion :
  131.     @$(CC) --version
  132.  
  133.  
  134. # Default target.
  135. all: begin gccversion flash-main finished end
  136.  
  137. # this is necessary if you're burning the AVR for the first time...
  138. # sets the proper fuse for external clock with no clk div
  139. burn-fuse:
  140.     $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U lfuse:w:0xE0:m
  141.  
  142.  
  143. %: begin flash-% finished end
  144.  
  145.  
  146. # this programs the dependant hex file using our default avrdude flags
  147. flash-%: %.hex
  148.     @echo
  149.     @echo $(MSG_FLASHING) $@
  150.     #stty -F /dev/ttyUSB0 hupcl
  151.     @echo $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)$<
  152.     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)$<
  153.     # stty -F /dev/ttyUSB0 hupcl
  154.    
  155. bootloader:
  156.     @echo
  157.     @echo $(MSG_FLASHING) $@
  158.     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)bootload.hex
  159.  
  160.  
  161. # Create final output files (.hex) from ELF output file.
  162. %.hex: %.elf
  163.     @echo
  164.     @echo $(MSG_PACKING) $@
  165.     $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  166.  
  167.  
  168. # Link: create ELF output file from object files.
  169. .SECONDARY : $(TARGET).elf
  170. .PRECIOUS : $(OBJ)
  171. %.elf: %.o
  172.     @echo
  173.     @echo $(MSG_LINKING) $@
  174.     $(CC) $(ALL_CFLAGS) $< --output $@ $(LDFLAGS)
  175.  
  176.  
  177. # Compile: create object files from C source files.
  178. %.o : %.cpp
  179.     @echo
  180.     @echo $(MSG_COMPILING) $<
  181.     $(CC) -c $(ALL_CFLAGS) $< -o $@
  182.  
  183.  
  184. # Compile: create assembler files from C source files.
  185. %.s : %.cpp
  186.     @echo
  187.     @echo $(MSG_ASSEMBLING2) $<
  188.     $(CC) -S $(ALL_CFLAGS) $< -o $@
  189.  
  190.  
  191. # Assemble: create object files from assembler source files.
  192. %.o : %.S
  193.     @echo
  194.     @echo $(MSG_ASSEMBLING) $<
  195.     $(CC) -c $(ALL_ASFLAGS) $< -o $@
  196.  
  197.  
  198.  
  199.  
  200.  
  201. # Target: clean project.
  202. clean: begin clean_list finished end
  203.  
  204. clean_list :
  205.     @echo
  206.     @echo $(MSG_CLEANING)
  207.     $(REMOVE) *.hex
  208.     $(REMOVE) *.lst
  209.     $(REMOVE) *.obj
  210.     $(REMOVE) *.elf
  211.     $(REMOVE) *.o
  212.  
  213. # Listing of phony targets.
  214. .PHONY : all begin finish end \
  215.     clean clean_list program
RAW Paste Data