【问题标题】:Hide targets when configure is run with certain options使用某些选项运行配置时隐藏目标
【发布时间】:2013-04-16 18:17:10
【问题描述】:

我的 configure.ac 允许用户指定 --enable-monitor。在一个子目录中,我有一个 Makefile.in,其中包含一定数量的要构建的目标。我希望其中一些仅在用户指定--enable-monitor时才可用

换句话说,我希望用户只能在./configure--enable-monitor 一起运行时才能运行make monitor

我该怎么做?

【问题讨论】:

    标签: makefile configure autotools


    【解决方案1】:

    把这个放到configure.ac就足够了:

    AC_ARG_ENABLE([monitor],[help string],[use_monitor=yes])
    AM_CONDITIONAL([USE_MONITOR],[test "$use_monitor" = yes])
    

    这在 Makefile.am 中:

    if USE_MONITOR
    bin_PROGRAMS = monitor
    else
    monitor:
        @echo Target not supported >&2 && exit 1
    endif
    

    带有显式监控目标的 else 子句用于覆盖 Make 可能使用的默认规则。请注意,“帮助字符串”应该更有用并使用AS_HELP_STRING 构造,但为简洁起见,这些细节已被省略。

    --编辑--

    由于未使用 automake,您可以将 configure.ac 中的 AM_CONDITIONAL 行替换为以下内容:

    AC_SUBST([USE_MONITOR],[$use_monitor])
    

    然后检查Makefile.in,例如:

    monitor:
            @if test "@USE_MONITOR@" = yes; then \
                ... ; \
            else \
                echo Target not supported >&2 && exit 1; \
            fi
    

    【讨论】:

    • 如果我使用 automake 那就完美了,但我的问题是“Makefile.in”,因为我没有。不使用 Automake 有什么可比的吗?
    猜你喜欢
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 2012-04-12
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多