Escaping in makefile

我只是一个虾纸丫 提交于 2019-11-26 05:54:10

问题


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?


回答1:


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]}')



回答2:


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


来源:https://stackoverflow.com/questions/2382764/escaping-in-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!