user3564658
user3564658

Reputation: 21

Check File Existence with Makefile Conditional

I am trying to check the existence of a file using Makefile conditionals.

I've tried the following syntax which don't seem to work:

Path = /usr/local/myFileVer1
ifeq ($(wildcard $(Path)),)  
version = 1
else
version = 2
endif

I thought the wildcard statement would evaluate to an empty string if the file did not exist so it would fall into the else statement. That isn't happening.

Any idea what else I can try?

Upvotes: 2

Views: 10350

Answers (2)

Diego Sevilla
Diego Sevilla

Reputation: 29001

You're close to the syntax. You can try something like this:

File = /usr/local/myFileVer1

ifeq ($(wildcard $(File)),)
all:
    echo 1
else
all:
    echo 2
endif

Or better, you can write two separate makefiles and include them at the right places:

File = /usr/local/myFileVer1

ifeq ($(wildcard $(File)),)
include Makefile1.mk
else
include Makefile2.mk
endif

Upvotes: 5

MadScientist
MadScientist

Reputation: 100781

Make, like all UNIX utilities, is case-sensitive. PATH is not the same as Path.

Also, you should not set the variable PATH as this will change the PATH when commands are invoked, and then your recipes will all fail.

Upvotes: 1

Related Questions