Boocko
Boocko

Reputation: 740

Makefile rule where one of the two prerequisites matches

I want to wite a makefile rule for a case, where files of type .bbb and .ccc are compiled into .aaa.

I could simply write two rules:

%.aaa: %.bbb
   process $<
%.aaa: %.ccc
   process $<

but I'm wodering whether this could be accomplished in one rule, such as:

%.aaa: %.bbb OR %.ccc
   process $<

Note that only one of the files bbb or ccc is enough for compilation, and in my case, only one exists (so either x.bbb OR x.ccc, not both).

Upvotes: 0

Views: 213

Answers (1)

wnoise
wnoise

Reputation: 9942

The first way is how you express this. All makefile rules are implicitly ored together. Saying you can create %.aaa from either %.bbb or %.ccc is the same as saying you can create %.aaa from %.bbb and you can create %.aaa from %.ccc.

If the body of the rule is complex and you want to "reuse the body", many makes have macro facilities that will let you define it one place and reuse it.

Upvotes: 2

Related Questions