使用autotools构建时如何生成源文件 [英] How to generate a source file when building using autotools

查看:33
本文介绍了使用autotools构建时如何生成源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Make,我可以做类似的事情

With Make, I do something like

generated.c: input.txt generator
    ./generator input.txt > generated.c

我如何从自动工具中获得等效的功能?(在清理时删除 generate.c 也是一个奖励).

How would I get equivalent functionality out of autotools? (removing generated.c on cleaning would also be a bonus).

推荐答案

我假设 input.txt 是一个已分发的源文件,您> 想要分发generated.c(即必须由每个用户构建),并且那个generator也是你的包构建的程序.

I'm assuming that input.txt is a source file that is distributed, that you do not want to distribute generated.c (i.e., it must be built by each user), and that generator is a program built by your package too.

EXTRA_DIST = input.txt
bin_PROGRAMS = prog
noinst_PROGRAMS = generator

# Source files for the generator
generator_SOURCES = generator.c ...

# Source files for prog
prog_SOURCES = prog.c ...
nodist_prog_SOURCES = generated.c 

# generated.c is a built source that must be cleaned
CLEANFILES = generated.c

# Build rule for generated.c
generated.c: $(srcdir)/input.txt generator$(EXEEXT)
        ./generator$(EXEEXT) $(srcdir)/input.txt

在某些情况下,例如在生成头文件时,在编译其余源代码之前生成文件很重要,因此可以包含它.在这种情况下,您还应该在变量 BUILT_SOURCES 中列出生成的文件(Automake 手册在其 内置源部分.在上述情况下,不需要.

In some situations, like when generating header files, it is important to generate the file before the rest of the sources are compiled, so it can be included. In that case you should also list the generated file in the variable BUILT_SOURCES (The Automake manual has many example in its Built sources section. In the above case it is not necessary.

EDIT:我已经修复了上面的 Makefile.am 示例,将 generator 声明为未安装的程序.

EDIT: I have fixed the above Makefile.am example to declare generator as a non-installed program.

这篇关于使用autotools构建时如何生成源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆