Bug 48743

Summary: pkg.m4 doesn't tell us where to install .pc files
Product: pkg-config Reporter: David Woodhouse <dwmw2>
Component: srcAssignee: Tollef Fog Heen <tfheen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: dbn.lists
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description David Woodhouse 2012-04-15 15:29:14 UTC
A lot of projects seem to install their .pc file something like this:

 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = myproject.pc

However, some systems (like FreeBSD) don't put their pkg-config files in $(libdir)/pkgconfig and thus they seem to end up patching a whole load of projects to *change* this. I discovered a patch to my own project which changes it thus:

	@${REINPLACE_CMD} -e 's|libdir)/pkgconfig|prefix)/libdata/pkgconfig|' \
		${WRKSRC}/Makefile.in ${WRKSRC}/Makefile.am

This is horrid. We should be able to *ask* pkg-config what the first directory on its search path is, and get it right in all cases. Or it should be possible to pass --pkgconfigdir= on the configure command line. Or something like that.

Either way, it would ideally be implemented once in pkg.m4 rather than in the configure.ac of *every* project that installs a .pc file.
Comment 1 zi 2012-04-15 15:40:46 UTC
The same issue surfaced over in libburnia:
http://libburnia-project.org/ticket/153
Comment 2 Dan Nicholson 2012-05-08 16:51:04 UTC
Something like this would work.

# 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.
AC_DEFUN([PKG_INSTALLDIR],
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
m4_pushdef([pkg_description],
    [pkg-config installation directory @<:@]pkg_default[@:>@])
AC_ARG_WITH([pkgconfigdir],
    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
    [with_pkgconfigdir=]pkg_default)
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
m4_popdef([pkg_default])
m4_popdef([pkg_description])
]) dnl PKG_INSTALLDIR

Obviously, we can't enforce anyone to use this, though.
Comment 3 David Woodhouse 2012-05-08 21:35:06 UTC
So, how does a system like FreeBSD make this work for their odd choice of pkg-config directory?

If I've run autoconf on *my* system, that'll pick up the setting of '${libdir}/pkgconfig' from *my* copy of pkg.m4, even if the FreeBSD folks have patched theirs? It'll only work if they check the project out from git and run autoconf for *themselves*?

Not quite what we were after... or am I missing something?
Comment 4 David Woodhouse 2012-05-09 16:19:22 UTC
I had imagined that we'd implement this by adding a --print-pkgconfig-dir option to pkg-config(1) itself, and using the output of that in the configure macro. That way, it works regardless of where autoconf was run, so even when they use my release tarballs on FreeBSD it should be fine.
Comment 5 Dan Nicholson 2012-05-09 16:57:49 UTC
They pass --with-pkgconfigdir=/unnecessarily/different/freebsd/location to configure. The _default_ for your package is $libdir/pkgconfig or whatever you pass to PKG_INSTALLDIR in your configure.ac. If you pass nothing to PKG_INSTALLDIR, you're default is $libdir/pkgconfig since that's easily the most common case. But the AC_ARG_WITH part of the macro is there so anybody can specify however they want. Then you'll just use pkgconfig_DATA in Makefile.am.

There are a couple reasons we can't pass you "the right thing" at run-time from pkg-config.

1. The path pkg-config knows about was built-in and corresponds to system pathways. Maybe that's what you want, but I'm positive most people would want this to follow $prefix. I don't have any appetite for trying to munge together a $prefix and some base-ish part of /usr/libdata/pkgconfig.

2. pkg-config doesn't know if you want the arch-dependent or arch-independent location. Should I give you /usr/lib/pkgconfig or /usr/share/pkgconfig?

And, anyway, there's no real way we can get this right for all people. Just let them choose what they want.

However, there is "pkg-config --print-variable=pc_path" if you want. Not the most discoverable option, but it is in pkg-config(1).
Comment 6 David Woodhouse 2012-05-09 19:13:05 UTC
Hm, OK. So FreeBSD would add '--pkgconfigdir' to the standard set of arguments it gives to configure? That's workable, I suppose. Except:
 
How does *its* build system know whether a package should be installing arch-dependent or arch-independent .pc files? And what if a given project actually installs *both*?

Perhaps we need two AC_ARG_WITH macros; one for each? On the basis that arch-dependent use is more common, perhaps they'd be 'pkgconfigdir' and 'noarch-pkgconfigdir' or something like that?
Comment 7 Dan Nicholson 2012-05-09 20:35:07 UTC
(In reply to comment #6)
> Hm, OK. So FreeBSD would add '--pkgconfigdir' to the standard set of arguments
> it gives to configure? That's workable, I suppose. Except:

--with-pkgconfigdir since autoconf doesn't let you add non-with/enable args, but yeah. Really it's no different than --prefix. There's a default, but you get to override it.

> How does *its* build system know whether a package should be installing
> arch-dependent or arch-independent .pc files? And what if a given project
> actually installs *both*?

It depends on the package, and this is no different than any package in fedora, for example. In my experience it's pretty unusual for a package to install both arch-dependent and arch-independent packages. I've done work on Xorg, and each package is pretty clearly arch-dependent (libraries) or arch-independent (data or most protocol headers).

> Perhaps we need two AC_ARG_WITH macros; one for each? On the basis that
> arch-dependent use is more common, perhaps they'd be 'pkgconfigdir' and
> 'noarch-pkgconfigdir' or something like that?

I suppose that's the way to go. Perhaps PKG_INSTALLDIR and PKG_NOARCH_INSTALLDIR where they default to $libdir/pkgconfig and $datadir/pkgconfig, respectively. The vast majority of packages would just add PKG_INSTALLDIR, but some would need PKG_NOARCH_INSTALLDIR and some would need both. Distro packagers could then pass --with-pkgconfigdir and --with-noarch-pkgconfigdir blindly and ignore warnings. For noarch .pc files, they'd need noarch_pkgconfigdir_DATA in Makefile.am. I just tested it locally and it seems to work.
Comment 8 David Woodhouse 2012-05-09 22:47:37 UTC
(In reply to comment #7) 
> It depends on the package, and this is no different than any package in fedora,

TBH it's the Fedora packaging that I'm thinking of; the %configure macro just sets a whole bunch of stuff, and the individual package specfiles mostly don't need to touch that. I know little of FreeBSD packaging except that they do this strange thing with the pkgconfig directory, they patch the shipped Makefiles in various packages to support it (including mine as described in comment 0), and that that solution really sucks.
 
> I suppose that's the way to go. Perhaps PKG_INSTALLDIR and
> PKG_NOARCH_INSTALLDIR where they default to $libdir/pkgconfig and
> $datadir/pkgconfig, respectively.

Sounds good; thanks!

Once a version of this is in upstream pkgconfig, I'll drop it into my own acincludes and the FreeBSD folks can use it across the board. Adoption by other packages can happen whenever; at least the FreeBSD folks will have patches that it's *sane* to push to upstream then.
Comment 9 Dan Nicholson 2012-05-10 05:41:20 UTC
Fixed in 5fc77a9. The new macros are PKG_INSTALLDIR and PKG_NOARCH_INSTALLDIR.
Comment 10 David Woodhouse 2012-05-18 06:38:04 UTC
Thanks. This is now fixed in OpenConnect, with backwards compatibility so it works without the latest pkg.m4 available:

http://git.infradead.org/users/dwmw2/openconnect.git/commitdiff/372bd3daf

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.