cinsk
cinsk

Reputation: 1706

automake and pkg-config conditional building

I want to include two sample programs A and B into the existing library packages.

program A depends on libfoo library, and program B depends on libbar library.

libfoo and libbar are provided as pkg-config aware.

And I want that configure will automatically detect the existence of libfoo and libbar, and if libfoo found, program A should be built, and if libbar found, program B should be built.

Here is what I'm trying to in configure.ac:

PKG_CHECK_MODULE([FOO], [libfoo])
PKG_CHECK_MODULE([BAR], [libbar])

Here is what I'm trying to in Makefile.am:

if LIBFOO
noinst_PROGRAMS += A
A_SOURCES = ...
A_CPPFLAGS = $(FOO_CFLAGS)
A_LDADD = $(FOO_LIBS)
endif

if LIBBAR
noinst_PROGRAMS += B
B_SOURCES = ...
B_CPPFLAGS = $(BAR_CFLAGS)
B_LDADD = $(BAR_LIBS)
end

The problem is, I don't know how to define the predicates, LIBFOO and LIBBAR.

Any idea?

Upvotes: 0

Views: 537

Answers (1)

ldav1s
ldav1s

Reputation: 16305

First, it's PKG_CHECK_MODULES:

 PKG_CHECK_MODULES([FOO], [libfoo], [have_libfoo=yes], [have_libfoo=no])
 PKG_CHECK_MODULES([BAR], [libbar], [have_libbar=yes], [have_libbar=no])

then it's AM_CONDITIONAL:

AM_CONDITIONAL([LIBFOO],  [test "$have_libfoo" = "yes"])
AM_CONDITIONAL([LIBBAR],  [test "$have_libbar" = "yes"])

BTW, since these are sample programs, building them as noinst_PROGRAMS probably isn't what you want, since they won't be installed when make install is invoked.

Upvotes: 1

Related Questions