Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

make `notdir`/`strip` with CURDIR combination seem to have different behaviour in definition versus conditional [comments and variables]

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,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading