Andrew K
Andrew K

Reputation: 11

Automake conditional ENABLE_GUI

I'm trying to set an --enable-gui switch for my program but it doesn't seem to work.

In configure.ac I have

AC_INIT([cwallet], [1.1], [[email protected]])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AM_PROG_CC_C_O
AC_CONFIG_HEADERS([config.h])

AC_ARG_ENABLE([gui],
  [AS_HELP_STRING([--enable-gui],
  [enable GUI (default is yes)])],
  [enable_gui=$enableval],
  [enable_gui=yes]) 


if test x$enable_gui != xno; then
   PKG_CHECK_MODULES([GTK2],[gtk+-2.0])
fi

< ... some stuff ... >

AC_CONFIG_FILES([
 Makefile
 src/Makefile
])
AC_OUTPUT

AM_CONDITIONAL([ENABLE_GUI],[test x$enable_gui == xyes])

In src/Makefile.am I have

if ENABLE_GUI
bin_PROGRAMS = cwallet cwallet-gui
cwallet_SOURCES = main.c cwallet.c
cwallet_gui_SOURCES = main-gui.c cwallet.c
cwallet_gui_LDADD = $(GTK2_LIBS)
cwallet_gui_CPPFLAGS = $(GTK2_CFLAGS)
else
bin_PROGRAMS = cwallet
cwallet_SOURCES = main.c cwallet.c
endif

But when I do ./autogen.sh && ./configure -with-gui=no && make, it says it can't find gtk.h, so I guess it is using ENABLE_GUI = true for the Makefile, when it shouldn't.

What's the proper way to do this?

Upvotes: 0

Views: 16

Answers (1)

Andrew K
Andrew K

Reputation: 11

OK I think I figured out the problem. The AM_CONDITIONAL statement should be further up in the configure.ac (right after if test x$enable_gui... block)

Upvotes: 0

Related Questions