简体   繁体   中英

ifdef in Makefile.am

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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