RFC: PKG_CHECK_MODULES() should honor ${libdir} and ${datadir}

Colin Close itchka at compuserve.com
Fri Mar 26 16:12:46 PDT 2010


Hi All,

This kind of thing is a perennial problem for me; it is particularly troublesome when 
one has a dual-arch system. In systems like this one can end up with four possible 
locations for pkg-config pc files. There is also the problem where one may be cross-
compiling where there may be a fifth location that contains the pc files for cross-
compiling.

I have solved this rather inelegantly with the following placed in a configure file. 
This perhaps could form the basis of a macro which perhaps could be used as part of the 
pkg-config m4 macro package.

In the form it is now it can deal with pkgconfig directories in /usr/lib /usr/lib64 
/usr/local/lib /usr/local/lib64. In addition it will also deal with a mingw32 cross 
compiling environment. Since the `macro` creates a pkg-config script it can be named 
with the prefix used for the cross-compiler autoconf automatically looks for a program 
prefixed with the host name and thus this script is automatically selected.

This script fragment could I'm sure be better implemented but it does illustrate how the 
problem can be solved.

Colin Close



 
On Friday 26 March 2010 04:19:07 pm Peter Johansson wrote:
> Hi Benjamin,
>
> Benjamin Otte wrote:
> > I talked to Tollef about this on IRC and he liked the idea in general.
> > But we were both not sure if this could have any unwanted side
> > effects. So I'm asking here if anyone thinks this is a bad idea. If
> > so, please speak up now before I dust off my m4-fu and try to come up
> > with a patch.
>
> I think it is a bit unexpected if a search path depends on `--prefix'.
> IMVHO, a changed `--prefix' should only modify where the package will be
> installed and not where to find 3rd party libraries and other tools. I
> expect, e.g., that if
> ./configure
> works that also
> ./configure --prefix=$HOME
> will work and that the same libraries are linked in.
>
> I understand the reported pain, but the suggested fix, I think, might
> cause some severe headache.
>
> Cheers,
> Peter

-------------- next part --------------
#AC_CANONICAL_HOST
case $host_os in
	*linux)
	windows_build=false 
	;;
	*mingw32*)
	windows_build=true
	;;
	*)
	windows_build=false
	;;
esac

dnl here we also try to determine the path for the *.pc files
#set the path prefix in the pc files

#Test for the existance of pg_config
#Here we create the shell script to run pkg-config. This allows the pkg-config search path to be set before execution 
#The shell script is named after the host if we are cross-compiling which means that configure will prefer this script rather than the built in pkg-config
#when cross-compiling. Additional checks are done to try to deal with bi-arch systems where it may be possible to build both 32 and 64 bit packages.

#In addition we have a situation where binary packages of glib-2.0. gtk+ etc will point to directories in another universe
#to over come this and to minimise grief for the user we use the  PKG_CONFIG_SYSROOT_DIR environment variable
#which allows the setting of a new base root directory for the x-compile and reports all the flags with this directory
#prepended to pkg-config's output. This saves having to use sed or similar on the .pc files to cause them to point to the right place.
#AFTER TESTING IT WAS FOUND THAT THE PKG_CONFIG_SYSROOT VARIABLE DOES NOT CHANGE THE SYSROOT FOR THE DEPENDENCIES OF A PACKAGE THUS ANY ATTEMPT TO
#USE THIS VARIABLE IS DOOMED TO FAILURE IF THERE ARE DEPENDENCIES IN THE .pc FILE.

#IF WINDOWS
#The pkg-config macros have no means of providing a path to the .pc files the only way the search path can be controlled is by
#two environment variables. PKG_CONFIG_LIBDIR overrides the default search path and PKG_CONFIG_PATH adds additional search locations
#if the defaults fail.  To work these environment variables have to exist in the same shell that is running pkg-config.
#In order to do this we create our own pkg-config which is really a shell script which sets the environment variables
#and then executes pkg-config in the same environment. Once the shell script is created the macro AC_PATH_PROG is used to set the 
#PKG_CONFIG variable which contains the path to our new pkg-config. Note that the PATH statement for AC_PATH_PROG 
#does not use the current directory only but prepends the parent. Do not be tempted to change this as the although it is not
#properly documented the AC_PATH_PROG always rejects the first program name it finds if it is in the current directory, the 
#addition of the parent to the search PATH overcomes this.  
#export PKG_CONFIG_SYSROOT_DIR=/opt

if test "$windows_build" = true ; then
	rm -f $ac_pwd/*-pkg-config pkg-config
	pkglibpth="$mingw_libs/pkgconfig"
	pkgconfpth="$mingw_sysroot/local/lib/pkgconfig"
AS_ECHO "[#!/bin/bash
export PKG_CONFIG_LIBDIR=${pkglibpth}
export PKG_CONFIG_PATH=${pkgconfpth}
pkg-config \$@]" >${ac_pwd}/${host_cpu}-${host_vendor}-${host_os}-pkg-config
		chmod 777 ${ac_pwd}/${host_cpu}-${host_vendor}-${host_os}-pkg-config
		PATH="/$ac_pwd:$PATH"
#		fi
	AC_CHECK_TOOLS(PKG_CONFIG, pkg-config, yes, "PATH=../:$ac_pwd")
	PKG_CHECK_EXISTS([$pkgsrch],[cairo-ps],[pkg_pathok=yes],
	[AC_MSG_ERROR("***cairo-ps not found! Its Needed to build $PACKAGE_NAME. ***")])

#IF SIXTY-FOUR BIT
#We have to be careful here because the user might have installed to /usr/local so in this case we must
#set the pkg-config environment variables to check both the install 'prefix'/lib/pkgconfig and /usr/lib64/lib/pkgconfig
#directories therefore the PKG_CONFIG_PATH will be set to the value of the install 'prefix' that has been set
#at the command line to configure. 

elif	test "$sixtyfourb" = yes ; then
	pkglibpth=/usr/lib64/pkgconfig
	pkgconfpth=${prefix}/lib/pkgconfig
	rm -f /$ac_pwd/*-pkg-config pkg-config
AS_ECHO "[#!/bin/bash
export PKG_CONFIG_LIBDIR=${pkglibpth}
#export PKG_CONFIG_PATH=${pkgconfpth}
pkg-config \$@]" >$ac_pwd/pkg-config
		chmod 777 pkg-config
		AC_PATH_PROGS(PKG_CONFIG, pkg-config , yes, PATH=../:$ac_pwd)
		PKG_CHECK_EXISTS([$pkgsrch],[cairo-ps],[pkg_pathok=yes],
		[AC_MSG_ERROR("***cairo-ps not found! Its Needed to build $PACKAGE_NAME. ***")])

#THIRTY TWO BIT
#Here we are trying to find things on a 32 bit bi-arch machine we must set both 
#PKG_LIBDIR_PATH  to /usr/lib/pkgconfig & PKG_CONFIG_PATH to the install 'prefix'
#to ensure that that we do not pick up any 64 bit libaries if installed.

else
	/bin/rm -f $ac_pwd/pkg-config
	pkglibpth=/usr/lib/pkgconfig
	pkgconfpath=$prefix/lib/pkgconfig
AS_ECHO "[#!/bin/bash
export PKG_CONFIG_LIBDIR=${pkglibpth}
export PKG_CONFIG_PATH=${pkgconfpath}
pkg-config \$@]" >$ac_pwd/pkg-config
	chmod 777 $ac_pwd/pkg-config
	AC_PATH_PROGS(PKG_CONFIG, pkg-config, no, PATH="../:$ac_pwd")
fi


More information about the pkg-config mailing list