set path for pkg-config when using sysroot

This commit is contained in:
Robo 2016-03-09 19:41:17 +05:30
parent 91951472bf
commit dfe1641d1e
4 changed files with 154 additions and 23 deletions

View file

@ -260,5 +260,11 @@
},
},
}], # OS=="mac"
['OS=="linux"', {
'variables': {
'pkg-config': '<(source_root)/tools/linux/pkg-config-wrapper "<(sysroot)" "<(target_arch)" "<(system_libdir)"',
},
}], # OS=="linux"
],
}

View file

@ -5,8 +5,7 @@
# Set this to true when building with Clang.
'clang%': 1,
# Path to sysroot dir.
'sysroot%': '',
'system_libdir%': 'lib',
'variables': {
# The minimum OS X SDK version to use.
@ -17,12 +16,20 @@
# Set NEON compilation flags.
'arm_neon%': 1,
'conditions': [
# Define the abosulte version of <(DEPTH).
['OS!="win"', {
'source_root%': '<!(cd <(DEPTH) && pwd -P)',
}], # OS!="win"
],
},
# Copy conditionally-set variables out one scope.
'mac_sdk_min%': '<(mac_sdk_min)',
'arm_version%': '<(arm_version)',
'arm_neon%': '<(arm_neon)',
'source_root%': '<(source_root)',
# Variables to control Link-Time Optimization (LTO).
'use_lto%': 0,
@ -34,16 +41,29 @@
'clang%': 0,
}], # OS=="win"
# Define the abosulte version of <(DEPTH).
['OS!="win"', {
'source_root': '<!(cd <(DEPTH) && pwd -P)',
}], # OS!="win"
# Search for the available version of SDK.
['OS=="mac"', {
'mac_sdk%': '<!(python <(DEPTH)/tools/mac/find_sdk.py <(mac_sdk_min))',
}],
['OS=="linux"', {
'conditions': [
['target_arch=="arm"', {
# sysroot needs to be an absolute path otherwise it generates
# incorrect results when passed to pkg-config
'sysroot%': '<(source_root)/vendor/debian_wheezy_arm-sysroot',
}],
['target_arch=="ia32"', {
'sysroot%': '<(source_root)/vendor/debian_wheezy_i386-sysroot',
}],
['target_arch=="x64"', {
'sysroot%': '<(source_root)/vendor/debian_wheezy_amd64-sysroot',
}],
],
}, {
'sysroot%': ' ',
}],
# Set default compiler flags depending on ARM version.
['arm_version==6', {
'arm_arch%': 'armv6',
@ -114,21 +134,6 @@
# Setup sysroot environment.
['OS=="linux" and target_arch in ["arm", "ia32", "x64"]', {
'variables': {
'conditions': [
['target_arch=="arm"', {
# sysroot needs to be an absolute path otherwise it generates
# incorrect results when passed to pkg-config
'sysroot': '<(source_root)/vendor/debian_wheezy_arm-sysroot',
}],
['target_arch=="ia32"', {
'sysroot': '<(source_root)/vendor/debian_wheezy_i386-sysroot',
}],
['target_arch=="x64"', {
'sysroot': '<(source_root)/vendor/debian_wheezy_amd64-sysroot',
}],
],
},
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
@ -142,7 +147,7 @@
}]
],
},
}], # target_arch==arm
}], # sysroot
# Setup cross-compilation on Linux.
['OS=="linux"', {

49
tools/linux/pkg-config-wrapper Executable file
View file

@ -0,0 +1,49 @@
#!/bin/bash
# Copyright (c) 2012 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.
# Additional directories containing .pc files may be specified by setting
# the PKG_CONFIG_PATH environment variable- these will be prepended to the
# generated paths.
set -o nounset
set -o errexit
root="$1"
shift
target_arch="$1"
shift
libpath="$1"
shift
if [ -z "$root" -o -z "$target_arch" ]
then
echo "usage: $0 /path/to/sysroot target_arch libdir [pkg-config-arguments] package" >&2
exit 1
fi
rewrite=`dirname $0`/rewrite_dirs.py
package=${!#}
libdir=$root/usr/$libpath/pkgconfig:$root/usr/share/pkgconfig
set -e
# 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_LIBDIR=$libdir pkg-config --variable=prefix "$package" | sed -e 's|/usr$||'`
result=`PKG_CONFIG_LIBDIR=$libdir pkg-config "$@"`
echo "$result"| $rewrite --sysroot "$root" --strip-prefix "$prefix"

71
tools/linux/rewrite_dirs.py Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env python
# Copyright (c) 2011 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.
"""Rewrites paths in -I, -L and other option to be relative to a sysroot."""
import sys
import os
import optparse
REWRITE_PREFIX = ['-I',
'-idirafter',
'-imacros',
'-imultilib',
'-include',
'-iprefix',
'-iquote',
'-isystem',
'-L']
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, opts):
"""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], 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):], opts)
i += 1
return ' '.join(args)
def main(argv):
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(), opts)
print line
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))