Advertisement
Guest User

Arduino 0017 Makefile

a guest
Sep 28th, 2009
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. # Arduino 0015 Makefile
  2. # Arduino adaptation by mellis, eighthave, oli.keller
  3. #
  4. # This makefile allows you to build sketches from the command line
  5. # without the Arduino environment (or Java).
  6. #
  7. # Detailed instructions for using the makefile:
  8. #
  9. # 1. Copy this file into the folder with your sketch. There should be a
  10. # file with the same name as the folder and with the extension .pde
  11. # (e.g. foo.pde in the foo/ folder).
  12. #
  13. # 2. Modify the line containg "INSTALL_DIR" to point to the directory that
  14. # contains the Arduino installation (for example, under Mac OS X, this
  15. # might be /Applications/arduino-0012).
  16. #
  17. # 3. Modify the line containing "PORT" to refer to the filename
  18. # representing the USB or serial connection to your Arduino board
  19. # (e.g. PORT = /dev/tty.USB0). If the exact name of this file
  20. # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
  21. #
  22. # 4. Set the line containing "MCU" to match your board's processor.
  23. # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
  24. # or Diecimila have the atmega168. If you're using a LilyPad Arduino,
  25. # change F_CPU to 8000000.
  26. #
  27. # 5. At the command line, change to the directory containing your
  28. # program's file and the makefile.
  29. #
  30. # 6. Type "make" and press enter to compile/verify your program.
  31. #
  32. # 7. Type "make upload", reset your Arduino board, and press enter to
  33. # upload your program to the Arduino board.
  34. #
  35. # $Id$
  36.  
  37. TARGET = main
  38. PORT = /dev/ttyUSB*
  39. UPLOAD_RATE = 57600
  40. AVRDUDE_PROGRAMMER = stk500v1
  41. MCU = atmega328p
  42. F_CPU = 16000000
  43.  
  44. ############################################################################
  45. # Below here nothing should be changed...
  46.  
  47. ARDUINO = ./arduino
  48.  
  49. SRC = $(ARDUINO)/pins_arduino.c \
  50. $(ARDUINO)/wiring.c \
  51. $(ARDUINO)/wiring_analog.c \
  52. $(ARDUINO)/wiring_digital.c \
  53. $(ARDUINO)/wiring_pulse.c \
  54. $(ARDUINO)/wiring_shift.c \
  55. $(ARDUINO)/WInterrupts.c
  56.  
  57. CXXSRC = $(ARDUINO)/HardwareSerial.cpp \
  58. $(ARDUINO)/WMath.cpp \
  59. $(ARDUINO)/Print.cpp
  60.  
  61. FORMAT = ihex
  62.  
  63.  
  64. # Name of this Makefile (used for "make depend").
  65. MAKEFILE = Makefile
  66.  
  67. # Debugging format.
  68. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  69. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  70. DEBUG = stabs
  71.  
  72. OPT = s
  73.  
  74. # Place -D or -U options here
  75. CDEFS = -DF_CPU=$(F_CPU)
  76. CXXDEFS = -DF_CPU=$(F_CPU)
  77.  
  78. # Place -I options here
  79. CINCS = -I$(ARDUINO)
  80. CXXINCS = -I$(ARDUINO)
  81.  
  82. # Compiler flag to set the C Standard level.
  83. # c89 - "ANSI" C
  84. # gnu89 - c89 plus GCC extensions
  85. # c99 - ISO C99 standard (not yet fully implemented)
  86. # gnu99 - c99 plus GCC extensions
  87. CSTANDARD = -std=gnu99
  88. CDEBUG = -g$(DEBUG)
  89. CWARN = -Wall -Wstrict-prototypes
  90. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  91. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  92.  
  93. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
  94. CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
  95. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  96. LDFLAGS = -lm
  97.  
  98.  
  99. # Programming support using avrdude. Settings and variables.
  100. AVRDUDE_PORT = $(PORT)
  101. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  102. AVRDUDE_FLAGS = -V -F -C /etc/avrdude.conf \
  103. -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
  104. -b $(UPLOAD_RATE)
  105.  
  106. # Program settings
  107. CC = avr-gcc
  108. CXX = avr-g++
  109. OBJCOPY = avr-objcopy
  110. OBJDUMP = avr-objdump
  111. AR = avr-ar
  112. SIZE = avr-size
  113. NM = avr-nm
  114. AVRDUDE = avrdude
  115. REMOVE = rm -f
  116. MV = mv -f
  117.  
  118. # Define all object files.
  119. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  120.  
  121. # Define all listing files.
  122. LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
  123.  
  124. # Combine all necessary flags and optional flags.
  125. # Add target processor to flags.
  126. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  127. ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
  128. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  129.  
  130.  
  131. # Default target.
  132. all: build sizeafter
  133.  
  134. build: elf hex
  135.  
  136. elf: $(TARGET).elf
  137. hex: $(TARGET).hex
  138. eep: $(TARGET).eep
  139. lss: $(TARGET).lss
  140. sym: $(TARGET).sym
  141.  
  142. # Program the device.
  143. upload: $(TARGET).hex
  144. stty -F $(AVRDUDE_PORT) hupcl
  145. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  146.  
  147.  
  148. # Display size of file.
  149. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  150. ELFSIZE = $(SIZE) $(TARGET).elf
  151. sizebefore:
  152. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
  153.  
  154. sizeafter:
  155. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
  156.  
  157.  
  158. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  159. COFFCONVERT=$(OBJCOPY) --debugging \
  160. --change-section-address .data-0x800000 \
  161. --change-section-address .bss-0x800000 \
  162. --change-section-address .noinit-0x800000 \
  163. --change-section-address .eeprom-0x810000
  164.  
  165.  
  166. coff: $(TARGET).elf
  167. $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
  168.  
  169.  
  170. extcoff: $(TARGET).elf
  171. $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
  172.  
  173.  
  174. .SUFFIXES: .elf .hex .eep .lss .sym
  175.  
  176. .elf.hex:
  177. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  178.  
  179. .elf.eep:
  180. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  181. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  182.  
  183. # Create extended listing file from ELF output file.
  184. .elf.lss:
  185. $(OBJDUMP) -h -S $< > $@
  186.  
  187. # Create a symbol table from ELF output file.
  188. .elf.sym:
  189. $(NM) -n $< > $@
  190.  
  191. # Link: create ELF output file from library.
  192. $(TARGET).elf: $(TARGET).cpp core.a
  193. $(CC) $(ALL_CFLAGS) -o $@ $(TARGET).cpp -L. core.a $(LDFLAGS)
  194.  
  195. core.a: $(OBJ)
  196. @for i in $(OBJ); do echo $(AR) rcs core.a $$i; $(AR) rcs core.a $$i; done
  197.  
  198.  
  199.  
  200. # Compile: create object files from C++ source files.
  201. .cpp.o:
  202. $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
  203.  
  204. # Compile: create object files from C source files.
  205. .c.o:
  206. $(CC) -c $(ALL_CFLAGS) $< -o $@
  207.  
  208.  
  209. # Compile: create assembler files from C source files.
  210. .c.s:
  211. $(CC) -S $(ALL_CFLAGS) $< -o $@
  212.  
  213.  
  214. # Assemble: create object files from assembler source files.
  215. .S.o:
  216. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  217.  
  218.  
  219. # Automatic dependencies
  220. %.d: %.c
  221. $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  222.  
  223. %.d: %.cpp
  224. $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  225.  
  226.  
  227. # Target: clean project.
  228. clean:
  229. $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
  230. $(TARGET).map $(TARGET).sym $(TARGET).lss core.a \
  231. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
  232.  
  233. .PHONY: all build elf hex eep lss sym program coff extcoff clean sizebefore sizeafter
  234.  
  235. #include $(SRC:.c=.d)
  236. #include $(CXXSRC:.cpp=.d)
  237.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement