Skip to content

Commit

Permalink
Added the TOOL_PREFIX variable for setting up the executable tools.
Browse files Browse the repository at this point in the history
Currently three different tool chains seem to be used:
   * avr-*
   * pic32-*
   * arm-none-eabi-*

These all get set up independently. This patch centralizes the
definitions of the executable tools and does it generically, by means
of the newly introduced TOOL_PREFIX variable. Setting up a
tool chain is now simply a matter of defining the TOOL_PREFIX
variable. For the currently supported tool chains it gets set to avr,
pic32 or arm-none-eabi. Arbitrary tool chains can now easily be set up,
by the TOOL_PREFIX variable.

Although the use of the OVERRIDE_EXECUTABLES variable is now almost
not justifiable, it was left as-is, in order to assure backwards
compatibility.
  • Loading branch information
wingunder committed Sep 14, 2018
1 parent 2442daf commit e445400
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 274 deletions.
110 changes: 83 additions & 27 deletions Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -388,28 +388,80 @@ endif
########################################################################
# Arduino and system paths

ifndef TOOL_PREFIX
TOOL_PREFIX = avr
endif

ifndef CC_NAME
CC_NAME = avr-gcc
CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME
CC_NAME := $(TOOL_PREFIX)-gcc
else
$(call show_config_variable,CC_NAME,[COMPUTED])
endif
endif

ifndef CXX_NAME
CXX_NAME = avr-g++
CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME
CXX_NAME := $(TOOL_PREFIX)-g++
else
$(call show_config_variable,CXX_NAME,[COMPUTED])
endif
endif

ifndef AS_NAME
AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME
AS_NAME := $(TOOL_PREFIX)-as
else
$(call show_config_variable,AS_NAME,[COMPUTED])
endif
endif

ifndef OBJCOPY_NAME
OBJCOPY_NAME = avr-objcopy
OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(TOOL_PREFIX)-objcopy
else
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
endif
endif

ifndef OBJDUMP_NAME
OBJDUMP_NAME = avr-objdump
OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(TOOL_PREFIX)-objdump
else
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
endif
endif

ifndef AR_NAME
AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME
AR_NAME := $(TOOL_PREFIX)-ar
else
$(call show_config_variable,AR_NAME,[COMPUTED])
endif
endif

ifndef SIZE_NAME
SIZE_NAME = avr-size
SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME
SIZE_NAME := $(TOOL_PREFIX)-size
else
$(call show_config_variable,SIZE_NAME,[COMPUTED])
endif
endif

ifndef NM_NAME
NM_NAME = avr-nm
NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME
NM_NAME := $(TOOL_PREFIX)-nm
else
$(call show_config_variable,NM_NAME,[COMPUTED])
endif
endif

ifndef AVR_TOOLS_DIR
Expand Down Expand Up @@ -457,8 +509,8 @@ ifndef AVR_TOOLS_DIR
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR)
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
else
# One last attempt using avr-gcc in case using arm
SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(avr-gcc)))/..))
# One last attempt using $(TOOL_PREFIX)-gcc in case using arm
SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $($(TOOL_PREFIX)-gcc)))/..))
ifdef SYSTEMPATH_AVR_TOOLS_DIR
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR)
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
Expand All @@ -483,8 +535,8 @@ else

endif #ndef AVR_TOOLS_DIR

ifndef AVR_TOOLS_PATH
AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin
ifndef TOOLS_PATH
TOOLS_PATH = $(AVR_TOOLS_DIR)/bin
endif

ifndef ARDUINO_LIB_PATH
Expand Down Expand Up @@ -821,7 +873,7 @@ endif
ifeq ($(strip $(NO_CORE)),)
ifdef ARDUINO_CORE_PATH
CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr-libc/*.c)
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/$(TOOL_PREFIX)-libc/*.c)
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S)

Expand Down Expand Up @@ -931,18 +983,22 @@ TARGET_EEP = $(OBJDIR)/$(TARGET).eep
TARGET_BIN = $(OBJDIR)/$(TARGET).bin
CORE_LIB = $(OBJDIR)/libcore.a

# Names of executables - chipKIT needs to override all to set paths to PIC32
# tools, and we can't use "?=" assignment because these are already implicitly
# Names of executables
# In the rare case of wanting to override a path and/or excecutable
# name, the OVERRIDE_EXECUTABLES variable must be defned and _all_
# the excecutables (CC, CXX, AS, OBJCOPY, OBJDUMP AR, SIZE and NM)
# _must_ be defined in the calling makefile.
# We can't use "?=" assignment because these are already implicitly
# defined by Make (e.g. $(CC) == cc).
ifndef OVERRIDE_EXECUTABLES
CC = $(AVR_TOOLS_PATH)/$(CC_NAME)
CXX = $(AVR_TOOLS_PATH)/$(CXX_NAME)
AS = $(AVR_TOOLS_PATH)/$(AS_NAME)
OBJCOPY = $(AVR_TOOLS_PATH)/$(OBJCOPY_NAME)
OBJDUMP = $(AVR_TOOLS_PATH)/$(OBJDUMP_NAME)
AR = $(AVR_TOOLS_PATH)/$(AR_NAME)
SIZE = $(AVR_TOOLS_PATH)/$(SIZE_NAME)
NM = $(AVR_TOOLS_PATH)/$(NM_NAME)
CC = $(TOOLS_PATH)/$(CC_NAME)
CXX = $(TOOLS_PATH)/$(CXX_NAME)
AS = $(TOOLS_PATH)/$(AS_NAME)
OBJCOPY = $(TOOLS_PATH)/$(OBJCOPY_NAME)
OBJDUMP = $(TOOLS_PATH)/$(OBJDUMP_NAME)
AR = $(TOOLS_PATH)/$(AR_NAME)
SIZE = $(TOOLS_PATH)/$(SIZE_NAME)
NM = $(TOOLS_PATH)/$(NM_NAME)
endif

REMOVE = rm -rf
Expand Down Expand Up @@ -1078,15 +1134,15 @@ ifneq ($(CATERINA),)
CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID)
endif

# avr-gcc version that we can do maths on
# $(TOOL_PREFIX)-gcc version that we can do maths on
CC_VERNUM = $(shell $(CC) -dumpversion | sed 's/\.//g')

# moved from above so we can find version-dependant ar
ifndef AR_NAME
ifeq ($(TOOL_PREFIX), avr)
ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
AR_NAME = avr-gcc-ar
AR_NAME := $(TOOL_PREFIX)-gcc-ar
else
AR_NAME = avr-ar
AR_NAME := $(TOOL_PREFIX)-ar
endif
endif

Expand Down Expand Up @@ -1404,7 +1460,7 @@ CTAGS_CMD = $(CTAGS_EXEC) $(CTAGS_OPTS) -auf

# If avrdude is installed separately, it can find its own config file
ifndef AVRDUDE
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
AVRDUDE = $(TOOLS_PATH)/avrdude
endif

# Default avrdude options
Expand Down Expand Up @@ -1747,7 +1803,7 @@ help:
make debug_init - start openocd gdb server\n\
make debug - connect to gdb target and begin debugging\n\
make size - show the size of the compiled output (relative to\n\
resources, if you have a patched avr-size).\n\
resources, if you have a patched $(TOOL_PREFIX)-size).\n\
make verify_size - verify that the size of the final file is less than\n\
the capacity of the micro controller.\n\
make symbol_sizes - generate a .sym file containing symbols and their\n\
Expand Down
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
- New: Support Arduino ARM SAMD devices (Zero, M0 Pro, Feather M0). (https://github.com/tuna-f1sh)
- New: Support Arduino ARM SAM devices (Due). (https://github.com/tuna-f1sh)
- New: Moved the PARSE_BOARD macro to Common.mk and use only this to parse the boards.txt file. (https://github.com/wingunder)
- New: Added the TOOL_PREFIX variable for setting up the executable tools centrally and generically. (https://github.com/wingunder)

### 1.6.0 (2017-07-11)
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)
Expand Down
72 changes: 1 addition & 71 deletions OpenCM.mk
Original file line number Diff line number Diff line change
Expand Up @@ -69,77 +69,7 @@ endif
########################################################################
# command names

ifndef CC_NAME
CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME
CC_NAME := arm-none-eabi-gcc
else
$(call show_config_variable,CC_NAME,[COMPUTED])
endif
endif

ifndef CXX_NAME
CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME
CXX_NAME := arm-none-eabi-g++
else
$(call show_config_variable,CXX_NAME,[COMPUTED])
endif
endif

ifndef AS_NAME
AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME
AS_NAME := arm-none-eabi-as
else
$(call show_config_variable,AS_NAME,[COMPUTED])
endif
endif

ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME
OBJDUMP_NAME := arm-none-eabi-objdump
else
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
endif
endif

ifndef AR_NAME
AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME
AR_NAME := arm-none-eabi-ar
else
$(call show_config_variable,AR_NAME,[COMPUTED])
endif
endif

ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME
SIZE_NAME := arm-none-eabi-size
else
$(call show_config_variable,SIZE_NAME,[COMPUTED])
endif
endif

ifndef NM_NAME
NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME
NM_NAME := arm-none-eabi-nm
else
$(call show_config_variable,NM_NAME,[COMPUTED])
endif
endif

ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME
OBJCOPY_NAME := arm-none-eabi-objcopy
else
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
endif
endif
TOOL_PREFIX = arm-none-eabi

# processor stuff
ifndef MCU
Expand Down
89 changes: 5 additions & 84 deletions Sam.mk
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ 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/arm-none-eabi-gcc/*))
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])
Expand All @@ -182,82 +182,12 @@ endif
########################################################################
# command names

ifndef CC_NAME
CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME
CC_NAME := arm-none-eabi-gcc
else
$(call show_config_variable,CC_NAME,[COMPUTED])
endif
endif

ifndef CXX_NAME
CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g\+\+)
ifndef CXX_NAME
CXX_NAME := arm-none-eabi-g++
else
$(call show_config_variable,CXX_NAME,[COMPUTED])
endif
endif

ifndef AS_NAME
AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME
AS_NAME := arm-none-eabi-gcc-as
else
$(call show_config_variable,AS_NAME,[COMPUTED])
endif
endif

ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME
OBJCOPY_NAME := arm-none-eabi-objcopy
else
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
endif
endif

ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME
OBJDUMP_NAME := arm-none-eabi-objdump
else
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
endif
endif

ifndef AR_NAME
AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME
AR_NAME := arm-none-eabi-ar
else
$(call show_config_variable,AR_NAME,[COMPUTED])
endif
endif

ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME
SIZE_NAME := arm-none-eabi-size
else
$(call show_config_variable,SIZE_NAME,[COMPUTED])
endif
endif

ifndef NM_NAME
NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME
NM_NAME := arm-none-eabi-gcc-nm
else
$(call show_config_variable,NM_NAME,[COMPUTED])
endif
endif
TOOL_PREFIX = arm-none-eabi

ifndef GDB_NAME
GDB_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gdb)
ifndef GDB_NAME
GDB_NAME := arm-none-eabi-gdb
GDB_NAME := $(TOOL_PREFIX)-gdb
else
$(call show_config_variable,GDB_NAME,[COMPUTED])
endif
Expand Down Expand Up @@ -385,17 +315,8 @@ endif
########################################################################
# EXECUTABLES
# Define them here to use ARM_TOOLS_PATH and allow auto finding of AVR_TOOLS_PATH
OVERRIDE_EXECUTABLES = 1

ARM_TOOLS_PATH := $(ARM_TOOLS_DIR)/bin
CC = $(ARM_TOOLS_PATH)/$(CC_NAME)
CXX = $(ARM_TOOLS_PATH)/$(CXX_NAME)
AS = $(ARM_TOOLS_PATH)/$(AS_NAME)
OBJCOPY = $(ARM_TOOLS_PATH)/$(OBJCOPY_NAME)
OBJDUMP = $(ARM_TOOLS_PATH)/$(OBJDUMP_NAME)
AR = $(ARM_TOOLS_PATH)/$(AR_NAME)
SIZE = $(ARM_TOOLS_PATH)/$(SIZE_NAME)
NM = $(ARM_TOOLS_PATH)/$(NM_NAME)

AVR_TOOLS_DIR := $(ARM_TOOLS_DIR)
#GDB = $(ARM_TOOLS_PATH)/$(GDB_NAME)
# Use system gdb for now as Arduino supplied has lib error?
GDB = $(GDB_NAME)
Expand Down
Loading

0 comments on commit e445400

Please sign in to comment.