Reputation: 3452
I want to use flags to compile my C project:
in configure.ac I Define the default model
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 :
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
Thanks
Upvotes: 3
Views: 1880
Reputation: 2280
In order to use the variables in Makefiles, you need to use the automake
versions, that is AM_*
not AC_
.
I would be using AM_CONDITIONAL
. For your example:
In 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
./configure --enable-model=98
Then you can also enable 181 by calling configure as ./configure --enable-model=181
. Or for that matter any model number as we set enable_model
to be the value passed in.
Then in your 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
.
Upvotes: 5