0

I have a single command my_app that produces two files file1.o and file2.o following an answer from SO I came up with the follwoing:

all: file1.o file2.o 
%1.o %2.o : input.txt
    my_app input.txt

But that doesn't work and triggers every time even when file1.o and file2.o already exist and input.txt hasn't changed. Then I realized that the targets need to be mentioned with $* so the following works

all: file1.o file2.o
%1.o %2.o : input.txt
    @echo ($*1.o) 
    @echo ($*2.o)
    my_app input.txt

Which produces

$ make
file1.o
file2.o
my_app input.txt

Ok, good enough, but how do I make it without printing the files? Do I have to trick Make by suppressing the output somehow or is there another more programmatic way to solve this?

user2506946
  • 131
  • 9
  • _Then I realized that the targets need to be mentioned with $*_ that is definitely not true, so you need to go back to the original. The only thing make cares about is the timestamps of the target(s) and the prerequisite(s). It doesn't care in the slightest what variables your recipe does, or does not, reference. If (a) the `my_app` tool creates `file1.o` _and_ `file2.o` _and_ their timestamps are changed to be newer than `input.txt`, then make won't re-run that rule. So if make is re-running the rule, one of those things is not true. – MadScientist Jun 13 '23 at 19:20
  • If you want to understand what's happening, run make with the `-d` option, then investigate the (voluminous) output to see why make decided those targets were out of date and needed to be rebuilt. – MadScientist Jun 13 '23 at 19:21
  • Ah, you are right. That's it. Thanks! I knowit fits in a comment but I you want to add an answer I'll accept it. – user2506946 Jun 13 '23 at 19:28
  • Well, I didn't really answer it because there wasn't enough info here to tell you what was wrong with what you were doing :). I just mentioned how you could figure it out. – MadScientist Jun 13 '23 at 21:01

0 Answers0