[PATCH] Ignore the default %libdir/pkgconfig directory

Richard W.M. Jones rjones at redhat.com
Wed Jan 28 04:35:32 PST 2009


Hi,

When cross-compiling packages for Windows, we have two pkgconfig
directories:

  /usr/i686-pc-mingw/sys-root/mingw/lib/pkgconfig
     - contains *.pc files for the cross-compiled dependencies
  /usr/lib{,64}/pkgconfig
     - contains *.pc files for native libraries

Basically we never want pkg-config to look at native libraries.  When
cross-compiling, it is always an error if a program tries to include
native headers or link with native libraries.

But pkg-config currently always falls back on the native directory,
which causes us a problem in the following situations:

(a) User meant to install cross-compiled libfoo, but forgot to, yet the
native libfoo is installed.

More seriously:

(b) libfoo isn't available at all on Windows, but libfoo must be
installed natively.  The configure script will always pick up the
native version in this case, and there is no way we can tell pkgconfig
that libfoo doesn't exist.

The attached patch, written by Erik van Pienbroek, adds an environment
variable (PKG_CONFIG_IGNORE_NATIVE=1) to allow pkg-config's
undesirable fallback-to-native behaviour to be suppressed.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
-------------- next part --------------
--- pkg-config-0.23/main.c.orig	2009-01-27 19:46:16.185717396 +0100
+++ pkg-config-0.23/main.c	2009-01-27 19:48:53.313714182 +0100
@@ -199,6 +199,7 @@
   GString *str;
   GSList *packages = NULL;
   char *search_path;
+  char *ignore_native;
   char *pcbuilddir;
   const char *pkglibdir;
   char **search_dirs;
@@ -293,15 +294,19 @@
     {
       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
+
+  ignore_native = getenv ("PKG_CONFIG_IGNORE_NATIVE");
+  if (!(ignore_native && atoi(ignore_native) == 1))
     {
-      add_search_dirs(PKG_CONFIG_PC_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);
+        }
     }
-
 #ifdef G_OS_WIN32
   {
     /* Add search directories from the Registry */


More information about the pkg-config mailing list