93

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?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
  • 6
    How does it fail? What error messages does it produce? What do you expect it to do? –  Mar 04 '10 at 21:20

2 Answers2

177

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]}')
Martin
  • 37,119
  • 15
  • 73
  • 82
18

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)))

all:
    $(info $(M_ARCH))
richq
  • 55,548
  • 20
  • 150
  • 144