Guest User

Untitled

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