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: http://src.chromium.org/svn/trunk/src/build@25418 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
piman@chromium.org 2009-09-04 01:53:01 +00:00
Родитель bf5ec4ed42
Коммит 42120e1293
4 изменённых файлов: 126 добавлений и 28 удалений

Просмотреть файл

@ -101,6 +101,9 @@
'chromeos%': 0,
# The system root for cross-compiles. Default: none.
'sysroot%': '',
# This is the location of the sandbox binary. Chrome looks for this before
# running the zygote process. If found, and SUID, it will be used to
# sandbox the zygote process and, thus, all renderer processes.
@ -532,6 +535,14 @@
}],
],
}],
['sysroot!=""', {
'cflags': [
'--sysroot=<(sysroot)',
],
'ldflags': [
'--sysroot=<(sysroot)',
],
}],
['no_strict_aliasing==1', {
'cflags': [
'-fno-strict-aliasing',
@ -766,4 +777,4 @@
# and therefore SYMROOT, needs to be set at the project level.
'SYMROOT': '<(DEPTH)/xcodebuild',
},
}
}

14
linux/pkg-config-wrapper Executable file
Просмотреть файл

@ -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

61
linux/rewrite_dirs.py Executable file
Просмотреть файл

@ -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))

Просмотреть файл

@ -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)',
# ],
# },
# },