automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can I use pkg-config in my Makefile.am?


From: Brian Dessent
Subject: Re: can I use pkg-config in my Makefile.am?
Date: Tue, 27 May 2008 00:51:11 -0700

eawiggins wrote:

> bin_PROGRAMS= myprog
> cxp_CPPFLAGS= -I$(top_srcdir)/include $(shell pkg-config --cflags glib-2.0)
> cxp_SOURCES= main.cpp
> cxp_CXXFLAGS= $(OGRE_CFLAGS) $(OIS_CFLAGS)
> cxp_LDADD= $(OGRE_LIBS) $(OIS_LIBS) $(shell pkg-config --libs glib-2.0)

In addition to what Erik said, this is bad:

- $(shell) is a GNU make feature, and is not portable to other makes.
- Using $(shell) with a deferred assignment ('=') means the shell
command is executed every time that variable is expanded by make, which
could potentially be dozens of times; this can be very bad for
performance.
- Using $(shell) hides the value of the variable from automake, since it
is only expanded when make is run.

You should do all the pkg-config stuff from configure.ac, and then just
refer to the substituted values in the Makefile.am.  In fact the
pkg-config software already comes with all the m4 macros for this, e.g.
just:

configure.ac:
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES([GLIB], [glib-2.0])

Makefile.am:
whatever_CXXFLAGS += @GLIB_CFLAGS@
whatever_LIBS += @GLIB_LIBS@

You can even get fancy, such as if you have version prerequisites you
can specify them with PKG_CHECK_MODULES([GLIB], [glib-2.0 >= x.y.z]).

Brian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]