Archive for October, 2008

pkg-config for cross compiling

October 17, 2008

I’ve become a big fan of using pkg-config of late, it simplifies configuration, dependency resolution and cross compile setups.

The suite of software that I’m maintaining is a collection of sub packages with a lot of inter-dependencies. Not that long ago compilation consisted of configuring, making, then installing each package in turn; decidely sub-optimal.

In order to get an in place build working PKG_CONFIG_PATH has to have a lot of little relative paths added to it. Building on top of Erik’s cross compile setup my pkg-config script basically just sanitizes PKG_CONFIG_PATH.

Using this pkg-config scripts allows us to use the cross crompile system paths while installing our stuff in a separate directory for easier deployment.


arch=`basename $0 -pkg-config`


export PKG_CONFIG_LIBDIR=${sysroot}/lib/pkgconfig

# Remove non relative and non $sysroot paths from PKG_CONFIG_PATH 
for element in `echo $PKG_CONFIG_PATH | tr : ' '` ; do
    if [[ $element =~ ^\. || $element =~ ^$sysroot ]] ; then         


pkg-config $@