I am using GNU make version 4.2.1 with an Eclipse framework called 'STM32CubeIDE'. It is structured with targets in sub-directories such as 'Release', 'Debug' and 'bootloader' that have the main makefile. In the directory above, there are optional support files to modify the build behaviour such as,
-include ../makefile.init # Define lists of source files -include ../makefile.defs # Define make variable and rules -include ../makefile.targets
The above makefile is generated automatically by Java code within the Eclipse/STM32CubeIDE framework.
I have a makefile.defs and I attempt a definition like this,
TYPE=$(strip $(notdir $(CURDIR))) # Debug, Release or bootloader
However, the $(strip) seems to be in-effective. If I apply it directly in a condition, it works.
ifeq ($(strip $(TYPE)),bootloader)
$(info bootloader active)
endif
I don't understand what make facilities would cause this? The purpose of 'TYPE' is to be used in the subsequent makefile.targets to over-ride the linker commands.
strip
definitely works. But it only strips the content that you provide to the strip
function. Here:
TYPE=$(strip $(notdir $(CURDIR))) # Debug, Release or bootloader
the strip
will remove whitespace from the results of expanding $(notdir $(CURDIR))
just as you'd expect. But after that you add more whitespace to the end, by adding the # Debug, ...
The standard behavior for make variables etc. is that preceding space is trimmed automatically, and trailing space is not trimmed at all.
You can use this:
TYPE=$(strip $(notdir $(CURDIR)))# Debug, Release or bootloader
By removing the extra spaces between the value and the comment. Another option is to put the comment first:
# Debug, Release or bootloader
TYPE=$(strip $(notdir $(CURDIR)))
Or you can do something like this (since CURDIR
is a static variable you might as well use :=
):
TYPE = $(notdir $(CURDIR)) # Debug, Release or bootloader
TYPE := $(strip $(TYPE))