(In the hope of being clear, my examples all involve architectures where the
compiler-name prefix differs from the multiarch tuple: armv5tel vs. arm
and i486 vs. i386. s/i486/i686/ throughout if you use Ubuntu.)

Bug #631275 and Bug #642292 both relate to cross-compilation with pkg-config.
I don't think the patches proposed on either bug are quite what's needed.

Steve's patch in #631275 sets PKG_CONFIG_PATH, but in a cross-compilation
environment, I don't think that's right: if you're compiling for
arm-linux-gnueabi on an i486-linux-gnu system, you never want to try to link
x86 libraries. So we should use PKG_CONFIG_LIBDIR to replace the hard-coded
path entirely, like in the current cross-wrapper in Debian, and Vincent's
patch in #642292. Also, this means the user can still set
PKG_CONFIG_PATH=/opt/my-embedded-app/lib/pkgconfig (or whatever) to be
prepended to the search path, like they'd be able to for a native build.

Steve's patch in #631275 also uses the GNU triplet as if it was a multiarch
tuple (or, equivalently, assumes that your --host is one of the "base" GNU
triplets like arm-linux-gnueabi or i386-linux-gnu that is its own multiarch
tuple, as opposed to something like armv5tel-linux-gnueabi or i486-linux-gnu).

Vincent's patch in #642292 is closer, but doesn't allow PKG_CONFIG_LIBDIR to
be overridden, and doesn't search /usr/local (which native pkg-config does).

Currently, native compilation on Debian i386 (i486-linux-gnu-gcc, i386- in
the multiarch tuple) will search:

    if PKG_CONFIG_PATH is set:
        the elements of PKG_CONFIG_PATH

    if PKG_CONFIG_LIBDIR is set:
        the elements of PKG_CONFIG_LIBDIR
    else:
        /usr/local/lib/i386-linux-gnu/pkgconfig         (site multiarch)
        /usr/local/lib/pkgconfig                        (site pre-multiarch)
        /usr/local/share/pkgconfig                      (site arch-indep)
        /usr/lib/i386-linux-gnu/pkgconfig               (distro multiarch)
        /usr/lib/pkgconfig                              (distro pre-multiarch)
        /usr/share/pkgconfig                            (distro arch-indep)

I think cross-compilation with (say) armv5tel-linux-gnueabi-pkg-config should,
analogously, search:

    if PKG_CONFIG_PATH is set:
        the elements of PKG_CONFIG_PATH

    if PKG_CONFIG_LIBDIR is set:
        the elements of PKG_CONFIG_LIBDIR
    else:
        /usr/local/lib/arm-linux-gnueabi/pkgconfig      (site multiarch)
        /usr/local/share/pkg-config                     (site arch-indep)
        /usr/local/armv5tel-linux-gnueabi/lib/pkgconfig (site pre-MA cross)
        /usr/lib/arm-linux-gnueabi/pkgconfig            (distro multiarch)
        /usr/share/pkg-config                           (distro arch-indep)
        /usr/armv5tel-linux-gnueabi/lib/pkgconfig       (distro pre-MA cross)

One subtle departure from Steve's patch here is that if you run
armv5tel-linux-gnueabi-pkg-config on an i386 system, it will never search
/usr/lib/pkgconfig - which I think is desirable. If you're missing a
cross-compiled dependency (zlib, say), it's better that configure fails
early, rather than trying to link an i386 zlib into an armel binary
and failing horribly later.

The down side of that is that on an i486-linux-gnu system, if
i486-linux-gnu-pkg-config is a symlink to the cross-wrapper, it is not
equivalent to bare pkg-config, until/unless every i486 library has moved its
.pc file to the multiarch directory. I think the answer is "don't make a
symlink from the cross-wrapper for your native architecture, then", tbh.

I attach a patch to give the semantics I suggest, plus a patch to put
pkg-config-crosswrapper into a directory that complies with the FHS (with
a compatibility symlink). Also available in
http://anonscm.debian.org/gitweb/?p=users/smcv/multiarch/pkg-config.git;a=shortlog;h=refs/heads/multiarch
if you prefer reviewing that way.

Thoughts?

    S
>From c0ae63630dcbb8789f6fe2e546f29f827918d504 Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@debian.org>
Date: Wed, 21 Sep 2011 14:29:59 +0100
Subject: [PATCH 1/2] Search multiarch directories in pkg-config-crosswrapper

We use PKG_CONFIG_LIBDIR, not PKG_CONFIG_PATH, so that we don't search
/usr/lib/pkgconfig (legacy path likely to contain wrong-arch libraries),
and so that the user can prepend paths in /opt or whatever by using
PKG_CONFIG_PATH in the usual way.

If the user has set PKG_CONFIG_LIBDIR, the cross-wrapper does nothing -
the user is assumed to know best, just as they are with native pkg-config.

This leaves the search path as something like this (if you invoke
armv5tel-linux-gnueabi-pkg-config):

    if PKG_CONFIG_PATH is set:
        the elements of PKG_CONFIG_PATH

    if PKG_CONFIG_LIBDIR is set:
        the elements of PKG_CONFIG_LIBDIR
    else:
        /usr/local/lib/arm-linux-gnueabi/pkgconfig      (site multiarch)
        /usr/local/share/pkg-config                     (site arch-indep)
        /usr/local/armv5tel-linux-gnueabi/lib/pkgconfig (site pre-MA cross)
        /usr/lib/arm-linux-gnueabi/pkgconfig            (distro multiarch)
        /usr/share/pkg-config                           (distro arch-indep)
        /usr/armv5tel-linux-gnueabi/lib/pkgconfig       (distro pre-MA cross)

Signed-off-by: Simon McVittie <s...@debian.org>
---
 debian/changelog               |   18 ++++++++++++++++++
 debian/control                 |    1 +
 debian/pkg-config-crosswrapper |   30 ++++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 debian/pkg-config-crosswrapper

diff --git a/debian/changelog b/debian/changelog
index b6adc3c..07814f7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,21 @@
+pkg-config (0.26-1+multiarch) UNRELEASED; urgency=low
+
+  [ Steve Langasek ]
+  * debian/control: mark pkg-config Multi-Arch: foreign; it provides an
+    executable interface which points to architecture-dependent paths, but
+    those paths only need to be overridden in a cross-build environment, in
+    which case it's the responsibility of the cross-toolchain packages to
+    provide the appropriate glue.
+
+  [ Simon McVittie ]
+  * In pkg-config-crosswrapper, search the multiarch directory (using the
+    multiarch tuple), the traditional cross-compilation directory (using the
+    GNU tuple), /usr/share/pkgconfig and their /usr/local counterparts.
+    Based on patches from Steve Langasek and Vincent Danjean.
+    Closes: #631275, #642292.
+
+ -- Simon McVittie <s...@debian.org>  Wed, 21 Sep 2011 12:46:26 +0100
+
 pkg-config (0.26-1) unstable; urgency=low
 
   * New upstream release
diff --git a/debian/control b/debian/control
index 2c9bf46..d4f1707 100644
--- a/debian/control
+++ b/debian/control
@@ -8,6 +8,7 @@ Standards-Version: 3.8.4
 
 Package: pkg-config
 Architecture: any
+Multi-Arch: foreign
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: manage compile and link flags for libraries
  pkg-config is a system for managing library compile and link flags that 
diff --git a/debian/pkg-config-crosswrapper b/debian/pkg-config-crosswrapper
old mode 100644
new mode 100755
index ab38abb..15e9e2f
--- a/debian/pkg-config-crosswrapper
+++ b/debian/pkg-config-crosswrapper
@@ -2,5 +2,31 @@
 # pkg-config wrapper for cross-building
 # Sets pkg-config search path to target arch path only.
 
-triplet=`basename $0 | sed -e 's:-pkg-config::'`
-PKG_CONFIG_LIBDIR=/usr/${triplet}/lib/pkgconfig pkg-config $@
+# If the user has already set PKG_CONFIG_LIBDIR, believe it: it's documented
+# to be an override
+if [ -z "$PKG_CONFIG_LIBDIR" ]; then
+  # GNU triplet for the compiler, e.g. i486-linux-gnu for Debian i386,
+  # i686-linux-gnu for Ubuntu i386
+  triplet="`basename $0 | sed -e 's:-pkg-config::'`"
+  # Normalized multiarch path if any, e.g. i386-linux-gnu for i386
+  multiarch="`dpkg-architecture -t"${triplet}" -qDEB_HOST_MULTIARCH 2>/dev/null`"
+
+  PKG_CONFIG_LIBDIR="/usr/local/${triplet}/lib/pkgconfig"
+  # For a native build we would also want to append /usr/local/lib/pkgconfig
+  # at this point; but this is a cross-building script, so don't
+  PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR:/usr/local/share/pkgconfig"
+
+  if [ -n "$multiarch" ]; then
+    PKG_CONFIG_LIBDIR="/usr/local/lib/${multiarch}/pkgconfig:$PKG_CONFIG_LIBDIR"
+    PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR:/usr/lib/${multiarch}/pkgconfig"
+  fi
+
+  PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR:/usr/${triplet}/lib/pkgconfig"
+  # For a native build we would also want to append /usr/lib/pkgconfig
+  # at this point; but this is a cross-building script, so don't
+  PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR:/usr/share/pkgconfig"
+
+  export PKG_CONFIG_LIBDIR
+fi
+
+exec pkg-config $@
-- 
1.7.6.3

>From 04198ddee6880eb592223bf46563b40f420ab0a5 Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@debian.org>
Date: Wed, 21 Sep 2011 14:30:49 +0100
Subject: [PATCH 2/2] Install pkg-config-crosswrapper into
 /usr/share/pkgconfig, with a compatibility symlink

Signed-off-by: Simon McVittie <s...@debian.org>
---
 debian/changelog          |    2 ++
 debian/pkg-config.install |    2 +-
 debian/pkg-config.links   |    1 +
 3 files changed, 4 insertions(+), 1 deletions(-)
 create mode 100644 debian/pkg-config.links

diff --git a/debian/changelog b/debian/changelog
index 07814f7..c5545c4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,6 +13,8 @@ pkg-config (0.26-1+multiarch) UNRELEASED; urgency=low
     GNU tuple), /usr/share/pkgconfig and their /usr/local counterparts.
     Based on patches from Steve Langasek and Vincent Danjean.
     Closes: #631275, #642292.
+  * Install pkg-config-crosswrapper into /usr/share/pkgconfig, with a
+    compatibility symlink
 
  -- Simon McVittie <s...@debian.org>  Wed, 21 Sep 2011 12:46:26 +0100
 
diff --git a/debian/pkg-config.install b/debian/pkg-config.install
index 89c190e..0f33868 100644
--- a/debian/pkg-config.install
+++ b/debian/pkg-config.install
@@ -1 +1 @@
-debian/pkg-config-crosswrapper usr/share
+debian/pkg-config-crosswrapper usr/share/pkgconfig
diff --git a/debian/pkg-config.links b/debian/pkg-config.links
new file mode 100644
index 0000000..c568fd1
--- /dev/null
+++ b/debian/pkg-config.links
@@ -0,0 +1 @@
+usr/share/pkgconfig/pkg-config-crosswrapper usr/share/pkg-config-crosswrapper
-- 
1.7.6.3

Reply via email to