diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 01:53:01 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 01:53:01 +0000 |
commit | ee28c9fa1dc4b7d092ddea96e2c19d41970e18bb (patch) | |
tree | 68f4f01503522cec6442f03198ee2acf3ec01827 /build/linux | |
parent | 60f2ea2a43fd576f8e88ae85929a423f686889b0 (diff) | |
download | chromium_src-ee28c9fa1dc4b7d092ddea96e2c19d41970e18bb.zip chromium_src-ee28c9fa1dc4b7d092ddea96e2c19d41970e18bb.tar.gz chromium_src-ee28c9fa1dc4b7d092ddea96e2c19d41970e18bb.tar.bz2 |
linux: improve support for cross-compiling
This CL adds support for a 'sysroot' GYP define, that should point to the target root filesystem for cross-compilation.
It passes that argument to the compiler and linker which uses it to prefix its hard-coded path (e.g. /usr/include)
It also points pkg-config to look for package configs there, and rewrite the paths to be prefixed by 'sysroot' (since pkg-config doesn't do it itself)
Review URL: http://codereview.chromium.org/199016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/linux')
-rwxr-xr-x | build/linux/pkg-config-wrapper | 14 | ||||
-rwxr-xr-x | build/linux/rewrite_dirs.py | 61 | ||||
-rw-r--r-- | build/linux/system.gyp | 66 |
3 files changed, 114 insertions, 27 deletions
diff --git a/build/linux/pkg-config-wrapper b/build/linux/pkg-config-wrapper new file mode 100755 index 0000000..abd34ef --- /dev/null +++ b/build/linux/pkg-config-wrapper @@ -0,0 +1,14 @@ +#!/bin/sh + +root="$1" +if [ -z "$root" ] +then + echo "usage: $0 /path/to/sysroot [pkg-config-arguments]" >&2 + exit 1 +fi + +rewrite=`dirname $0`/rewrite_dirs.py + +shift +config_path=$root/usr/lib/pkgconfig:$root/usr/share/pkgconfig +PKG_CONFIG_PATH=$config_path pkg-config "$@" | $rewrite $root diff --git a/build/linux/rewrite_dirs.py b/build/linux/rewrite_dirs.py new file mode 100755 index 0000000..9a00f96 --- /dev/null +++ b/build/linux/rewrite_dirs.py @@ -0,0 +1,61 @@ +#!/usr/bin/python + +"""Rewrites paths in -I, -L and other option to be relative to a sysroot.""" + +import sys +import os + +REWRITE_PREFIX = ['-I', + '-idirafter', + '-imacros', + '-imultilib', + '-include', + '-iprefix', + '-iquote', + '-isystem', + '-L'] + +def RewritePath(path, sysroot): + """Rewrites a path by prefixing it with the sysroot if it is absolute.""" + if os.path.isabs(path): + path = path.lstrip('/') + return os.path.join(sysroot, path) + else: + return path + +def RewriteLine(line, sysroot): + """Rewrites all the paths in recognized options.""" + args = line.split() + count = len(args) + i = 0 + while i < count: + for prefix in REWRITE_PREFIX: + # The option can be either in the form "-I /path/to/dir" or + # "-I/path/to/dir" so handle both. + if args[i] == prefix: + i += 1 + try: + args[i] = RewritePath(args[i], sysroot) + 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) + 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 + + for line in sys.stdin.readlines(): + line = RewriteLine(line.strip(), sysroot) + print line + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/build/linux/system.gyp b/build/linux/system.gyp index e10c905..7b6d82c 100644 --- a/build/linux/system.gyp +++ b/build/linux/system.gyp @@ -3,21 +3,33 @@ # found in the LICENSE file. { + 'variables' : { + 'includes': [ + '../common.gypi', + ], + 'conditions': [ + ['sysroot!=""', { + 'pkg-config': './pkg-config-wrapper "<(sysroot)"', + }, { + 'pkg-config': 'pkg-config' + }], + ], + }, 'targets': [ { 'target_name': 'gtk', 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags gtk+-2.0 gthread-2.0)', + '<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other gtk+-2.0 gthread-2.0)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other gtk+-2.0 gthread-2.0)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l gtk+-2.0 gthread-2.0)', + '<!@(<(pkg-config) --libs-only-l gtk+-2.0 gthread-2.0)', ], }, }, @@ -26,15 +38,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags nss)', + '<!@(<(pkg-config) --cflags nss)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other nss)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other nss)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l nss)', + '<!@(<(pkg-config) --libs-only-l nss)', ], }, }, @@ -43,15 +55,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags freetype2)', + '<!@(<(pkg-config) --cflags freetype2)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other freetype2)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other freetype2)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l freetype2)', + '<!@(<(pkg-config) --libs-only-l freetype2)', ], }, }, @@ -60,15 +72,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags fontconfig)', + '<!@(<(pkg-config) --cflags fontconfig)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other fontconfig)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other fontconfig)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l fontconfig)', + '<!@(<(pkg-config) --libs-only-l fontconfig)', ], }, }, @@ -77,15 +89,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags gdk-2.0)', + '<!@(<(pkg-config) --cflags gdk-2.0)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other gdk-2.0)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other gdk-2.0)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l gdk-2.0)', + '<!@(<(pkg-config) --libs-only-l gdk-2.0)', ], }, }, @@ -94,15 +106,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags gconf-2.0)', + '<!@(<(pkg-config) --cflags gconf-2.0)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other gconf-2.0)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other gconf-2.0)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l gconf-2.0)', + '<!@(<(pkg-config) --libs-only-l gconf-2.0)', ], }, }, @@ -111,15 +123,15 @@ 'type': 'settings', 'direct_dependent_settings': { 'cflags': [ - '<!@(pkg-config --cflags x11)', + '<!@(<(pkg-config) --cflags x11)', ], }, 'link_settings': { 'ldflags': [ - '<!@(pkg-config --libs-only-L --libs-only-other x11)', + '<!@(<(pkg-config) --libs-only-L --libs-only-other x11)', ], 'libraries': [ - '<!@(pkg-config --libs-only-l x11)', + '<!@(<(pkg-config) --libs-only-l x11)', ], }, }, @@ -131,15 +143,15 @@ # 'type': 'settings', # 'direct_dependent_settings': { # 'cflags': [ -# '<!@(pkg-config --cflags gnome-keyring-1)', +# '<!@(<(pkg-config) --cflags gnome-keyring-1)', # ], # }, # 'link_settings': { # 'ldflags': [ -# '<!@(pkg-config --libs-only-L --libs-only-other gnome-keyring-1)', +# '<!@(<(pkg-config) --libs-only-L --libs-only-other gnome-keyring-1)', # ], # 'libraries': [ -# '<!@(pkg-config --libs-only-l gnome-keyring-1)', +# '<!@(<(pkg-config) --libs-only-l gnome-keyring-1)', # ], # }, # }, @@ -148,15 +160,15 @@ # 'type': 'settings', # 'direct_dependent_settings': { # 'cflags': [ -# '<!@(pkg-config --cflags dbus-glib-1)', +# '<!@(<(pkg-config) --cflags dbus-glib-1)', # ], # }, # 'link_settings': { # 'ldflags': [ -# '<!@(pkg-config --libs-only-L --libs-only-other dbus-glib-1)', +# '<!@(<(pkg-config) --libs-only-L --libs-only-other dbus-glib-1)', # ], # 'libraries': [ -# '<!@(pkg-config --libs-only-l dbus-glib-1)', +# '<!@(<(pkg-config) --libs-only-l dbus-glib-1)', # ], # }, # }, |