How to conditional set up a Makefile variable by testing if a file exists

Makefile

Makefile Problem Overview


For example: I want:

if file1 exists:

CLEAN_SRC = *.h file3

else

CLEAN_SRC = 

Makefile Solutions


Solution 1 - Makefile

If file1 does not exist then $(wildcard file1) will evaluate to an empty string.

ifeq ($(wildcard file1),) 
    CLEAN_SRC =
else 
    CLEAN_SRC = *.h file3
endif 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSam LiaoView Question on Stackoverflow
Solution 1 - MakefileJohn KugelmanView Answer on Stackoverflow