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 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #
  2. # Arduino 0022 Makefile
  3. # Uno with DOGS102 Shield
  4. #
  5. # written by olikraus@gmail.com
  6. #
  7. # Features:
  8. # - boards.txt is used to derive parameters
  9. # - All intermediate files are put into a separate directory (TMPDIRNAME)
  10. # - Simple use: Copy Makefile into the same directory of the .pde file
  11. #
  12. # Limitations:
  13. # - requires UNIX environment
  14. # - TMPDIRNAME must be subdirectory of the current directory.
  15. #
  16. # Targets
  17. # all build everything
  18. # upload build and upload to arduino
  19. # clean remove all temporary files (includes final hex file)
  20. #
  21. # History
  22. # 001 28 Apr 2010 first release
  23. # 002 05 Oct 2010 added 'uno'
  24. #
  25. #=== user configuration ===
  26. # All ...PATH variables must have a '/' at the end
  27. # Board (and prozessor) information: see $(ARDUINO_PATH)hardware/arduino/boards.txt
  28. # Some examples:
  29. # BOARD DESCRIPTION
  30. # uno Arduino Uno
  31. # atmega328 Arduino Duemilanove or Nano w/ ATmega328
  32. # diecimila Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
  33. # mega Arduino Mega
  34. # mini Arduino Mini
  35. # lilypad328 LilyPad Arduino w/ ATmega328
  36. BOARD:=mega
  37. # additional (comma separated) defines
  38. # -DDOGM128_HW board is connected to DOGM128 display
  39. # -DDOGM132_HW board is connected to DOGM132 display
  40. # -DDOGS102_HW board is connected to DOGS102 display
  41. # -DDOG_REVERSE 180 degree rotation
  42. # -DDOG_SPI_SW_ARDUINO force SW shiftOut
  43. DEFS=-DDOGS102_HW -DDOG_DOUBLE_MEMORY -DDOG_SPI_SW_ARDUINO
  44. # The location where the avr tools (e.g. avr-gcc) are located. Requires a '/' at the end.
  45. # Can be empty if all tools are accessable through the search path
  46. AVR_TOOLS_PATH:=/usr/bin/
  47. # Install path of the arduino software. Requires a '/' at the end.
  48. ARDUINO_PATH:=/home/bkubicek/software/arduino-0022/
  49. # Install path for avrdude. Requires a '/' at the end. Can be empty if avrdude is in the search path.
  50. AVRDUDE_PATH:=
  51. # The unix device where we can reach the arduino board
  52. # Uno: /dev/ttyACM0
  53. # Duemilanove: /dev/ttyUSB0
  54. AVRDUDE_PORT:=/dev/ttyACM0
  55. # List of all libaries which should be included.
  56. #EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
  57. #EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Dogm/
  58. #EXTRA_DIRS+=/home/kraus/src/arduino/dogm128/hg/libraries/Dogm/
  59. #=== fetch parameter from boards.txt processor parameter ===
  60. # the basic idea is to get most of the information from boards.txt
  61. BOARDS_TXT:=$(ARDUINO_PATH)hardware/arduino/boards.txt
  62. # get the MCU value from the $(BOARD).build.mcu variable. For the atmega328 board this is atmega328p
  63. MCU:=$(shell sed -n -e "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_TXT))
  64. # get the F_CPU value from the $(BOARD).build.f_cpu variable. For the atmega328 board this is 16000000
  65. F_CPU:=$(shell sed -n -e "s/$(BOARD).build.f_cpu=\(.*\)/\1/p" $(BOARDS_TXT))
  66. # avrdude
  67. # get the AVRDUDE_UPLOAD_RATE value from the $(BOARD).upload.speed variable. For the atmega328 board this is 57600
  68. AVRDUDE_UPLOAD_RATE:=$(shell sed -n -e "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_TXT))
  69. # get the AVRDUDE_PROGRAMMER value from the $(BOARD).upload.protocol variable. For the atmega328 board this is stk500
  70. # AVRDUDE_PROGRAMMER:=$(shell sed -n -e "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_TXT))
  71. # use stk500v1, because stk500 will default to stk500v2
  72. AVRDUDE_PROGRAMMER:=stk500v1
  73. #=== identify user files ===
  74. PDESRC:=$(shell ls *.pde)
  75. TARGETNAME=$(basename $(PDESRC))
  76. CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
  77. CDIRS:=*.c utility/*.c $(addsuffix *.c,$(CDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.c
  78. CSRC:=$(shell ls $(CDIRS) 2>/dev/null)
  79. CCSRC:=$(shell ls *.cc 2>/dev/null)
  80. CPPDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
  81. CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.cpp
  82. CPPSRC:=$(shell ls $(CPPDIRS) 2>/dev/null)
  83. #=== build internal variables ===
  84. # the name of the subdirectory where everything is stored
  85. TMPDIRNAME:=tmp
  86. TMPDIRPATH:=$(TMPDIRNAME)/
  87. AVRTOOLSPATH:=$(AVR_TOOLS_PATH)
  88. OBJCOPY:=$(AVRTOOLSPATH)avr-objcopy
  89. OBJDUMP:=$(AVRTOOLSPATH)avr-objdump
  90. SIZE:=$(AVRTOOLSPATH)avr-size
  91. CPPSRC:=$(addprefix $(TMPDIRPATH),$(PDESRC:.pde=.cpp)) $(CPPSRC)
  92. COBJ:=$(CSRC:.c=.o)
  93. CCOBJ:=$(CCSRC:.cc=.o)
  94. CPPOBJ:=$(CPPSRC:.cpp=.o)
  95. OBJFILES:=$(COBJ) $(CCOBJ) $(CPPOBJ)
  96. DIRS:= $(dir $(OBJFILES))
  97. DEPFILES:=$(OBJFILES:.o=.d)
  98. # assembler files from avr-gcc -S
  99. ASSFILES:=$(OBJFILES:.o=.s)
  100. # disassembled object files with avr-objdump -S
  101. DISFILES:=$(OBJFILES:.o=.dis)
  102. LIBNAME:=$(TMPDIRPATH)$(TARGETNAME).a
  103. ELFNAME:=$(TMPDIRPATH)$(TARGETNAME).elf
  104. HEXNAME:=$(TMPDIRPATH)$(TARGETNAME).hex
  105. AVRDUDE_FLAGS = -V -F
  106. AVRDUDE_FLAGS += -C $(ARDUINO_PATH)/hardware/tools/avrdude.conf
  107. AVRDUDE_FLAGS += -p $(MCU)
  108. AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
  109. AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER)
  110. AVRDUDE_FLAGS += -b $(AVRDUDE_UPLOAD_RATE)
  111. AVRDUDE_FLAGS += -U flash:w:$(HEXNAME)
  112. AVRDUDE = avrdude
  113. #=== predefined variable override ===
  114. # use "make -p -f/dev/null" to see the default rules and definitions
  115. # Build C and C++ flags. Include path information must be placed here
  116. COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DEFS)
  117. # COMMON_FLAGS += -gdwarf-2
  118. COMMON_FLAGS += -Os
  119. COMMON_FLAGS += -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  120. COMMON_FLAGS += -I.
  121. COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
  122. COMMON_FLAGS += $(addprefix -I,$(EXTRA_DIRS))
  123. COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
  124. COMMON_FLAGS += -Wl,--relax
  125. COMMON_FLAGS += -mcall-prologues
  126. CFLAGS = $(COMMON_FLAGS) -std=gnu99 -Wstrict-prototypes
  127. CXXFLAGS = $(COMMON_FLAGS)
  128. # Replace standard build tools by avr tools
  129. CC = $(AVRTOOLSPATH)avr-gcc
  130. CXX = $(AVRTOOLSPATH)avr-g++
  131. AR = @$(AVRTOOLSPATH)avr-ar
  132. # "rm" must be able to delete a directory tree
  133. RM = rm -rf
  134. #=== rules ===
  135. # add rules for the C/C++ files where the .o file is placed in the TMPDIRPATH
  136. # reuse existing variables as far as possible
  137. $(TMPDIRPATH)%.o: %.c
  138. @echo compile $<
  139. @$(COMPILE.c) $(OUTPUT_OPTION) $<
  140. $(TMPDIRPATH)%.o: %.cc
  141. @echo compile $<
  142. @$(COMPILE.cc) $(OUTPUT_OPTION) $<
  143. $(TMPDIRPATH)%.o: %.cpp
  144. @echo compile $<
  145. @$(COMPILE.cpp) $(OUTPUT_OPTION) $<
  146. $(TMPDIRPATH)%.s: %.c
  147. @$(COMPILE.c) $(OUTPUT_OPTION) -S $<
  148. $(TMPDIRPATH)%.s: %.cc
  149. @$(COMPILE.cc) $(OUTPUT_OPTION) -S $<
  150. $(TMPDIRPATH)%.s: %.cpp
  151. @$(COMPILE.cpp) $(OUTPUT_OPTION) -S $<
  152. $(TMPDIRPATH)%.dis: $(TMPDIRPATH)%.o
  153. @$(OBJDUMP) -S $< > $@
  154. .SUFFIXES: .elf .hex .pde
  155. .elf.hex:
  156. @$(OBJCOPY) -O ihex -R .eeprom $< $@
  157. $(TMPDIRPATH)%.cpp: %.pde
  158. @cat $(ARDUINO_PATH)hardware/arduino/cores/arduino/main.cpp > $@
  159. @cat $< >> $@
  160. @echo >> $@
  161. @echo 'extern "C" void __cxa_pure_virtual() { while (1); }' >> $@
  162. .PHONY: all
  163. all: tmpdir $(HEXNAME) assemblersource showsize
  164. ls -al $(HEXNAME) $(ELFNAME)
  165. $(ELFNAME): $(LIBNAME)($(addprefix $(TMPDIRPATH),$(OBJFILES)))
  166. $(LINK.o) $(COMMON_FLAGS) $(LIBNAME) $(LOADLIBES) $(LDLIBS) -o $@
  167. $(LIBNAME)(): $(addprefix $(TMPDIRPATH),$(OBJFILES))
  168. #=== create temp directory ===
  169. # not really required, because it will be also created during the dependency handling
  170. .PHONY: tmpdir
  171. tmpdir:
  172. @test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH)
  173. #=== create assembler files for each C/C++ file ===
  174. .PHONY: assemblersource
  175. assemblersource: $(addprefix $(TMPDIRPATH),$(ASSFILES)) $(addprefix $(TMPDIRPATH),$(DISFILES))
  176. #=== show the section sizes of the ELF file ===
  177. .PHONY: showsize
  178. showsize: $(ELFNAME)
  179. $(SIZE) $<
  180. #=== clean up target ===
  181. # this is simple: the TMPDIRPATH is removed
  182. .PHONY: clean
  183. clean:
  184. $(RM) $(TMPDIRPATH)
  185. # Program the device.
  186. # step 1: reset the arduino board with the stty command
  187. # step 2: user avrdude to upload the software
  188. .PHONY: upload
  189. upload: $(HEXNAME)
  190. stty -F $(AVRDUDE_PORT) hupcl
  191. $(AVRDUDE) $(AVRDUDE_FLAGS)
  192. # === dependency handling ===
  193. # From the gnu make manual (section 4.14, Generating Prerequisites Automatically)
  194. # Additionally (because this will be the first executed rule) TMPDIRPATH is created here.
  195. # Instead of "sed" the "echo" command is used
  196. # cd $(TMPDIRPATH); mkdir -p $(DIRS) 2> /dev/null; cd ..
  197. DEPACTION=test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH);\
  198. mkdir -p $(addprefix $(TMPDIRPATH),$(DIRS));\
  199. set -e; echo -n $@ $(dir $@) > $@; $(CC) -MM $(COMMON_FLAGS) $< >> $@
  200. $(TMPDIRPATH)%.d: %.c
  201. @$(DEPACTION)
  202. $(TMPDIRPATH)%.d: %.cc
  203. @$(DEPACTION)
  204. $(TMPDIRPATH)%.d: %.cpp
  205. @$(DEPACTION)
  206. # Include dependency files. If a .d file is missing, a warning is created and the .d file is created
  207. # This warning is not a problem (gnu make manual, section 3.3 Including Other Makefiles)
  208. -include $(addprefix $(TMPDIRPATH),$(DEPFILES))