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.


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 $@ 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: