Browse Source

Update on makefile, should make it easier to compile for different boards without changing the makefile. (Still missing Arduino 1.x.x support).

pull/1/head
daid303 12 years ago
parent
commit
789be03b4f
  1. 264
      Marlin/Makefile

264
Marlin/Makefile

@ -3,6 +3,7 @@
# Makefile Based on: # Makefile Based on:
# Arduino 0011 Makefile # Arduino 0011 Makefile
# Arduino adaptation by mellis, eighthave, oli.keller # Arduino adaptation by mellis, eighthave, oli.keller
# Marlin adaption by Daid
# #
# This has been tested with Arduino 0022. # This has been tested with Arduino 0022.
# #
@ -11,14 +12,14 @@
# #
# Detailed instructions for using the makefile: # 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 # contains the Arduino installation (for example, under Mac OS X, this
# might be /Applications/arduino-0012). # 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 # representing the USB or serial connection to your Arduino board
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file # (e.g. UPLOAD_PORT = /dev/tty.USB0). If the exact name of this file
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*). # 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. # 3. Set the line containing "MCU" to match your board's processor.
# Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth # 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 # 5. Type "make upload", reset your Arduino board, and press enter to
# upload your program to the Arduino board. # 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 # This defined the board you are compiling for (see Configuration.h for the options)
#MCU = atmega1280 HARDWARE_MOTHERBOARD ?= 11
#For Arduino Mega2560
#MCU = atmega2560
#For Sanguinololu
MCU = atmega644p
# Here you select "arduino", "Sanguino", "Gen7", ... # Arduino source install directory, and version number
HARDWARE_VARIANT = Sanguino ARDUINO_INSTALL_DIR ?= ../../arduino-0022
# This defined the board you are compiling for ARDUINO_VERSION ?= 22
HARDWARE_MOTHERBOARD = 91
# Arduino source install directory # You can optionally set a path to the avr-gcc tools. Requires a trailing slash. (ex: /usr/local/avr-gcc/bin)
INSTALL_DIR = ../../arduino-0022 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 # Arduino containd the main source code for the Arduino
# Libraries, the "hardware variant" are for boards # Libraries, the "hardware variant" are for boards
# that derives from that, and their source are present in # that derives from that, and their source are present in
# the main Marlin source directory # the main Marlin source directory
ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino ARDUINO = $(ARDUINO_INSTALL_DIR)/hardware/arduino/cores/arduino
ifeq (${HARDWARE_VARIANT}, arduino) ifeq (${HARDWARE_VARIANT}, arduino)
HARDWARE_SRC= $(ARDUINO) HARDWARE_SRC = $(ARDUINO)
else else
HARDWARE_SRC= $(HARDWARE_VARIANT)/cores/arduino HARDWARE_SRC = $(HARDWARE_VARIANT)/cores/arduino
endif 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)) TARGET = $(notdir $(CURDIR))
# VPATH tells make to look into these directory for source files, # VPATH tells make to look into these directory for source files,
@ -76,20 +173,18 @@ TARGET = $(notdir $(CURDIR))
# directory is added here # directory is added here
VPATH = . VPATH = .
VPATH += applet VPATH += $(BUILD_DIR)
VPATH += $(HARDWARE_SRC) VPATH += $(HARDWARE_SRC)
VPATH += $(ARDUINO) 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
############################################################################ SRC = pins_arduino.c main.c wiring.c \
# Below here nothing should be changed...
AVR_TOOLS_PATH =
SRC = pins_arduino.c wiring.c \
wiring_analog.c wiring_digital.c \ wiring_analog.c wiring_digital.c \
wiring_pulse.c \ wiring_pulse.c \
wiring_shift.c WInterrupts.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 \ MarlinSerial.cpp Sd2Card.cpp SdBaseFile.cpp SdFatUtil.cpp \
SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp \ SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp \
stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp
@ -125,8 +220,8 @@ CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes CWARN = -Wall -Wstrict-prototypes
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \ CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct \
-fshort-enums -w -ffunction-sections -fdata-sections \ -fshort-enums -w -ffunction-sections -fdata-sections \
-DARDUINO=22 -DARDUINO=$(ARDUINO_VERSION)
ifneq (${HARDWARE_MOTHERBOARD},) ifneq ($(HARDWARE_MOTHERBOARD),)
CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD} CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
endif endif
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
@ -138,9 +233,9 @@ LDFLAGS = -lm
# Programming support using avrdude. Settings and variables. # Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT) AVRDUDE_PORT = $(UPLOAD_PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex:i AVRDUDE_WRITE_FLASH = -U flash:w:$(BUILD_DIR)/$(TARGET).hex:i
AVRDUDE_FLAGS = -D -C $(INSTALL_DIR)/hardware/tools/avrdude.conf \ AVRDUDE_FLAGS = -D -C $(ARDUINO_INSTALL_DIR)/hardware/tools/avrdude.conf \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE) -b $(UPLOAD_RATE)
@ -157,9 +252,9 @@ REMOVE = rm -f
MV = mv -f MV = mv -f
# Define all object files. # Define all object files.
OBJ = ${patsubst %.c, applet/%.o, ${SRC}} OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}}
OBJ += ${patsubst %.cpp, applet/%.o, ${CXXSRC}} OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
OBJ += ${patsubst %.S, applet/%.o, ${ASRC}} OBJ += ${patsubst %.S, $(BUILD_DIR)/%.o, ${ASRC}}
# Define all listing files. # Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
@ -182,52 +277,38 @@ endif
# Default target. # Default target.
all: sizeafter all: sizeafter
build: applet elf hex build: $(BUILD_DIR) elf hex
# Creates the object directory # Creates the object directory
applet: $(BUILD_DIR):
$P mkdir -p applet $P mkdir -p $(BUILD_DIR)
# the .cpp for Marlin depends on the .pde elf: $(BUILD_DIR)/$(TARGET).elf
#applet/$(TARGET).cpp: $(TARGET).pde hex: $(BUILD_DIR)/$(TARGET).hex
# ..and the .o depends from the .cpp eep: $(BUILD_DIR)/$(TARGET).eep
#applet/%.o: applet/%.cpp lss: $(BUILD_DIR)/$(TARGET).lss
sym: $(BUILD_DIR)/$(TARGET).sym
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
# Program the device. # Program the device.
# Do not try to reset an arduino if it's not one # 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) ifeq (${AVRDUDE_PROGRAMMER}, arduino)
stty hup < $(PORT); true stty hup < $(UPLOAD_PORT); true
endif endif
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
ifeq (${AVRDUDE_PROGRAMMER}, arduino) ifeq (${AVRDUDE_PROGRAMMER}, arduino)
stty -hup < $(PORT); true stty -hup < $(UPLOAD_PORT); true
endif endif
# Display size of file. # Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex
ELFSIZE = $(SIZE) --mcu=$(MCU) -C applet/$(TARGET).elf; \ ELFSIZE = $(SIZE) --mcu=$(MCU) -C $(BUILD_DIR)/$(TARGET).elf; \
$(SIZE) applet/$(TARGET).elf $(SIZE) $(BUILD_DIR)/$(TARGET).elf
sizebefore: 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 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. # 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 --change-section-address .eeprom-0x810000
coff: applet/$(TARGET).elf coff: $(BUILD_DIR)/$(TARGET).elf
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof $(COFFCONVERT) -O coff-avr $(BUILD_DIR)/$(TARGET).elf $(TARGET).cof
extcoff: $(TARGET).elf 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 .SUFFIXES: .elf .hex .eep .lss .sym
@ -266,37 +347,34 @@ extcoff: $(TARGET).elf
$(NM) -n $< > $@ $(NM) -n $< > $@
# Link: create ELF output file from library. # 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 $@" $(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 $@" $(Pecho) " CC $@"
$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@ $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 $@" $(Pecho) " CXX $@"
$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ $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 $@" $(Pecho) " CXX $@"
$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ $P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
# Target: clean project. # Target: clean project.
clean: clean:
$(Pecho) " RM applet/*" $(Pecho) " RM $(BUILD_DIR)/*"
$P $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ $P $(REMOVE) $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET).cof $(BUILD_DIR)/$(TARGET).elf \
applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \ $(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) $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
$(Pecho) " RMDIR applet/" $(Pecho) " RMDIR $(BUILD_DIR)/"
$P rm -rf applet $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 # Automaticaly include the dependency files created by gcc
-include ${wildcard applet/*.d} -include ${wildcard $(BUILD_DIR)/*.d}

Loading…
Cancel
Save