Skip to content

Commit

Permalink
Merge pull request #580 from wingunder/master
Browse files Browse the repository at this point in the history
Moved the PARSE_BOARD macro and added the TOOL_PREFIX variable for setting up tool chains.
  • Loading branch information
sudar authored Sep 30, 2018
2 parents 089b535 + 62d23d6 commit fe84c59
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 368 deletions.
209 changes: 132 additions & 77 deletions Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -388,28 +388,129 @@ endif
########################################################################
# Arduino and system paths

# Third party hardware and core like ATtiny or ATmega 16
ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE,[USER])

ifndef ALTERNATE_CORE_PATH
ALTERNATE_CORE_PATH = $(ARDUINO_SKETCHBOOK)/hardware/$(ALTERNATE_CORE)/$(ARCHITECTURE)
endif
endif

ifdef ALTERNATE_CORE_PATH

ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE_PATH,[COMPUTED], (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE))
else
$(call show_config_variable,ALTERNATE_CORE_PATH,[USER])
endif

ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ALTERNATE_CORE_PATH)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif

ifndef BOARDS_TXT
BOARDS_TXT = $(ALTERNATE_CORE_PATH)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif

else

ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,ARDUINO_VAR_PATH,[USER])
endif

ifndef BOARDS_TXT
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,BOARDS_TXT,[USER])
endif

endif

ifeq (,$(wildcard $(BOARDS_TXT)))
$(error Currently BOARDS_TXT='$(BOARDS_TXT)', which is not an existing file or an invalid filename.)
endif

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 +558,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 +584,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 All @@ -505,51 +606,6 @@ else
$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER])
endif

# Third party hardware and core like ATtiny or ATmega 16
ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE,[USER])

ifndef ALTERNATE_CORE_PATH
ALTERNATE_CORE_PATH = $(ARDUINO_SKETCHBOOK)/hardware/$(ALTERNATE_CORE)/$(ARCHITECTURE)
endif
endif

ifdef ALTERNATE_CORE_PATH

ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE_PATH,[COMPUTED], (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE))
else
$(call show_config_variable,ALTERNATE_CORE_PATH,[USER])
endif

ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ALTERNATE_CORE_PATH)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif

ifndef BOARDS_TXT
BOARDS_TXT = $(ALTERNATE_CORE_PATH)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif

else

ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,ARDUINO_VAR_PATH,[USER])
endif

ifndef BOARDS_TXT
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,BOARDS_TXT,[USER])
endif

endif

########################################################################
# Miscellaneous

Expand Down Expand Up @@ -585,11 +641,6 @@ else
$(call show_config_variable,BOARD_TAG,[USER])
endif

ifndef PARSE_BOARD
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_BOARD = $(shell grep -Ev '^\#' $(BOARDS_TXT) | grep -E "^[ \t]*$(1).$(2)=" | cut -d = -f 2 | cut -d : -f 2)
endif

# If NO_CORE is set, then we don't have to parse boards.txt file
# But the user might have to define MCU, F_CPU etc
ifeq ($(strip $(NO_CORE)),)
Expand Down Expand Up @@ -826,7 +877,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 @@ -936,18 +987,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 @@ -1083,15 +1138,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 @@ -1409,7 +1464,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 @@ -1752,7 +1807,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
11 changes: 11 additions & 0 deletions Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ COMMON_INCLUDED = TRUE
# (directory and optional filename) exists
dir_if_exists = $(if $(wildcard $(1)$(2)),$(1))

ifndef PARSE_BOARD
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_BOARD = $(shell if [ -f $(BOARDS_TXT) ]; \
then \
grep -Ev '^\#' $(BOARDS_TXT) | \
grep -E "^[ \t]*$(1).$(2)=" | \
cut -d = -f 2 | \
cut -d : -f 2; \
fi)
endif

# Run a shell script if it exists. Stops make on error.
runscript_if_exists = \
$(if $(wildcard $(1)), \
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
- New: Compatibility with deprecated pgmspace.h API can now be disabled since it sometimes causes bogus compiler warnings (issue #546)
- 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
Loading

0 comments on commit fe84c59

Please sign in to comment.