Meph-
Meph-

Reputation: 677

How to use condition in Makefile.am

from configure.ac I have set variable ALSA=1 or nothing

./configure --enable-alsa=yes
or
./configure //nothing

and I need add source code alsa.c to Makefile.am:

__abs_top_srcdir__bin_myprogram_SOURCES+=alsa.c

I tried: Makefile.am:

__abs_top_srcdir__bin_myprogram_SOURCES=main.c some.c anothercode.c
if ALSA
     __abs_top_srcdir__bin_myprogram_SOURCES+=alsa.c
else
     __abs_top_srcdir__bin_myprogram_SOURCES+=somethingelse.c
endif

and it creates Makefile.in ending with

@ALSA_TRUE@     __abs_top_srcdir__bin_myprogram_SOURCES += \
@ALSA_TRUE@     alsa.c
@ALSA_FALSE@    __abs_top_srcdir__bin_myprogram_SOURCES += \
@ALSA_FALSE@    somethingelse.c

and Makefile ending with:

#       __abs_top_srcdir__bin_myprogram_SOURCES += \
#       alsa.c
        __abs_top_srcdir__bin_myprogram_SOURCES += \
        somethingelse.c

but I need this rows on top of this file with other source code files, because this Makefile doesn't work. I hope you understand me :)

and related part of configure.ac:

AC_ARG_ENABLE(alsa,
  AS_HELP_STRING(
    [--enable-alsa],
    [enable alsa, default: no]),
    [case "${enableval}" in
      yes)  alsa=true ;;
      no)   alsa=false ;;
      *)   AC_MSG_ERROR([bad value ${enableval} for --enable-alsa]) ;;
    esac],
    [alsa=false])
AM_CONDITIONAL(ALSA, test x"$alsa" = x"true")
AM_COND_IF(ALSA, 
    AC_DEFINE(ALSA, 1, [Define to 0 for Something else]),[])

What is it wrong? May I use ALSA variable like that?Thanks you for help.

Upvotes: 0

Views: 856

Answers (1)

ldav1s
ldav1s

Reputation: 16315

Change this:

__abs_top_srcdir__bin_myprogram_SOURCES=main.c some.c anothercode.c
if ALSA
     __abs_top_srcdir__bin_myprogram_SOURCES+=alsa.c
else
     __abs_top_srcdir__bin_myprogram_SOURCES+=somethingelse.c
endif

to this:

__abs_top_srcdir__bin_myprogram_SOURCES=main.c some.c anothercode.c
if ALSA
__abs_top_srcdir__bin_myprogram_SOURCES+=alsa.c
else
__abs_top_srcdir__bin_myprogram_SOURCES+=somethingelse.c
endif

and it should work.

BTW, your're also making the code in configure.ac overly complex. This'll do the same thing:

AC_ARG_ENABLE(alsa,
  AS_HELP_STRING(
    [--enable-alsa],
    [enable alsa, default: no]))
AM_CONDITIONAL([ALSA], [test "x$enable_alsa" = "xyes"])
AM_COND_IF([ALSA],
    [AC_DEFINE(ALSA, 1, [Define to 0 for Something else])],[])

Upvotes: 2

Related Questions