makefile - ifndef 变量在定义变量时触发
问题描述
为什么,当我运行时make run-e2e-docker
ifndef 被激活?应该设置变量,但 make 确定它不是。它可用于运行的 echo 命令。如果我删除 ifndef 并运行 make 它会打印变量。
run-e2e:
ifndef environment
$(error "You can't run run-e2e directly, choose one of the run-e2e-* tasks ${environment}")
endif
@echo extra_profiles=${extra_profiles}
@echo environment=${environment}
run-e2e-docker: override extra_profiles = docker-e2e,dev-performance
run-e2e-docker: override environment = docker
run-e2e-docker: run-e2e
解决方案
您不能在上下文中使用 make 条件。当您明显思考时,它们不会被评估。但是您可以使用 shell 条件,而不是:
run-e2e:
@if [ -z "$(environment)" ]; then \
echo "You can't run run-e2e directly, choose one of the run-e2e-* tasks"; \
exit 1; \
fi
@echo extra_profiles=${extra_profiles}
@echo environment=${environment}
GNU Make 手册说……
条件控制 make 在 makefile 中实际“看到”的内容,因此它们不能用于在执行时控制配方。
https://www.gnu.org/software/make/manual/html_node/Conditionals.html
推荐阅读
- python - 如何使用 Selenium 和 Python 将字符发送到输入字段
- c++ - 如何在windbg中查看类成员变量?
- c# - 我需要在启动时在 ASP .Net Core 3.1 Web API 中执行异步方法
- tensorflow - 为什么验证损失和准确率波动如此之大?
- php - Laravel:如何检索从父模型扩展的子模型的所有实例?
- java - C 中的 fprintf() 通过 Java 本机接口调用时会生成垃圾文件名
- python - 如何使用 mathplotlib 在彼此下方绘制 2 个图形?
- sql - 获取 MS ACCESS 的版本
- r - 修改使用 readOGR() 读取的 shapefile 空间对象中的属性值
- php - 棘轮Websocket异步mysql最佳实践