makefile - 使用多个规则制作单个文件的 Makefile
问题描述
我想用多种方式创建一个生成文件的 Makefile:
.PHONY: app bin tgt
app file: app-dependency ; touch file
bin file: bin-dependency ; touch file
tgt: file ; touch tgt
这样我就可以运行make tgt
并根据文件是否app-dependency
存在bin-dependency
来决定要运行的目标。
当我写类似上面的东西时,我收到以下警告:
警告:覆盖目标“文件”的
配方警告:忽略目标“文件”的旧配方
解决方案
您的规范不是 100% 完整的,所以让我们发明缺少的内容:如果app-dependency
存在,则使用app-rule
else,如果bin-dependency
存在,使用bin-rule
,否则会引发错误。如果这不是您想要的,请编辑您的问题并尝试添加缺少的规范位。
制作条件是一种做你想做的事的方法:
.PHONY: app bin tgt
ifeq ($(wildcard app-dependency),app-dependency)
app file: app-dependency
app-rule
else ifeq ($(wildcard bin-dependency),bin-dependency)
bin file: bin-dependency
bin-rule
else
app bin file:
$(error app-dependency and bin-dependency not found)
endif
tgt: file
tgt-rule
推荐阅读
- php - 如何用php在文本文件中用空格替换指定字符
- sql - Snowflake 无法识别在 Alteryx 中创建的表中的列
- c++ - 内部类变量中的读取访问冲突
- docker - MariaDB docker 从主机 Windows 10 与 Linux 访问
- python - 如何使用 AWS CLI 或 Python 列出 AWS S3 存储桶中的*最近*文件
- php - 对字符串上的成员函数格式()的致命错误调用
- html - 我的元素不在屏幕上,我不知道如何修复它
- pandas - 如何在非数值上构建条形图?
- modelica - Dymola 初始化过程中使用的非线性求解器是什么?
- html - 如何将图片从我的计算机放到我的 html 网站?