Makefile – Check if a file exists using wildcard function

The following snippet of code can be used to check for the existence of a file from within a Makefile.

ifneq ("$(wildcard $(PATH_TO_FILE))","")

Quoting from make documentation.

$(wildcard pattern)
The argument pattern is a file name pattern, typically containing
wildcard characters (as in shell file name patterns). The result of
wildcard is a space-separated list of the names of existing files
that match the pattern.

In this present case, we are not using any wildcards, but the absolute path to the file.

About Pratik Sinha

Linux Nerd, Socialist, Atheist, Adventuristic, Nature Lover, Geeky.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>