Makefile.include: turn CFLAGS into a sane variable
Contribution description
Variable in Makefiles are by default insane (a.k.a. recursively expended variable). However, sane variables (a.k.a. simply expended variables) are clearly better.
This assigns CFLAGS the empty string using a simple assignment. Subsequent use of += to extend CFLAGS will keep it a sane. This avoids calling shell functions generating the CPU_RAM_SIZE macro for each and every module that is compiled.
Testing procedure
make BOARD=native BUILD_IN_DOCKER=1 -j -C examples/hello-world
with this but without https://github.com/RIOT-OS/RIOT/pull/19761 should result in only one error message, rather than one per module.
Issues/PRs references
Noticed during https://github.com/RIOT-OS/RIOT/pull/19761
Murdock results
:x: FAILED
0ca48fd8537dc9b8949a9cbb65f515b9138d4b0c Makefile.include: turn CFLAGS into a sane variable
| Success | Failures | Total | Runtime |
|---|---|---|---|
| 19 | 0 | 9508 | 01m:45s |
Artifacts
Any way to move this forward?
I think the reason for the build failure is that MCPU is defined after it's being added to the CFLAGS and not evaluated correctly.
The sanatation of the CFLAGS likely caused an issue here.
To debug this, I added the following line:
diff --git a/makefiles/arch/cortexm.inc.mk b/makefiles/arch/cortexm.inc.mk
index fd9e0f1171..16332720cd 100644
--- a/makefiles/arch/cortexm.inc.mk
+++ b/makefiles/arch/cortexm.inc.mk
@@ -100,6 +100,8 @@ ifneq (,$(filter cmsis-dsp,$(USEPKG)))
endif
endif
+$(warning $(CFLAGS))
+
# CPU depends on the cortex-m common module, so include it:
include $(RIOTCPU)/cortexm_common/Makefile.include
and this is the output with master:
cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ BOARD=samr21-xpro make -C tests/net/l2scan_list/
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list'
/home/cbuec/RIOTstuff/riot-vanilla/RIOT/makefiles/arch/cortexm.inc.mk:103: -DNATIVE_AUTO_EXIT=1 -DDEVELHELP -Werror -DCPU_SAMR21 -DCPU_COMMON_SAMD21 -DCPU_FAM_SAMR21 -D__SAMR21G18A__ -DDONT_USE_CMSIS_INIT -DDONT_USE_PREDEFINED_CORE_HANDLERS -DDONT_USE_PREDEFINED_PERIPHERALS_HANDLERS -mno-thumb-interwork -mcpu=cortex-m0plus -mlittle-endian -mthumb -mfloat-abi=soft -march=armv6s-m -ffunction-sections -fdata-sections -fshort-enums -ggdb -g3 -Os -DCPU_MODEL_SAMR21G18A -DCPU_CORE_CORTEX_M0PLUS
Building application "tests_l2scan_list" for "samr21-xpro" with CPU "samd21".
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/build/pkg/mpaland-printf -f /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/mpaland-printf.mk
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/boards
...
With this PR, this is the output (and the build fails):
cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ BOARD=samr21-xpro make -C tests/net/l2scan_list/
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list'
/home/cbuec/RIOTstuff/riot-vanilla/RIOT/makefiles/arch/cortexm.inc.mk:103: -DDEVELHELP -Werror -DCPU_SAMR21 -DCPU_COMMON_SAMD21 -DCPU_FAM_SAMR21 -D__SAMR21G18A__ -DDONT_USE_CMSIS_INIT -DDONT_USE_PREDEFINED_CORE_HANDLERS -DDONT_USE_PREDEFINED_PERIPHERALS_HANDLERS -mno-thumb-interwork -mcpu= -mlittle-endian -mthumb -march=armv6s-m -ffunction-sections -fdata-sections -fshort-enums -ggdb -g3 -Os -DCPU_MODEL_SAMR21G18A -DCPU_CORE_CORTEX_M0PLUS
Building application "tests_l2scan_list" for "samr21-xpro" with CPU "samd21".
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/build/pkg/mpaland-printf -f /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/mpaland-printf.mk
arm-none-eabi-gcc: error: missing argument to '-mcpu='
make[2]: *** [/home/cbuec/RIOTstuff/riot-vanilla/RIOT/Makefile.base:157: /home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list/bin/samr21-xpro/mpaland-printf/printf.o] Error 1
make[1]: *** [Makefile:10: all] Error 2
make: *** [/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list/../../../Makefile.include:830: pkg-build] Error 2
make: Leaving directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list'
You can see that -mcpu= is empty.
Proposed fix:
diff --git a/makefiles/arch/cortexm.inc.mk b/makefiles/arch/cortexm.inc.mk
index fd9e0f1171..efd0a79e92 100644
--- a/makefiles/arch/cortexm.inc.mk
+++ b/makefiles/arch/cortexm.inc.mk
@@ -6,6 +6,12 @@ endif
TARGET_ARCH_CORTEXM ?= arm-none-eabi
TARGET_ARCH ?= $(TARGET_ARCH_CORTEXM)
+ifeq ($(CPU_CORE),cortex-m4f)
+ MCPU = cortex-m4
+else
+ MCPU ?= $(CPU_CORE)
+endif
+
# define build specific options
CFLAGS_CPU = -mcpu=$(MCPU) -mlittle-endian -mthumb $(CFLAGS_FPU)
@@ -72,12 +82,6 @@ else
CFLAGS_FPU ?= -mfloat-abi=soft
endif
-ifeq ($(CPU_CORE),cortex-m4f)
- MCPU = cortex-m4
-else
- MCPU ?= $(CPU_CORE)
-endif
-
# CMSIS DSP needs to know about the CPU core
ifneq (,$(filter cmsis-dsp,$(USEPKG)))
# definition needed to use cmsis-dsp headers
Result:
cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ BOARD=samr21-xpro make -C tests/net/l2scan_list/
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/net/l2scan_list'
/home/cbuec/RIOTstuff/riot-vanilla/RIOT/makefiles/arch/cortexm.inc.mk:103: -DDEVELHELP -Werror -DCPU_SAMR21 -DCPU_COMMON_SAMD21 -DCPU_FAM_SAMR21 -D__SAMR21G18A__ -DDONT_USE_CMSIS_INIT -DDONT_USE_PREDEFINED_CORE_HANDLERS -DDONT_USE_PREDEFINED_PERIPHERALS_HANDLERS -mno-thumb-interwork -mcpu=cortex-m0plus -mlittle-endian -mthumb -march=armv6s-m -ffunction-sections -fdata-sections -fshort-enums -ggdb -g3 -Os -DCPU_MODEL_SAMR21G18A -DCPU_CORE_CORTEX_M0PLUS
Building application "tests_l2scan_list" for "samr21-xpro" with CPU "samd21".
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/build/pkg/mpaland-printf -f /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/mpaland-printf/mpaland-printf.mk
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/boards
...
But please also apply the suggestion from the review above. I probably should've read it again before approving and merging 😅