[英]ifdef in Makefile.am
我想使用标志来编译我的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有什么问题
谢谢
要在Makefile中使用变量,您需要使用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
来启用./configure --enable-model=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
周围缺少引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.