blob: c4935d7b5970cbdadb6e782bbf4e1499b76c13f8 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/bin/bash
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This program wraps around pkg-config to generate the correct include and
7# library paths when cross-compiling using a sysroot.
8# The assumption is that the sysroot contains the .pc files in usr/lib/pkgconfig
9# and usr/share/pkgconfig (relative to the sysroot) and that they output paths
10# relative to some parent path of the sysroot.
11# This assumption is valid for a range of sysroots, in particular: a
12# LSB-compliant root filesystem mounted at the sysroot, and a board build
13# directory of a Chromium OS chroot.
14
15set -o nounset
16set -o errexit
17
18root="$1"
19shift
20target_arch="$1"
21shift
22libpath="$1"
23shift
24
25if [ -z "$root" -o -z "$target_arch" ]
26then
27 echo "usage: $0 /path/to/sysroot target_arch libdir [pkg-config-arguments] package" >&2
28 exit 1
29fi
30
31rewrite=`dirname $0`/rewrite_dirs.py
32package=${!#}
33
34libdir=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig
35
36set -e
37# Some sysroots, like the Chromium OS ones, may generate paths that are not
38# relative to the sysroot. For example,
39# /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all paths
40# relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) instead of
41# relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr).
42# To support this correctly, it's necessary to extract the prefix to strip from
43# pkg-config's |prefix| variable.
44prefix=`PKG_CONFIG_LIBDIR=$libdir pkg-config --variable=prefix "$package" | sed -e 's|/usr$||'`
45result=`PKG_CONFIG_LIBDIR=$libdir pkg-config "$@"`
46echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix"