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 |
| 15 # the PKG_CONFIG_PATH environment variable- these will be prepended to the |
| 16 # generated paths. |
14 | 17 |
15 root="$1" | 18 root="$1" |
16 shift | 19 shift |
17 target_arch="$1" | 20 target_arch="$1" |
18 shift | 21 shift |
19 | 22 |
20 if [ -z "$root" -o -z "$target_arch" ] | 23 if [ -z "$root" -o -z "$target_arch" ] |
21 then | 24 then |
22 echo "usage: $0 /path/to/sysroot target_arch [pkg-config-arguments] package" >
&2 | 25 echo "usage: $0 /path/to/sysroot target_arch [pkg-config-arguments] package" >
&2 |
23 exit 1 | 26 exit 1 |
24 fi | 27 fi |
25 | 28 |
26 if [ "$target_arch" = "x64" ] | 29 if [ "$target_arch" = "x64" ] |
27 then | 30 then |
28 libpath="lib64" | 31 libpath="lib64" |
29 else | 32 else |
30 libpath="lib" | 33 libpath="lib" |
31 fi | 34 fi |
32 | 35 |
33 rewrite=`dirname $0`/rewrite_dirs.py | 36 rewrite=`dirname $0`/rewrite_dirs.py |
34 package=${!#} | 37 package=${!#} |
35 | 38 |
36 config_path=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig | 39 config_path=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig |
| 40 |
| 41 # prepend any paths specified by the environment |
| 42 if [ -n "$PKG_CONFIG_PATH" ] |
| 43 then |
| 44 config_path="$PKG_CONFIG_PATH:$config_path" |
| 45 fi |
| 46 |
37 set -e | 47 set -e |
38 # Some sysroots, like the Chromium OS ones, may generate paths that are not | 48 # Some sysroots, like the Chromium OS ones, may generate paths that are not |
39 # relative to the sysroot. For example, | 49 # relative to the sysroot. For example, |
40 # /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all paths | 50 # /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all paths |
41 # relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) instead of | 51 # relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) instead of |
42 # relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr). | 52 # relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr). |
43 # To support this correctly, it's necessary to extract the prefix to strip from | 53 # To support this correctly, it's necessary to extract the prefix to strip from |
44 # pkg-config's |prefix| variable. | 54 # pkg-config's |prefix| variable. |
45 prefix=`PKG_CONFIG_PATH=$config_path pkg-config --variable=prefix "$package" | s
ed -e 's|/usr$||'` | 55 prefix=`PKG_CONFIG_PATH=$config_path pkg-config --variable=prefix "$package" | s
ed -e 's|/usr$||'` |
46 result=`PKG_CONFIG_PATH=$config_path pkg-config "$@"` | 56 result=`PKG_CONFIG_PATH=$config_path pkg-config "$@"` |
47 echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix" | 57 echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix" |
OLD | NEW |