'how to stop make -n from echoing same command multiple times

I am using GNU make and have a Makefile which looks like this:

AB = A.txt B.txt

${AB}: makeAB.py
    python makeAB.py

C.txt: ${AB} makeC.py
    python makeC.py

When I type make -n C.txt, assuming makeAB.py needs to run, I get the output:

python makeAB.py
python makeAB.py
python makeC.py

Is there any way to write the Makefile so that the line python makeAB.py is not repeated? This is just a toy example, but in my actual application AB consists of many files, so I potentially get a whole screen of unnecessary output.

p.s. When called without -n, make (sensibly) only runs python makeAB.py once. So my problem is just with make -n.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source