Arduino.mk: fixed per-target toolchains
This commit is contained in:
parent
eb530b86e8
commit
91b94c0f6c
171
mk/Arduino.mk
171
mk/Arduino.mk
@ -189,45 +189,53 @@ endif
|
|||||||
#
|
#
|
||||||
ifeq ($(SYSTYPE),Darwin)
|
ifeq ($(SYSTYPE),Darwin)
|
||||||
# use the tools that come with Arduino
|
# use the tools that come with Arduino
|
||||||
TOOLPATH := $(ARDUINOS)/hardware/tools/avr/bin
|
TOOLPATH := $(ARDUINOS)/hardware/tools/avr/bin
|
||||||
# use BWK awk
|
# use BWK awk
|
||||||
AWK = awk
|
AWK = awk
|
||||||
endif
|
endif
|
||||||
ifeq ($(SYSTYPE),Linux)
|
ifeq ($(SYSTYPE),Linux)
|
||||||
# expect that tools are on the path
|
# expect that tools are on the path
|
||||||
TOOLPATH := $(subst :, ,$(PATH))
|
TOOLPATH := $(subst :, ,$(PATH))
|
||||||
endif
|
endif
|
||||||
ifeq ($(findstring CYGWIN, $(SYSTYPE)),CYGWIN)
|
ifeq ($(findstring CYGWIN, $(SYSTYPE)),CYGWIN)
|
||||||
TOOLPATH := $(ARDUINO)/hardware/tools/avr/bin
|
TOOLPATH := $(ARDUINO)/hardware/tools/avr/bin
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(findstring CYGWIN, $(SYSTYPE)),)
|
ifeq ($(findstring CYGWIN, $(SYSTYPE)),)
|
||||||
FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1),$(TOOLPATH))))
|
FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1),$(TOOLPATH))))
|
||||||
else
|
else
|
||||||
FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1).exe,$(TOOLPATH))))
|
FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1).exe,$(TOOLPATH))))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(HAL_BOARD),HAL_BOARD_AVR_SITL)
|
NATIVE_CXX := $(call FIND_TOOL,g++)
|
||||||
CXX := $(call FIND_TOOL,g++)
|
NATIVE_CC := $(call FIND_TOOL,gcc)
|
||||||
CC := $(call FIND_TOOL,gcc)
|
NATIVE_AS := $(call FIND_TOOL,gcc)
|
||||||
AS := $(call FIND_TOOL,gcc)
|
NATIVE_AR := $(call FIND_TOOL,ar)
|
||||||
AR := $(call FIND_TOOL,ar)
|
NATIVE_LD := $(call FIND_TOOL,g++)
|
||||||
LD := $(call FIND_TOOL,g++)
|
NATIVE_GDB := $(call FIND_TOOL,gdb)
|
||||||
GDB := $(call FIND_TOOL,gdb)
|
NATIVE_OBJCOPY := $(call FIND_TOOL,objcopy)
|
||||||
OBJCOPY := $(call FIND_TOOL,objcopy)
|
|
||||||
else
|
AVR_CXX := $(call FIND_TOOL,avr-g++)
|
||||||
CXX := $(call FIND_TOOL,avr-g++)
|
AVR_CC := $(call FIND_TOOL,avr-gcc)
|
||||||
CC := $(call FIND_TOOL,avr-gcc)
|
AVR_AS := $(call FIND_TOOL,avr-gcc)
|
||||||
AS := $(call FIND_TOOL,avr-gcc)
|
AVR_AR := $(call FIND_TOOL,avr-ar)
|
||||||
AR := $(call FIND_TOOL,avr-ar)
|
AVR_LD := $(call FIND_TOOL,avr-gcc)
|
||||||
LD := $(call FIND_TOOL,avr-gcc)
|
AVR_GDB := $(call FIND_TOOL,avr-gdb)
|
||||||
GDB := $(call FIND_TOOL,avr-gdb)
|
AVR_OBJCOPY := $(call FIND_TOOL,avr-objcopy)
|
||||||
AVRDUDE := $(call FIND_TOOL,avrdude)
|
|
||||||
AVARICE := $(call FIND_TOOL,avarice)
|
AVRDUDE := $(call FIND_TOOL,avrdude)
|
||||||
OBJCOPY := $(call FIND_TOOL,avr-objcopy)
|
AVARICE := $(call FIND_TOOL,avarice)
|
||||||
endif
|
|
||||||
ifeq ($(CXX),)
|
CXX = $($(TOOLCHAIN)_CXX)
|
||||||
$(error ERROR: cannot find the compiler tools anywhere on the path $(TOOLPATH))
|
CC = $($(TOOLCHAIN)_CC)
|
||||||
|
AS = $($(TOOLCHAIN)_AS)
|
||||||
|
AR = $($(TOOLCHAIN)_AR)
|
||||||
|
LD = $($(TOOLCHAIN)_LD)
|
||||||
|
GDB = $($(TOOLCHAIN)_GDB)
|
||||||
|
OBJCOPY = $($(TOOLCHAIN)_OBJCOPY)
|
||||||
|
|
||||||
|
ifeq ($(AVR_CXX),)
|
||||||
|
$(error ERROR: cannot find the AVR compiler tools anywhere on the path $(TOOLPATH))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Find awk
|
# Find awk
|
||||||
@ -240,34 +248,43 @@ endif
|
|||||||
# Tool options
|
# Tool options
|
||||||
#
|
#
|
||||||
EXTRAFLAGS ?=
|
EXTRAFLAGS ?=
|
||||||
DEFINES = -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERS) $(EXTRAFLAGS) -DSKETCH=\"$(SKETCH)\"
|
DEFINES = -DF_CPU=$(F_CPU)
|
||||||
WARNFLAGS = -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder
|
DEFINES += -DARDUINO=$(ARDUINO_VERS)
|
||||||
DEPFLAGS = -MD -MT $@
|
DEFINES += $(EXTRAFLAGS)
|
||||||
|
DEFINES += -DSKETCH=\"$(SKETCH)\"
|
||||||
|
WARNFLAGS = -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align
|
||||||
|
WARNFLAGS += -Wwrite-strings -Wformat=2 -Wno-reorder
|
||||||
|
DEPFLAGS = -MD -MT $@
|
||||||
|
|
||||||
# XXX warning options TBD
|
CXXOPTS = -ffunction-sections -fdata-sections -fno-exceptions
|
||||||
CXXOPTS = -ffunction-sections -fdata-sections -fno-exceptions
|
COPTS = -ffunction-sections -fdata-sections
|
||||||
COPTS = -ffunction-sections -fdata-sections
|
|
||||||
|
|
||||||
ASOPTS = -x assembler-with-cpp
|
ASOPTS = -x assembler-with-cpp
|
||||||
LISTOPTS = -adhlns=$(@:.o=.lst)
|
LISTOPTS = -adhlns=$(@:.o=.lst)
|
||||||
|
|
||||||
ifeq ($(HAL_BOARD),HAL_BOARD_AVR_SITL)
|
NATIVE_CPUFLAGS = -D_GNU_SOURCE
|
||||||
CPUFLAGS = -D_GNU_SOURCE
|
NATIVE_CPULDFLAGS = -g
|
||||||
CPULDFLAGS = -g
|
NATIVE_OPTFLAGS = -O0 -g
|
||||||
OPTFLAGS = -O0 -g
|
|
||||||
else
|
|
||||||
CPUFLAGS = -mmcu=$(MCU) -mcall-prologues
|
|
||||||
CPULDFLAGS = -Wl,-m,avr6
|
|
||||||
OPTFLAGS = -Os
|
|
||||||
endif
|
|
||||||
|
|
||||||
CXXFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS) $(WARNFLAGS) $(DEPFLAGS) $(CXXOPTS)
|
AVR_CPUFLAGS = -mmcu=$(MCU) -mcall-prologues
|
||||||
CFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS) $(WARNFLAGS) $(DEPFLAGS) $(COPTS)
|
AVR_CPULDFLAGS = -Wl,-m,avr6
|
||||||
ASFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(DEPFLAGS) $(ASOPTS)
|
AVR_OPTFLAGS = -Os
|
||||||
LDFLAGS = -g $(CPUFLAGS) $(OPTFLAGS) $(WARNFLAGS) -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP) $(CPULDFLAGS)
|
|
||||||
|
|
||||||
ifeq ($(BOARD),mega)
|
CPUFLAGS= $($(TOOLCHAIN)_CPUFLAGS)
|
||||||
LDFLAGS = -g $(CPUFLAGS) $(OPTFLAGS) $(WARNFLAGS) -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP)
|
CPULDFLAGS= $($(TOOLCHAIN)_CPULDFLAGS)
|
||||||
|
OPTFLAGS= $($(TOOLCHAIN)_OPTFLAGS)
|
||||||
|
|
||||||
|
CXXFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
|
||||||
|
CXXFLAGS += $(WARNFLAGS) $(DEPFLAGS) $(CXXOPTS)
|
||||||
|
CFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
|
||||||
|
CFLAGS += $(WARNFLAGS) $(DEPFLAGS) $(COPTS)
|
||||||
|
ASFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(DEPFLAGS)
|
||||||
|
ASFLAGS += $(ASOPTS)
|
||||||
|
LDFLAGS = -g $(CPUFLAGS) $(OPTFLAGS) $(WARNFLAGS)
|
||||||
|
LDFLAGS += -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP)
|
||||||
|
|
||||||
|
ifneq ($(BOARD),mega)
|
||||||
|
LDFLAGS += $(CPULDFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# under certain situations with certain avr-gcc versions the --relax flag causes
|
# under certain situations with certain avr-gcc versions the --relax flag causes
|
||||||
@ -275,17 +292,17 @@ endif
|
|||||||
# I know this is a rotten hack but we're really close to sunset on AVR.
|
# I know this is a rotten hack but we're really close to sunset on AVR.
|
||||||
EXCLUDE_RELAX := $(wildcard $(SRCROOT)/norelax.inoflag)
|
EXCLUDE_RELAX := $(wildcard $(SRCROOT)/norelax.inoflag)
|
||||||
ifeq ($(EXCLUDE_RELAX),)
|
ifeq ($(EXCLUDE_RELAX),)
|
||||||
LDFLAGS += -Wl,--relax
|
LDFLAGS += -Wl,--relax
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBS = -lm
|
LIBS = -lm
|
||||||
|
|
||||||
SRCSUFFIXES = *.cpp *.c *.S
|
SRCSUFFIXES = *.cpp *.c *.S
|
||||||
|
|
||||||
ifeq ($(VERBOSE),)
|
ifeq ($(VERBOSE),)
|
||||||
v = @
|
v = @
|
||||||
else
|
else
|
||||||
v =
|
v =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
@ -294,21 +311,21 @@ endif
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Sketch source files
|
# Sketch source files
|
||||||
SKETCHPDESRCS := $(wildcard $(SRCROOT)/*.pde $(SRCROOT)/*.ino)
|
SKETCHPDESRCS := $(wildcard $(SRCROOT)/*.pde $(SRCROOT)/*.ino)
|
||||||
SKETCHSRCS := $(wildcard $(addprefix $(SRCROOT)/,$(SRCSUFFIXES)))
|
SKETCHSRCS := $(wildcard $(addprefix $(SRCROOT)/,$(SRCSUFFIXES)))
|
||||||
SKETCHPDE := $(wildcard $(SRCROOT)/$(SKETCH).pde $(SRCROOT)/$(SKETCH).ino)
|
SKETCHPDE := $(wildcard $(SRCROOT)/$(SKETCH).pde $(SRCROOT)/$(SKETCH).ino)
|
||||||
SKETCHCPP := $(BUILDROOT)/$(SKETCH).cpp
|
SKETCHCPP := $(BUILDROOT)/$(SKETCH).cpp
|
||||||
ifneq ($(words $(SKETCHPDE)),1)
|
ifneq ($(words $(SKETCHPDE)),1)
|
||||||
$(error ERROR: sketch $(SKETCH) must contain exactly one of $(SKETCH).pde or $(SKETCH).ino)
|
$(error ERROR: sketch $(SKETCH) must contain exactly one of $(SKETCH).pde or $(SKETCH).ino)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Sketch object files
|
# Sketch object files
|
||||||
SKETCHOBJS := $(subst $(SRCROOT),$(BUILDROOT),$(SKETCHSRCS)) $(SKETCHCPP)
|
SKETCHOBJS := $(subst $(SRCROOT),$(BUILDROOT),$(SKETCHSRCS)) $(SKETCHCPP)
|
||||||
SKETCHOBJS := $(addsuffix .o,$(basename $(SKETCHOBJS)))
|
SKETCHOBJS := $(addsuffix .o,$(basename $(SKETCHOBJS)))
|
||||||
|
|
||||||
# List of input files to the sketch.cpp file in the order they should
|
# List of input files to the sketch.cpp file in the order they should
|
||||||
# be appended to create it
|
# be appended to create it
|
||||||
SKETCHCPP_SRC := $(SKETCHPDE) $(sort $(filter-out $(SKETCHPDE),$(SKETCHPDESRCS)))
|
SKETCHCPP_SRC := $(SKETCHPDE) $(sort $(filter-out $(SKETCHPDE),$(SKETCHPDESRCS)))
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Libraries
|
# Libraries
|
||||||
@ -325,7 +342,7 @@ SKETCHCPP_SRC := $(SKETCHPDE) $(sort $(filter-out $(SKETCHPDE),$(SKETCHPDESRCS)
|
|||||||
# Note that the # and $ require special treatment to avoid upsetting
|
# Note that the # and $ require special treatment to avoid upsetting
|
||||||
# make.
|
# make.
|
||||||
#
|
#
|
||||||
SEXPR = 's/^[[:space:]]*\#include[[:space:]][<\"]([^>\"./]+).*$$/\1/p'
|
SEXPR = 's/^[[:space:]]*\#include[[:space:]][<\"]([^>\"./]+).*$$/\1/p'
|
||||||
ifeq ($(SYSTYPE),Darwin)
|
ifeq ($(SYSTYPE),Darwin)
|
||||||
LIBTOKENS := $(sort $(shell cat $(SKETCHPDESRCS) $(SKETCHSRCS) | sed -nEe $(SEXPR)))
|
LIBTOKENS := $(sort $(shell cat $(SKETCHPDESRCS) $(SKETCHSRCS) | sed -nEe $(SEXPR)))
|
||||||
else
|
else
|
||||||
@ -382,9 +399,9 @@ endif
|
|||||||
|
|
||||||
# Extract needed build parameters from the boardfile
|
# Extract needed build parameters from the boardfile
|
||||||
MCU := $(shell grep $(BOARD).build.mcu $(BOARDFILE) | cut -d = -f 2)
|
MCU := $(shell grep $(BOARD).build.mcu $(BOARDFILE) | cut -d = -f 2)
|
||||||
F_CPU := $(shell grep $(BOARD).build.f_cpu $(BOARDFILE) | cut -d = -f 2)
|
F_CPU := $(shell grep $(BOARD).build.f_cpu $(BOARDFILE) | cut -d = -f 2)
|
||||||
HARDWARE_CORE := $(shell grep $(BOARD).build.core $(BOARDFILE) | cut -d = -f 2)
|
HARDWARE_CORE := $(shell grep $(BOARD).build.core $(BOARDFILE) | cut -d = -f 2)
|
||||||
UPLOAD_SPEED := $(shell grep $(BOARD).upload.speed $(BOARDFILE) | cut -d = -f 2)
|
UPLOAD_SPEED := $(shell grep $(BOARD).upload.speed $(BOARDFILE) | cut -d = -f 2)
|
||||||
|
|
||||||
# User can define USERAVRDUDEFLAGS = -V in their config.mk to skip verification
|
# User can define USERAVRDUDEFLAGS = -V in their config.mk to skip verification
|
||||||
USERAVRDUDEFLAGS ?=
|
USERAVRDUDEFLAGS ?=
|
||||||
@ -456,17 +473,25 @@ endif
|
|||||||
# Targets
|
# Targets
|
||||||
#
|
#
|
||||||
|
|
||||||
all: $(SKETCHELF) $(SKETCHEEP) $(SKETCHHEX)
|
default: apm2
|
||||||
|
|
||||||
|
all: $(SKETCHELF) $(SKETCHEEP) $(SKETCHHEX)
|
||||||
|
|
||||||
|
print-%:
|
||||||
|
echo "$*=$($*)"
|
||||||
|
|
||||||
# convenient targets for our supported boards
|
# convenient targets for our supported boards
|
||||||
sitl:
|
sitl: HAL_BOARD = HAL_BOARD_AVR_SITL
|
||||||
make -f Makefile HAL_BOARD=HAL_BOARD_AVR_SITL
|
sitl: TOOLCHAIN = NATIVE
|
||||||
|
sitl: all
|
||||||
|
|
||||||
apm1:
|
apm1: HAL_BOARD = HAL_BOARD_APM1
|
||||||
make -f Makefile HAL_BOARD=HAL_BOARD_APM1
|
apm1: TOOLCHAIN = AVR
|
||||||
|
apm1: all
|
||||||
|
|
||||||
apm2:
|
apm2: HAL_BOARD = HAL_BOARD_APM2
|
||||||
make -f Makefile HAL_BOARD=HAL_BOARD_APM2
|
apm2: TOOLCHAIN = AVR
|
||||||
|
apm2: all
|
||||||
|
|
||||||
.PHONY: upload
|
.PHONY: upload
|
||||||
upload: $(SKETCHHEX)
|
upload: $(SKETCHHEX)
|
||||||
|
Loading…
Reference in New Issue
Block a user