michael@0: #!/bin/bash michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: # This program wraps around pkg-config to generate the correct include and michael@0: # library paths when cross-compiling using a sysroot. michael@0: # The assumption is that the sysroot contains the .pc files in usr/lib/pkgconfig michael@0: # and usr/share/pkgconfig (relative to the sysroot) and that they output paths michael@0: # relative to some parent path of the sysroot. michael@0: # This assumption is valid for a range of sysroots, in particular: a michael@0: # LSB-compliant root filesystem mounted at the sysroot, and a board build michael@0: # directory of a Chromium OS chroot. michael@0: michael@0: root="$1" michael@0: shift michael@0: target_arch="$1" michael@0: shift michael@0: michael@0: if [ -z "$root" -o -z "$target_arch" ] michael@0: then michael@0: echo "usage: $0 /path/to/sysroot target_arch [pkg-config-arguments] package" >&2 michael@0: exit 1 michael@0: fi michael@0: michael@0: if [ "$target_arch" = "x64" ] michael@0: then michael@0: libpath="lib64" michael@0: else michael@0: libpath="lib" michael@0: fi michael@0: michael@0: rewrite=`dirname $0`/rewrite_dirs.py michael@0: package=${!#} michael@0: michael@0: config_path=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig michael@0: set -e michael@0: # Some sysroots, like the Chromium OS ones, may generate paths that are not michael@0: # relative to the sysroot. For example, michael@0: # /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all paths michael@0: # relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) instead of michael@0: # relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr). michael@0: # To support this correctly, it's necessary to extract the prefix to strip from michael@0: # pkg-config's |prefix| variable. michael@0: prefix=`PKG_CONFIG_PATH=$config_path pkg-config --variable=prefix "$package" | sed -e 's|/usr$||'` michael@0: result=`PKG_CONFIG_PATH=$config_path pkg-config "$@"` michael@0: echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix"