Your Makefile says the following:
- all targets are phony (i.e. they don’t correspond to on-disk artifacts);
all depends on target1 and target2, and since it’s the first target, is the default target; target1 sets NUM to 1 (using target-specific variable assignments); target2 sets NUM to 2; target1 and target2 both depend on target; target must be satisfied by running the given echo command.
Running make with these definitions will result in the following:
all isn’t satisfied, since it’s phony, and needs target1 and target2; target1 isn’t satisfied, since it’s phony, and needs target (with NUM set to 1); target isn’t satisfied, since it’s phony, and has no prerequisites, so make runs the echo command; target2 isn’t satisfied, since it’s phony, but target is satisfied, since it’s been processed already, so nothing happens.
You can’t use targets as functions, as you’re trying to do here; some Make implementations do support functions, but you don’t need that:
target1 target2: @echo "this is target ${NUM}"