0

I have a script which generates some source files for my c++ project. The script itself looks like this:

echo "total args: $#"
if [ $# -eq 7 ]; then
echo "in if"
$1/../tools/xsde [...]
fi

It is executed from a makefile when target smt_response_files is run and file .xsd.files.make does not exists or it is older than .xsd file.

$(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

The problem: after I clean up my project and delete *.xsd.files.make they are recreated when makefiles are parsed (I've translated the output from Russian):

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)

The autogenerated files are removed by the clean target, but I don't like that they are created in the process.

The only way to do this, as far as I know is to exclude the rules for recreating *.xsd.files.make which are included as makefiles:

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

Is there other ways to solve my problem? Maybe some more general approach exists?

Thanks everyone in advance.

4

1 回答 1

0

它们在技术上不是在解析生成文件时构建的。请参阅 GNU make 手册,部分Makefiles are Remade。一旦 make 完成对所有 makefile 的解析,它将执行一个过程,以确保所有包含的 makefile 都是最新的,将它们全部视为目标并尝试重建它们。这就是你所看到的。

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

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

请记住,诸如clean,all等规则只是约定:它们除了诸如fooor之类的规则之外没有任何意义bar。所以,使不知道要特别对待他们。

于 2013-06-04T11:11:27.757 回答