简体   繁体   English

Makefile.am中的ifdef

[英]ifdef in Makefile.am

I want to use flags to compile my C project: 我想使用标志来编译我的C项目:

in configure.ac I Define the default model 在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)])

and then in Makefile.am i use these variable as following : 然后在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

but the project doesn't compile !! 但是项目没编译!!

what wrong in my Makefile.am 我的Makefile.am有什么问题

Thanks 谢谢

In order to use the variables in Makefiles, you need to use the automake versions, that is AM_* not AC_ . 要在Makefile中使用变量,您需要使用automake版本,即AM_*而不是AC_

I would be using AM_CONDITIONAL . 我会使用AM_CONDITIONAL For your example: 对于你的例子:

In configure.ac : 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"])

This means we can call configure to enable model 98 as 这意味着我们可以调用configure来启用模型98

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

Then you can also enable 181 by calling configure as ./configure --enable-model=181 . 然后,您也可以通过调用configure as ./configure --enable-model=181来启用./configure --enable-model=181 Or for that matter any model number as we set enable_model to be the value passed in. 或者就此而言任何型号,因为我们将enable_model设置为传入的值。

Then in your Makefile.am : 然后在你的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

Note the use of if and not ifdef and the lack of quoting around MODEL_98 . 注意使用if而不是ifdef以及MODEL_98周围缺少引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM