diff --git a/makefiles/arch/mips.inc.mk b/makefiles/arch/mips.inc.mk index 61e7ef1c2d..fc92ab78a3 100644 --- a/makefiles/arch/mips.inc.mk +++ b/makefiles/arch/mips.inc.mk @@ -14,8 +14,6 @@ priv_symbols += FLUSH_TO_ZERO priv_symbols += FLASH_START APP_START FLASH_APP_START priv_symbols += ISR_VEC_SPACE ISR_VECTOR_COUNT -comma := , - # A bit of makefile magic: # foreach symbol in overridable ld-symbols : # If symbol has a value, produce a linker argument for that symbol. diff --git a/makefiles/info.inc.mk b/makefiles/info.inc.mk index 846ff015c4..27e387ac20 100644 --- a/makefiles/info.inc.mk +++ b/makefiles/info.inc.mk @@ -114,6 +114,72 @@ info-build: @echo '' @echo -e 'MAKEFILE_LIST:$(patsubst %, \n\t%, $(abspath $(MAKEFILE_LIST)))' +define json_string_or_null +$(or $(1:%="%"), null) +endef + +# Convert a space separated list to a JSON array +define _to_json_string_list +[$(filter-out "","$(subst $(space),"$(comma)$(space)",$(1))")] +endef + +# Strips out any existing quotes so that the generated JSON is valid, not necessary sensible +define to_json_string_list +$(call _to_json_string_list,$(strip $(subst ",,$(subst \",,$(1))))) +endef + +# Crude json encoded build info. +# The output generated here is a best-effort JSON encoding, it is not perfect, +# converting the space separated lists in Make to a JSON array is flawed, it +# doesn't consider quoted parts as a single list item. This mainly shows up in +# cflags such as: -DNIMBLE_HOST_PRIO="(NIMBLE_CONTROLLER_PRIO + 1)", this is +# splitted into 3 array elements. To ensure that the generated JSON is valid, +# double quotes are currently stripped before generating the array. +info-build-json: + @echo '{ ' + @echo '"APPLICATION": "$(APPLICATION)",' + @echo '"APPDIR": "$(APPDIR)",' + @echo '"BOARD": "$(BOARD)",' + @echo '"CPU": "$(CPU)",' + @echo '"MCU": "$(MCU)",' + @echo '"RIOTBASE": "$(RIOTBASE)",' + @echo '"BOARDDIR": "$(BOARDDIR)",' + @echo '"RIOTCPU": "$(RIOTCPU)",' + @echo '"RIOTPKG": "$(RIOTPKG)",' + @echo '"EXTERNAL_BOARD_DIRS": $(call json_string_or_null $(EXTERNAL_BOARD_DIRS)),' + @echo '"BINDIR": "$(BINDIR)",' + @echo '"ELFFILE": "$(ELFFILE)",' + @echo '"HEXFILE": "$(HEXFILE)",' + @echo '"BINFILE": "$(BINFILE)",' + @echo '"FLASHFILE": "$(FLASHFILE)",' + @echo '"DEFAULT_MODULE": $(call to_json_string_list,$(sort $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)))),' + @echo '"DISABLE_MODULE": $(call to_json_string_list,$(sort $(DISABLE_MODULE))),' + @echo '"USEMODULE": $(call to_json_string_list,$(sort $(filter-out $(DEFAULT_MODULE), $(USEMODULE)))),' + @echo '"FEATURES_USED": $(call to_json_string_list,$(FEATURES_USED)),' + @echo '"FEATURES_REQUIRED": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED))),' + @echo '"FEATURES_REQUIRED_ANY": $(call to_json_string_list,$(sort $(FEATURES_REQUIRED_ANY))),' + @echo '"FEATURES_OPTIONAL_ONLY": $(call to_json_string_list,$(FEATURES_OPTIONAL_ONLY)),' + @echo '"FEATURES_OPTIONAL_MISSING": $(call to_json_string_list,$(FEATURES_OPTIONAL_MISSING)),' + @echo '"FEATURES_PROVIDED": $(call to_json_string_list,$(sort $(FEATURES_PROVIDED))),' + @echo '"FEATURES_MISSING": $(call to_json_string_list,$(FEATURES_MISSING)),' + @echo '"FEATURES_BLACKLIST": $(call to_json_string_list,$(sort $(FEATURES_BLACKLIST))),' + @echo '"FEATURES_USED_BLACKLISTED": $(call to_json_string_list,$(sort $(FEATURES_USED_BLACKLISTED))),' + @echo '"FEATURES_CONFLICT": $(call to_json_string_list,$(FEATURES_CONFLICT)),' + @echo '"FEATURES_CONFLICTING": $(call to_json_string_list,$(FEATURES_CONFLICTING)),' + @echo '"PREFIX": $(call json_string_or_null,$(PREFIX)),' + @echo '"CC": "$(CC)",' + @echo '"CXX": "$(CXX)",' + @echo '"LINK": "$(LINK)",' + @echo '"OBJCOPY": "$(OBJCOPY)",' + @echo '"INCLUDES": $(call to_json_string_list,$(strip $(INCLUDES))),' + @echo '"OFLAGS": $(call to_json_string_list,$(OFLAGS)),' + @echo '"CFLAGS": $(call to_json_string_list,$(CFLAGS)),' + @echo '"CXXUWFLAGS": $(call to_json_string_list,$(CXXUWFLAGS)),' + @echo '"CXXEXFLAGS": $(call to_json_string_list,$(CXXEXFLAGS)),' + @echo '"LINKFLAGS": $(call to_json_string_list,$(LINKFLAGS))' + @echo '}' + + info-files: QUIET := 0 info-files: @( \ diff --git a/makefiles/utils/variables.mk b/makefiles/utils/variables.mk index ead0099063..15fa2e53dd 100644 --- a/makefiles/utils/variables.mk +++ b/makefiles/utils/variables.mk @@ -1,6 +1,10 @@ # Utilities to set variables and environment for targets +# The variables defined here cover edge cases in make string handling. # These functions should help replacing immediate evaluation and global 'export' +comma := , +blank := +space := $(blank) $(blank) # Evaluate a deferred variable only once on its first usage # Uses after that will be as if it was an immediate evaluation diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index e8a82e3638..8fbe901739 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -39,11 +39,9 @@ info-unittests: $(UNIT_TESTS): all -charCOMMA := , - ifeq (, $(UNIT_TESTS)) CFLAGS += -DNO_TEST_SUITES $(warning There was no test suite specified!) else - CFLAGS += -DTEST_SUITES='$(subst $() $(),$(charCOMMA),$(UNIT_TESTS:tests-%=%))' + CFLAGS += -DTEST_SUITES='$(subst $() $(),$(comma),$(UNIT_TESTS:tests-%=%))' endif