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?
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.
The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
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.
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.
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]}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With