nachum
nachum

Reputation: 567

makefile bash recipe - include file if exists at recipe time

I have a makefile that runs some custom tools. One of those tools sometimes spits out an extra file. That file must be used in a subsequent recipe (if it exists). I can't assume it exists in the dependencies, but I must use add it to the subsequent recipe command if it is there. Here's how I currently handle it:

final_recipe:
 [ ! -f "maybe.file" ] || tool maybe.file ...
 [ -f "maybe.file" ] || tool ...

This is ugly. Any suggestions for a bash executable line where bash can evaluate whether the file exists and embed it if it does? Something more like:

final_recipe
 tool ([ -f "maybe.file"] ? maybe.file) ...

Upvotes: 0

Views: 175

Answers (1)

Philippe
Philippe

Reputation: 26592

This may achieve what you wanted :

final_recipe:
    tool $$(test -f maybe.file && echo maybe.file) ...

Updated upon MadScientist's comment

Upvotes: 1

Related Questions