diff options
author | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 00:43:49 +0000 |
---|---|---|
committer | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 00:43:49 +0000 |
commit | e06c3beae331e70eb038a859b0ab6945fef041fb (patch) | |
tree | 7ed17c010a3fbe6a5c29a6cd4c59a96886632d03 /build | |
parent | 59c9f0028c93f79b2b566b41b6fb5bf1d58d1c84 (diff) | |
download | chromium_src-e06c3beae331e70eb038a859b0ab6945fef041fb.zip chromium_src-e06c3beae331e70eb038a859b0ab6945fef041fb.tar.gz chromium_src-e06c3beae331e70eb038a859b0ab6945fef041fb.tar.bz2 |
Improve pkg-config-wrapper to support ChromiumOS sysroots
http://codereview.chromium.org/4516002/show had to be reverted because it
conflicts with "old style" sysroots that are still used on the arm builders.
This is a cleaner approach that should work there.
The previous approach assumed that all variables in .pc files were relative to |prefix|. It would be a desirable thing to have but in practice a few packages don't follow this and have already dereferenced |prefix| in other variables (e.g. |libdir|). So instead of forcing |prefix|, this version keeps the original one but strips the path before '/usr' (in |prefix|) from all returned paths before prepending the sysroot path.
For example if you have foo.pc:
prefix=/build/board/usr
libdir=/build/board/usr/lib # instead of libdir=${prefix}/lib
Libs: -L${libdir}/foo -lfoo
Then instead of forcing prefix=/usr (which doesn't fix |libdir|), we find the path before '/usr' in prefix ('/build/board'), that we strip from the returned -L flag ('/build/board/usr/lib/foo' -> '/usr/lib/foo') before prepending the sysroot path (-> '/path/to/sysroot/usr/lib/foo').
BUG=None
TEST=build with sysroot=/path/to/chromiumos/chroot/build/x86-generic
Review URL: http://codereview.chromium.org/5105005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-x | build/linux/pkg-config-wrapper | 29 | ||||
-rwxr-xr-x | build/linux/rewrite_dirs.py | 26 |
2 files changed, 40 insertions, 15 deletions
diff --git a/build/linux/pkg-config-wrapper b/build/linux/pkg-config-wrapper index d94b997..4b5455b 100755 --- a/build/linux/pkg-config-wrapper +++ b/build/linux/pkg-config-wrapper @@ -1,16 +1,37 @@ -#!/bin/sh +#!/bin/bash +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This program wraps around pkg-config to generate the correct include and +# library paths when cross-compiling using a sysroot. +# The assumption is that the sysroot contains the .pc files in usr/lib/pkgconfig +# and usr/share/pkgconfig (relative to the sysroot) and that they output paths +# relative to some parent path of the sysroot. +# This assumption is valid for a range of sysroots, in particular: a +# LSB-compliant root filesystem mounted at the sysroot, and a board build +# directory of a Chromium OS chroot. root="$1" if [ -z "$root" ] then - echo "usage: $0 /path/to/sysroot [pkg-config-arguments]" >&2 + echo "usage: $0 /path/to/sysroot [pkg-config-arguments] package" >&2 exit 1 fi rewrite=`dirname $0`/rewrite_dirs.py +package=${!#} shift config_path=$root/usr/lib/pkgconfig:$root/usr/share/pkgconfig set -e -result=`PKG_CONFIG_PATH=$config_path pkg-config --define-variable=prefix=/usr "$@"` -echo "$result"| $rewrite $root +# Some sysroots, like the Chromium OS ones, may generate paths that are not +# relative to the sysroot. For example, +# /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all paths +# relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) instead of +# relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr). +# To support this correctly, it's necessary to extract the prefix to strip from +# pkg-config's |prefix| variable. +prefix=`PKG_CONFIG_PATH=$config_path pkg-config --variable=prefix "$package" | sed -e 's|/usr$||'` +result=`PKG_CONFIG_PATH=$config_path pkg-config "$@"` +echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix" diff --git a/build/linux/rewrite_dirs.py b/build/linux/rewrite_dirs.py index 5c41cf9..9e166d0 100755 --- a/build/linux/rewrite_dirs.py +++ b/build/linux/rewrite_dirs.py @@ -7,6 +7,7 @@ import sys import os +import optparse REWRITE_PREFIX = ['-I', '-idirafter', @@ -18,15 +19,19 @@ REWRITE_PREFIX = ['-I', '-isystem', '-L'] -def RewritePath(path, sysroot): - """Rewrites a path by prefixing it with the sysroot if it is absolute.""" +def RewritePath(path, opts): + """Rewrites a path by stripping the prefix and prepending the sysroot.""" + sysroot = opts.sysroot + prefix = opts.strip_prefix if os.path.isabs(path) and not path.startswith(sysroot): + if path.startswith(prefix): + path = path[len(prefix):] path = path.lstrip('/') return os.path.join(sysroot, path) else: return path -def RewriteLine(line, sysroot): +def RewriteLine(line, opts): """Rewrites all the paths in recognized options.""" args = line.split() count = len(args) @@ -38,25 +43,24 @@ def RewriteLine(line, sysroot): if args[i] == prefix: i += 1 try: - args[i] = RewritePath(args[i], sysroot) + args[i] = RewritePath(args[i], opts) except IndexError: sys.stderr.write('Missing argument following %s\n' % prefix) break elif args[i].startswith(prefix): - args[i] = prefix + RewritePath(args[i][len(prefix):], sysroot) + args[i] = prefix + RewritePath(args[i][len(prefix):], opts) i += 1 return ' '.join(args) def main(argv): - try: - sysroot = argv[1] - except IndexError: - sys.stderr.write('usage: %s /path/to/sysroot\n' % argv[0]) - return 1 + parser = optparse.OptionParser() + parser.add_option('-s', '--sysroot', default='/', help='sysroot to prepend') + parser.add_option('-p', '--strip-prefix', default='', help='prefix to strip') + opts, args = parser.parse_args(argv[1:]) for line in sys.stdin.readlines(): - line = RewriteLine(line.strip(), sysroot) + line = RewriteLine(line.strip(), opts) print line return 0 |