diff --git a/Makefile.include b/Makefile.include index 1beff77416..dd41b1f931 100644 --- a/Makefile.include +++ b/Makefile.include @@ -783,13 +783,11 @@ $(RIOTBUILD_CONFIG_HEADER_C): FORCE $(Q)'$(RIOTTOOLS)/genconfigheader/genconfigheader.sh' $(CFLAGS_WITH_MACROS) \ | '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@' -# Immediate evaluation but keep CLAGS_WITH_MACROS deferred -_CFLAGS := $(CFLAGS) -CFLAGS_WITH_MACROS = $(_CFLAGS) +CFLAGS_WITH_MACROS += $(CFLAGS) CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION)\" +# MODULE_NAME defines. Declared in 'makefiles/modules.inc.mk' +CFLAGS_WITH_MACROS += $(EXTDEFINES) -CFLAGS := $(patsubst -D%,,$(CFLAGS)) -CFLAGS := $(patsubst -U%,,$(CFLAGS)) CFLAGS += -include '$(RIOTBUILD_CONFIG_HEADER_C)' # include mcuboot support diff --git a/dist/tools/cmake/generate-xcompile-toolchain.sh b/dist/tools/cmake/generate-xcompile-toolchain.sh index 55f4af8c45..e723b8205d 100755 --- a/dist/tools/cmake/generate-xcompile-toolchain.sh +++ b/dist/tools/cmake/generate-xcompile-toolchain.sh @@ -1,17 +1,31 @@ #!/usr/bin/env sh -echo "SET(CMAKE_SYSTEM_NAME Generic)" -echo "SET(CMAKE_SYSTEM_VERSION 1)" + +# When setting variables, use the 'bracket argument' format to allow having \" +# inside the string. Which is not supported by quoted arguments +# https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-argument +# +# bracket_argument ::= bracket_open bracket_content bracket_close +# bracket_open ::= '[' '='* '[' +# bracket_content ::= &2; false; } + +... +#define STRING_FROM_DOCKER "with space" +``` diff --git a/tests/build_system_cflags_spaces/main.c b/tests/build_system_cflags_spaces/main.c new file mode 100644 index 0000000000..62cc2efb49 --- /dev/null +++ b/tests/build_system_cflags_spaces/main.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test the CFLAGS handling + * + * @author Gaëtan Harter + * + * @} + */ + +#include + +/* Define a CFLAGS string with spaces from outside docker */ +/* DOCKER_ENVIRONMENT_CMDLINE=$'-e CFLAGS=-DSTRING_FROM_DOCKER=\'\\\"with\ space\\\"\''*/ +#ifndef STRING_FROM_DOCKER +#define STRING_FROM_DOCKER "" +#endif + + +int main(void) +{ + puts("The output of the configuration variables:"); + printf("SUPER_STRING: %s\n", SUPER_STRING); + printf("DEFINED_AFTER_MAKEFILE_INCLUDE: %u\n", DEFINED_AFTER_MAKEFILE_INCLUDE); + printf("CFLAGS_STRING_FROM_DOCKER: %s\n", STRING_FROM_DOCKER); + return 0; +} diff --git a/tests/build_system_cflags_spaces/tests/01-run.py b/tests/build_system_cflags_spaces/tests/01-run.py new file mode 100755 index 0000000000..a29ad95403 --- /dev/null +++ b/tests/build_system_cflags_spaces/tests/01-run.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +""" +Test for passing `CFLAGS` with spaces to the application. + +It also tests that even if a `CFLAGS` is set after including Makefile.include, +changing its value will trigger a rebuild. + +There is also a way to test passing additional values with spaces to docker +documented in the `README.md`. +""" + +import os +import sys +from testrunner import run + + +# Verify the macro matches the configuration value +CONFIGURATION_VALUE = os.environ['CONFIGURATION_VALUE'] + + +def testfunc(child): + child.expect_exact('The output of the configuration variables:') + child.expect_exact('SUPER_STRING: I love sentences with spaces') + child.expect_exact('DEFINED_AFTER_MAKEFILE_INCLUDE: %s' % + CONFIGURATION_VALUE) + # This one is not tested here, see the output in 'riotbuild.h' + child.expect(r'CFLAGS_STRING_FROM_DOCKER: .*') + + +if __name__ == "__main__": + sys.exit(run(testfunc))