On Sat, 26 Feb 2011 17:13:16 -0800
Steve Langasek <steve.langa...@linaro.org> wrote:

> Hi there,
> 
> On Fri, Feb 25, 2011 at 10:04:08AM +0000, Neil Williams wrote:
> > https://wiki.ubuntu.com/MultiarchCross
> 
> > I've had a quick look at pkg-config and the upstream wiki has, what
> > appears to be, a better idea of how to implement what we need for
> > cross-building on multiarch.
> 
> > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=217902
>
> > I created a patch to implement the --host idea from upstream which
> > is also already supported by autoconf m4 macros. The patch was
> > tested in a multiarch-style chroot and standard configure scripts
> > correctly pick up the multiarch paths without changes to the source
> > package and without needing autoreconf (unless the package is v.old
> > and already uses autoreconf).
> 
> When you say it's supported by autoconf m4 macros, does this mean
> that the existing pkg-config m4 macros that packages are using
> already pass a --host argument?  I find that rather surprising; I
> don't see any evidence of this in /usr/share/aclocal/pkg.m4.

Ooops. Let's have another go at the patch(es).

This does make the patch set more complex - it involves setting pkg.m4
to detect the upstream version of pkg-config and therefore involves a
new upstream release.

It also involves re-running autoreconf before cross-building existing
package versions - not sure why I missed that first time around. 

For this reason, I'm attaching the diffs individually - the changes to
pkg.m4, main.c and configure.in need to go in first, then a new
upstream tarball built with autoreconf, configure, make dist. That
tarball made into a suitable .orig.tar.gz and then the changelog, rules
and control diffs can take effect. (Otherwise, the diff would be full
of autotools-upstream-changes.)

However, what I've been able to do now is combine the need for
"traditional" -cross support for current cross-builds with a "dormant"
Multi-Arch implementation which knows about the new paths, does not
enable them by default in the upstream but does in the debian/rules
file. The new paths are ignored if no files exist at those locations.

This gives us a single upload with both sets available and no flag-day.
Multi-Arch paths take precedence, followed by dpkg-cross paths,
followed by non-Multi-Arch native paths.

The m4 change is:
        if test -n "$host_alias"; then
                _pkg_host_version=[0.26]
                AC_MSG_CHECKING([pkg-config is at least version 
$_pkg_host_version])
                if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_host_version; 
then
                        AC_MSG_RESULT([yes - using --host $host_alias])
                        PKG_CONFIG="$PKG_CONFIG --host $host_alias"
                else
                        AC_MSG_RESULT([no])
                        PKG_CONFIG="$PKG_CONFIG"
                fi
        fi

> > Currently, the patch implements both the dpkg-cross and multiarch
> > paths - this may be a mistake or it could turn out to be a useful
> > assist during the transition - more testing is needed but before I
> > can really test with a lot of packages, we need to prepare a
> > cross-building toolchain which provides multiarch-aware linker and
> > which depends on a multiarch version of libc6 etc.
> 
> The patch you've submitted to the bug,

... needed improvement .... and still needs more testing.

However, the new patches do implement both dpkg-cross and multiarch.

> > > appears to only add support for the /usr/${triplet}/lib path, not
> > > the multiarch-style /usr/lib/${triplet} path.  Am I missing
> > > something?
> > 
> > Nevermind, I read your comments on the bug more closely now and see
> > that multiarch is deliberately omitted. :)

The Multi-Arch situation is more complex because it requires breaking
the ${libdir} variable into the component ${prefix} and "lib" and
inserting the $host_name inside and "pkgconfig" at the end. This can
break a lot of upstream expectations - like being able to set pc_path
to /opt/project/lib/pkgconfig instead.

This makes pc_path largely unusable in a Multi-Arch world - the patch
implements a method based on $prefix. 

> > Still don't see anything in the upstream .m4 macros to suggest
> > --host is being passed automatically, though.

Yes, that was a slip on my part. The snippet from the wiki page adds
--host unconditionally whenever the relevant version of pkg-config is
found but the patch means that the original paths are still supported
and --host is only used if the version supports it and -host was passed
to ./configure.

One downside is that pkg-config no longer fails if the cross-dependency
is not installed - it returns the native data instead. This can be
changed without affecting the desired support for being able to call
pkg-config without --host during a cross-build for the use of internal
build tools. (Simply wrap the defaults in an } else { .... })

Another possible issue is this:
checking pkg-config is at least version 0.16... yes
checking pkg-config is at least version 0.26... yes - using --host 
arm-linux-gnueabi
checking for GLIB - version >= 2.9.0... ./configure: line 16260: test: too many 
arguments

This results from configure tests of the type:
  if test x$PKG_CONFIG != xno ; then
compared to
  if test "x$PKG_CONFIG" != "xno" ; then

This may limit the ability of some cross-builds to detect if the
correct version of the cross dependency is installed, although it
doesn't stop the --cflags or --libs being retrieved.

Tested in a standard cross-building chroot without some of the native
build dependencies installed but all of the cross-dependencies
installed via xapt and dpkg-cross. Native build correctly halts in the
pkg-config check cross build correctly proceeds and gets the correct
(dpkg-cross) paths to the dependencies.

-- 


Neil Williams
=============
http://www.linux.codehelp.co.uk/

--- pkg-config-0.25/debian/changelog 
+++ pkg-config-0.26/debian/changelog 
@@ -1,3 +1,13 @@
+pkg-config (0.26-1) unstable; urgency=low
+
+  * Non-maintainer upload. Needs upstream version change for correct
+    support in pkg.m4
+  * Add --host support for cross-building
+  * Add MultiArch paths support (dormant until Multi-Arch -dev
+    packages start becoming available.)
+
+ -- Neil Williams <codeh...@debian.org>  Sun, 27 Feb 2011 14:24:54 +0000
+
 pkg-config (0.25-1.1) unstable; urgency=low
 
   * Non-maintainer upload.
--- pkg-config-0.25/configure.in 
+++ pkg-config-0.26/configure.in 
@@ -1,7 +1,7 @@
 
 AC_INIT(pkg-config.1)
 
-AM_INIT_AUTOMAKE(pkg-config, 0.25)
+AM_INIT_AUTOMAKE(pkg-config, 0.26)
 AM_MAINTAINER_MODE
 
 AM_CONFIG_HEADER(config.h)
@@ -9,6 +9,19 @@
 AM_PROG_LIBTOOL
 
 AC_PROG_CC
+
+multiarch=no
+AC_ARG_ENABLE(multiarch,
+  [  --enable-multiarch      enable additional Multi-Arch paths.],
+  [case "${enableval}" in
+        no) multiarch="no" ;;
+        yes) multiarch="yes"
+        AC_DEFINE(MULTIARCH,,[pkg-config will add Multi-Arch paths])
+        AC_SUBST([prefix])
+        ;;
+        *) AC_MSG_ERROR(bad value ${enableval} for --enable-multiarch) ;;
+        esac])
+AM_CONDITIONAL(USE_MULTIARCH, test "$multiarch" = "yes")
 
 AC_DEFUN([PKG_CONFIG_FIND_PC_PATH],
 [
--- pkg-config-0.25/debian/control 
+++ pkg-config-0.26/debian/control 
@@ -8,6 +8,7 @@
 
 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 
--- pkg-config-0.25/main.c 
+++ pkg-config-0.26/main.c 
@@ -188,6 +188,7 @@
   static int want_short_errors = 0;
   static int want_uninstalled = 0;
   static char *variable_name = NULL;
+  static char *host_name = NULL;
   static int want_exists = 0;
   static int want_provides = 0;
   static int want_requires = 0;
@@ -245,6 +246,8 @@
       "set variable NAME to VALUE", "NAME=VALUE" },
     { "exists", 0, POPT_ARG_NONE, &want_exists, 0,
       "return 0 if the module(s) exist" },
+    { "host", 0, POPT_ARG_STRING, &host_name, 0,
+      "set the host architecture triplet", "NAME=VALUE" },
     { "print-variables", 0, POPT_ARG_NONE, &want_variable_list, 0,
       "output list of variables defined by the module" },
     { "uninstalled", 0, POPT_ARG_NONE, &want_uninstalled, 0,
@@ -297,20 +300,6 @@
       debug_spew ("PKG_CONFIG_DEBUG_SPEW variable enabling debug spew\n");
     }
 
-  search_path = getenv ("PKG_CONFIG_PATH");
-  if (search_path) 
-    {
-      add_search_dirs(search_path, G_SEARCHPATH_SEPARATOR_S);
-    }
-  if (getenv("PKG_CONFIG_LIBDIR") != NULL) 
-    {
-      add_search_dirs(getenv("PKG_CONFIG_LIBDIR"), G_SEARCHPATH_SEPARATOR_S);
-    }
-  else
-    {
-      add_search_dirs(PKG_CONFIG_PC_PATH, G_SEARCHPATH_SEPARATOR_S);
-    }
-
   pcsysrootdir = getenv ("PKG_CONFIG_SYSROOT_DIR");
   if (pcsysrootdir)
     {
@@ -350,7 +339,50 @@
       return 1;
     }
 
-
+  if (host_name)
+    {
+      gchar * host_path = NULL;
+#ifdef MULTIARCH
+      /* use Multi-Arch paths of:
+       * /$prefix/lib/$triplet/pkgconfig
+       * /usr/lib/$triplet/pkgconfig
+       */
+      host_path = g_strconcat(PREFIX, G_DIR_SEPARATOR_S,"lib", G_DIR_SEPARATOR_S,
+      host_name, G_DIR_SEPARATOR_S, "pkgconfig", G_SEARCHPATH_SEPARATOR_S,
+      G_DIR_SEPARATOR_S, "usr", G_DIR_SEPARATOR_S, "lib", G_DIR_SEPARATOR_S,
+      host_name, G_DIR_SEPARATOR_S, "pkgconfig", G_SEARCHPATH_SEPARATOR_S,
+      NULL);
+      add_search_dirs(host_path, G_SEARCHPATH_SEPARATOR_S);
+      debug_spew ("Multi-Arch paths added.\n");
+      g_free (host_path);
+#endif
+      /* use traditional cross paths of
+       * /$prefix/$triplet/lib/pkgconfig
+       * /usr/$triplet/lib/pkgconfig
+       */
+      host_path = g_strconcat(PREFIX, G_DIR_SEPARATOR_S, host_name, G_DIR_SEPARATOR_S,
+      "lib", G_DIR_SEPARATOR_S, "pkgconfig", G_SEARCHPATH_SEPARATOR_S,
+      G_DIR_SEPARATOR_S, "usr", G_DIR_SEPARATOR_S, host_name, G_DIR_SEPARATOR_S,
+      "lib", G_DIR_SEPARATOR_S, "pkgconfig", G_SEARCHPATH_SEPARATOR_S,
+      NULL);
+      add_search_dirs(host_path, G_SEARCHPATH_SEPARATOR_S);
+      debug_spew ("traditional -cross paths added.\n");
+      g_free (host_path);
+  }
+  search_path = getenv ("PKG_CONFIG_PATH");
+  if (search_path) 
+    {
+      add_search_dirs(search_path, G_SEARCHPATH_SEPARATOR_S);
+    }
+  if (getenv("PKG_CONFIG_LIBDIR") != NULL) 
+    {
+      add_search_dirs(getenv("PKG_CONFIG_LIBDIR"), G_SEARCHPATH_SEPARATOR_S);
+    }
+  else
+    {
+      add_search_dirs(PKG_CONFIG_PC_PATH, G_SEARCHPATH_SEPARATOR_S);
+    }
+  
   /* Error printing is determined as follows:
    *     - for --cflags, --libs, etc. it's on by default
    *       and --silence-errors can turn it off
--- pkg-config-0.25/debian/rules 
+++ pkg-config-0.26/debian/rules 
@@ -8,9 +8,9 @@
 override_dh_auto_configure:
 	./configure --prefix=/usr --with-installed-glib \
 		--with-installed-popt \
+		--enable-multiarch \
 		--mandir=\$${prefix}/share/man \
-		--infodir=\$${prefix}/share/info --disable-shared \
-		--with-pc-path=/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig/$(DEB_BUILD_GNU_TYPE):/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/pkgconfig/$(DEB_BUILD_GNU_TYPE):/usr/share/pkgconfig \
+		--infodir=\$${prefix}/share/info --disable-shared
 
 override_dh_auto_clean:
 	[ ! -f Makefile ] || $(MAKE) distclean DIST_SUBDIRS="popt check"
--- pkg-config-0.25/pkg.m4 
+++ pkg-config-0.26/pkg.m4 
@@ -42,6 +42,17 @@
 	else
 		AC_MSG_RESULT([no])
 		PKG_CONFIG=""
+	fi
+	if test -n "$host_alias"; then
+		_pkg_host_version=[0.26]
+		AC_MSG_CHECKING([pkg-config is at least version $_pkg_host_version])
+		if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_host_version; then
+			AC_MSG_RESULT([yes - using --host $host_alias])
+			PKG_CONFIG="$PKG_CONFIG --host $host_alias"
+		else
+			AC_MSG_RESULT([no])
+			PKG_CONFIG="$PKG_CONFIG"
+		fi
 	fi
 fi[]dnl
 ])# PKG_PROG_PKG_CONFIG

Attachment: pgpSsYfpAGd9F.pgp
Description: PGP signature

Reply via email to