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