1

I have such code snippet:

.PHONY: program1 program2

a=A
b=B
c=C

program1: 
    @python example.py a=$(a) b=$(b)

program2:
    program1 c=$(c) d=d

Due to the DRY principle, I don't want to replicate code and composed program2 in a way calling program1.

But I understand that program1 is not in a path.

How can I correctly define program2 target?

Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109

1 Answers1

0

The recipe of a rule contains shell commands. make does not execute them directly. The shell it uses to execute them does not recognize make target names as commands any more than any other shell does, so a recipe cannot use make targets as commands.

But a recipe can run make, a procedure conventionally described as "recursive make". For example, this rule would achieve what I think you are describing:

program2:
        $(MAKE) program1 c='$(c)' d=d

The MAKE variable will normally expand to the name of make command you used -- often just make, but perhaps something like gmake or /special/path/make. You can also redefine it yourself inside the makefile, maybe to add flags to it, for example.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157