Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # Sprinter Arduino Project Makefile
  2. #
  3. # Makefile Based on:
  4. # Arduino 0011 Makefile
  5. # Arduino adaptation by mellis, eighthave, oli.keller
  6. #
  7. # This has been tested with Arduino 0022.
  8. #
  9. # This makefile allows you to build sketches from the command line
  10. # without the Arduino environment (or Java).
  11. #
  12. # Detailed instructions for using the makefile:
  13. #
  14. # 1. Modify the line containg "INSTALL_DIR" to point to the directory that
  15. # contains the Arduino installation (for example, under Mac OS X, this
  16. # might be /Applications/arduino-0012).
  17. #
  18. # 2. Modify the line containing "PORT" to refer to the filename
  19. # representing the USB or serial connection to your Arduino board
  20. # (e.g. PORT = /dev/tty.USB0). If the exact name of this file
  21. # changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
  22. #
  23. # 3. Set the line containing "MCU" to match your board's processor.
  24. # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
  25. # or Diecimila have the atmega168. If you're using a LilyPad Arduino,
  26. # change F_CPU to 8000000.
  27. #
  28. # 4. Type "make" and press enter to compile/verify your program.
  29. #
  30. # 5. Type "make upload", reset your Arduino board, and press enter to
  31. # upload your program to the Arduino board.
  32. #
  33. # $Id$
  34. TARGET = $(notdir $(CURDIR))
  35. INSTALL_DIR = ../../arduino22/arduino-0022/
  36. UPLOAD_RATE = 38400
  37. AVRDUDE_PROGRAMMER = stk500v1
  38. PORT = /dev/ttyUSB0
  39. MCU = atmega2560
  40. #For "old" Arduino Mega
  41. #MCU = atmega1280
  42. #For Sanguinololu
  43. #MCU = atmega644p
  44. F_CPU = 16000000
  45. ############################################################################
  46. # Below here nothing should be changed...
  47. ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
  48. AVR_TOOLS_PATH = /usr/bin
  49. SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
  50. $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
  51. $(ARDUINO)/wiring_pulse.c \
  52. $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
  53. CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp $(ARDUINO)/WString.cpp\
  54. $(ARDUINO)/Print.cpp ./SdFile.cpp ./SdVolume.cpp ./Sd2Card.cpp ./heater.cpp ./arc_func.cpp ./store_eeprom.cpp
  55. FORMAT = ihex
  56. # Name of this Makefile (used for "make depend").
  57. MAKEFILE = Makefile
  58. # Debugging format.
  59. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  60. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  61. DEBUG = stabs
  62. OPT = s
  63. # Place -D or -U options here
  64. CDEFS = -DF_CPU=$(F_CPU)
  65. CXXDEFS = -DF_CPU=$(F_CPU)
  66. # Place -I options here
  67. CINCS = -I$(ARDUINO)
  68. CXXINCS = -I$(ARDUINO)
  69. # Compiler flag to set the C Standard level.
  70. # c89 - "ANSI" C
  71. # gnu89 - c89 plus GCC extensions
  72. # c99 - ISO C99 standard (not yet fully implemented)
  73. # gnu99 - c99 plus GCC extensions
  74. #CSTANDARD = -std=gnu99
  75. CDEBUG = -g$(DEBUG)
  76. CWARN = -Wall -Wstrict-prototypes
  77. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -w -ffunction-sections -fdata-sections -DARDUINO=22
  78. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  79. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING)
  80. CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING)
  81. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  82. LDFLAGS = -lm
  83. # Programming support using avrdude. Settings and variables.
  84. AVRDUDE_PORT = $(PORT)
  85. AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i
  86. AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \
  87. -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
  88. -b $(UPLOAD_RATE)
  89. # Program settings
  90. CC = $(AVR_TOOLS_PATH)/avr-gcc
  91. CXX = $(AVR_TOOLS_PATH)/avr-g++
  92. OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
  93. OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
  94. AR = $(AVR_TOOLS_PATH)/avr-ar
  95. SIZE = $(AVR_TOOLS_PATH)/avr-size
  96. NM = $(AVR_TOOLS_PATH)/avr-nm
  97. AVRDUDE = $(INSTALL_DIR)/hardware/tools/avrdude
  98. REMOVE = rm -f
  99. MV = mv -f
  100. # Define all object files.
  101. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  102. # Define all listing files.
  103. LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
  104. # Combine all necessary flags and optional flags.
  105. # Add target processor to flags.
  106. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
  107. ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
  108. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  109. # Default target.
  110. all: build sizeafter
  111. build: elf hex
  112. applet/$(TARGET).cpp: $(TARGET).pde
  113. # Here is the "preprocessing".
  114. # It creates a .cpp file based with the same name as the .pde file.
  115. # On top of the new .cpp file comes the WProgram.h header.
  116. # At the end there is a generic main() function attached.
  117. # Then the .cpp file will be compiled. Errors during compile will
  118. # refer to this new, automatically generated, file.
  119. # Not the original .pde file you actually edit...
  120. test -d applet || mkdir applet
  121. echo '#include "WProgram.h"' > applet/$(TARGET).cpp
  122. cat $(TARGET).pde >> applet/$(TARGET).cpp
  123. cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
  124. elf: applet/$(TARGET).elf
  125. hex: applet/$(TARGET).hex
  126. eep: applet/$(TARGET).eep
  127. lss: applet/$(TARGET).lss
  128. sym: applet/$(TARGET).sym
  129. # Program the device.
  130. upload: applet/$(TARGET).hex
  131. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  132. # Display size of file.
  133. HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
  134. ELFSIZE = $(SIZE) applet/$(TARGET).elf
  135. sizebefore:
  136. @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
  137. sizeafter:
  138. @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
  139. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  140. COFFCONVERT=$(OBJCOPY) --debugging \
  141. --change-section-address .data-0x800000 \
  142. --change-section-address .bss-0x800000 \
  143. --change-section-address .noinit-0x800000 \
  144. --change-section-address .eeprom-0x810000
  145. coff: applet/$(TARGET).elf
  146. $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
  147. extcoff: $(TARGET).elf
  148. $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
  149. .SUFFIXES: .elf .hex .eep .lss .sym
  150. .elf.hex:
  151. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  152. .elf.eep:
  153. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  154. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  155. # Create extended listing file from ELF output file.
  156. .elf.lss:
  157. $(OBJDUMP) -h -S $< > $@
  158. # Create a symbol table from ELF output file.
  159. .elf.sym:
  160. $(NM) -n $< > $@
  161. # Link: create ELF output file from library.
  162. applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a
  163. $(CC) $(ALL_CFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
  164. applet/core.a: $(OBJ)
  165. @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
  166. # Compile: create object files from C++ source files.
  167. .cpp.o:
  168. $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
  169. # Compile: create object files from C source files.
  170. .c.o:
  171. $(CC) -c $(ALL_CFLAGS) $< -o $@
  172. # Compile: create assembler files from C source files.
  173. .c.s:
  174. $(CC) -S $(ALL_CFLAGS) $< -o $@
  175. # Assemble: create object files from assembler source files.
  176. .S.o:
  177. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  178. # Target: clean project.
  179. clean:
  180. $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
  181. applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
  182. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
  183. depend:
  184. if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
  185. then \
  186. sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
  187. $(MAKEFILE).$$$$ && \
  188. $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
  189. fi
  190. echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
  191. >> $(MAKEFILE); \
  192. $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
  193. .PHONY: all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter