GNU makes a rule for several purposes.

I am trying to get GNU make to produce multiple outputs from a single input. The simplest example I can demonstrate:

ab : test cp $< $@ 

which, I believe, should copy the test file to the file names a and b . However, it only makes the file a , which, it seems to me, contradicts the instructions given here:

http://www.gnu.org/software/automake/manual/make/Multiple-Targets.html

Am I doing something wrong?

Thanks Tom

+4
source share
3 answers

If you run a rule that depends on a , it will run your rule with $< as test and $@ as a . If you run a rule that depends on b , $@ will be b . If you make a rule above your current rule, for example:

 all: ab 

It will run the rules for a and b , which is the same rule twice. Otherwise, if your rule is the first in the file, it will run it only with the first goal, which is equal to a

+9
source

A little explanation for the comment by @MichaelMrozek.

It:

 ab : test cp $< $@ 

In the same way as:

 a : test cp $< $@ b : test cp $< $@ 

a is the first target in the file, so it is the default target. Only rule for runs, since there is no dependency on b.

Like @MichaelMrozek, you can add another rule or run

 make ab 
0
source

Everything is good. The manual says:

 bigoutput littleoutput : text.g generate text.g -$(subst output,, $@ ) > $@ 

equivalently

 bigoutput : text.g generate text.g -big > bigoutput littleoutput : text.g generate text.g -little > littleoutput 

So your makefile is also equivalent

 a : test cp $< $@ b : test cp $< $@ 

and when you entered the make command, the program built the first target by default, that is, a.

0
source

Source: https://habr.com/ru/post/1310406/


All Articles