2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Reads etc/ld.so.conf and/or etc/ld.so.conf.d/*.conf and returns the
7 # appropriate linker flags.
9 # sysroot_ld_path.sh /abspath/to/sysroot
12 log_error_and_exit
() {
18 if [ -z "$1" ] ||
[ -z "$2" ]; then
19 log_error_and_exit
"bad arguments to process_entry()"
24 echo $localpath |
grep -qs '^/'
26 log_error_and_exit
$localpath does not start with
/
28 local entry
="$root$localpath"
30 echo -Wl,-rpath-link=$entry
33 process_ld_so_conf
() {
34 if [ -z "$1" ] ||
[ -z "$2" ]; then
35 log_error_and_exit
"bad arguments to process_ld_so_conf()"
40 # ld.so.conf may include relative include paths. pushd is a bashism.
41 local saved_pwd
=$
(pwd)
42 cd $
(dirname "$ld_so_conf")
46 echo "$ENTRY" |
grep -qs ^include
48 local included_files
=$
(echo "$ENTRY" |
sed 's/^include //')
49 echo "$included_files" |
grep -qs ^
/
51 if ls $root$included_files >/dev
/null
2>&1 ; then
52 for inc_file
in $root$included_files; do
53 process_ld_so_conf
"$root" "$inc_file"
57 if ls $
(pwd)/$included_files >/dev
/null
2>&1 ; then
58 for inc_file
in $
(pwd)/$included_files; do
59 process_ld_so_conf
"$root" "$inc_file"
66 echo "$ENTRY" |
grep -qs ^
/
68 process_entry
"$root" "$ENTRY"
79 echo Usage
$0 /abspath
/to
/sysroot
83 echo $1 |
grep -qs ' '
85 log_error_and_exit
$1 contains whitespace.
88 LD_SO_CONF
="$1/etc/ld.so.conf"
89 LD_SO_CONF_D
="$1/etc/ld.so.conf.d"
91 if [ -e "$LD_SO_CONF" ]; then
92 process_ld_so_conf
"$1" "$LD_SO_CONF" |
xargs echo
93 elif [ -e "$LD_SO_CONF_D" ]; then
94 find "$LD_SO_CONF_D" -maxdepth 1 -name '*.conf' -print -quit > /dev
/null
96 for entry
in $LD_SO_CONF_D/*.conf
; do
97 process_ld_so_conf
"$1" "$entry"