简体   繁体   English

在自动工具中生成标题的构建过程

[英]build process that generates headers in autotools

I'm porting a home-baked makefile setup into the autotools suite. 我正在将家庭制作的makefile设置移植到autotools套件中。 I've run into a problem for which I haven't yet found a suitable answer. 我遇到了一个尚未找到合适答案的问题。 It may be that I'm just not using the correct terms in my searches. 可能是我在搜索中使用的字词不正确。 Being a complete neophyte to autotools, I probably just don't know enough of the jargon. 作为汽车工具的完整新手,我可能只是不太了解行话。

The problem: our build process has a dependency for a header file which is generated from a csv file. 问题:我们的构建过程依赖于从csv文件生成的头文件。 (I don't know why. It is what it is.) In our old system, we did something like this: (我不知道为什么。它就是它。)在我们的旧系统中,我们做了如下操作:

.PHONY: all
all : header.csv.h $(objects)

header.csv.h:
    python prebuild.py

# remainder for building objects and the file lib.a

Finding this link to extend default rules , I've added this to my Makefile.am 找到此链接以扩展默认规则 ,我已将其添加到我的Makefile.am

noninst_LIBRARIES = libstuff.a

# .. Additional CXXFLAGS and CPPFLAGS, and listing the sources

all-local: header.csv.h

header.csv.h:
    python prebuild.py

The remade Makefile s still didn't work. 重新制作的Makefile仍然无法正常工作。 Inspection of the generated Makefile for this part of the library showed this: 检查该库的此部分生成的Makefile显示如下:

# lots of stuff preceeding
all: all-am
all-am: Makefile $(LIBRARIES) all-local

all-local: header.csv.h
# the rest as above

Right there in all-am: is the problem. 就在all-am:问题是。 The $(LIBRARIES) dependencies are listed first and are therefore being built first. $(LIBRARIES)依赖关系首先列出,因此首先被构建。 Some further reading on the extending link above shows this is to be expected: no way to guaranteeing the order. 对上面扩展链接的进一步阅读显示这是可以预期的:没有办法保证顺序。 It's simple enough to "fix": move all-local to precede $(LIBRARIES) . “修复”非常简单:将all-local移动到$(LIBRARIES)之前。 However, this only fixes it once. 但是,这只能修复一次。 I must guarantee this is always built first. 我必须保证始终要首先构建它。

Can I add things to the configure script to be executed during the configuration process? 是否可以在configure脚本中添加要在配置过程中执行的内容? What's the right way to handle something like this? 处理这样的事情的正确方法是什么?

You're not supposed to write rules which depend on the order things are listed in the Makefile. 您不应该编写依赖于Makefile中列出的顺序的规则。 There's no reason to have this rule at all (I understand it's a direct translation of your old Makefile -- which was also wrong): 完全没有理由使用此规则(我知道这是您以前的Makefile的直接翻译-这也是错误的):

all-local: header.csv.h

because header.csv.h is not a build product that needs to appear at the end of the make process. 因为header.csv.h不是生成产品,因此不需要出现在make过程的末尾。 Instead you need 相反,您需要

somesourcefile.o : header.csv.h

reflecting the true fact, that building somesourcefile.o requires the header file to exist, because somesourcefile.cpp includes it. 反映真实的事实是,构建somesourcefile.o需要头文件存在,因为somesourcefile.cpp包含了它。 If it is included in multiple places, you might need multiple of these rules. 如果它包含在多个位置,则可能需要多个规则。

When you specify dependencies correctly, make will calculate the dependency graph, and build things in the correct order. 当正确指定依赖项时, make将计算依赖关系图,并以正确的顺序构建事物。

Also, this rule 另外,这条规则

header.csv.h:
    python prebuild.py

should almost certainly be 几乎应该是

header.csv.h : header.csv prebuild.py
    python prebuild.py

to make sure it gets rebuilt when either the source data or the translation rules change, and not when they don't. 以确保在源数据或翻译规则发生更改时(而不是在不更改时)进行重建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM