【问题标题】:How to generate a source file when building using autotools使用自动工具构建时如何生成源文件
【发布时间】:2011-09-11 05:04:50
【问题描述】:

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

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

如何从自动工具中获得同等功能? (在清理时删除 generated.c 也是一种奖励)。

【问题讨论】:

    标签: makefile autotools autoconf automake


    【解决方案1】:

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

    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 手册在其Built sources section 中有很多示例。在上述情况下,没有必要。

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

    【讨论】:

    • 谢谢你,正是我要找的东西,以及阅读更多内容的参考资料!
    • 我有一个follow-on question,关于如何使它适用于 VPATH 构建。
    • @Craig 已回答。 HTH。
    猜你喜欢
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多