Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate multiple target using single action/rule [duplicate]

Tags:

How do I write a rule to generate set of files using a single action.

Example: Files x, y, z are generated as a result of single execution of script t.sh which takes file a as input.

x y z: a
    t.sh $@

GNU make tries to execute t.sh 3 times.

like image 244
shoban Avatar asked Jun 10 '10 16:06

shoban


People also ask

Can you have multiple rules in a makefile?

There can only be one recipe to be executed for a file. If more than one rule gives a recipe for the same file, make uses the last one given and prints an error message.

What is $@ in makefile?

The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.

How many targets can a makefile have?

Makefile Syntax The targets are file names, separated by spaces. Typically, there is only one per rule.

What is the default make target?

By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe.


1 Answers

You could implement one of the solutions specified in the automake manual.

Because you've tagged this gnumake, I should also point out that using a GNU make pattern rule (the ones with %) with multiple targets WILL consider both generated from one execution of the rule: see the GNU make manual.

like image 86
Jack Kelly Avatar answered Oct 04 '22 16:10

Jack Kelly