aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Arduino.mk23
-rw-r--r--Common.mk13
-rw-r--r--HISTORY.md1
-rw-r--r--Sam.mk32
-rw-r--r--arduino-mk-vars.md39
5 files changed, 88 insertions, 20 deletions
diff --git a/Arduino.mk b/Arduino.mk
index 2a51a95..30bf36b 100644
--- a/Arduino.mk
+++ b/Arduino.mk
@@ -1227,15 +1227,24 @@ CFLAGS += $(CFLAGS_STD)
CXXFLAGS += -fpermissive -fno-exceptions $(CXXFLAGS_STD)
ASFLAGS += -x assembler-with-cpp
DIAGNOSTICS_COLOR_WHEN ?= always
-ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
- ASFLAGS += -flto
- CXXFLAGS += -fno-threadsafe-statics -flto -fno-devirtualize -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
- CFLAGS += -flto -fno-fat-lto-objects -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
+
+# Flags for AVR
+ifeq ($(findstring avr, $(strip $(CC_NAME))), avr)
+ ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
+ ASFLAGS += -flto
+ CXXFLAGS += -fno-threadsafe-statics -flto -fno-devirtualize -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
+ CFLAGS += -flto -fno-fat-lto-objects -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
+ LDFLAGS += -flto -fuse-linker-plugin
+ endif
+# Flags for ARM (most set in Sam.mk)
+else
+ ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
+ CXXFLAGS += -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
+ CFLAGS += -fdiagnostics-color=$(DIAGNOSTICS_COLOR_WHEN)
+ endif
endif
+
LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL)
-ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
- LDFLAGS += -flto -fuse-linker-plugin
-endif
SIZEFLAGS ?= --mcu=$(MCU) -C
# for backwards compatibility, grab ARDUINO_PORT if the user has it set
diff --git a/Common.mk b/Common.mk
index d4fb9c1..5421b96 100644
--- a/Common.mk
+++ b/Common.mk
@@ -8,8 +8,8 @@ dir_if_exists = $(if $(wildcard $(1)$(2)),$(1))
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_BOARD = $(shell if [ -f $(BOARDS_TXT) ]; \
then \
- grep -Ev '^\#' $(BOARDS_TXT) | \
- grep -E "^[ \t]*$(1).$(2)=" | \
+ $(GREP) -Ev '^\#' $(BOARDS_TXT) | \
+ $(GREP) -E "^[ \t]*$(1).$(2)=" | \
cut -d = -f 2- | \
cut -d : -f 2; \
fi)
@@ -45,15 +45,24 @@ $(call arduino_output,$(call ardmk_include) Configuration:)
########################################################################
#
# Detect OS
+
ifeq ($(OS),Windows_NT)
CURRENT_OS = WINDOWS
+ GREP := grep
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CURRENT_OS = LINUX
+ GREP := grep
endif
ifeq ($(UNAME_S),Darwin)
CURRENT_OS = MAC
+ ifeq (, $(shell which ggrep))
+ echo $(info Using macOS BSD grep, please install GNU grep to avoid warnings)
+ GREP := grep
+ else
+ GREP := ggrep
+ endif
endif
endif
$(call show_config_variable,CURRENT_OS,[AUTODETECTED])
diff --git a/HISTORY.md b/HISTORY.md
index 7751bde..8950c7e 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -18,6 +18,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
- Tweak: Update Windows usage documentation and allow non-relative paths (issue #519) (https://github.com/tuna-f1sh)
- Tweak: Support Cygwin Unix Python and Windows installation on Windows to pass correct port binding. (https://github.com/tuna-f1sh)
- Tweak: Update how avr-size is called on Sam, also moved to gnu11 std (issue #602) (https://github.com/tuna-f1sh)
+- Tweak: Detect most recent toolchain if multiple found, add `*_VER` variable to override (issue #611) (https://github.com/tuna-f1sh)
- New: Added -fdiagnostics-color to \*STD flags (https://github.com/sej7278)
- New: Made -fdiagnostics-color take a variiable DIAGNOSTICS_COLOR_WHEN: never, always, auto. (https://github.com/wingunder)
- New: Add generation of tags file using ctags, which automatically includes project libs and Arduino core. (https://github.com/tuna-f1sh)
diff --git a/Sam.mk b/Sam.mk
index a014e63..f11554f 100644
--- a/Sam.mk
+++ b/Sam.mk
@@ -160,14 +160,6 @@ ifeq ($(findstring arduino_due, $(strip $(VARIANT))), arduino_due)
SAM_CORE_C_SRCS += $(wildcard $(SAM_SYSTEM_PATH)/source/*.c)
endif
-# Use arm-toolchain from Arduino install if exists and user has not defined global version
-ifndef ARM_TOOLS_DIR
- ARM_TOOLS_DIR = $(call dir_if_exists,$(wildcard $(ARDUINO_PACKAGE_DIR)/$(ARDMK_VENDOR)/tools/$(TOOL_PREFIX)-gcc/*))
- $(call show_config_variable,ARM_TOOLS_DIR,[COMPUTED],(from ARDUINO_PACKAGE_DIR))
-else
- $(call show_config_variable,ARM_TOOLS_DIR,[USER])
-endif
-
# define plaform lib dir from Arduino ARM support
ifndef ARDUINO_PLATFORM_LIB_PATH
ARDUINO_PLATFORM_LIB_PATH := $(ALTERNATE_CORE_PATH)/libraries
@@ -179,6 +171,20 @@ endif
TOOL_PREFIX = arm-none-eabi
+# Use arm-toolchain from Arduino package install if exists and user has not defined global version
+# if undefined, AVR_TOOLS_DIR will resolve in Arduino.mk as a last resort as Arduino now installs with arm-gcc
+ifndef ARM_TOOLS_DIR
+ ifndef ARM_TOOLS_VER
+ ARM_TOOLS_VER := $(shell basename $(lastword $(wildcard $(ARDUINO_PACKAGE_DIR)/$(ARDMK_VENDOR)/tools/$(TOOL_PREFIX)-gcc/*)))
+ endif
+ ARM_TOOLS_DIR = $(ARDUINO_PACKAGE_DIR)/$(ARDMK_VENDOR)/tools/$(TOOL_PREFIX)-gcc/$(ARM_TOOLS_VER)
+ ifdef ARM_TOOLS_DIR
+ $(call show_config_variable,ARM_TOOLS_DIR,[COMPUTED],(from ARDUINO_PACKAGE_DIR))
+ endif
+else
+ $(call show_config_variable,ARM_TOOLS_DIR,[USER])
+endif
+
ifndef GDB_NAME
GDB_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gdb)
ifndef GDB_NAME
@@ -246,7 +252,9 @@ ifndef OPENOCD
BUNDLED_OPENOCD_DIR := $(call dir_if_exists,$(ARDUINO_PACKAGE_DIR)/$(ARDMK_VENDOR)/tools/openocd)
# Try Arduino support package first
ifdef BUNDLED_OPENOCD_DIR
- OPENOCD_VER := $(shell basename $(wildcard $(BUNDLED_OPENOCD_DIR)/*))
+ ifndef OPENOCD_VER
+ OPENOCD_VER := $(shell basename $(lastword $(wildcard $(BUNDLED_OPENOCD_DIR)/*)))
+ endif
OPENOCD = $(BUNDLED_OPENOCD_DIR)/$(OPENOCD_VER)/bin/openocd -s $(BUNDLED_OPENOCD_DIR)/$(OPENOCD_VER)/share/openocd/scripts/
$(call show_config_variable,OPENOCD,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
else
@@ -271,7 +279,9 @@ ifndef BOSSA
BUNDLED_BOSSA_DIR := $(call dir_if_exists,$(ARDUINO_PACKAGE_DIR)/$(ARDMK_VENDOR)/tools/bossac)
# Try Arduino support package first
ifdef BUNDLED_BOSSA_DIR
- BOSSA_VER := $(shell basename $(wildcard $(BUNDLED_BOSSA_DIR)/*))
+ ifndef BOSSA_VER
+ BOSSA_VER := $(shell basename $(lastword $(wildcard $(BUNDLED_BOSSA_DIR)/*)))
+ endif
BOSSA = $(BUNDLED_BOSSA_DIR)/$(BOSSA_VER)/bossac
$(call show_config_variable,BOSSA,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
else
@@ -394,7 +404,7 @@ CFLAGS_STD += -std=gnu11
CPPFLAGS += -DMD -D$(USB_TYPE) '-DUSB_PRODUCT=$(USB_PRODUCT)' '-DUSB_MANUFACTURER=$(USB_MANUFACTURER)'
# Get extra define flags from boards.txt
-EXFLAGS := $(shell echo $(call PARSE_BOARD,$(BOARD_TAG),build.extra_flags) | grep -oE '(-D)\w+')
+EXFLAGS := $(shell echo $(call PARSE_BOARD,$(BOARD_TAG),build.extra_flags) | $(GREP) -oE '(-D)\w+')
# Strip only defines from extra flags as boards file appends user {build.usb}
CPPFLAGS += $(EXFLAGS)
diff --git a/arduino-mk-vars.md b/arduino-mk-vars.md
index adda523..e0b8618 100644
--- a/arduino-mk-vars.md
+++ b/arduino-mk-vars.md
@@ -97,6 +97,25 @@ ARM_TOOLS_DIR =
----
+### ARM_TOOLS_VER
+
+**Description:**
+
+Sub-directory where the arm toolchain is installed - usually the tool version.
+
+Can usually be detected from `$ARDUINO_PACKAGE_DIR` /tools subdirectory when ARM
+device support is installed. Will resolve latest version if multiple found.
+
+**Example:**
+
+```Makefile
+ARM_TOOLS_VER = 7-2017q4
+```
+
+**Requirement:** *Optional*
+
+----
+
### RESET_CMD
**Description:**
@@ -1832,6 +1851,16 @@ device support is installed.
----
+### BOSSA_VER
+
+**Description:**
+
+`bossa` sub-directory - usually the tool version. Will auto-detect to highest version found.
+
+**Requirement:** *Optional*
+
+----
+
### BOSSA_OPTS
**Description:**
@@ -1857,6 +1886,16 @@ device support is installed.
----
+### OPENOCD_VER
+
+**Description:**
+
+`openocd` sub-directory - usually the tool version. Will auto-detect to highest version found.
+
+**Requirement:** *Optional*
+
+----
+
### OPENOCD_OPTS
**Description:**