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

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