My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Makefile 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. TARGET = $(notdir $(CURDIR))
  2. # CHANGE BELOW:
  3. #~ INSTALL_DIR = /Applications/Arduino.app/Contents/Resources/Java
  4. INSTALL_DIR = /home/bkubicek/software/arduino-0023
  5. #~ PORT = /dev/cu.usbserial*
  6. PORT = /dev/ttyACM0
  7. # Get these values from:
  8. # $(INSTALL_DIR)/hardware/boards.txt
  9. # (arduino-0022/hardware/arduino/boards.txt)
  10. # The values below are for the "Arduino Duemilanove or Nano w/ ATmega328"
  11. # now for "Arduino Mega 2560"
  12. UPLOAD_SPEED = 115200
  13. UPLOAD_PROTOCOL = stk500v2
  14. BUILD_MCU = atmega2560
  15. BUILD_F_CPU = 16000000L
  16. TERM=bash
  17. # getting undefined reference to `__cxa_pure_virtual'
  18. #~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
  19. #~ http://www.arduino.cc/playground/OpenBSD/CLI
  20. #~ [http://arduino.cc/forum/index.php?topic=52041.0 A "simple" makefile for Arduino]
  21. #~ [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275488191 Arduino Forum - Configuring avr-gcc options in arduino IDE]
  22. # found in /usr/lib/gcc/avr/4.3.5/cc1plus; fixed with -Wl,--gc-section
  23. ############################################################################
  24. # Below here nothing should be changed...
  25. LINKORDER=\
  26. applet/Marlin.cpp.o \
  27. applet/EEPROM.o \
  28. applet/main.o \
  29. applet/MarlinSerial.o \
  30. applet/motion_control.o\
  31. applet/pins_arduino.o\
  32. applet/planner.o\
  33. applet/Print.o\
  34. applet/Sd2Card.o\
  35. applet/SdBaseFile.o\
  36. applet/SdFatUtil.o\
  37. applet/SdFile.o\
  38. applet/SdVolume.o\
  39. applet/stepper.o\
  40. applet/temperature.o\
  41. applet/WInterrupts.o\
  42. applet/wiring_analog.o\
  43. applet/wiring_digital.o\
  44. applet/wiring.o\
  45. applet/wiring_pulse.o\
  46. applet/wiring_shift.o\
  47. applet/WMath.o
  48. PDES=Marlin.pde ultralcd.pde watchdog.pde cardreader.pde
  49. ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
  50. #
  51. #~ AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
  52. # in Ubuntu, avr-gcc is installed separate;
  53. # only avrdude comes with the IDE
  54. AVR_TOOLS_PATH = /usr/bin
  55. AVR_DUDE_PATH = $(INSTALL_DIR)/hardware/tools
  56. #
  57. SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
  58. $(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
  59. $(ARDUINO)/wiring_pulse.c \
  60. $(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
  61. # added applet/$(TARGET).cpp as in IDE 0022
  62. CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp \
  63. $(ARDUINO)/Print.cpp \
  64. $(ARDUINO)/main.cpp
  65. # applet/$(TARGET).cpp # no need, having a rule now for applet/$(TARGET).cpp.o
  66. # added main.cpp, as in 0022
  67. FORMAT = ihex
  68. # Name of this Makefile (used for "make depend").
  69. MAKEFILE = Makefile
  70. # Debugging format.
  71. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  72. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  73. DEBUG = stabs
  74. OPT = 2
  75. # Place -D or -U options here
  76. #~ CDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
  77. #~ CXXDEFS = -DBUILD_F_CPU=$(BUILD_F_CPU)
  78. # now called DF_CPU
  79. CDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=23
  80. CXXDEFS = -DF_CPU=$(BUILD_F_CPU) -DARDUINO=23
  81. # Place -I options here
  82. CINCS = -I$(ARDUINO) -I$(INSTALL_DIR)/libraries/LiquidCrystal/ -I$(INSTALL_DIR)/libraries/EEPROM/
  83. CXXINCS = -I$(ARDUINO)
  84. # Compiler flag to set the C Standard level.
  85. # c89 - "ANSI" C
  86. # gnu89 - c89 plus GCC extensions
  87. # c99 - ISO C99 standard (not yet fully implemented)
  88. # gnu99 - c99 plus GCC extensions
  89. CSTANDARD = -std=gnu99
  90. CDEBUG = -g$(DEBUG)
  91. # note that typically, IDE 0022 uses -w to suppress warnings (both in cpp and c)!
  92. CWARN = -Wall
  93. #~ CWARN = -w
  94. # "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++:
  95. CCWARN = -Wstrict-prototypes
  96. CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  97. #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
  98. # to eliminate pins_ardiuno warnings:
  99. # http://arduino.cc/pipermail/developers_arduino.cc/2010-December/004005.html
  100. # [http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254180518 Arduino Forum - Makefile]
  101. #~ For building the objects files "-ffunction-sections -fdata-sections" was missing
  102. #~ and the final avr-gcc call needs "-Wl,--gc-section".
  103. CXSECTF = -fno-exceptions -ffunction-sections -fdata-sections
  104. CFINALF = -Wl,--gc-section
  105. CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CCWARN) $(CSTANDARD) $(CEXTRA)
  106. # added CWARN also to .cpp
  107. CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CXSECTF)
  108. #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  109. LDFLAGS = -lm
  110. # Programming support using avrdude. Settings and variables.
  111. AVRDUDE_PORT = $(PORT)
  112. AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
  113. AVRDUDE_FLAGS = -V -F \
  114. -p $(BUILD_MCU) -P $(AVRDUDE_PORT) -c $(UPLOAD_PROTOCOL) \
  115. -b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avrdude.conf
  116. # -b $(UPLOAD_SPEED) -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf
  117. # Program settings
  118. CC = $(AVR_TOOLS_PATH)/avr-gcc
  119. CXX = $(AVR_TOOLS_PATH)/avr-g++
  120. OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
  121. OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
  122. AR = $(AVR_TOOLS_PATH)/avr-ar
  123. SIZE = $(AVR_TOOLS_PATH)/avr-size
  124. NM = $(AVR_TOOLS_PATH)/avr-nm
  125. #~ AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
  126. AVRDUDE = $(AVR_DUDE_PATH)/avrdude
  127. REMOVE = rm -f
  128. MV = mv -f
  129. # Define all object files.
  130. # NOTE: obj files will be created in respective src directories (libraries or $(INSTALL_DIR));
  131. # make clean deletes them fine
  132. # note that srcs are in libraries or other directories;
  133. # $(CXXSRC:.cpp=.o) will cause obj files to be in same loc as src files
  134. #~ OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  135. # to change the output directory for object files;
  136. # must change the obj list here!
  137. # and then, match to corresponding rule somehow?
  138. # or leave this - and parse in rule (auth automatic variable $(@F))?
  139. # "Suffix Replacement"
  140. CXXSRC+=MarlinSerial.cpp SdBaseFile.cpp stepper.cpp motion_control.cpp SdFatUtil.cpp temperature.cpp planner.cpp SdFile.cpp Sd2Card.cpp SdVolume.cpp
  141. OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
  142. # added - OBJ list, transformed into applet/
  143. OBJT = $(addprefix applet/,$(notdir $(OBJ)))
  144. ALLSRC = $(SRC) $(CXXSRC) $(ASRC)
  145. # Define all listing files.
  146. LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
  147. # Combine all necessary flags and optional flags.
  148. # Add target processor to flags.
  149. ALL_CFLAGS = -mmcu=$(BUILD_MCU) -I. $(CFLAGS)
  150. ALL_CXXFLAGS = -mmcu=$(BUILD_MCU) -I. $(CXXFLAGS)
  151. ALL_ASFLAGS = -mmcu=$(BUILD_MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  152. # depended libraries of .pde need to be added from
  153. # $(INSTALL_DIR)/libraries (TODO: and/or ~/sketchbook/libraries)
  154. # grep for 'include', test if exists, add...
  155. # note: prefix "a real tab character" http://www.delorie.com/djgpp/doc/ug/larger/makefiles.html
  156. # $$ to escape $ for shell;
  157. # note: must NOT put comments # inside bash execution;
  158. # those would get removed by make; making shell see "EOF in backquote substitution"
  159. # echo $$ix ; \
  160. # 'shell' twice - for each subprocess! Backtick doesn't get expanded?
  161. GREPRES:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
  162. if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
  163. LINCS="$$LINCS -I$(INSTALL_DIR)/libraries/$$ix" ;\
  164. fi; \
  165. done; \
  166. echo $$LINCS)
  167. # append includes:
  168. CINCS += $(GREPRES)
  169. CXXINCS += $(GREPRES)
  170. # append library source .cpp files too (CXXSRC)
  171. GREPRESB:=$(shell for ix in $(shell grep include $(TARGET).pde | sed 's/.*[<"]\(.*\).h[>"].*/\1/'); do \
  172. if [ -d $(INSTALL_DIR)/libraries/$$ix ] ; then \
  173. CPPSRCS="$$CPPSRCS $(INSTALL_DIR)/libraries/$$ix/*.cpp" ;\
  174. fi; \
  175. done; \
  176. echo $$CPPSRCS)
  177. CXXSRC += $(GREPRESB)
  178. # added - only CXX obj from libraries:
  179. CXXLIBOBJ = $(GREPRESB:.cpp=.o)
  180. # Default target.
  181. all: applet_files build sizeafter
  182. build: elf hex
  183. applet_files: $(TARGET).pde
  184. # Here is the "preprocessing".
  185. # It creates a .cpp file based with the same name as the .pde file.
  186. # On top of the new .cpp file comes the WProgram.h header.
  187. # At the end there is a generic main() function attached.
  188. # Then the .cpp file will be compiled. Errors during compile will
  189. # refer to this new, automatically generated, file.
  190. # Not the original .pde file you actually edit...
  191. test -d applet || mkdir applet
  192. # @ supresses printout of the cmdline itself; so only the out of echo is printed
  193. @echo ALL OBJT: $(OBJT)
  194. @echo ALL CXXLIBOBJ: $(CXXLIBOBJ)
  195. # echo '#include "WProgram.h"' > applet/$(TARGET).cpp
  196. @echo "#include \"WProgram.h\"\nvoid setup();\nvoid loop();\n" > applet/$(TARGET).cpp
  197. ##cat $(TARGET).pde >> applet/$(TARGET).cpp
  198. cat ${PDES}>> applet/$(TARGET).cpp
  199. cp *.cpp applet/
  200. # no more need to cat main.cpp (v0022) - now it is compiled in
  201. # cat $(ARDUINO)/main.cpp >> applet/$(TARGET).cpp
  202. elf: applet/$(TARGET).elf
  203. hex: applet/$(TARGET).hex
  204. eep: applet/$(TARGET).eep
  205. lss: applet/$(TARGET).lss
  206. sym: applet/$(TARGET).sym
  207. # Program the device.
  208. upload: applet/$(TARGET).hex
  209. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
  210. # Display size of file.
  211. HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
  212. ELFSIZE = $(SIZE) applet/$(TARGET).elf
  213. sizebefore:
  214. @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
  215. sizeafter:
  216. @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
  217. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  218. COFFCONVERT=$(OBJCOPY) --debugging \
  219. --change-section-address .data-0x800000 \
  220. --change-section-address .bss-0x800000 \
  221. --change-section-address .noinit-0x800000 \
  222. --change-section-address .eeprom-0x810000
  223. coff: applet/$(TARGET).elf
  224. $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
  225. extcoff: $(TARGET).elf
  226. $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
  227. .SUFFIXES: .elf .hex .eep .lss .sym
  228. .elf.hex:
  229. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  230. .elf.eep:
  231. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  232. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  233. # Create extended listing file from ELF output file.
  234. .elf.lss:
  235. $(OBJDUMP) -h -S $< > $@
  236. # Create a symbol table from ELF output file.
  237. .elf.sym:
  238. $(NM) -n $< > $@
  239. # Link: create ELF output file from library.
  240. # NOTE: applet/$(TARGET).cpp.o MUST BE BEFORE applet/core.a
  241. # in the dependency list, so its rule runs first!
  242. applet/$(TARGET).elf: $(TARGET).pde applet/$(TARGET).cpp.o applet/core.a
  243. # $(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
  244. # changed as in IDE v0022: link cpp obj files
  245. @echo $$(tput bold)$$(tput setaf 2) $(CC) $$(tput sgr0) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
  246. echo ${OBJT}
  247. #$(CC) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/$(TARGET).cpp.o -L. applet/core.a $(LDFLAGS)
  248. $(CC) $(ALL_CFLAGS) $(CFINALF) -o $@ ${LINKORDER} $(LDFLAGS)
  249. #@$(CC) $(ALL_CFLAGS) $(CFINALF) -o $@ applet/*.o applet/$(TARGET).cpp.o $(CXXOBJ) -L. applet/core.a $(LDFLAGS)
  250. # added: cpp.o depends on cpp (and .pde which generates it)
  251. # $< "first item in the dependencies list"; $@ "left side of the :"; $^ "right side of the :"
  252. # http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
  253. applet/$(TARGET).cpp.o: applet/$(TARGET).cpp
  254. @echo $$(tput bold) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $< -o $@
  255. @$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
  256. #~ applet/core.a: $(OBJ)
  257. #~ @for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
  258. applet/core.a: $(OBJT)
  259. @for i in $(OBJT); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
  260. # iterate through OBJ to find the original location; then build depending on source extension
  261. # TODO: add handling of assembler files
  262. applet/%.o:
  263. @for iob in $(OBJ); do \
  264. if [ "`basename $$iob`" = "`basename $@`" ]; then \
  265. for ios in $(ALLSRC); do \
  266. if [ "$${iob%%.*}" = "$${ios%%.*}" ]; then \
  267. case $${ios##*.} in \
  268. "cpp") \
  269. echo "$$(tput bold)$$(tput setaf 1) $(CXX) $$(tput sgr0) -c $(ALL_CXXFLAGS) $$ios -o $@"; \
  270. $(CXX) -c $(ALL_CXXFLAGS) $$ios -o $@;; \
  271. "c") \
  272. echo "$$(tput bold)$$(tput setaf 1) $(CC) $$(tput sgr0) -c $(ALL_CFLAGS) $$ios -o $@"; \
  273. $(CC) -c $(ALL_CFLAGS) $$ios -o $@;; \
  274. esac; \
  275. fi; \
  276. done; \
  277. fi; \
  278. done;
  279. #~ # Compile: create object files from C++ source files.
  280. #~ .cpp.o:
  281. #~ $(CXX) -c $(ALL_CXXFLAGS) $< -o $@
  282. #~ # Compile: create object files from C source files.
  283. #~ .c.o:
  284. #~ $(CC) -c $(ALL_CFLAGS) $< -o $@
  285. #~ # Compile: create assembler files from C source files.
  286. #~ .c.s:
  287. #~ $(CC) -S $(ALL_CFLAGS) $< -o $@
  288. #~ # Assemble: create object files from assembler source files.
  289. #~ .S.o:
  290. #~ $(CC) -c $(ALL_ASFLAGS) $< -o $@
  291. #~ # Automatic dependencies
  292. #~ %.d: %.c
  293. #~ $(CC) -M $(ALL_CFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  294. #~ %.d: %.cpp
  295. #~ $(CXX) -M $(ALL_CXXFLAGS) $< | sed "s;$(notdir $*).o:;$*.o $*.d:;" > $@
  296. # Target: clean project.
  297. clean:
  298. $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
  299. applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
  300. $(OBJT) applet/$(TARGET).cpp.o \
  301. $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
  302. .PHONY: all build elf hex eep lss sym program coff extcoff clean applet_files sizebefore sizeafter