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

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

问题描述

使用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中列出生成的文件(《自动制作》手册的

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.

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

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

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

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