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.

1 comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Error While Parsing Json using Python – TypeError: list indices must be integers, not str

Jotting this down for fellow googlers. I recently started learning a bit…

Makefile Tricks: Arithmetic – Addition, Subtraction, Multiplication, Division, Modulo, Comparison

While working on a project, I needed to do some calculations inside…