Mat*_*ner 8 shell gcc makefile gnu-make variable-expansion
在这一行:
GCCVER:=$(shell a=`mktemp` && echo $'#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$a" -xc -; "$a"; rm "$a")
Run Code Online (Sandbox Code Playgroud)
我明白了:
*** unterminated call to function `shell': missing `)'. Stop.
Run Code Online (Sandbox Code Playgroud)
我愚蠢的迂回变量出了什么问题?
$ make --version
GNU Make 3.81
$ bash --version
GNU bash, version 4.2.8(1)-release (x86_64-pc-linux-gnu)
$ uname -a
Linux 2.6.38-10-generic #46-Ubuntu SMP x86_64 GNU/Linux
$ gcc --version
gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
Run Code Online (Sandbox Code Playgroud)
jco*_*ctx 12
当$在Makefile中使用Bash 时,你需要将它们加倍:$$a例如.我不熟悉这种符号,$'但我必须假设你知道你在做什么.除非它是Makefile构造,否则你需要在该构造上加倍美元符号.
此外,哈希符号#在Make的评估中终止了shell扩展,这就是为什么它永远不会看到正确的paren.逃避它有所帮助,但我还没有正常工作.
我正在通过两个步骤来调试它:首先将GCCVER设置为没有封闭的命令列表$(shell),然后在第二步设置中GCCVER := $(shell $(GCCVER)).你可能也想尝试一下,$(shell)在它不起作用的时候注释掉它,使用export并制作一个"设置"食谱:
GCCVER := some commands here
#GCCVER := $(shell $(GCCVER)) # expand the commands, commented out now
export # all variables available to shell
set:
set # make sure this is prefixed by a tab, not spaces
Run Code Online (Sandbox Code Playgroud)
然后:
make set | grep GCCVER
Run Code Online (Sandbox Code Playgroud)
[更新]这个有效:
GCCVER := a=`mktemp` && echo -e '\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a"
GCCVER := $(shell $(GCCVER))
export
default:
set
jcomeau@intrepid:/tmp$ make | grep GCCVER
GCCVER=4.6
Run Code Online (Sandbox Code Playgroud)
完整的循环,摆脱了额外的步骤:
jcomeau@intrepid:/tmp$ make | grep GCCVER; cat Makefile
GCCVER=4.6
GCCVER := $(shell a=`mktemp` && echo -e '\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a")
export
default:
set
Run Code Online (Sandbox Code Playgroud)
使用$'Bash构造:
jcomeau@intrepid:/tmp$ make | grep GCCVER; cat Makefile
GCCVER=4.6
GCCVER := $(shell a=`mktemp` && echo $$'\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a")
export
default:
set
Run Code Online (Sandbox Code Playgroud)
由于你的系统与我的系统不一样,我会说出来并说要么使用reinierpost的建议,要么:
GCCVER := $(shell gcc -dumpversion | cut -d. -f1,2)
Run Code Online (Sandbox Code Playgroud)