I have a couple projects I maintain that are built using automake (let's call them lib1 and lib2). lib2 is dependent on lib1 as a library and I'm having some issues with the pkg-config defaults on CentOS. Ideally, I'd like users to not have to set any environment variables to get everything to install properly.
Right now, it's just assuming ${PREFIX}/lib/pkgconfig
as the destination for my .pc files, but on CentOS 7, the default for ${PREFIX}
is /usr/local
but pkgconfig
by default only looks in /usr/share/pkgconfig
and /usr/lib64/pkgconfig
. Therefore, lib2
can't find lib1
with pkg-config
and the configure script blows up.
So, the question is, how can my make install
in lib1
properly detect the directory to install the pkg-config
files?
From man pkg-config
PKG_INSTALLDIR(DIRECTORY)
Substitutes the variable pkgconfigdir as the location where a module should install pkg-config .pc files. By default the directory is $libdir/pkgconfig, but the default can be changed by passing DIRECTORY. The user can override through the
--with-pkgconfigdir
parameter.
This allows you expose the install-directory of the pkg-config file to the user (and - if your distribution patched pkg-config to use non-standard search-paths, it hopefully will pick the proper default for your system).
Example:
configure.ac:
[...]
PKG_INSTALLDIR
[...]
Makefile.am:
[...]
pkgconfig_DATA = lib1.pc
[...]
Usage
$ ./configure --prefix=/usr --with-pkgconfigdir=/usr/lib64/pkgconfig
Please do not make distro-specific assumptions about where pkg-config
will look for files.
Always use the defaults (they are defaults for good reasons), and provide a way to override these defaults for non-standard systems.
There are a lot distributions out there, and just because in my community one is prevailing, this doesn't mean that this is true for other communities (or not going to change).
If your distro does not follow the standard that's ok, but it should be consistent; if it fails to do be consistent (e.g. pkg-config
looking for files in /foo/baz
, but PKG_INSTALLDIR
expanding pkgconfigdir
to /usr/lib/pkg-config
), then you should report a bug at your distribution.
Also I think it rather weird, that your pkg-config
won't search for files in /usr/local
.
E.g. on my Debian/sid system, it first searches /usr/local
and then /usr
:
$ which pkg-config
/usr/bin/pkg-config
$ strace -e trace=open pkg-config --cflags foo 2>&1 | grep /usr
open("/usr/local/lib/x86_64-linux-gnu/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/share/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/usr/lib/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/usr/share/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
$