residue
residue

Reputation: 207

Make variable treated as command and ifeq-statement syntax error with parentheses

I want to create a variable in my Makefile. It will be compared in ifeq-statement. But my variable name is treated like command:

make: dif: Command not found

I have:

dif := $(shell diff file1 <(./myprog < file2))

I've been reading some manuals and testing, but nothing worked. My non-working effects of it are as seen as above.

EDIT:

Made some progress, but the second problem is with ifeq-statement

$(eval dif = diff ./test0.out <(./rozwiązanie < ./test0.in)) // OK

ifeq ($(dif),null)

Gives error:

ifeq (diff ./test0.out <(./rozwiązanie < ./test0.in),null)
Syntax error: word unexpected (expecting ")")
Makefile:18: recipe for target 'test' failed

Upvotes: 0

Views: 228

Answers (1)

MadScientist
MadScientist

Reputation: 100966

There are many issues here. First, please specify what operating system you're using and what version of make; some of the above errors don't appear to have been generated by GNU make (which is the makefile syntax you're using) while others were. So that's very strange. Please run make --version and show the output.

Second, your syntax that you're using with the shell function is specific to the bash shell, but by default GNU make (like all versions of make) use the POSIX sh shell. The output redirection syntax you're using there (<(./myprog <file2)) is not support in sh. If you must use non-standard, bash-specific syntax you'll have to invoke bash directly; something like:

dif := $(shell bash -c 'diff file1 <(./myprog <file2)')

Third, your use of eval is incorrect. eval is used to expand makefile syntax, not shell syntax. This statement:

$(eval dif = diff ./test0.out <(./rozwiązanie < ./test0.in))

is absolutely identical in every way to this statement:

dif = diff ./test0.out <(./rozwiązanie < ./test0.in)

so you're not actually running the shell command at all, you're just setting the variable dif to this static string.

Finally, the output from diff will never be just the string null, so the if-statement:

ifeq ($(dif),null)

will never be true.

Upvotes: 1

Related Questions