2

I wanted to determine the version of the Intel Fortran compiler in my makefile, so I added some script using GNU shell function as below for testing,

VERIFORT := $(shell ifort --version)
#VERIFORT := $(shell ifort --version | grep ^ifort) # error occurred too

.PHONY: test
test:
    echo $(VERIFORT)

If you copy those code lines shown above, make sure there is a tab before the echo command.

which gives me some errors

/bin/sh: -c: line 0: syntax error near unexpected token `('

When I ran the command ifort --version or ifort --version | grep ^ifort in a terminal, it gave proper result and no error occurred.

My system: 64-bit CentOS 7

Appreciate any correction suggestions.

[EDIT]

Add more output details:

With the grep version of VERIFORT, the make command produced the following result,

echo ifort (IFORT) 18.0.2 20180210
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `echo ifort (IFORT) 18.0.2 20180210'
make: *** [test] Error 1

[SOLVED]

It turns out to be an echo-usage problem as mentioned by @MadScientist

I think you need to quote the value of the VERIFORT variable when you print it, so that the shell doesn't interpret special characters.

Quoting the VERIFORT variable produced the following result (the grep version)

echo 'ifort (IFORT) 18.0.2 20180210'
ifort (IFORT) 18.0.2 20180210

and no error occurred.

I also tested it by using echo in a terminal

echo ifort (IFORT) 18.0.2 20180210

Which generated the same error

bash: syntax error near unexpected token `('
Rubin
  • 332
  • 1
  • 10
  • This is odd, since your command doesn't even contain a `(`. I guess the error then occurs even if you use a command which consists just of a single word, for instance (just for testing) `VERIFORT := $(ls)`? In this case, it seems that the shell is somehow setup badly for make. I would also verify, what shell `/bin/sh` exactly refers to. What does `/bin/sh --version` say? – user1934428 Apr 18 '18 at 06:42
  • @user1934428 The `/bin/sh --version` prints `GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)`. – Rubin Apr 18 '18 at 07:15

1 Answers1

4

It seems you didn't show the complete output of the make command. I think before this error message, make printed an echo line (unless the makefile you showed us isn't actually what you invoked, and your actual makefile adds a @ before the echo... in which case you should remove it while you debug). If you'd shown us what that output was it would be more clear what the problem is. Also you didn't show what the output of the ifort --version command is when you run it from the command line, but I think it probably contains parentheses.

I think you need to quote the value of the VERIFORT variable when you print it, so that the shell doesn't interpret any special characters:

test:
        echo '$(VERIFORT)'
MadScientist
  • 92,819
  • 9
  • 109
  • 136