1

I have the following Makefile:

all: print1 print2 

world=world1
print1:
    @echo $(world)

world=world2
print2:
    @echo $(world)

.PHONY: all print1 print2

When running with make I expected to get:

world1
world2

But I got:

world2
world2

Is it possible to get the expected output only with the variable world?

Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109
  • Short answer: no. Are you exploring Make, or do you have a purpose in mind? – Beta May 27 '20 at 02:49
  • @Beta yes, I want to run different models (targets) but they have common arguments name like `$(num_layers)` but depending on the target it should be different. – Kenenbek Arzymatov May 27 '20 at 02:53

1 Answers1

2

Target-specific variable values were made for this.

print1: world=world1
print1:
    @echo $(world)

print2: world=world2
print2:
    @echo $(world)

And if the recipes are identical, you can combine the rules:

print1: world=world1
print2: world=world2

print1 print2:
    @echo $(world)
Beta
  • 96,650
  • 16
  • 149
  • 150