Chris G.
Chris G.

Reputation: 25974

How to remove substring in makefile

Line by line this works in terminal, but not in makefile?

test:
    FOO="MACOS" ; \
    FOO=$${FOO//OS/} ; \
    @echo $FOO

Expected:

make test
MAC

Upvotes: 0

Views: 5656

Answers (1)

Renaud Pacalet
Renaud Pacalet

Reputation: 29167

The last shell expansion of shell variable FOO must be escaped ($$). And if you want to suppress the echo of the recipe, put the @ at the beginning, not in the middle of the recipe.

test:
    @FOO="MACOS" ; \
    FOO=$${FOO//OS/} ; \
    echo $$FOO

Note that you could also use make variables and functions:

FOO := MACOS
FOO := $(patsubst %OS,%,$(FOO))

test:
    @echo '$(FOO)'

Upvotes: 1

Related Questions