3

within a makefile I need to check if a file exists. Regarding to this answer from holms, I tried it in this way:

all:
    ifeq ("","$(wildcard testFile)")
       echo "File exists"
    else
       echo "File is missing"
    endif

Nevertheless I get this error:

ifeq ("","")
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 2

Where is my mistake and how to interpret this syntax error message?

Community
  • 1
  • 1
eDeviser
  • 1,605
  • 2
  • 17
  • 44

1 Answers1

4

You've tabbed the make syntax lines, so make is passing them to your shell, get rid of the tabs (also reverse the conditional and remove the quotes)

all:
ifeq (,$(wildcard testFile))
    echo File is missing
else
    echo File exists
endif
user657267
  • 20,568
  • 5
  • 58
  • 77
  • Okay, thank you that helped. I understand, the `ifeq`statement is interpreted by `make`. But the lines with `echo` should have a tabulator because they needed to be passed to my shell, right? – eDeviser Dec 02 '16 at 07:53
  • Okay, your answer seems to show four spaces instead a tabulator, which could be just a stylistic issue of the stackExchanges editor. – eDeviser Dec 02 '16 at 08:19