pkg-config-wrapper 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/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. # This program wraps around pkg-config to generate the correct include and
  6. # library paths when cross-compiling using a sysroot.
  7. # The assumption is that the sysroot contains the .pc files in usr/lib/pkgconfig
  8. # and usr/share/pkgconfig (relative to the sysroot) and that they output paths
  9. # relative to some parent path of the sysroot.
  10. # This assumption is valid for a range of sysroots, in particular: a
  11. # LSB-compliant root filesystem mounted at the sysroot, and a board build
  12. # directory of a Chromium OS chroot.
  13. # Additional directories containing .pc files may be specified by setting
  14. # the PKG_CONFIG_PATH environment variable- these will be prepended to the
  15. # generated paths.
  16. set -o nounset
  17. set -o errexit
  18. root="$1"
  19. shift
  20. target_arch="$1"
  21. shift
  22. libpath="$1"
  23. shift
  24. if [ -z "$root" -o -z "$target_arch" ]
  25. then
  26. echo "usage: $0 /path/to/sysroot target_arch libdir [pkg-config-arguments] package" >&2
  27. exit 1
  28. fi
  29. python2=$(which python2)
  30. if [ ! -x "$python2" ] ; then
  31. python2=python
  32. fi
  33. rewrite=`dirname $0`/rewrite_dirs.py
  34. package=${!#}
  35. libdir=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig
  36. set -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.
  44. prefix=`PKG_CONFIG_LIBDIR=$libdir pkg-config --variable=prefix "$package" | sed -e 's|/usr$||'`
  45. result=`PKG_CONFIG_LIBDIR=$libdir pkg-config "$@"`
  46. echo "$result"| $python2 $rewrite --sysroot "$root" --strip-prefix "$prefix"