【问题标题】:ifdef in Makefile.amMakefile.am 中的 ifdef
【发布时间】:2016-06-22 16:28:33
【问题描述】:

我想使用标志来编译我的 C 项目:

在configure.ac中我定义了默认模型

AC_ARG_ENABLE(model, [AS_HELP_STRING([--enable-model],
    [specify which Model will be used; (default --enable-model=98]))],,
    [AC_DEFINE(MODEL_98)])

AS_IF([test "x$enable_model" = "x98"], [AC_DEFINE(MODEL_98)])
AS_IF([test "x$enable_model" = "x181"], [AC_DEFINE(MODEL_181)])

然后在 Makefile.am 我使用这些变量如下:

proj_SOURCES =          \
    ../bac.c        \
    ../conf.c               \
    ../cw.c             \

ifdef $(MODEL_98)
proj_SOURCES +=                                 \
    ../dm/98/interfaces.c               \
    ../dm/98/device.c                   \
    ../dm/98/ging.c         \
    ../dm/98/wa.c                   

endif
ifdef $(MODEL_181)
proj_SOURCES +=                                 \
    ../dm/181/fi.c
endif

但是项目没有编译!!

我的 Makefile.am 有什么问题

谢谢

【问题讨论】:

  • 看起来你的许多问题中只有不到一半被接受。这么多答案都那么弱吗?

标签: c++ c makefile autotools


【解决方案1】:

要使用 Makefiles 中的变量,您需要使用 automake 版本,即 AM_* 而不是 AC_

我会使用AM_CONDITIONAL。以您为例:

configure.ac 中:

AC_ARG_ENABLE([model], 
              [AS_HELP_STRING([--enable-model],
                [specify which Model will be used; (default --enable-model=98]))],
              [enable_model=$enableval],
              [enable_model=98])

 AM_CONDITIONAL([MODEL_98],  [test "x$enable_model" = "x98"])
 AM_CONDITIONAL([MODEL_181], [test "x$enable_model" = "x181"])

这意味着我们可以调用configure来启用98型

  • ./configure
  • ./configure --enable-model=98

那么你也可以通过调用configure as ./configure --enable-model=181来启用181。或者就此而言,任何型号,因为我们将 enable_model 设置为传入的值。

然后在您的 Makefile.am 中:

proj_SOURCES =             \
    ../bac.c               \
    ../conf.c              \
    ../cw.c                \

if MODEL_98
proj_SOURCES +=            \
    ../dm/98/interfaces.c  \
    ../dm/98/device.c      \
    ../dm/98/ging.c        \
    ../dm/98/wa.c                   

endif
if MODEL_181
proj_SOURCES +=            \
    ../dm/181/fi.c
endif

注意if 的使用,而不是ifdef,以及MODEL_98 周围没有引用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-01
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多