pkg-config for cross compiling

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.

 #!/bin/bash

arch=`basename $0 -pkg-config`

sysroot="/usr/$arch/"

export PKG_CONFIG_LIBDIR=${sysroot}/lib/pkgconfig

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

PKG_CONFIG_PATH=$pkg_config_path

pkg-config $@ 

Leave a comment