pkg-config-wrapper 1.7 KB

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