Moved the PARSE_BOARD macro from Arduino.mk to Common.mk.

There seems to be 3 different macros to parse the boards.txt file.
This patch moves the PARSE_BOARD macro from Arduino.mk to Common.mk.
The PARSE_OPENCM and PARSE_TEENSY macros in Teensy.mk and OpenCM.mk
were removed and the common PARSE_BOARD is now being called from
everywhere.

Advantages of this fix are:
  1. Less code, i.e. no redundant parse macros.
  2. A single standardized algorithm to parse the boards.txt file.
This commit is contained in:
Pieter du Preez 2018-09-13 23:44:12 +02:00
parent 22ca63614d
commit 2442dafb4f
5 changed files with 55 additions and 65 deletions

View file

@ -585,11 +585,6 @@ else
$(call show_config_variable,BOARD_TAG,[USER]) $(call show_config_variable,BOARD_TAG,[USER])
endif 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 # 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 # But the user might have to define MCU, F_CPU etc
ifeq ($(strip $(NO_CORE)),) ifeq ($(strip $(NO_CORE)),)

View file

@ -5,6 +5,11 @@ COMMON_INCLUDED = TRUE
# (directory and optional filename) exists # (directory and optional filename) exists
dir_if_exists = $(if $(wildcard $(1)$(2)),$(1)) dir_if_exists = $(if $(wildcard $(1)$(2)),$(1))
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
# Run a shell script if it exists. Stops make on error. # Run a shell script if it exists. Stops make on error.
runscript_if_exists = \ runscript_if_exists = \
$(if $(wildcard $(1)), \ $(if $(wildcard $(1)), \

View file

@ -22,6 +22,7 @@ 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: 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 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: 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)
### 1.6.0 (2017-07-11) ### 1.6.0 (2017-07-11)
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278) - Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)

View file

@ -44,17 +44,12 @@ ifndef BOARDS_TXT
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/boards.txt BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/boards.txt
endif endif
ifndef PARSE_OPENCM
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_OPENCM = $(shell grep -v "^\#" "$(BOARDS_TXT)" | grep $(1).$(2) | cut -d = -f 2- )
endif
ifndef F_CPU ifndef F_CPU
F_CPU := $(call PARSE_OPENCM,$(BOARD_TAG),build.f_cpu) F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu)
endif endif
# if boards.txt gets modified, look there, else hard code it # if boards.txt gets modified, look there, else hard code it
ARCHITECTURE = $(call PARSE_OPENCM,$(BOARD_TAG),build.architecture) ARCHITECTURE = $(call PARSE_BOARD,$(BOARD_TAG),build.architecture)
ifeq ($(strip $(ARCHITECTURE)),) ifeq ($(strip $(ARCHITECTURE)),)
ARCHITECTURE = arm ARCHITECTURE = arm
endif endif
@ -75,7 +70,7 @@ endif
# command names # command names
ifndef CC_NAME ifndef CC_NAME
CC_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.gcc) CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME ifndef CC_NAME
CC_NAME := arm-none-eabi-gcc CC_NAME := arm-none-eabi-gcc
else else
@ -84,7 +79,7 @@ ifndef CC_NAME
endif endif
ifndef CXX_NAME ifndef CXX_NAME
CXX_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.g++) CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME ifndef CXX_NAME
CXX_NAME := arm-none-eabi-g++ CXX_NAME := arm-none-eabi-g++
else else
@ -93,7 +88,7 @@ ifndef CXX_NAME
endif endif
ifndef AS_NAME ifndef AS_NAME
AS_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.as) AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME ifndef AS_NAME
AS_NAME := arm-none-eabi-as AS_NAME := arm-none-eabi-as
else else
@ -102,7 +97,7 @@ ifndef AS_NAME
endif endif
ifndef OBJDUMP_NAME ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.objdump) OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME ifndef OBJDUMP_NAME
OBJDUMP_NAME := arm-none-eabi-objdump OBJDUMP_NAME := arm-none-eabi-objdump
else else
@ -111,7 +106,7 @@ ifndef OBJDUMP_NAME
endif endif
ifndef AR_NAME ifndef AR_NAME
AR_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.ar) AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME ifndef AR_NAME
AR_NAME := arm-none-eabi-ar AR_NAME := arm-none-eabi-ar
else else
@ -120,7 +115,7 @@ ifndef AR_NAME
endif endif
ifndef SIZE_NAME ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.size) SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME ifndef SIZE_NAME
SIZE_NAME := arm-none-eabi-size SIZE_NAME := arm-none-eabi-size
else else
@ -129,7 +124,7 @@ ifndef SIZE_NAME
endif endif
ifndef NM_NAME ifndef NM_NAME
NM_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.nm) NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME ifndef NM_NAME
NM_NAME := arm-none-eabi-nm NM_NAME := arm-none-eabi-nm
else else
@ -138,7 +133,7 @@ ifndef NM_NAME
endif endif
ifndef OBJCOPY_NAME ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_OPENCM,$(BOARD_TAG),build.command.objcopy) OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME ifndef OBJCOPY_NAME
OBJCOPY_NAME := arm-none-eabi-objcopy OBJCOPY_NAME := arm-none-eabi-objcopy
else else
@ -148,7 +143,7 @@ endif
# processor stuff # processor stuff
ifndef MCU ifndef MCU
MCU := $(call PARSE_OPENCM,$(BOARD_TAG),build.family) MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.family)
endif endif
ifndef MCU_FLAG_NAME ifndef MCU_FLAG_NAME
@ -161,20 +156,20 @@ ifndef USB_TYPE
USB_TYPE = USB_SERIAL USB_TYPE = USB_SERIAL
endif endif
CPPFLAGS += -DBOARD_$(call PARSE_OPENCM,$(BOARD_TAG),build.board) CPPFLAGS += -DBOARD_$(call PARSE_BOARD,$(BOARD_TAG),build.board)
CPPFLAGS += -DMCU_$(call PARSE_OPENCM,$(BOARD_TAG),build.mcu) CPPFLAGS += -DMCU_$(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
CPPFLAGS += -DSTM32_MEDIUM_DENSITY -DVECT_TAB_FLASH CPPFLAGS += -DSTM32_MEDIUM_DENSITY -DVECT_TAB_FLASH
CPPFLAGS += $(call PARSE_OPENCM,$(BOARD_TAG),build.option) CPPFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.option)
CXXFLAGS += -fno-rtti CXXFLAGS += -fno-rtti
CXXFLAGS += $(call PARSE_OPENCM,$(BOARD_TAG),build.cppoption) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.cppoption)
ifeq ("$(call PARSE_OPENCM,$(BOARD_TAG),build.gnu0x)","true") ifeq ("$(call PARSE_BOARD,$(BOARD_TAG),build.gnu0x)","true")
CXXFLAGS_STD += -std=gnu++0x CXXFLAGS_STD += -std=gnu++0x
endif endif
ifeq ("$(call PARSE_OPENCM,$(BOARD_TAG),build.elide_constructors)", "true") ifeq ("$(call PARSE_BOARD,$(BOARD_TAG),build.elide_constructors)", "true")
CXXFLAGS += -felide-constructors CXXFLAGS += -felide-constructors
endif endif
@ -209,7 +204,7 @@ ifeq ($(CURRENT_OS), WINDOWS)
else else
override AVRDUDE_ARD_OPTS = $(call get_monitor_port) override AVRDUDE_ARD_OPTS = $(call get_monitor_port)
endif endif
override AVRDUDE_UPLOAD_HEX = $(TARGET_HEX) override AVRDUDE_UPLOAD_HEX = $(TARGET_HEX)
######################################################################## ########################################################################

View file

@ -38,25 +38,19 @@ ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/teensy/avr/cores/teensy3
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/avr/boards.txt BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/avr/boards.txt
ifndef PARSE_TEENSY
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_TEENSY = $(shell grep -v "^\#" "$(BOARDS_TXT)" | grep $(1).$(2) | cut -d = -f 2- )
endif
ifndef F_CPU ifndef F_CPU
ifndef BOARD_SUB ifndef BOARD_SUB
SPEEDS := $(call PARSE_TEENSY,"$(BOARD_TAG),menu.speed.*.build.fcpu") # Obtain sequence of supported frequencies. SPEEDS := $(call PARSE_BOARD,"$(BOARD_TAG),menu.speed.*.build.fcpu") # Obtain sequence of supported frequencies.
SPEEDS := $(shell printf "%d\n" $(SPEEDS) | sort -g) # Sort it, just in case. Printf to re-append newlines so that sort works. SPEEDS := $(shell printf "%d\n" $(SPEEDS) | sort -g) # Sort it, just in case. Printf to re-append newlines so that sort works.
F_CPU := $(lastword $(SPEEDS)) # List is sorted in ascending order. Take the fastest speed. F_CPU := $(lastword $(SPEEDS)) # List is sorted in ascending order. Take the fastest speed.
#$(info "speeds is " $(SPEEDS)) # Good for debugging #$(info "speeds is " $(SPEEDS)) # Good for debugging
else else
F_CPU := $(call PARSE_TEENSY,$(BOARD_TAG),menu.speed.$(BOARD_SUB).build.fcpu) F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.speed.$(BOARD_SUB).build.fcpu)
endif endif
endif endif
# if boards.txt gets modified, look there, else hard code it # if boards.txt gets modified, look there, else hard code it
ARCHITECTURE = $(call PARSE_TEENSY,$(BOARD_TAG),build.architecture) ARCHITECTURE = $(call PARSE_BOARD,$(BOARD_TAG),build.architecture)
ifeq ($(strip $(ARCHITECTURE)),) ifeq ($(strip $(ARCHITECTURE)),)
ARCHITECTURE = arm ARCHITECTURE = arm
endif endif
@ -73,7 +67,7 @@ endif
# command names # command names
ifndef CC_NAME ifndef CC_NAME
CC_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.gcc) CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME ifndef CC_NAME
CC_NAME := arm-none-eabi-gcc CC_NAME := arm-none-eabi-gcc
else else
@ -82,7 +76,7 @@ ifndef CC_NAME
endif endif
ifndef CXX_NAME ifndef CXX_NAME
CXX_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.g++) CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME ifndef CXX_NAME
CXX_NAME := arm-none-eabi-g++ CXX_NAME := arm-none-eabi-g++
else else
@ -91,7 +85,7 @@ ifndef CXX_NAME
endif endif
ifndef AS_NAME ifndef AS_NAME
AS_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.as) AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME ifndef AS_NAME
AS_NAME := arm-none-eabi-gcc-as AS_NAME := arm-none-eabi-gcc-as
else else
@ -100,7 +94,7 @@ ifndef AS_NAME
endif endif
ifndef OBJCOPY_NAME ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.objcopy) OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME ifndef OBJCOPY_NAME
OBJCOPY_NAME := arm-none-eabi-objcopy OBJCOPY_NAME := arm-none-eabi-objcopy
else else
@ -109,7 +103,7 @@ ifndef OBJCOPY_NAME
endif endif
ifndef OBJDUMP_NAME ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.objdump) OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME ifndef OBJDUMP_NAME
OBJDUMP_NAME := arm-none-eabi-objdump OBJDUMP_NAME := arm-none-eabi-objdump
else else
@ -118,7 +112,7 @@ ifndef OBJDUMP_NAME
endif endif
ifndef AR_NAME ifndef AR_NAME
AR_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.ar) AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME ifndef AR_NAME
AR_NAME := arm-none-eabi-ar AR_NAME := arm-none-eabi-ar
else else
@ -127,7 +121,7 @@ ifndef AR_NAME
endif endif
ifndef SIZE_NAME ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.size) SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME ifndef SIZE_NAME
SIZE_NAME := arm-none-eabi-size SIZE_NAME := arm-none-eabi-size
else else
@ -136,7 +130,7 @@ ifndef SIZE_NAME
endif endif
ifndef NM_NAME ifndef NM_NAME
NM_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.nm) NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME ifndef NM_NAME
NM_NAME := arm-none-eabi-gcc-nm NM_NAME := arm-none-eabi-gcc-nm
else else
@ -146,7 +140,7 @@ endif
# processor stuff # processor stuff
ifndef MCU ifndef MCU
MCU := $(call PARSE_TEENSY,$(BOARD_TAG),build.mcu) MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
endif endif
ifndef MCU_FLAG_NAME ifndef MCU_FLAG_NAME
@ -161,39 +155,39 @@ endif
CPPFLAGS += -DLAYOUT_US_ENGLISH -D$(USB_TYPE) CPPFLAGS += -DLAYOUT_US_ENGLISH -D$(USB_TYPE)
CPPFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.option) CPPFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.option)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.cppoption) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.cppoption)
ifeq ("$(call PARSE_TEENSY,$(BOARD_TAG),build.gnu0x)","true") ifeq ("$(call PARSE_BOARD,$(BOARD_TAG),build.gnu0x)","true")
CXXFLAGS_STD += -std=gnu++0x CXXFLAGS_STD += -std=gnu++0x
endif endif
ifeq ("$(call PARSE_TEENSY,$(BOARD_TAG),build.elide_constructors)", "true") ifeq ("$(call PARSE_BOARD,$(BOARD_TAG),build.elide_constructors)", "true")
CXXFLAGS += -felide-constructors CXXFLAGS += -felide-constructors
endif endif
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.common)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpu)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.defs)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpp) CXXFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpp)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common) CFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.common)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu) CFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpu)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs) CFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.defs)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common) ASFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.common)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu) ASFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpu)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs) ASFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.defs)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.S) ASFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.S)
LDFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu) LDFLAGS += $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpu)
AMCU := $(call PARSE_TEENSY,$(BOARD_TAG),build.mcu) AMCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
LDFLAGS += -Wl,--gc-sections,--relax LDFLAGS += -Wl,--gc-sections,--relax
LINKER_SCRIPTS = -T${ARDUINO_CORE_PATH}/${AMCU}.ld LINKER_SCRIPTS = -T${ARDUINO_CORE_PATH}/${AMCU}.ld
OTHER_LIBS = $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.libs) OTHER_LIBS = $(call PARSE_BOARD,$(BOARD_TAG),build.flags.libs)
CPUFLAGS = $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu) CPUFLAGS = $(call PARSE_BOARD,$(BOARD_TAG),build.flags.cpu)
# usually defined as per teensy31.build.mcu=mk20dx256 but that isn't valid switch # usually defined as per teensy31.build.mcu=mk20dx256 but that isn't valid switch
MCU := $(shell echo ${CPUFLAGS} | sed -n -e 's/.*-mcpu=\([a-zA-Z0-9_-]*\).*/\1/p') MCU := $(shell echo ${CPUFLAGS} | sed -n -e 's/.*-mcpu=\([a-zA-Z0-9_-]*\).*/\1/p')