From 789be03b4fb0e03b88ce151e488b07c0fb8ad0a3 Mon Sep 17 00:00:00 2001 From: daid303 Date: Sun, 11 Nov 2012 11:05:52 +0100 Subject: [PATCH] Update on makefile, should make it easier to compile for different boards without changing the makefile. (Still missing Arduino 1.x.x support). --- Marlin/Makefile | 262 +++++++++++++++++++++++++++++++----------------- 1 file changed, 170 insertions(+), 92 deletions(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index 9a319a6d4..84231b212 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -3,6 +3,7 @@ # Makefile Based on: # Arduino 0011 Makefile # Arduino adaptation by mellis, eighthave, oli.keller +# Marlin adaption by Daid # # This has been tested with Arduino 0022. # @@ -11,14 +12,14 @@ # # Detailed instructions for using the makefile: # -# 1. Modify the line containg "INSTALL_DIR" to point to the directory that +# 1. Modify the line containg "ARDUINO_INSTALL_DIR" to point to the directory that # contains the Arduino installation (for example, under Mac OS X, this # might be /Applications/arduino-0012). # -# 2. Modify the line containing "PORT" to refer to the filename +# 2. Modify the line containing "UPLOAD_PORT" to refer to the filename # representing the USB or serial connection to your Arduino board -# (e.g. PORT = /dev/tty.USB0). If the exact name of this file -# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*). +# (e.g. UPLOAD_PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. UPLOAD_PORT = /dev/tty.usb*). # # 3. Set the line containing "MCU" to match your board's processor. # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth @@ -32,43 +33,139 @@ # 5. Type "make upload", reset your Arduino board, and press enter to # upload your program to the Arduino board. # -# $Id$ +# Note that all settings are set with ?=, this means you can override them +# from the commandline with "make HARDWARE_MOTHERBOARD=71" for example -#For "old" Arduino Mega -#MCU = atmega1280 -#For Arduino Mega2560 -#MCU = atmega2560 -#For Sanguinololu -MCU = atmega644p +# This defined the board you are compiling for (see Configuration.h for the options) +HARDWARE_MOTHERBOARD ?= 11 -# Here you select "arduino", "Sanguino", "Gen7", ... -HARDWARE_VARIANT = Sanguino -# This defined the board you are compiling for -HARDWARE_MOTHERBOARD = 91 +# Arduino source install directory, and version number +ARDUINO_INSTALL_DIR ?= ../../arduino-0022 +ARDUINO_VERSION ?= 22 -# Arduino source install directory -INSTALL_DIR = ../../arduino-0022 +# You can optionally set a path to the avr-gcc tools. Requires a trailing slash. (ex: /usr/local/avr-gcc/bin) +AVR_TOOLS_PATH ?= + +#Programmer configuration +UPLOAD_RATE ?= 115200 +AVRDUDE_PROGRAMMER ?= arduino +UPLOAD_PORT ?= /dev/arduino + +#Directory used to build files in, contains all the build files, from object files to the final hex file. +BUILD_DIR ?= applet + +############################################################################ +# Below here nothing should be changed... + +# Here the Arduino variant is selected by the board type +# HARDWARE_VARIANT = "arduino", "Sanguino", "Gen7", ... +# MCU = "atmega1280", "Mega2560", "atmega2560", "atmega644p", ... + +#Gen7 +ifeq ($(HARDWARE_MOTHERBOARD),10) +HARDWARE_VARIANT ?= Gen7 +MCU ?= atmega644 +F_CPU ?= 20000000 +else ifeq ($(HARDWARE_MOTHERBOARD),11) +HARDWARE_VARIANT ?= Gen7 +MCU ?= atmega644p +F_CPU ?= 20000000 +else ifeq ($(HARDWARE_MOTHERBOARD),12) +HARDWARE_VARIANT ?= Gen7 +MCU ?= atmega644p +F_CPU ?= 20000000 +else ifeq ($(HARDWARE_MOTHERBOARD),13) +HARDWARE_VARIANT ?= Gen7 +MCU ?= atmega1284p +F_CPU ?= 20000000 + +#RAMPS +else ifeq ($(HARDWARE_MOTHERBOARD),3) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega2560 +else ifeq ($(HARDWARE_MOTHERBOARD),33) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega2560 +else ifeq ($(HARDWARE_MOTHERBOARD),34) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega2560 + +#Duemilanove w/ ATMega328P pin assignment +else ifeq ($(HARDWARE_MOTHERBOARD),4) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega328p + +#Gen6 +else ifeq ($(HARDWARE_MOTHERBOARD),5) +HARDWARE_VARIANT ?= Gen6 +MCU ?= atmega664p +else ifeq ($(HARDWARE_MOTHERBOARD),51) +HARDWARE_VARIANT ?= Gen6 +MCU ?= atmega664p + +#Sanguinololu +else ifeq ($(HARDWARE_MOTHERBOARD),6) +HARDWARE_VARIANT ?= Sanguino +MCU ?= atmega1284p +else ifeq ($(HARDWARE_MOTHERBOARD),62) +HARDWARE_VARIANT ?= Sanguino +MCU ?= atmega1284p +else ifeq ($(HARDWARE_MOTHERBOARD),63) +HARDWARE_VARIANT ?= Sanguino +MCU ?= atmega1284p + +#Ultimaker +else ifeq ($(HARDWARE_MOTHERBOARD),7) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega2560 +else ifeq ($(HARDWARE_MOTHERBOARD),71) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega1280 + +#Teensylu +else ifeq ($(HARDWARE_MOTHERBOARD),8) +HARDWARE_VARIANT ?= Teensyduino +MCU ?= at90usb1286 + +#Gen3+ +else ifeq ($(HARDWARE_MOTHERBOARD),9) +HARDWARE_VARIANT ?= Sanguino +MCU ?= atmega644p + +#Megatronics +else ifeq ($(HARDWARE_MOTHERBOARD),70) +HARDWARE_VARIANT ?= arduino +MCU ?= atmega2560 + +#Alpha OMCA board +else ifeq ($(HARDWARE_MOTHERBOARD),90) +HARDWARE_VARIANT ?= SanguinoA +MCU ?= atmega644 + +#Final OMCA board +else ifeq ($(HARDWARE_MOTHERBOARD),91) +HARDWARE_VARIANT ?= Sanguino +MCU ?= atmega644p + +endif + +# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py +# if you are setting this to something other than 16MHz +# Set to 16Mhz if not yet set. +F_CPU ?= 16000000 # Arduino containd the main source code for the Arduino # Libraries, the "hardware variant" are for boards # that derives from that, and their source are present in # the main Marlin source directory -ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino +ARDUINO = $(ARDUINO_INSTALL_DIR)/hardware/arduino/cores/arduino ifeq (${HARDWARE_VARIANT}, arduino) -HARDWARE_SRC= $(ARDUINO) +HARDWARE_SRC = $(ARDUINO) else -HARDWARE_SRC= $(HARDWARE_VARIANT)/cores/arduino +HARDWARE_SRC = $(HARDWARE_VARIANT)/cores/arduino endif -# Be sure to regenerate speed_lookuptable.h with create_speed_lookuptable.py -# if you are setting this to something other than 16MHz -F_CPU = 16000000 - -UPLOAD_RATE = 115200 -AVRDUDE_PROGRAMMER = arduino -PORT = /dev/arduino - TARGET = $(notdir $(CURDIR)) # VPATH tells make to look into these directory for source files, @@ -76,20 +173,18 @@ TARGET = $(notdir $(CURDIR)) # directory is added here VPATH = . -VPATH += applet +VPATH += $(BUILD_DIR) VPATH += $(HARDWARE_SRC) VPATH += $(ARDUINO) -VPATH += $(INSTALL_DIR)/libraries/LiquidCrystal +VPATH += $(ARDUINO_INSTALL_DIR)/libraries/LiquidCrystal +#TODO: Add the path to the hardware variant when using Arduino >= 100, and adjust the files required for compilation. +#VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/variants/mega -############################################################################ -# Below here nothing should be changed... - -AVR_TOOLS_PATH = -SRC = pins_arduino.c wiring.c \ +SRC = pins_arduino.c main.c wiring.c \ wiring_analog.c wiring_digital.c \ wiring_pulse.c \ wiring_shift.c WInterrupts.c -CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin.cpp Marlin_main.cpp \ +CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \ MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp \ SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp \ stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp @@ -125,8 +220,8 @@ CDEBUG = -g$(DEBUG) CWARN = -Wall -Wstrict-prototypes CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \ -fshort-enums -w -ffunction-sections -fdata-sections \ - -DARDUINO=22 -ifneq (${HARDWARE_MOTHERBOARD},) + -DARDUINO=$(ARDUINO_VERSION) +ifneq ($(HARDWARE_MOTHERBOARD),) CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD} endif #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) @@ -138,9 +233,9 @@ LDFLAGS = -lm # Programming support using avrdude. Settings and variables. -AVRDUDE_PORT = $(PORT) -AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i -AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \ +AVRDUDE_PORT = $(UPLOAD_PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex:i +AVRDUDE_FLAGS = -D -C $(ARDUINO_INSTALL_DIR)/hardware/tools/avrdude.conf \ -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ -b $(UPLOAD_RATE) @@ -157,9 +252,9 @@ REMOVE = rm -f MV = mv -f # Define all object files. -OBJ = ${patsubst %.c, applet/%.o, ${SRC}} -OBJ += ${patsubst %.cpp, applet/%.o, ${CXXSRC}} -OBJ += ${patsubst %.S, applet/%.o, ${ASRC}} +OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}} +OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}} +OBJ += ${patsubst %.S, $(BUILD_DIR)/%.o, ${ASRC}} # Define all listing files. LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) @@ -182,52 +277,38 @@ endif # Default target. all: sizeafter -build: applet elf hex +build: $(BUILD_DIR) elf hex # Creates the object directory -applet: - $P mkdir -p applet +$(BUILD_DIR): + $P mkdir -p $(BUILD_DIR) -# the .cpp for Marlin depends on the .pde -#applet/$(TARGET).cpp: $(TARGET).pde -# ..and the .o depends from the .cpp -#applet/%.o: applet/%.cpp - -applet/%.cpp: %.pde $(MAKEFILE) -# Here is the "preprocessing". -# It creates a .cpp file based with the same name as the .pde file. -# On top of the new .cpp file comes the WProgram.h header. - $(Pecho) " WR $@" - $P echo '#include "WProgram.h"' > $@ - $P echo '#include "$<"' >>$@ - $P echo '#include "$(ARDUINO)/main.cpp"' >> $@ - -elf: applet/$(TARGET).elf -hex: applet/$(TARGET).hex -eep: applet/$(TARGET).eep -lss: applet/$(TARGET).lss -sym: applet/$(TARGET).sym +elf: $(BUILD_DIR)/$(TARGET).elf +hex: $(BUILD_DIR)/$(TARGET).hex +eep: $(BUILD_DIR)/$(TARGET).eep +lss: $(BUILD_DIR)/$(TARGET).lss +sym: $(BUILD_DIR)/$(TARGET).sym # Program the device. # Do not try to reset an arduino if it's not one -upload: applet/$(TARGET).hex +upload: $(BUILD_DIR)/$(TARGET).hex ifeq (${AVRDUDE_PROGRAMMER}, arduino) - stty hup < $(PORT); true + stty hup < $(UPLOAD_PORT); true endif $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) ifeq (${AVRDUDE_PROGRAMMER}, arduino) - stty -hup < $(PORT); true + stty -hup < $(UPLOAD_PORT); true endif # Display size of file. -HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex -ELFSIZE = $(SIZE) --mcu=$(MCU) -C applet/$(TARGET).elf; \ - $(SIZE) applet/$(TARGET).elf +HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex +ELFSIZE = $(SIZE) --mcu=$(MCU) -C $(BUILD_DIR)/$(TARGET).elf; \ + $(SIZE) $(BUILD_DIR)/$(TARGET).elf sizebefore: - $P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi + $P if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi sizeafter: build - $P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + $P if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. @@ -238,12 +319,12 @@ COFFCONVERT=$(OBJCOPY) --debugging \ --change-section-address .eeprom-0x810000 -coff: applet/$(TARGET).elf - $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof +coff: $(BUILD_DIR)/$(TARGET).elf + $(COFFCONVERT) -O coff-avr $(BUILD_DIR)/$(TARGET).elf $(TARGET).cof extcoff: $(TARGET).elf - $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof + $(COFFCONVERT) -O coff-ext-avr $(BUILD_DIR)/$(TARGET).elf $(TARGET).cof .SUFFIXES: .elf .hex .eep .lss .sym @@ -266,37 +347,34 @@ extcoff: $(TARGET).elf $(NM) -n $< > $@ # Link: create ELF output file from library. -applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h +$(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h $(Pecho) " CXX $@" - $P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) + $P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ -L. $(OBJ) $(LDFLAGS) -applet/core.a: $(OBJ) - $P for i in $(OBJ); do echo " AR $$i"; $(AR) rcs applet/core.a $$i; done - -applet/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE) +$(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE) $(Pecho) " CC $@" $P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@ -applet/%.o: applet/%.cpp Configuration.h Configuration_adv.h $(MAKEFILE) +$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.cpp Configuration.h Configuration_adv.h $(MAKEFILE) $(Pecho) " CXX $@" $P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ -applet/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE) +$(BUILD_DIR)/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE) $(Pecho) " CXX $@" $P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ # Target: clean project. clean: - $(Pecho) " RM applet/*" - $P $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ - applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \ + $(Pecho) " RM $(BUILD_DIR)/*" + $P $(REMOVE) $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET).cof $(BUILD_DIR)/$(TARGET).elf \ + $(BUILD_DIR)/$(TARGET).map $(BUILD_DIR)/$(TARGET).sym $(BUILD_DIR)/$(TARGET).lss $(BUILD_DIR)/$(TARGET).cpp \ $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) - $(Pecho) " RMDIR applet/" - $P rm -rf applet + $(Pecho) " RMDIR $(BUILD_DIR)/" + $P rm -rf $(BUILD_DIR) -.PHONY: all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter # Automaticaly include the dependency files created by gcc --include ${wildcard applet/*.d} +-include ${wildcard $(BUILD_DIR)/*.d}