makefile - Make:我们可以优化 make 文件目标吗?
问题描述
我们在工作流程中支持 32 位和 64 位构建。为此,我们在 makefile 中有多个规则,这些规则分别用于 32 位和 64 位。让我展示一对除了字符串“32”和“64”之外相同的规则。
生成文件片段:-
$(TGTDIR32)/logdir/set_user.c: $(CURDIR)/slv/set_user.c
$(file_transfer)
$(TGTDIR64)/logdir/set_user.c: $(CURDIR)/slv/set_user.c
$(file_transfer)
如果您注意到,除了字符串“32”和“64”之外,我们有相同的目标,我想用单个规则/定义替换它们。因为我们的基础设施代码中有数百条类似上面的规则。
我们在 GNUmake 中是否有任何简化的方法来做到这一点?
提前致谢!
解决方案
具有相同先决条件和配方的目标可以简单地组合,如下所示:
$(TGTDIR32)/logdir/set_user.c $(TGTDIR64)/logdir/set_user.c: $(CURDIR)/slv/set_user.c
$(file_transfer)
或更一般地说:
THESE_TARGETS := $(TGTDIR32)/logdir/set_user.c $(TGTDIR64)/logdir/set_user.c # More...?
...
$(THESE_TARGETS): $(CURDIR)/slv/set_user.c
$(file_transfer)
如果 Make 确定 的任何成员$(THESE_TARGETS)
在先决条件方面已经过时,那么它将运行该目标的配方。
这个生成文件:
.PHONY: all clean
all: a b c
a: d e
touch $@
b: d e
touch $@
c: d e
touch $@
d:
touch $@
e:
touch $@
clean:
$(RM) a b c d e
相当于这个:
.PHONY: all clean
all: a b c
a b c: d e
touch $@
d e:
touch $@
clean:
$(RM) a b c d e
之后
有一些静态模式规则......
同样适用。这个带有静态模式规则的makefile:
.PHONY: default clean
default: a.k b.k
a.k: %.k: %.j
cp -f $< $@
b.k: %.k: %.j
cp -f $< $@
a.j:
touch $@
b.j:
touch $@
clean:
$(RM) a.k b.k a.j b.j
相当于这个:
.PHONY: default clean
JS := a.j b.j
KS := $(JS:.j=.k)
default: $(KS)
$(KS): %.k: %.j
cp -f $< $@
$(JS):
touch $@
clean:
$(RM) $(JS) $(KS)
推荐阅读
- java - Glide 4 - 特定调用的 ResourceDecoder
- computer-science - 带加权边的二分图
- python - 使用字符串库的 Python 字符串问题
- node.js - 如何在 nodejs 模型中获取用户 ip?并在我的表列 ip_address 中更新
- css - 有没有办法在 woocommerce 结账时“浮动标签”?(如 Shopify)
- docker - Openshift Nginx权限问题【nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)]
- php - Laravel 在获取路线中设置值
- django - Django - 如何创建文件并将其保存到 ModelSerializer 中的字段
- yocto - 如何在 qemu 中运行 yocto 开发的树莓派镜像?
- ssh - ssh v2 最大压缩 (xzip/7zip)