首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >异常行为: makefile在解析时执行shell脚本

异常行为: makefile在解析时执行shell脚本
EN

Stack Overflow用户
提问于 2013-06-04 17:29:07
回答 1查看 160关注 0票数 0

我有一个为我的c++项目生成一些源文件的脚本。脚本本身看起来像这样:

代码语言:javascript
复制
echo "total args: $#"
if [ $# -eq 7 ]; then
echo "in if"
$1/../tools/xsde [...]
fi

当运行目标smt_response_files并且文件.xsd.files.make不存在或比.xsd文件旧时,它从makefile执行。

代码语言:javascript
复制
$(smt_path) ?= .
$(smt_build) ?= $(smt_path)/build
$(common_build) ?= ../build

-include $(smt_build)/$(smt_gen_response_xsd).files.make

smt_response_files : | $(smt_build)/$(smt_gen_response_xsd).files.make
    @:

$(smt_build)/$(smt_gen_response_xsd).files.make : $(smt_gen_response_path)/$(smt_gen_response_xsd)
    @$(common_build)/generate_xml.sh $(smt_path) $(smt_gen_response_path) $(smt_gen_response_xsd) xml::$(smt_gen_response_class) make_list $(smt_build)/$(smt_gen_response_xsd).files.make smt_response_files

问题:在清理项目并删除*.xsd.files.make之后,在解析makefile时会重新创建它们(我已经将输出从俄语翻译过来):

代码语言:javascript
复制
Reading make-files...
total args: 7
in if
...
total: 2193
Updating makefile goals...
 File `smt_clean' does not exist.
... (and a normal clean proccess goes next)

自动生成的文件由clean目标删除,但我不喜欢在此过程中创建它们。

据我所知,要做到这一点,唯一的方法是排除重新创建*.xsd.files.make的规则,这些规则包含在makefile中:

代码语言:javascript
复制
inc_gen ?= true
ifeq ($(MAKECMDGOALS),clean)
    inc_gen := false
endif
# ... other excluded targets here (smt_clean, etc.)

ifeq ($(inc_gen),true)
$(smt_build)/$(smt_gen_response_xsd).files.make : $(smt_gen_response_path)/$(smt_gen_response_xsd)
    @$(common_build)/generate_xml.sh $(smt_path) $(smt_gen_response_path) $(smt_gen_response_xsd) xml::$(smt_gen_response_class) make_list $(smt_build)/$(smt_gen_response_xsd).files.make smt_response_files
endif

有没有其他方法来解决我的问题?也许存在更通用的方法?

提前感谢大家。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-04 19:11:28

从技术上讲,它们不是在解析makefile时构建的。请参阅GNU make手册,Makefiles是如何重建的。在make完成对所有makefile的解析后,它将执行一次传递,确保所有包含的makefile都是最新的,方法是将它们都视为目标并尝试重新构建它们。这就是你所看到的。

如果任何makefile已更改,则make将从头开始重新执行自身,以便它可以重新读取更新的makefile的内容。

推荐的解决方案是您拥有的解决方案(检查clean目标,以及您不想强制重建makefile的任何其他目标,如果发现,要么不执行include,要么不提供重建makefile的规则)。

请记住,像cleanall等规则只是一些约定:它们只不过是像foobar这样的规则而已。所以,做不到要特别对待他们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16914253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档