Advertisement
Guest User

Untitled

a guest
May 25th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. # Arduino makefile
  2. #
  3. # This makefile allows you to build sketches from the command line
  4. # without the Arduino environment (or Java).
  5. #
  6. # The Arduino environment does preliminary processing on a sketch before
  7. # compiling it. If you're using this makefile instead, you'll need to do
  8. # a few things differently:
  9. #
  10. # - Give your program's file a .cpp extension (e.g. foo.cpp).
  11. #
  12. # - Put this line at top of your code: #include <WProgram.h>
  13. #
  14. # - Write prototypes for all your functions (or define them before you
  15. # call them). A prototype declares the types of parameters a
  16. # function will take and what type of value it will return. This
  17. # means that you can have a call to a function before the definition
  18. # of the function. A function prototype looks like the first line of
  19. # the function, with a semi-colon at the end. For example:
  20. # int digitalRead(int pin);
  21. #
  22. # Instructions for using the makefile:
  23. #
  24. # 1. Copy this file into the folder with your sketch.
  25. #
  26. # 2. Below, modify the line containing "TARGET" to refer to the name of
  27. # of your program's file without an extension (e.g. TARGET = foo).
  28. #
  29. # 3. Modify the line containg "ARDUINO" to point the directory that
  30. # contains the Arduino core (for normal Arduino installations, this
  31. # is the lib/targets/arduino sub-directory).
  32. #
  33. # 4. Modify the line containing "PORT" to refer to the filename
  34. # representing the USB or serial connection to your Arduino board
  35. # (e.g. PORT = /dev/tty.USB0). If the exact name of this file
  36. # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
  37. #
  38. # 5. At the command line, change to the directory containing your
  39. # program's file and the makefile.
  40. #
  41. # 6. Type "make" and press enter to compile/verify your program.
  42. #
  43. # 7. Type "make upload", reset your Arduino board, and press enter to
  44. # upload your program to the Arduino board.
  45. #
  46. # $Id$
  47.  
  48. PORT = /dev/tty.usbserial*
  49. TARGET = foo
  50. ARDUINO = /Applications/arduino-0005/lib/targets/arduino
  51. SRC = $(ARDUINO)/buffer.c $(ARDUINO)/pins_arduino.c \
  52. $(ARDUINO)/Serial.c $(ARDUINO)/uart.c $(ARDUINO)/wiring.c
  53. CXXSRC = $(TARGET).cpp $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp
  54. MCU = atmega8
  55. F_CPU = 16000000
  56. FORMAT = ihex
  57. UPLOAD_RATE = 19200
  58.  
  59. # Name of this Makefile (used for "make depend").
  60. MAKEFILE = Makefile
  61.  
  62. # Debugging format.
  63. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  64. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  65. DEBUG = stabs
  66.  
  67. OPT = s
  68.  
  69. # Place -D or -U options here
  70. CDEFS = -DF_CPU=$(F_CPU)
  71. CXXDEFS = -DF_CPU=$(F_CPU)
  72.  
  73. # Place -I options here
  74. CINCS = -I$(ARDUINO)
  75. CXXINCS = -I$(ARDUINO)
  76.  
  77. # Compiler flag to set the C Standard level.
  78. # c89 - "ANSI" C
  79. # gnu89 - c89 plus GCC extensions
  80. # c99 - ISO C99 standard (not yet fully implemented)
  81. # gnu99 - c99 plus GCC extensions
  82. CSTANDARD = -std=gnu99
  83. CDEBUG = -g$(DEBUG)
  84. CWARN = -Wall -Wstrict-prototypes
  85. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  86. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  87.  
  88. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
  89. CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
  90. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  91. LDFLAGS =
  92.  
  93.  
  94. # Programming support using avrdude. Settings and variables.
  95. AVRDUDE_PROGRAMMER = stk500
  96. AVRDUDE_PORT = $(PORT)
  97. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  98. AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
  99. -b $(UPLOAD_RATE)
  100.  
  101. # Program settings
  102. CC = avr-gcc
  103. CXX = avr-g++
  104. OBJCOPY = avr-objcopy
  105. OBJDUMP = avr-objdump
  106. SIZE = avr-size
  107. NM = avr-nm
  108. AVRDUDE = avrdude
  109. REMOVE = rm -f
  110. MV = mv -f
  111.  
  112. # Define all object files.
  113. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  114.  
  115. # Define all listing files.
  116. LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
  117.  
  118. # Combine all necessary flags and optional flags.
  119. # Add target processor to flags.
  120. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  121. ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
  122. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  123.  
  124.  
  125. # Default target.
  126. all: build
  127.  
  128. build: elf hex eep
  129.  
  130. elf: $(TARGET).elf
  131. hex: $(TARGET).hex
  132. eep: $(TARGET).eep
  133. lss: $(TARGET).lss
  134. sym: $(TARGET).sym
  135.  
  136. # Program the device.
  137. upload: $(TARGET).hex $(TARGET).eep
  138. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  139.  
  140.  
  141.  
  142.  
  143. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  144. COFFCONVERT=$(OBJCOPY) --debugging \
  145. --change-section-address .data-0x800000 \
  146. --change-section-address .bss-0x800000 \
  147. --change-section-address .noinit-0x800000 \
  148. --change-section-address .eeprom-0x810000
  149.  
  150.  
  151. coff: $(TARGET).elf
  152. $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
  153.  
  154.  
  155. extcoff: $(TARGET).elf
  156. $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
  157.  
  158.  
  159. .SUFFIXES: .elf .hex .eep .lss .sym
  160.  
  161. .elf.hex:
  162. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  163.  
  164. .elf.eep:
  165. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  166. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  167.  
  168. # Create extended listing file from ELF output file.
  169. .elf.lss:
  170. $(OBJDUMP) -h -S $< > $@
  171.  
  172. # Create a symbol table from ELF output file.
  173. .elf.sym:
  174. $(NM) -n $< > $@
  175.  
  176.  
  177.  
  178. # Link: create ELF output file from object files.
  179. $(TARGET).elf: $(OBJ)
  180. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  181.  
  182.  
  183. # Compile: create object files from C++ source files.
  184. .cpp.o:
  185. $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
  186.  
  187. # Compile: create object files from C source files.
  188. .c.o:
  189. $(CC) -c $(ALL_CFLAGS) $< -o $@
  190.  
  191.  
  192. # Compile: create assembler files from C source files.
  193. .c.s:
  194. $(CC) -S $(ALL_CFLAGS) $< -o $@
  195.  
  196.  
  197. # Assemble: create object files from assembler source files.
  198. .S.o:
  199. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  200.  
  201.  
  202.  
  203. # Target: clean project.
  204. clean:
  205. $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
  206. $(TARGET).map $(TARGET).sym $(TARGET).lss \
  207. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
  208.  
  209. depend:
  210. if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
  211. then \
  212. sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
  213. $(MAKEFILE).$$$$ && \
  214. $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
  215. fi
  216. echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
  217. >> $(MAKEFILE); \
  218. $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
  219.  
  220. .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement