如何解决设置变量以用于不同的make target
我有一个调用另一个目标的make目标,我想在调用目标所依赖的目标的make目标中设置变量并将变量向下传递。
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
我希望能够运行make generate-transaction-command
,然后我的generate-service
命令使用generate-transaction-command
中设置的变量,此刻它给了我这个错误。
FILENAME: No such file or directory
所以我认为它没有正确设置变量。
解决方法
请参见Target-specific Variable Values
示例:
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
输出:
curl -s http:// localhost:8181 / swagger / proto / swagger.json --output ./swagger.json
./gen -input ./swagger.json -output ./cli/cmd/transaction.go
生成交易命令配方
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。