[英]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.