我想在Makefile中创建一个变量。它将在ifeq语句中进行比较。但我的变量名称被视为命令:
make: dif: Command not found
我有:
dif := $(shell diff file1 <(./myprog < file2))
我一直在阅读一些手册和测试,但没有任何效果。我的非工作效果如上所示。
编辑:
取得了一些进展,但第二个问题是ifeq-statement
$(eval dif = diff ./test0.out <(./rozwiązanie < ./test0.in)) // OK
ifeq ($(dif),null)
给出错误:
ifeq (diff ./test0.out <(./rozwiązanie < ./test0.in),null)
Syntax error: word unexpected (expecting ")")
Makefile:18: recipe for target 'test' failed
答案 0 :(得分:0)
这里有很多问题。首先,请说明您正在使用的操作系统和make的版本;上面的一些错误似乎不是由GNU make生成的(这是你正在使用的makefile语法),而其他错误则是。所以这很奇怪。请运行make --version
并显示输出。
其次,您使用shell
函数的语法特定于bash
shell,但默认情况下GNU make(与make的所有版本一样)使用POSIX {{1} } 贝壳。 sh
中不支持您在那里使用的输出重定向语法(<(./myprog <file2)
)。如果您必须使用非标准sh
特定语法,则必须直接调用bash
;类似的东西:
bash
第三,您对dif := $(shell bash -c 'diff file1 <(./myprog <file2)')
的使用不正确。 eval
用于扩展 makefile 语法,而不是shell语法。这句话:
eval
在各种方面完全相同:
$(eval dif = diff ./test0.out <(./rozwiązanie < ./test0.in))
所以你根本就没有运行shell命令,只是将变量dif = diff ./test0.out <(./rozwiązanie < ./test0.in)
设置为这个静态字符串。
最后,dif
的输出永远不会只是字符串diff
,所以if语句:
null
永远不会成真。