Skip to content

Commit

Permalink
linux: improve support for cross-compiling
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piman@chromium.org committed Sep 4, 2009
1 parent 60f2ea2 commit ee28c9f
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 28 deletions.
13 changes: 12 additions & 1 deletion build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -532,6 +535,14 @@
}],
],
}],
['sysroot!=""', {
'cflags': [
'--sysroot=<(sysroot)',
],
'ldflags': [
'--sysroot=<(sysroot)',
],
}],
['no_strict_aliasing==1', {
'cflags': [
'-fno-strict-aliasing',
Expand Down Expand Up @@ -766,4 +777,4 @@
# and therefore SYMROOT, needs to be set at the project level.
'SYMROOT': '<(DEPTH)/xcodebuild',
},
}
}
14 changes: 14 additions & 0 deletions build/linux/pkg-config-wrapper
Original file line number Diff line number Diff line change
@@ -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 changes: 61 additions & 0 deletions build/linux/rewrite_dirs.py
Original file line number Diff line number Diff line change
@@ -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))
66 changes: 39 additions & 27 deletions build/linux/system.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
],
},
},
Expand All @@ -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)',
# ],
# },
# },
Expand All @@ -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)',
# ],
# },
# },
Expand Down

0 comments on commit ee28c9f

Please sign in to comment.