bash - 如何根据 Makefile 目标命令中的参数有条件地添加`--flag value`?
问题描述
考虑 2 个 makefile 目标触发器:
make print # Print everything
make print filter=topic-a # Print only topic-a
现在,在 Makefile 目标中,filter
功能是通过一些命令的标志来实现的,如下所示:
print:
some_command --arg --anotherarg \
--filter <filter>
在某些情况下,该命令不能很好地处理空 --filter
,所以问题是..
问题
如何--filter <filter
根据参数是否已传递给make
自身(make print filter=topic-a
)有条件地在 Makefile 目标内部添加/删除?
解决方案
这可以通过make
条件函数来实现(https://www.gnu.org/software/make/manual/html_node/Conditional-Functions.html):
print:
some_command --arg --anotherarg \
$(if $(filter),--filter $(filter),)
内联条件表达式的工作方式如下:
$(if condition,then-part[,else-part])
请注意如何condition
评估:
如果它扩展为任何非空字符串,则该条件被认为是真的。如果它扩展为空字符串,则该条件被认为是错误的。
推荐阅读
- c++ - 是否可以考虑在 CGAL Delaunay 三角剖分(或任何其他支持的三角剖分)中共面的点,即使它们不是?
- python - 有没有办法填充插值区域外的空间?
- python - Django 错误:未解决的导入“extra_views”
- java - (char) (i + 'a') JAVA:这里发生了什么?
- javascript - 如何对齐比例描述?
- airflow - 在 Apached Airflow Airflow 1.10.12 - 没有名为“httplib2”的模块
- python-3.x - Python Keras 多个输出返回空数组
- pandas - 试图找到给定城市的最高得分提升
- regex - 修复 RewriteRule - 访问由连字符分隔的字符串末尾的 ID
- c - C语言可以忘记变量吗?