--atleast-pkgconfig-version widely misused

Dan Nicholson dbn.lists at gmail.com
Wed Mar 31 14:34:10 PDT 2010


On Tue, Mar 30, 2010 at 5:42 PM, Martin Unsal <martinunsal at gmail.com> wrote:
> Hi all,
>
> I'm running into a bug but I'm not sure if it's properly considered a bug in
> pkg-config, or in a widely used aclocal.m4 test, or (I believe) both. I
> wanted to run this past the developers and see what you think.
>
> 1) The bug in pkg-config is that it expects a command line of the form:
>  $ pkgconfig --atleast-pkgconfig-version=0.9.0
> but silently accepts (and misparses) a command line of the form:
>  $ pkgconfig --atleast-pkgconfig-version 0.9.0
>
> Consider the following. All but the last invocation produce the expected
> result. The last invocation produces an unexpected result, and is arguably a
> bug.
>
> $ ./pkg-config --version
> 0.23
> $ ./pkg-config --atleast-pkgconfig-version=0.24.0
> $ echo $?
> 1
> $ ./pkg-config --atleast-pkgconfig-version 0.24.0
> $ echo $?
> 1
> $ ./pkg-config --define-variable=0=0 --atleast-pkgconfig-version=0.24.0
> $ echo $?
> 1
> $ ./pkg-config --define-variable=0=0 --atleast-pkgconfig-version 0.24.0
> $ echo $?
> 0
>
> Digging further indicates that the first three invocations call
> compare_versions("0.23", "0.24.0") returning -1, whereas the last invocation
> calls compare_versions("0.23", "0=0") returning 1.
>
> 2) The bug in aclocal.m4 tests is simply that it invokes
> --atleast-pkgconfig-version with the wrong syntax. This is widespread,
> almost everywhere pkg-config is used by configure, in the
> PKG_PROG_PKG_CONFIG macro.
>
> I ran into this problem doing something like this:
>
> PKG_CONFIG="/usr/bin/pkg-config --define-variable=prefix=/foo/bar"
> ./configure
>
> ... which does not function as expected and I believe is a perfectly
> reasonable thing to expect to do with pkg-config and configure!
>
> What do you think?

Wow, that's too bad. Two things should get fixed here:

1. Change pkg.m4 to use the "correct" syntax with = separating the
long option from it's value. That won't help much immediately since
this has already been distributed into many releases.

2. Fix the bug in popt (the option parser) that's causing this.
pkg-config has an imported copy of the popt library that's seen very
few updates over the years. I don't know enough about the popt library
to find the bug. However, if I make pkg-config link to my system's
libpopt, the problem goes away.

$ ./pkg-config --version
0.23
$ ./pkg-config --atleast-pkgconfig-version=0.24.0
$ echo $?
1
$ ./pkg-config --atleast-pkgconfig-version 0.24.0
$ echo $?
1
$ ./pkg-config --define-variable=0=0 --atleast-pkgconfig-version=0.24.0
$ echo $?
1
$ ./pkg-config --define-variable=0=0 --atleast-pkgconfig-version 0.24.0
$ echo $?
1

So, apparently the bug's been fixed upstream. Someone can try and find
and backport the fix from upstream. I can also post my patches for an
external popt.

--
Dan


More information about the pkg-config mailing list