gpt4 book ai didi

linux - 当 gnu make phony 目标恰好与目录名称相同时的行为

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:14 26 4
gpt4 key购买 nike

一个 makefile 有一个假目标 libs,还有一个要进入的目录 libs。在一台机器上运行良好,而在另一台机器上它不会进入 libs 目标的 libs 目录。在这两种情况下,gnu make 版本都是 3.81,但一个在 Windows 上,另一个在 centos 上。

顶层生成文件:

$ cat Makefile

SUBDIRS := libs

.phony: all headers libs exes

all: headers libs exes

headers libs exes:
@for d in $(SUBDIRS); do \
echo -e "\n\n"; \
echo -e "=================\n"; \
echo -e " ++Build subdir $$d target $(@)\n"; \
make -f $$d/Makefile DIR=$$d TGT=$(@) $(@); \
y=$$?; if [ ! "x$$y" == "x0" ]; then \
echo -e "\n Error $$y: in top makefile\n"; exit 1; fi; \
echo ; \
echo -e " --Build subdir $$d target $(@) done\n"; \
echo -e "=================\n"; \
done

子生成文件:

$ cat libs/Makefile

.phony: headers libs exes

headers libs exes:
@echo -e "\n\n **** " submake target $(@) " **** \n\n"

不下降的结果:

$ make

=================
++Build subdir libs target headers
make[1]: Entering directory `/home/dev2/tmp/tt'

**** submake target headers ****

make[1]: Leaving directory `/home/dev2/tmp/tt'

--Build subdir libs target headers done
=================

=================
++Build subdir libs target exes
make[1]: Entering directory `/home/dev2/tmp/tt'

**** submake target exes ****

make[1]: Leaving directory `/home/dev2/tmp/tt'
--Build subdir libs target exes done
=================

我希望它在中间有一个部分:

    ****  submake target libs  ****

[Edit] 问题是 .PHONY: 必须是大写的,正如回答者所建议的,我验证了。 windows 版本的 make 不需要这个。

最佳答案

特殊目标区分大小写。要使 libs 等实际上成为虚假目标,您需要这样拼写 .PHONY:

.PHONY: all headers libs exes

事实上,您有一个普通的规则和一个有点不寻常命名的目标!

关于linux - 当 gnu make phony 目标恰好与目录名称相同时的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com