From 162850b332acdce6d68d010f3aa0c8beb03ec5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sun, 26 Oct 2014 23:18:58 +0100 Subject: [PATCH 1/3] make: Implement optional features Fixes #1876 This PR introduces `FEATURES_OPTIONAL` which can be used to tell the Make system, that the application would like to use some feature, but the build should proceed even if the selected board cannot provide the optional feature. `make buildtest` and `make info-supported-boards` heed this variable when examining the list of supported boards. If a word is present in `FEATURES_REQUIRED` and `FEATURES_OPTIONAL`, then `FEATURES_OPTIONAL` takes precedence. --- Makefile.buildtests | 19 ++++++++++++++++--- Makefile.include | 4 ++-- examples/default/Makefile | 2 ++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile.buildtests b/Makefile.buildtests index 1c161ef8ef43..fde12f697483 100644 --- a/Makefile.buildtests +++ b/Makefile.buildtests @@ -169,8 +169,16 @@ info-build: @echo 'ELFFILE: $(ELFFILE)' @echo 'HEXFILE: $(HEXFILE)' @echo '' - @echo 'FEATURES_REQUIRED: $(sort $(FEATURES_REQUIRED))' - @echo 'FEATURES_PROVIDED: $(sort $(FEATURES_PROVIDED))' + @echo 'FEATURES_REQUIRED (excl. optional features):' + @echo ' $(or $(sort $(filter-out $(FEATURES_OPTIONAL), $(FEATURES_REQUIRED))), -none-)' + @echo 'FEATURES_OPTIONAL (strictly "nice to have"):' + @echo ' $(or $(sort $(FEATURES_OPTIONAL)), -none-)' + @echo 'FEATURES_PROVIDED (by the board):' + @echo ' $(or $(sort $(FEATURES_PROVIDED)), -none-)' + @echo 'FEATURES_MISSING (incl. optional features):' + @echo ' $(or $(sort $(filter-out $(FEATURES_PROVIDED), $(FEATURES_REQUIRED))), -none-)' + @echo 'FEATURES_MISSING (only non-optional features):' + @echo ' $(or $(sort $(filter-out $(FEATURES_OPTIONAL) $(FEATURES_PROVIDED), $(FEATURES_REQUIRED))), -none-)' @echo '' @echo 'CC: $(CC)' @echo -e 'CFLAGS:$(patsubst %, \n\t%, $(CFLAGS))' @@ -215,6 +223,8 @@ info-features-missing: info-boards-features-missing: @for f in $(BOARDS_FEATURES_MISSING); do echo $${f}; done | column -t +FEATURES_REQUIRED += $(FEATURES_OPTIONAL) + ifneq (, $(filter info-boards-supported info-boards-features-missing info-build, $(MAKECMDGOALS))) FEATURES_PROVIDED_BAK := $(FEATURES_PROVIDED) @@ -224,8 +234,11 @@ ifneq (, $(filter info-boards-supported info-boards-features-missing info-build, FEATURES_MISSING := $$(filter-out $$(FEATURES_PROVIDED), $$(FEATURES_REQUIRED)) ifneq (, $${FEATURES_MISSING}) - BOARDS_WITH_MISSING_FEATURES += ${1} BOARDS_FEATURES_MISSING += "${1} $${FEATURES_MISSING}" + + ifneq (, $$(filter-out $$(FEATURES_OPTIONAL), $$(FEATURES_MISSING))) + BOARDS_WITH_MISSING_FEATURES += ${1} + endif endif endef diff --git a/Makefile.include b/Makefile.include index 5daf23058cf4..16a34ee622ce 100644 --- a/Makefile.include +++ b/Makefile.include @@ -219,9 +219,9 @@ ifneq (, $(filter all, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all))) endif # Test if all feature requirements were met by the selected board. - ifneq (, $(filter-out $(FEATURES_PROVIDED), $(FEATURES_REQUIRED))) + ifneq (, $(filter-out $(FEATURES_PROVIDED) $(FEATURES_OPTIONAL), $(FEATURES_REQUIRED))) $(shell $(COLOR_ECHO) "$(COLOR_RED)There are unsatisfied feature requirements:$(COLOR_RESET)"\ - "$(filter-out $(FEATURES_PROVIDED), $(FEATURES_REQUIRED))" 1>&2) + "$(sort $(filter-out $(FEATURES_PROVIDED) $(FEATURES_OPTIONAL), $(FEATURES_REQUIRED)))" 1>&2) EXPECT_ERRORS := 1 endif diff --git a/examples/default/Makefile b/examples/default/Makefile index 33746afc9ca7..fa481bfd4995 100644 --- a/examples/default/Makefile +++ b/examples/default/Makefile @@ -36,6 +36,8 @@ USEMODULE += ps USEMODULE += vtimer USEMODULE += defaulttransceiver +FEATURES_OPTIONAL += transceiver + ifneq (,$(filter msb-430,$(BOARD))) USEMODULE += sht11 endif From 938d7d441b8c8bccb0c71eeba1b6112fe930cead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sun, 26 Oct 2014 23:27:43 +0100 Subject: [PATCH 2/3] make: expose used features with `-DFEATURE_ABC` All used feature requests (both in `FEATURES_REQUIRED` and `FEATURES_OPTIONAL`) that could be satisfied get exposed to C with `-DFEATURE_ABC`. --- Makefile.modules | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.modules b/Makefile.modules index 3728ae6a1d78..9411480d584e 100644 --- a/Makefile.modules +++ b/Makefile.modules @@ -5,6 +5,7 @@ USEMODULE += $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)) INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include ED = $(patsubst %,-DMODULE_%,$(subst -,_,$(USEMODULE) $(USEPKG))) +ED += $(patsubst %,-DFEATURE_%,$(subst -,_,$(filter $(FEATURES_PROVIDED), $(FEATURES_REQUIRED)))) EXTDEFINES = $(shell echo $(sort $(ED))|tr 'a-z' 'A-Z') REALMODULES = $(filter-out $(PSEUDOMODULES), $(sort $(USEMODULE))) export BASELIBS += $(REALMODULES:%=$(BINDIR)%.a) From 765c88d08abe71259f3810356d01c96597a3b657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sun, 26 Oct 2014 23:36:05 +0100 Subject: [PATCH 3/3] make: allow drivers to implement features This change allows drivers (or any module for that matter) to provide features. This is e.g. useful if a board does not have a transceiver, but your application uses `USEMODULE += some_driver`, which implements the transceiver interface. The line `FEATURES_PROVIDED += some_feature` should go to the guarded block in `{sys,drivers}/Makefile.include`. --- Makefile.buildtests | 4 ++-- Makefile.include | 8 +++++--- boards/arduino-due/Makefile.features | 2 +- boards/arduino-mega2560/Makefile.features | 2 +- boards/avsextrem/Makefile.features | 2 +- boards/cc2538dk/Makefile.features | 2 +- boards/iot-lab_M3/Makefile.features | 2 +- boards/msb-430h/Makefile.features | 2 +- boards/msba2/Makefile.features | 2 +- boards/msbiot/Makefile.features | 2 +- boards/native/Makefile.features | 2 +- boards/openmote/Makefile.features | 2 +- boards/pca10000/Makefile.features | 2 +- boards/pca10005/Makefile.features | 2 +- boards/pttu/Makefile.features | 2 +- boards/redbee-econotag/Makefile.features | 2 +- boards/samr21-xpro/Makefile.features | 2 +- boards/stm32f0discovery/Makefile.features | 2 +- boards/stm32f3discovery/Makefile.features | 2 +- boards/stm32f4discovery/Makefile.features | 2 +- boards/telosb/Makefile.features | 2 +- boards/udoo/Makefile.features | 2 +- boards/wsn430-v1_3b/Makefile.features | 2 +- boards/wsn430-v1_4/Makefile.features | 2 +- boards/yunjia-nrf51822/Makefile.features | 2 +- boards/z1/Makefile.features | 2 +- 26 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Makefile.buildtests b/Makefile.buildtests index fde12f697483..7037278fe673 100644 --- a/Makefile.buildtests +++ b/Makefile.buildtests @@ -173,7 +173,7 @@ info-build: @echo ' $(or $(sort $(filter-out $(FEATURES_OPTIONAL), $(FEATURES_REQUIRED))), -none-)' @echo 'FEATURES_OPTIONAL (strictly "nice to have"):' @echo ' $(or $(sort $(FEATURES_OPTIONAL)), -none-)' - @echo 'FEATURES_PROVIDED (by the board):' + @echo 'FEATURES_PROVIDED (by the board or USEMODULE'"'"'d drivers):' @echo ' $(or $(sort $(FEATURES_PROVIDED)), -none-)' @echo 'FEATURES_MISSING (incl. optional features):' @echo ' $(or $(sort $(filter-out $(FEATURES_PROVIDED), $(FEATURES_REQUIRED))), -none-)' @@ -229,7 +229,7 @@ ifneq (, $(filter info-boards-supported info-boards-features-missing info-build, FEATURES_PROVIDED_BAK := $(FEATURES_PROVIDED) define board_missing_features - FEATURES_PROVIDED := + FEATURES_PROVIDED := $(FEATURES_PROVIDED_BAK) -include $${RIOTBOARD}/${1}/Makefile.features FEATURES_MISSING := $$(filter-out $$(FEATURES_PROVIDED), $$(FEATURES_REQUIRED)) diff --git a/Makefile.include b/Makefile.include index 16a34ee622ce..1144efbd5ac6 100644 --- a/Makefile.include +++ b/Makefile.include @@ -77,9 +77,6 @@ ifeq ($(strip $(MCU)),) MCU = $(CPU) endif -# import list of provided features --include $(RIOTBOARD)/$(BOARD)/Makefile.features - # if you want to publish the board into the sources as an uppercase #define BOARDDEF := $(shell echo $(BOARD) | tr 'a-z' 'A-Z' | tr '-' '_') CPUDEF := $(shell echo $(CPU) | tr 'a-z' 'A-Z' | tr '-' '_') @@ -205,10 +202,15 @@ objdump: # Extra make goals for testing and comparing changes. include $(RIOTBASE)/Makefile.buildtests +# import list of provided features +-include $(RIOTBOARD)/$(BOARD)/Makefile.features + # Export variables used throughout the whole make system: include $(RIOTBASE)/Makefile.vars +# Warn if the selected board and drivers don't provide all needed featues: ifneq (, $(filter all, $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all))) + EXPECT_ERRORS := # Test if there where dependencies against a module in DISABLE_MODULE. diff --git a/boards/arduino-due/Makefile.features b/boards/arduino-due/Makefile.features index 9b7846ee4af9..9be17cbb4ba3 100644 --- a/boards/arduino-due/Makefile.features +++ b/boards/arduino-due/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_spi periph_random +FEATURES_PROVIDED += periph_gpio periph_spi periph_random diff --git a/boards/arduino-mega2560/Makefile.features b/boards/arduino-mega2560/Makefile.features index 177003f9fca8..a1c67793450c 100644 --- a/boards/arduino-mega2560/Makefile.features +++ b/boards/arduino-mega2560/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = +FEATURES_PROVIDED += diff --git a/boards/avsextrem/Makefile.features b/boards/avsextrem/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/avsextrem/Makefile.features +++ b/boards/avsextrem/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/cc2538dk/Makefile.features b/boards/cc2538dk/Makefile.features index 42f40abd5fa0..68545ecde2e3 100644 --- a/boards/cc2538dk/Makefile.features +++ b/boards/cc2538dk/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_random periph_cpuid +FEATURES_PROVIDED += periph_gpio periph_random periph_cpuid diff --git a/boards/iot-lab_M3/Makefile.features b/boards/iot-lab_M3/Makefile.features index 0c2220101c6b..dc1292029c6e 100644 --- a/boards/iot-lab_M3/Makefile.features +++ b/boards/iot-lab_M3/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver periph_gpio periph_uart periph_spi periph_i2c periph_rtt +FEATURES_PROVIDED += transceiver periph_gpio periph_uart periph_spi periph_i2c periph_rtt diff --git a/boards/msb-430h/Makefile.features b/boards/msb-430h/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/msb-430h/Makefile.features +++ b/boards/msb-430h/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/msba2/Makefile.features b/boards/msba2/Makefile.features index 75b005a0cb45..8876943e34b7 100644 --- a/boards/msba2/Makefile.features +++ b/boards/msba2/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver periph_pwm +FEATURES_PROVIDED += transceiver periph_pwm diff --git a/boards/msbiot/Makefile.features b/boards/msbiot/Makefile.features index 0f33fa562902..12b64e8090a4 100644 --- a/boards/msbiot/Makefile.features +++ b/boards/msbiot/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio +FEATURES_PROVIDED += periph_gpio diff --git a/boards/native/Makefile.features b/boards/native/Makefile.features index 91747cc07860..7cd83d38436b 100644 --- a/boards/native/Makefile.features +++ b/boards/native/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver periph_cpuid +FEATURES_PROVIDED += transceiver periph_cpuid diff --git a/boards/openmote/Makefile.features b/boards/openmote/Makefile.features index 42f40abd5fa0..68545ecde2e3 100644 --- a/boards/openmote/Makefile.features +++ b/boards/openmote/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_random periph_cpuid +FEATURES_PROVIDED += periph_gpio periph_random periph_cpuid diff --git a/boards/pca10000/Makefile.features b/boards/pca10000/Makefile.features index c21f92a56aa3..ec97f16d1961 100644 --- a/boards/pca10000/Makefile.features +++ b/boards/pca10000/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_random periph_rtt periph_cpuid +FEATURES_PROVIDED += periph_gpio periph_random periph_rtt periph_cpuid diff --git a/boards/pca10005/Makefile.features b/boards/pca10005/Makefile.features index c21f92a56aa3..ec97f16d1961 100644 --- a/boards/pca10005/Makefile.features +++ b/boards/pca10005/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_random periph_rtt periph_cpuid +FEATURES_PROVIDED += periph_gpio periph_random periph_rtt periph_cpuid diff --git a/boards/pttu/Makefile.features b/boards/pttu/Makefile.features index bb7f2c751d40..9efa2cc57fea 100644 --- a/boards/pttu/Makefile.features +++ b/boards/pttu/Makefile.features @@ -1,2 +1,2 @@ # Enable this after fixing https://github.com/RIOT-OS/RIOT/issues/659 -#FEATURES_PROVIDED = transceiver +#FEATURES_PROVIDED += transceiver diff --git a/boards/redbee-econotag/Makefile.features b/boards/redbee-econotag/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/redbee-econotag/Makefile.features +++ b/boards/redbee-econotag/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/samr21-xpro/Makefile.features b/boards/samr21-xpro/Makefile.features index 0f33fa562902..12b64e8090a4 100644 --- a/boards/samr21-xpro/Makefile.features +++ b/boards/samr21-xpro/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio +FEATURES_PROVIDED += periph_gpio diff --git a/boards/stm32f0discovery/Makefile.features b/boards/stm32f0discovery/Makefile.features index 9ac4a53d6b72..026c14e2beb3 100644 --- a/boards/stm32f0discovery/Makefile.features +++ b/boards/stm32f0discovery/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_spi +FEATURES_PROVIDED += periph_gpio periph_spi diff --git a/boards/stm32f3discovery/Makefile.features b/boards/stm32f3discovery/Makefile.features index 0f33fa562902..12b64e8090a4 100644 --- a/boards/stm32f3discovery/Makefile.features +++ b/boards/stm32f3discovery/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio +FEATURES_PROVIDED += periph_gpio diff --git a/boards/stm32f4discovery/Makefile.features b/boards/stm32f4discovery/Makefile.features index 548a0f3f4c48..a7ee3b28fe77 100644 --- a/boards/stm32f4discovery/Makefile.features +++ b/boards/stm32f4discovery/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_spi periph_pwm periph_random +FEATURES_PROVIDED += periph_gpio periph_spi periph_pwm periph_random diff --git a/boards/telosb/Makefile.features b/boards/telosb/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/telosb/Makefile.features +++ b/boards/telosb/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/udoo/Makefile.features b/boards/udoo/Makefile.features index 0f33fa562902..12b64e8090a4 100644 --- a/boards/udoo/Makefile.features +++ b/boards/udoo/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio +FEATURES_PROVIDED += periph_gpio diff --git a/boards/wsn430-v1_3b/Makefile.features b/boards/wsn430-v1_3b/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/wsn430-v1_3b/Makefile.features +++ b/boards/wsn430-v1_3b/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/wsn430-v1_4/Makefile.features b/boards/wsn430-v1_4/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/wsn430-v1_4/Makefile.features +++ b/boards/wsn430-v1_4/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver diff --git a/boards/yunjia-nrf51822/Makefile.features b/boards/yunjia-nrf51822/Makefile.features index c21f92a56aa3..ec97f16d1961 100644 --- a/boards/yunjia-nrf51822/Makefile.features +++ b/boards/yunjia-nrf51822/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = periph_gpio periph_random periph_rtt periph_cpuid +FEATURES_PROVIDED += periph_gpio periph_random periph_rtt periph_cpuid diff --git a/boards/z1/Makefile.features b/boards/z1/Makefile.features index 762734b9564f..af23a974c897 100644 --- a/boards/z1/Makefile.features +++ b/boards/z1/Makefile.features @@ -1 +1 @@ -FEATURES_PROVIDED = transceiver +FEATURES_PROVIDED += transceiver