Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU make rule for multiple targets

Tags:

makefile

I'm trying to get GNU make to produce multiple outputs from a single input. The most simple example I can demonstrate is:

a b : test
    cp $< $@

which, I believe, should copy the file test to the files name a and b. However, it only makes the file a, which seems to me to be contrary to the instructions listed here:

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

Am I doing something wrong?

Thanks, Tom

like image 336
Tom Sharp Avatar asked Jan 23 '23 01:01

Tom Sharp


1 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 instead. If you make a rule above your current rule like:

all: a b

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

like image 98
Michael Mrozek Avatar answered Mar 01 '23 22:03

Michael Mrozek