• Uncategorized

About shell : Escaping-in-makefile

Question Detail

I’m trying to do this in a makefile and it fails horribly:

M_ARCH := $(shell g++ -dumpmachine | awk '{split($1,a,"-");print a[1]}')

do you know why? I guess it has to do with escaping, but what and where?

Question Answer

It’s the dollar sign, in makefiles you’ll have to type $$ to get a single dollar sign:

M_ARCH := $(shell g++ -dumpmachine | awk '{split($$1,a,"-");print a[1]}')

Make is quite lispy when you get down to it. Here’s a non-awk version that does the same thing:

space := $() #

M_ARCH := $(firstword $(subst -,$(space),$(shell g++ -dumpmachine)))

    $(info $(M_ARCH))

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.