Makefile.am中的ifdef

时间:2016-03-08 16:07:48

标签: c++ c makefile autotools

我想使用标志来编译我的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中有什么问题

由于

1 个答案:

答案 0 :(得分:5)

要在Makefile中使用变量,您需要使用automakeAM_*而不是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 ./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周围缺少引号。

相关问题