Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping in makefile

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?

like image 632
Jonas Byström Avatar asked Mar 04 '10 21:03

Jonas Byström


People also ask

How do you escape a Makefile?

I just learned that if you want to use a dollar sign inside a Makefile you need to escape $ with an extra $ , so double it. Otherwise make will think that you are accessing a make variable, not a shell one.

What is $@ in Makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

How do you use special characters in Makefile?

Special characters in a makefileA caret ( ^ ) within a quoted string is treated as a literal caret character. A caret at the end of a line inserts a literal newline character in a string or macro. In macros, a backslash ( \ ) followed by a newline character is replaced by a space.

What is escaping in Linux?

Escaping is a method of quoting single characters. The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.


1 Answers

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]}') 
like image 82
Martin Avatar answered Oct 14 '22 20:10

Martin