How to generate a source file when building using autotools

☆樱花仙子☆ 提交于 2019-11-27 23:55:32

问题


With Make, I do something like

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

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


回答1:


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

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: I have fixed the above Makefile.am example to declare generator as a non-installed program.



来源:https://stackoverflow.com/questions/6284918/how-to-generate-a-source-file-when-building-using-autotools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!