Correct default paths on W32

LRN lrn1986 at gmail.com
Sat Apr 6 12:24:08 PDT 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06.04.2013 21:20, Dan Nicholson wrote:
> On Sat, Mar 30, 2013 at 10:52:22PM +0400, LRN wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>> 
>> On 30.03.2013 21:52, LRN wrote:
>>> (2) has some build-time implications. For example, you'll need
>>> to reconfigure pkg-config to build with different paths (with
>>> current system you can just pass different stuff via command
>>> line), and variables (such as ${libdir}) will also expand
>>> during configure, not at the moment of compiler invocation.
> 
> I do think the default on Windows should stay as it is where by
> default the search path is determined at runtime and the system
> include/library paths are defined at build time. In both cases
> there are mechanisms for overriding the defaults if necessary. I
> would like to get rid of those warnings, though.
> 
> Longer term, I'd like it if all the Windows specific stuff was
> available as an option everywhere and vice versa. For instance, I'd
> like it if the runtime search path determination was available on
> Linux even if it wasn't the default. Then I could test that
> behavior without any hassle.
> 
>> After tinkering with the code i've realized that ${libdir} should
>> not be expanded at all, in fact. It is passed like that all the
>> way to the source code, and used as-is.
>> 
>> Anyway, here's a patch. Tell me what you think of it.
> 
> Thanks for looking at this. I think this is pretty good, but I
> think there would be a couple issues as is. See below. [...]
>> + dnl dnl Default pkg-config search path dnl @@ -44,12 +60,13 @@
>> AC_ARG_WITH([pc_path], # This is slightly wrong, but hopefully
>> causes less confusion than # people being unable to find their
>> .pc files in the standard location. if test "${prefix}" = "NONE";
>> then -
>> pc_path='${libdir}/pkgconfig:${datadir}/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig'
>>
>> 
+
pc_path="\${libdir}/pkgconfig${pathseparator}\${datadir}/pkgconfig${pathseparator}${defaultprefix}/lib/pkgconfig${pathseparator}${defaultprefix}/share/pkgconfig"
>> else -	pc_path='${libdir}/pkgconfig:${datadir}/pkgconfig' +
>> pc_path="\${libdir}/pkgconfig${pathseparator}\${datadir}/pkgconfig"
>
>> 
> I don't think this is OK to do for a couple reasons.
> 
> 1. This is supposed to be a fixed path, and PKG_CONFIG_LIBDIR is
> there if you want to tweak at runtime. This makes the path
> expansion entirely delayed until runtime, and would be subject to
> someone passing --define-variable=libdir=/foo. That would cause not
> only the packages to be affected, but also pkg-config itself. This
> is kind of par for the course on the Windows build, but everywhere
> else, pkg-config is expected to be unchanged.
> 
> 2. What ${libdir} and ${datadir} would this correspond to? At the
> time that pkg-config expands the path, I can't even think what
> these would be. And if it ever became dependent on ${libdir} in a
> .pc file, that would be bad.
As far as pc_path goes, i don't really care. As i have said, it is
determined at runtime, thus anything you hardcode at configure-time has
absolutely no effect when compiling W32 version of pkg-config.
This change is there just for the sake of consistency.

>> 
>> dnl @@ -60,8 +77,9 @@ AC_ARG_WITH([system_include_path], 
>> [AS_HELP_STRING([--with-system-include-path], [avoid -I flags
>> from the given path])], [system_include_path="$withval"], -
>> [system_include_path="/usr/include"]) +
>> [system_include_path="${defaultprefix}/include"]) 
>> AC_MSG_RESULT([$system_include_path]) 
>> +AC_DEFINE_UNQUOTED([PKG_CONFIG_SYSTEM_INCLUDE_PATH],
>> ["$system_include_path"], [Default location of headers]) 
>> AC_SUBST([system_include_path])
>> 
>> dnl @@ -76,14 +94,15 @@ AC_ARG_WITH([system_library_path], 
>> pc_lib_sfx=`echo "$libdir" | sed 's:.*/lib::'` case "$pc_lib_sfx"
>> in */*|"") -  system_library_path="/usr/lib:/lib" +
>> system_library_path="${defaultprefix}/lib${pathseparator}/lib" 
>> ;; *) -
>> system_library_path="/usr/lib$pc_lib_sfx:/lib$pc_lib_sfx:/usr/lib:/lib"
>>
>> 
+
system_library_path="${defaultprefix}/lib$pc_lib_sfx${pathseparator}/lib$pc_lib_sfx${pathseparator}${defaultprefix}/lib${pathseparator}/lib"
>> ;; esac
> 
> This part I think is good. I'm attaching a patch that does the
> full expansion in configure. Could you try that out? Then maybe you
> could split out the /mingw paths part on top of it.

OK, i've tried your 8 patches (fixed as suggested by Tollef) +
expand-paths patch

Here's what i get in config.h:

/* Default pkg-config path */
#define PKG_CONFIG_PC_PATH "/mingw/lib/pkgconfig:/mingw/share/pkgconfig"

/* Default system include path */
#define PKG_CONFIG_SYSTEM_INCLUDE_PATH "/usr/include"

/* Default system library path */
#define PKG_CONFIG_SYSTEM_LIBRARY_PATH "/usr/lib:/lib"

With my ":" -> ":/;" and "usr" -> "${defprefix}" patch (attached,
0011-platform-dependent-separator-and-adjustable-prefix.mingw32.patch),
i get this instead (when i configure with
- --with-default-prefix-for-default-paths=/mingw):

/* Default pkg-config path */
#define PKG_CONFIG_PC_PATH "/mingw/lib/pkgconfig;/mingw/share/pkgconfig"

/* Default system include path */
#define PKG_CONFIG_SYSTEM_INCLUDE_PATH "/mingw/include"

/* Default system library path */
#define PKG_CONFIG_SYSTEM_LIBRARY_PATH "/mingw/lib;/lib"

The --with-default-prefix-for-default-paths option is, IMO, better than
just hard-coding host-dependent prefixes (/usr or /mingw) into
configure.ac.
Name seems a bit long though...


I've also attached my local prefix patch
(0099-no-prefix-on.mingw32.patch), which hacks pkg.m4 to add
- --dont-define-prefix to all pkg-config invocations that produce paths.

This forces pkg-config to use the prefix from .pc files (which, if
packages are built correctly, will be prefix=/mingw), thus resolving
things like -I${prefix}/include to -I/mingw/include, not
- -Ic:/foo/bar/mymingw/include. That works well with fixed default
directories, as pkg-config will correctly detect that -I/mingw/include
is the default include path, and will strip it from the output. Thus for
most packages i get empty --cflags and only "-lfoo" --libs (without
- -L/mingw/lib).

I'm not sure this second patch is appropriate for committing as-is,
since it might have unintended effect on other platforms.
On W32 it should be fine, since using configure scripts (where code from
this m4 file goes) means MSys (or Cygwin...? Didn't check how this works
on Cygwin), and /mingw is the conventional location for the toolchain
and user-installed stuff when MSys is used. If pkg-config is used from
makefiles or by non-autotools buildsystems, --dont-define-prefix won't
be there, and it will produce DOS-style paths, as expected.

The alternative that i've mentioned is to detect default include and lib
paths at runtime (the same way pc_path is detected), in which case
pkg-config will be able to detect -Ic:/foo/bar/mymingw/include as the
default path and strip it, so --dont-define-prefix will not be needed.
Using ${prefix} in these default paths might do the trick (if pkg-config
expands default paths at runtime).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJRYHZYAAoJEOs4Jb6SI2CwfPwIAMqHFFAz7t2NvCLMV8QN/kjV
ka4ilvJGfrr19vtxJvrNlWo1gsa/vXEjyq/5XFhKwD+bZ587HzsNjqrzc11saegV
84y9o3C8n7UJg4heijhhYX1y76NzERf8HFp7MqIA9Rr3X6l5psCvsLpfNfV4ln7G
llGvaxHvOdBdQjkLKQ6roKNGa25m0leSy2tewfxdkXrCanozWMKm7kuXb3CFGlRP
6Il8eJCdA8ZsZnTPcUnz2G8yDHea4qZtw4SQLxASSMPvxLnzMQqjYcoBVFQfwxCJ
E+vR9Lg+7brNJ1RSspQxit2E2Zstq4KLKuxP2SzjkLhqXbbq2Gv0q9/mDl5dahI=
=izLy
-----END PGP SIGNATURE-----
-------------- next part --------------
--- pkg-config-0.28/pkg.m4.orig	2013-04-01 15:45:41 +0400
+++ pkg-config-0.28/pkg.m4	2013-04-03 02:13:38 +0400
@@ -73,7 +73,7 @@
     pkg_cv_[]$1="$$1"
  elif test -n "$PKG_CONFIG"; then
     PKG_CHECK_EXISTS([$3],
-                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
+                     [pkg_cv_[]$1=`$PKG_CONFIG --dont-define-prefix --[]$2 "$3" 2>/dev/null`
 		      test "x$?" != "x0" && pkg_failed=yes ],
 		     [pkg_failed=yes])
  else
@@ -122,9 +122,9 @@
    	AC_MSG_RESULT([no])
         _PKG_SHORT_ERRORS_SUPPORTED
         if test $_pkg_short_errors_supported = yes; then
-	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --dont-define-prefix --short-errors --print-errors --cflags --libs "$2" 2>&1`
         else 
-	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --dont-define-prefix --print-errors --cflags --libs "$2" 2>&1`
         fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
-------------- next part --------------
--- pkg-config-0.28/configure.ac.orig	2013-04-06 22:23:21 +0400
+++ pkg-config-0.28/configure.ac	2013-04-06 22:48:16 +0400
@@ -24,6 +24,21 @@
 dnl Check for headers
 AC_CHECK_HEADERS([dirent.h unistd.h sys/wait.h malloc.h])
 
+AC_MSG_CHECKING([for Win32])
+case "$host" in
+  *-*-mingw*)
+    native_win32=yes
+    sep=";"
+  ;;
+  *)
+    native_win32=no
+    sep=":"
+  ;;
+esac
+AC_MSG_RESULT([$native_win32])
+AC_SUBST([native_win32])
+AM_CONDITIONAL(NATIVE_WIN32, [test "x$native_win32" = xyes])
+
 dnl A POSIX shell is required for the tests. If TEST_SHELL hasn't been
 dnl set on the command line then we try to find bash or ksh or sh from
 dnl the path. If none of those are available, we just use whatever
@@ -56,6 +71,17 @@
 m4_popdef([var])])
 
 dnl
+dnl Default prefix for hardcoded paths
+dnl
+AC_MSG_CHECKING([for default prefix for default paths])
+AC_ARG_WITH([default_prefix_for_default_paths],
+  [AS_HELP_STRING([--with-default-prefix-for-default-paths],
+    [default prefix for default paths])],
+  [defprefix="$withval"],
+  [defprefix="/usr"])
+AC_MSG_RESULT([$defprefix])
+
+dnl
 dnl Default pkg-config search path
 dnl
 AC_MSG_CHECKING([for default search path for .pc files])
@@ -67,9 +93,9 @@
 # This is slightly wrong, but hopefully causes less confusion than
 # people being unable to find their .pc files in the standard location.
 if test "${prefix}" = "NONE"; then
-	pc_path='${libdir}/pkgconfig:${datadir}/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig'
+	pc_path='${libdir}/pkgconfig${sep}${datadir}/pkgconfig${sep}${defprefix}/lib/pkgconfig${sep}${defprefix}/share/pkgconfig'
 else
-	pc_path='${libdir}/pkgconfig:${datadir}/pkgconfig'
+	pc_path='${libdir}/pkgconfig${sep}${datadir}/pkgconfig'
 fi
 ])
 PKG_EXPAND_VAR([pc_path])
@@ -86,7 +112,7 @@
   [AS_HELP_STRING([--with-system-include-path],
     [avoid -I flags from the given path])],
   [system_include_path="$withval"],
-  [system_include_path="/usr/include"])
+  [system_include_path="${defprefix}/include"])
 PKG_EXPAND_VAR([system_include_path])
 AC_MSG_RESULT([$system_include_path])
 AC_SUBST([system_include_path])
@@ -105,10 +131,10 @@
 pc_lib_sfx=`echo "$libdir" | sed 's:.*/lib::'`
 case "$pc_lib_sfx" in
 */*|"")
-  system_library_path="/usr/lib:/lib"
+  system_library_path="${defprefix}/lib${sep}/lib"
   ;;
 *)
-  system_library_path="/usr/lib$pc_lib_sfx:/lib$pc_lib_sfx:/usr/lib:/lib"
+  system_library_path="${defprefix}/lib${pc_lib_sfx}${sep}/lib${pc_lib_sfx}${sep}${defprefix}/lib${sep}/lib"
   ;;
 esac
 ])
@@ -169,19 +195,6 @@
 fi
 AC_SUBST(WARN_CFLAGS)
 
-AC_MSG_CHECKING([for Win32])
-case "$host" in
-  *-*-mingw*)
-    native_win32=yes
-  ;;
-  *)
-    native_win32=no
-  ;;
-esac
-AC_MSG_RESULT([$native_win32])
-AC_SUBST([native_win32])
-AM_CONDITIONAL(NATIVE_WIN32, [test "x$native_win32" = xyes])
-
 dnl When cross compiling to Windows, Wine might be available to help
 dnl for testing.
 if test "$cross_compiling" = yes && test "$native_win32" = yes; then


More information about the pkg-config mailing list