gcb
gcb

Reputation: 14550

makefile, rule for multiple inputs

have one time consuming step that flattens a bunch of files.

basically i'd like this to be valid syntax

%.out: %.input1 %.input2
    merge $<1 $<2 $@

doit: project.out
    # project.out merged

i'm far from a makefile expert, but i like to use .SULFFIXS to do that when only have two files, would be great to adapt that to two inputs, or two outputs for future use...

.SULFFIX: .in.out
.in.out:
    dosomething $< $@
doit: project.out

GNU Make 3.81

I've found several discussions on how to have a rule with several outputs, but none with several inputs.

Upvotes: 2

Views: 5715

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136505

%.out: %.input1 %.input2
    merge $<1 $<2 $@

There are no $1 and $2 automatic variables in makefile rules, however, there is $^ which is the list of all prerequisites. As the rule only has two prerequisites it expands to %.input1 %.input2, or, more precisely, to $*.input1 $*.input2. Hence:

%.out: %.input1 %.input2
    merge $^ $@

Should suffice.

.SULFFIXES, IMO, is not very useful, since it uses implicit rule definitions which one can't see and change.

[update]

With regards to doit target, to prevent it from executing every time you might like to change the rule commands to:

doit: project.out
    # project.out merged
    touch $@

Upvotes: 5

Related Questions