Reputation: 2063
I have a make target that calls another, I want to set the variables in the make target that calls the target it depends on and pass the variables down.
FILENAME ?=
SERVICE ?=
generate-transaction-command: generate-service
FILENAME := swagger.json
SERVICE := transaction
generate-service:
@curl -s http://localhost:8181/swagger/proto/$(FILENAME) --output ./$(FILENAME)
@./gen -input ./$(FILENAME) -output ./cli/cmd/$(SERVICE).go
I want to be able to run make generate-transaction-command
and then my generate-service
command uses the variables set in the generate-transaction-command
, at the moment it gives me this error.
FILENAME: No such file or directory
So I assume it isn't setting the variables correctly.
Upvotes: 0
Views: 100
Reputation: 1976
See Target-specific Variable Values
Example:
FILENAME ?=
SERVICE ?=
generate-transaction-command: generate-service
@echo $@ recipe
# set variables for a target:
generate-transaction-command: FILENAME := swagger.json
generate-transaction-command: SERVICE := transaction
# added echo
generate-service:
@echo curl -s http://localhost:8181/swagger/proto/$(FILENAME) --output ./$(FILENAME)
@echo ./gen -input ./$(FILENAME) -output ./cli/cmd/$(SERVICE).go
output:
curl -s http://localhost:8181/swagger/proto/swagger.json --output ./swagger.json
./gen -input ./swagger.json -output ./cli/cmd/transaction.go
generate-transaction-command recipe
Upvotes: 1