My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 12KB

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