TheWatcher
TheWatcher

Reputation: 177

How to check whether a file exists inside of a "foreach" in Makefile?

So I have a variable with file names, however I am not sure whether these file names exist. I want to put the ones that exist into some other variable. All this is happening in a Makefile.

Here is one of my many tries to accomplish it:

FILES is the preset variable containing the set of the files.

OUTPUT += $(foreach file, $(FILES), \
                   ifneq (,$(wildcard $(file))
                     $(file)
                   endif

Obviously it doesn't work for many reasons, just trying to make clear what I want to achieve.

Also I would like to avoid using $(shell *) if possible.

Thanks!

Upvotes: 0

Views: 718

Answers (1)

l0b0
l0b0

Reputation: 58828

The wildcard function takes multiple targets, and unlike shell globs non-matching patterns are omitted from the output, so I would expect this to work:

OUTPUT = $(wildcard $(FILES))

Upvotes: 2

Related Questions