My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Makefile 12KB

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