gpt4 book ai didi

makefile,处理多个文件

转载 作者:行者123 更新时间:2023-12-03 06:24:49 25 4
gpt4 key购买 nike

我如何处理一个 makefile (gnu make) 中的多个文件,以及:

  • 为每个文件运行一个命令或一系列命令
  • 因单个错误代码大于零而失败
  • 无需在 makefile 中键入每个文件名
  • 即使在第一次失败后仍继续对所有文件运行

我想出了这个。除了最后一个要求之外,它可以工作,并且非常不Make:

.PHONY: lint
.PHONY: all

all: lint

lint:
for f in `find src/ -name \*.inc -o -name \*.html`; do php -l $$f && continue || exit 1; done

最佳答案

原始 makefile 的更像 make 的转录:

files := $(shell find src/ -name \*.inc -o -name \*.html)
.PHONY: ${files}
${files}: ; php -l $@

.PHONY: lint
lint: ${files} ; echo Lint finished

我真的真的不喜欢在makefile中使用$(shell…)。就我个人而言,我会列出 Makefile 中的所有文件,也许有一个目标来断言列表是完整的。

如果您需要最后一点(“即使在第一次失败后仍继续在所有文件上运行”),请使用 make -k

关于makefile,处理多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5414418/

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