1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Makefile*: Allow multiple external board dirs

- Add the new EXTERNAL_BOARD_DIRS variable that can contain a space separated
  list of folders containing external boards
- Introduce $(BOARDDIR) as shortcut for $(BOARDSDIR)/$(BOARD)
- Map the existing BOARDSDIR to the new approach
    - If BOARDSDIR is provided by the user, it will be added to
      EXTERNAL_BOARD_DIRS for backward compatibility. (And a warning is issued
      to encourage users migrating to EXTRA_BOARDS.)
    - BOARDSDIR is updated after the board is found to "$(BOARDDIR)/..".
        - Useful for `include $(BOARDSDIR)/common/external_common/Makefile.dep`
        - Provides backward compatibility
This commit is contained in:
Marian Buschsieweke 2020-04-14 15:23:23 +02:00
parent 1c22ee8782
commit ba7815163c
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
16 changed files with 112 additions and 92 deletions

View File

@ -2,7 +2,7 @@
-include $(APPDIR)/Makefile.board.dep
# include board dependencies
-include $(BOARDSDIR)/$(BOARD)/Makefile.dep
-include $(BOARDDIR)/Makefile.dep
# include cpu dependencies
-include $(RIOTCPU)/$(CPU)/Makefile.dep

View File

@ -9,7 +9,7 @@
# Moving 'CPU/CPU_MODEL' to Makefile.features is an ongoing work and may not
# reflect the state of all boards for the moment.
include $(BOARDSDIR)/$(BOARD)/Makefile.features
include $(BOARDDIR)/Makefile.features
# Sanity check
ifeq (,$(CPU))

View File

@ -23,24 +23,24 @@ include $(RIOT_MAKEFILES_GLOBAL_PRE)
-include Makefile.local
# set undefined variables
RIOTBASE ?= $(_riotbase)
RIOTCPU ?= $(RIOTBASE)/cpu
# Deprecated to set RIOTBOARD, use BOARDSDIR
RIOTBOARD ?= $(RIOTBASE)/boards
BOARDSDIR ?= $(RIOTBOARD)
RIOTMAKE ?= $(RIOTBASE)/makefiles
RIOTPKG ?= $(RIOTBASE)/pkg
RIOTTOOLS ?= $(RIOTBASE)/dist/tools
RIOTPROJECT ?= $(shell git rev-parse --show-toplevel 2>/dev/null || pwd)
GITCACHE ?= $(RIOTTOOLS)/git/git-cache
GIT_CACHE_DIR ?= $(HOME)/.gitcache
BUILD_DIR ?= $(RIOTBASE)/build
APPDIR ?= $(CURDIR)
BINDIRBASE ?= $(APPDIR)/bin
BINDIR ?= $(BINDIRBASE)/$(BOARD)
PKGDIRBASE ?= $(BINDIRBASE)/pkg/$(BOARD)
DLCACHE ?= $(RIOTTOOLS)/dlcache/dlcache.sh
DLCACHE_DIR ?= $(RIOTBASE)/.dlcache
RIOTBASE ?= $(_riotbase)
RIOTCPU ?= $(RIOTBASE)/cpu
# Deprecated to set RIOTBOARD, use EXTERNAL_BOARD_DIRS
RIOTBOARD ?= $(RIOTBASE)/boards
EXTERNAL_BOARD_DIRS ?=
RIOTMAKE ?= $(RIOTBASE)/makefiles
RIOTPKG ?= $(RIOTBASE)/pkg
RIOTTOOLS ?= $(RIOTBASE)/dist/tools
RIOTPROJECT ?= $(shell git rev-parse --show-toplevel 2>/dev/null || pwd)
GITCACHE ?= $(RIOTTOOLS)/git/git-cache
GIT_CACHE_DIR ?= $(HOME)/.gitcache
BUILD_DIR ?= $(RIOTBASE)/build
APPDIR ?= $(CURDIR)
BINDIRBASE ?= $(APPDIR)/bin
BINDIR ?= $(BINDIRBASE)/$(BOARD)
PKGDIRBASE ?= $(BINDIRBASE)/pkg/$(BOARD)
DLCACHE ?= $(RIOTTOOLS)/dlcache/dlcache.sh
DLCACHE_DIR ?= $(RIOTBASE)/.dlcache
# include CI info such as BOARD_INSUFFICIENT_MEMORY, if existing
-include Makefile.ci
@ -67,34 +67,52 @@ __OVERRIDE_DIRECTORY_VARIABLES := $(__DIRECTORY_VARIABLES)
# Use absolute paths in recursive "make" even if overridden on command line.
MAKEOVERRIDES += $(foreach v,$(__OVERRIDE_DIRECTORY_VARIABLES),$(v)=$($(v)))
# Setting EXTERNAL_BOARD_DIRS as command line argument is too messy to handle:
# Even when every path in EXTERNAL_BOARD_DIRS is turned into an absolute path
# using override, sub-makes will still get the original value. Using
# MAKEOVERRIDES has issues with spaces in the values, which are used as
# separator in EXTERNAL_BOARD_DIRS. So we just enforce setting the value
# either in a Makefile, or as environment variable.
ifeq ($(origin EXTERNAL_BOARD_DIRS),command line)
# In Docker absolute paths are always given, so only fail when not in docker
ifeq ($(INSIDE_DOCKER),0)
$(error EXTERNAL_BOARD_DIRS must be passed as environment variable, and not as command line argument)
endif
endif
# Deprecation of configuring 'RIOTBOARD'
ifneq ($(abspath $(RIOTBASE)/boards),$(abspath $(RIOTBOARD)))
$(warning overriding RIOTBOARD for external boards is deprecated, please use an absolute BOARDSDIR)
$(warning overriding RIOTBOARD for external boards is deprecated, use EXTERNAL_BOARD_DIRS instead)
override RIOTBOARD := $(abspath $(RIOTBOARD))
__DIRECTORY_VARIABLES += RIOTBOARD
endif
ifneq (,$(BOARDSDIR))
# Only warn users, not the CI.
ifneq ($(RIOT_CI_BUILD),1)
$(warning Using BOARDSDIR is deprecated use EXTERNAL_BOARD_DIRS instead)
$(info EXTERNAL_BOARD_DIRS can contain multiple folders separated by space)
endif
EXTERNAL_BOARD_DIRS += $(BOARDSDIR)
endif
# Make all paths absolute.
override RIOTBASE := $(abspath $(RIOTBASE))
override RIOTCPU := $(abspath $(RIOTCPU))
override RIOTMAKE := $(abspath $(RIOTMAKE))
override RIOTPKG := $(abspath $(RIOTPKG))
override RIOTTOOLS := $(abspath $(RIOTTOOLS))
override RIOTPROJECT := $(abspath $(RIOTPROJECT))
override GITCACHE := $(abspath $(GITCACHE))
override APPDIR := $(abspath $(APPDIR))
override BUILD_DIR := $(abspath $(BUILD_DIR))
override BINDIRBASE := $(abspath $(BINDIRBASE))
override BINDIR := $(abspath $(BINDIR))
override PKGDIRBASE := $(abspath $(PKGDIRBASE))
override DLCACHE_DIR := $(abspath $(DLCACHE_DIR))
# Keep standard make behavior for new variables
__DIRECTORY_VARIABLES += \
BOARDSDIR \
#
BOARDSDIR := $(abspath $(BOARDSDIR))
override RIOTBASE := $(abspath $(RIOTBASE))
override RIOTCPU := $(abspath $(RIOTCPU))
override RIOTMAKE := $(abspath $(RIOTMAKE))
override RIOTPKG := $(abspath $(RIOTPKG))
override RIOTTOOLS := $(abspath $(RIOTTOOLS))
override RIOTPROJECT := $(abspath $(RIOTPROJECT))
override GITCACHE := $(abspath $(GITCACHE))
override APPDIR := $(abspath $(APPDIR))
override BUILD_DIR := $(abspath $(BUILD_DIR))
override BINDIRBASE := $(abspath $(BINDIRBASE))
override BINDIR := $(abspath $(BINDIR))
override PKGDIRBASE := $(abspath $(PKGDIRBASE))
override DLCACHE_DIR := $(abspath $(DLCACHE_DIR))
EXTERNAL_BOARD_DIRS := $(foreach dir,\
$(EXTERNAL_BOARD_DIRS),\
$(abspath $(dir)))
# Ensure that all directories are set and don't contain spaces.
ifneq (, $(filter-out 1, $(foreach v,$(__DIRECTORY_VARIABLES),$(words $($(v))))))
@ -159,18 +177,21 @@ else
all: link
# Include Board and CPU configuration, if BOARD is not found in BOARDSDIR
# e.g. when set by the environment fallback to searching in RIOTBOARD
ifeq (,$(wildcard $(BOARDSDIR)/$(BOARD)/.))
ifneq ($(RIOTBOARD),$(BOARDSDIR))
# The specified board $(BOARD) was not found in $(BOARDSDIR) fallback to RIOTBOARD
BOARDSDIR = $(RIOTBOARD)
endif
ifeq ($(RIOTBOARD),$(BOARDSDIR))
ifeq (,$(wildcard $(BOARDSDIR)/$(BOARD)/.))
$(error The specified board $(BOARD) does not exist.)
endif
endif
# Folders to search: First the external boards, than the official
BOARDSDIRS := $(EXTERNAL_BOARD_DIRS) $(RIOTBOARD)
# Take the first folder in $(BOARDSDIRS) that contains a folder named $(BOARD)
BOARDDIR := $(word 1,$(foreach dir,$(BOARDSDIRS),$(wildcard $(dir)/$(BOARD)/.)))
# Sanitize folder
BOARDDIR := $(abspath $(BOARDDIR))
# Also provide BOARDSDIR for compatibility and for accessing common folders
# (e.g. include $(BOARDSDIR)/common/external_common/Makefile.dep)
BOARDSDIR := $(dir $(BOARDDIR))
ifeq (,$(BOARDDIR))
$(info Folders searched for the board: $(BOARDSDIRS))
$(error The specified board $(BOARD) does not exist.)
endif
include $(RIOTMAKE)/info.inc.mk
@ -332,8 +353,8 @@ include $(RIOTMAKE)/pseudomodules.inc.mk
include $(RIOTMAKE)/defaultmodules.inc.mk
# Include Board and CPU configuration
INCLUDES += $(addprefix -I,$(wildcard $(BOARDSDIR)/$(BOARD)/include))
include $(BOARDSDIR)/$(BOARD)/Makefile.include
INCLUDES += $(addprefix -I,$(wildcard $(BOARDDIR)/include))
include $(BOARDDIR)/Makefile.include
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
include $(RIOTCPU)/$(CPU)/Makefile.include

View File

@ -226,9 +226,10 @@ All `BOARD`s in RIOT reside in `RIOTBOARD` (`RIOTBOARD` being a make variable
set to `$(RIOTBOARD)/boards`).
If one wants to use a `BOARD` outside of `RIOTBOARD`, the way to go is setting
the `BOARDSDIR` variable to the path to the directory containing your external
boards, e.g.: `BOARDSDIR=/home/external-boards/` (this would commonly be done
in your application `Makefile` or your environment).
the `EXTERNAL_BOARD_DIRS` variable to the path to the directory containing your
external boards, e.g.: `EXTERNAL_BOARD_DIRS=/home/external-boards/` (this would
commonly be done in your application `Makefile` or your environment). You can
specify multiple directories separated by spaces.
```
/home/

View File

@ -1,6 +1,6 @@
MODULE = $(APPLICATION_MODULE)
DIRS += $(RIOTCPU)/$(CPU) $(BOARDSDIR)/$(BOARD)
DIRS += $(RIOTCPU)/$(CPU) $(BOARDDIR)
DIRS += $(RIOTBASE)/core $(RIOTBASE)/drivers $(RIOTBASE)/sys
# For regular modules, adding files to BLOBS to their Makefile is sufficient to

View File

@ -1,19 +1,17 @@
# Default when RIOTBASE is not set and is executed from the RIOT directory
RIOTBOARD ?= $(or $(RIOTBASE),$(CURDIR))/boards
BOARDSDIR ?= $(RIOTBOARD)
BOARDSDIRS ?= $(EXTERNAL_BOARD_DIRS) $(RIOTBOARD)
# List all boards in a directory
# By default, all directories in BOARDSDIR except 'common'
# By default, all directories in board directory except 'common'
# use 'wildcard */.' to only list directories
_get_boards_in_directory = $(filter-out common,$(patsubst $1/%/.,%,$(wildcard $1/*/.)))
# If BOARDSDIR is not in RIOTBOARD also list BOARDS in RIOTBOARD
ifneq ($(RIOTBOARD),$(BOARDSDIR))
ALLBOARDS_RIOTBOARD ?= $(call _get_boards_in_directory,$(RIOTBOARD))
endif
# Use `:=` so that it is evaluated before BOARDSDIR gets eventually changed
ALLBOARDS := $(sort $(call _get_boards_in_directory,$(BOARDSDIR)) $(ALLBOARDS_RIOTBOARD))
# Use `:=` so that it is evaluated before BOARDSDIRS gets eventually changed
ALLBOARDS := $(sort \
$(foreach dir,\
$(BOARDSDIRS),\
$(call _get_boards_in_directory,$(dir))))
# Set the default value from `BOARDS`
BOARDS ?= $(ALLBOARDS)

View File

@ -79,7 +79,7 @@ riotboot/flash-bootloader: riotboot/bootloader/flash
riotboot/bootloader/%:
$(Q)/usr/bin/env -i \
QUIET=$(QUIET) PATH=$(PATH)\
BOARDSDIR=$(BOARDSDIR) BOARD=$(BOARD)\
EXTERNAL_BOARD_DIRS="$(EXTERNAL_BOARD_DIRS)" BOARD=$(BOARD)\
DEBUG_ADAPTER_ID=$(DEBUG_ADAPTER_ID)\
$(MAKE) --no-print-directory -C $(RIOTBOOT_DIR) $*

View File

@ -251,11 +251,11 @@ DOCKER_VOLUMES_AND_ENV += $(if $(wildcard $(GIT_CACHE_DIR)),-e 'GIT_CACHE_DIR=$(
DOCKER_VOLUMES_AND_ENV += $(call docker_volumes_mapping,$(EXTERNAL_MODULE_DIRS),$(DOCKER_BUILD_ROOT)/external,)
DOCKER_OVERRIDE_CMDLINE += $(call docker_cmdline_mapping,EXTERNAL_MODULE_DIRS,$(DOCKER_BUILD_ROOT)/external,)
# Remap 'BOARDSDIR' if it is external
DOCKER_VOLUMES_AND_ENV += $(call docker_volumes_mapping,$(BOARDSDIR),,boards)
# Remap 'EXTERNAL_BOARD_DIRS' if they are external
DOCKER_VOLUMES_AND_ENV += $(call docker_volumes_mapping,$(EXTERNAL_BOARD_DIRS),$(DOCKER_BUILD_ROOT)/external,)
# Value is overridden from command line if it is not the default value
# This allows handling even if the value is set in the 'Makefile'.
DOCKER_OVERRIDE_CMDLINE += $(if $(findstring $(RIOTBOARD),$(BOARDSDIR)),,$(call docker_cmdline_mapping,BOARDSDIR,,boards))
DOCKER_OVERRIDE_CMDLINE += $(call docker_cmdline_mapping,EXTERNAL_BOARD_DIRS,$(DOCKER_BUILD_ROOT)/external,)
# External module directories sanity check:
#

View File

@ -11,7 +11,7 @@ include $(RIOTMAKE)/defaultmodules.inc.mk
USEMODULE += $(filter-out $(DISABLE_MODULE),$(DEFAULT_MODULE))
include $(RIOTMAKE)/dependency_resolution.inc.mk
BOARDSDIR_GLOBAL := $(BOARDSDIR)
BOARDDIR_GLOBAL := $(BOARDDIR)
USEMODULE_GLOBAL := $(USEMODULE)
USEPKG_GLOBAL := $(USEPKG)
FEATURES_REQUIRED_GLOBAL := $(FEATURES_REQUIRED)
@ -24,7 +24,6 @@ FEATURES_BLACKLIST_GLOBAL := $(FEATURES_BLACKLIST)
define board_unsatisfied_features
BOARD := $(1)
BOARDSDIR := $(BOARDSDIR_GLOBAL)
USEMODULE := $(USEMODULE_GLOBAL)
USEPKG := $(USEPKG_GLOBAL)
DISABLE_MODULE := $(DISABLE_MODULE_GLOBAL)
@ -35,6 +34,9 @@ define board_unsatisfied_features
FEATURES_CONFLICT_MSG := $(FEATURES_CONFLICT_MSG_GLOBAL)
FEATURES_BLACKLIST:= $(FEATURES_BLACKLIST_GLOBAL)
# Find matching board folder
BOARDDIR := $(word 1,$(foreach dir,$(BOARDSDIRS),$(wildcard $(dir)/$(BOARD)/.)))
# Remove board specific variables set by Makefile.features/Makefile.dep
FEATURES_PROVIDED :=
FEATURES_USED :=
@ -46,12 +48,6 @@ define board_unsatisfied_features
undefine CPU_ARCH
undefine CPU_FAM
# Replicate Makefile.include handling that sets BOARDSDIR to RIOTBOARD
# when BOARD is not found in BOARDSDIR
ifeq (,$(wildcard $(BOARDSDIR_GLOBAL)/$(BOARD)/.))
BOARDSDIR = $(RIOTBOARD)
endif
include $(RIOTBASE)/Makefile.features
# FEATURES_USED must be populated first in this case so that dependency
# resolution can take optional features into account during the first pass.
@ -132,4 +128,4 @@ info-boards-features-missing:
# Reset BOARDSDIR so unchanged for makefiles included after, for now only
# needed for buildtests.inc.mk
BOARDSDIR := $(BOARDSDIR_GLOBAL)
BOARDDIR := $(BOARDDIR_GLOBAL)

View File

@ -34,10 +34,11 @@ info-build:
@echo 'CPU: $(CPU)'
@echo 'MCU: $(MCU)'
@echo ''
@echo 'RIOTBASE: $(RIOTBASE)'
@echo 'BOARDSDIR: $(BOARDSDIR)'
@echo 'RIOTCPU: $(RIOTCPU)'
@echo 'RIOTPKG: $(RIOTPKG)'
@echo 'RIOTBASE: $(RIOTBASE)'
@echo 'BOARDDIR: $(BOARDDIR)'
@echo 'EXTERNAL_BOARD_DIRS:$(EXTERNAL_BOARD_DIRS)'
@echo 'RIOTCPU: $(RIOTCPU)'
@echo 'RIOTPKG: $(RIOTPKG)'
@echo ''
@echo 'DEFAULT_MODULE: $(sort $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)))'
@echo 'DISABLE_MODULE: $(sort $(DISABLE_MODULE))'

View File

@ -7,6 +7,7 @@ SCANBUILD_ENV_VARS := \
BINDIR \
BINDIRBASE \
BOARD \
BOARDDIR \
BOARDSDIR \
BUILD_DIR \
BUILDRELPATH \

View File

@ -1,5 +1,5 @@
FLASHER = avrdude
DIST_PATH = $(BOARDSDIR)/$(BOARD)/dist
DIST_PATH = $(BOARDDIR)/dist
AVARICE_PATH = $(RIOTTOOLS)/avarice
DEBUGSERVER_PORT = 4242
DEBUGSERVER = $(AVARICE_PATH)/debug_srv.sh

View File

@ -17,7 +17,7 @@ endif
ifeq (,$(OPENOCD_CONFIG))
# if no openocd default configuration is provided by the board,
# use the STM32 common one
ifeq (0,$(words $(wildcard $(BOARDSDIR)/$(BOARD)/dist/openocd.cfg)))
ifeq (0,$(words $(wildcard $(BOARDDIR)/dist/openocd.cfg)))
OPENOCD_CONFIG = $(RIOTBASE)/boards/common/stm32/dist/$(CPU).cfg
endif
endif

View File

@ -13,7 +13,7 @@ ifneq (,$(DEBUG_ADAPTER))
include $(RIOTMAKE)/tools/openocd-adapters/$(DEBUG_ADAPTER).inc.mk
endif
OPENOCD_CONFIG ?= $(BOARDSDIR)/$(BOARD)/dist/openocd.cfg
OPENOCD_CONFIG ?= $(BOARDDIR)/dist/openocd.cfg
# Export OPENOCD_CONFIG to required targets
OPENOCD_TARGETS = debug% flash% reset

View File

@ -1,9 +1,9 @@
# http://www.ti.com/tool/uniflash
FLASHFILE ?= $(ELFFILE)
UNIFLASH_CONFIG_CCXML ?= $(BOARDSDIR)/$(BOARD)/dist/$(CPU_MODEL)_$(XDEBUGGER).ccxml
UNIFLASH_CONFIG_DAT ?= $(BOARDSDIR)/$(BOARD)/dist/$(CPU_MODEL)_$(XDEBUGGER).dat
UNIFLASH_CONFIG_GDB ?= $(BOARDSDIR)/$(BOARD)/dist/$(CPU_MODEL)_gdb.conf
UNIFLASH_CONFIG_CCXML ?= $(BOARDDIR)/dist/$(CPU_MODEL)_$(XDEBUGGER).ccxml
UNIFLASH_CONFIG_DAT ?= $(BOARDDIR)/dist/$(CPU_MODEL)_$(XDEBUGGER).dat
UNIFLASH_CONFIG_GDB ?= $(BOARDDIR)/dist/$(CPU_MODEL)_gdb.conf
UNIFLASH_PATH ?= "UNIFLASH_PATH unconfigured"
# check which uniflash version is available, either 4.x or 3.x

View File

@ -29,7 +29,9 @@ export APPDEPS # Files / Makefile targets that need to be created
export RIOTBASE # The root folder of RIOT. The folder where this very file lives in.
export RIOTCPU # For third party CPUs this folder is the base of the CPUs.
export RIOTBOARD # This folder is the base of the riot boards.
export BOARDSDIR # For third party BOARDs this folder is the base of the BOARDs.
export BOARDSDIR # This is the folder containing the board dir
export EXTERNAL_BOARD_DIRS # List of folders containing external board dirs
export BOARDDIR # This folder contains the board
export RIOTPKG # For overriding RIOT's pkg directory
export RIOTTOOLS # Location of host machine tools
export RIOTPROJECT # Top level git root of the project being built, or PWD if not a git repository