OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 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. |
| 5 |
| 6 # Reads etc/ld.so.conf and/or etc/ld.so.conf.d/*.conf and returns the |
| 7 # appropriate linker flags. |
| 8 # |
| 9 # sysroot_ld_path.sh /abspath/to/sysroot |
| 10 # |
| 11 |
| 12 log_error_and_exit() { |
| 13 echo $0: $@ |
| 14 exit 1 |
| 15 } |
| 16 |
| 17 process_entry() { |
| 18 if [ -z "$1" ] || [ -z "$2" ]; then |
| 19 log_error_and_exit "bad arguments to process_entry()" |
| 20 fi |
| 21 local root="$1" |
| 22 local localpath="$2" |
| 23 |
| 24 echo $localpath | grep -qs '^/' |
| 25 if [ $? -ne 0 ]; then |
| 26 log_error_and_exit $localpath does not start with / |
| 27 fi |
| 28 local entry="$root$localpath" |
| 29 echo -L$entry |
| 30 echo -Wl,-rpath-link=$entry |
| 31 } |
| 32 |
| 33 process_ld_so_conf() { |
| 34 if [ -z "$1" ] || [ -z "$2" ]; then |
| 35 log_error_and_exit "bad arguments to process_ld_so_conf()" |
| 36 fi |
| 37 local root="$1" |
| 38 local ld_so_conf="$2" |
| 39 |
| 40 # ld.so.conf may include relative include paths. pushd is a bashism. |
| 41 local saved_pwd=$(pwd) |
| 42 cd $(dirname "$ld_so_conf") |
| 43 |
| 44 cat "$ld_so_conf" | \ |
| 45 while read ENTRY; do |
| 46 echo "$ENTRY" | grep -qs ^include |
| 47 if [ $? -eq 0 ]; then |
| 48 local included_files=$(echo "$ENTRY" | sed 's/^include //') |
| 49 for inc_file in $included_files; do |
| 50 echo $inc_file | grep -qs ^/ |
| 51 if [ $? -eq 0 ]; then |
| 52 process_ld_so_conf "$root" "$root$inc_file" |
| 53 else |
| 54 process_ld_so_conf "$root" "$(pwd)/$inc_file" |
| 55 fi |
| 56 done |
| 57 continue |
| 58 fi |
| 59 |
| 60 echo "$ENTRY" | grep -qs ^/ |
| 61 if [ $? -eq 0 ]; then |
| 62 process_entry "$root" "$ENTRY" |
| 63 fi |
| 64 done |
| 65 |
| 66 # popd is a bashism |
| 67 cd "$saved_pwd" |
| 68 } |
| 69 |
| 70 # Main |
| 71 |
| 72 if [ $# -ne 1 ]; then |
| 73 echo Usage $0 /abspath/to/sysroot |
| 74 exit 1 |
| 75 fi |
| 76 |
| 77 echo $1 | grep -qs ' ' |
| 78 if [ $? -eq 0 ]; then |
| 79 log_error_and_exit $1 contains whitespace. |
| 80 fi |
| 81 |
| 82 LD_SO_CONF="$1/etc/ld.so.conf" |
| 83 LD_SO_CONF_D="$1/etc/ld.so.conf.d" |
| 84 |
| 85 if [ -e "$LD_SO_CONF" ]; then |
| 86 process_ld_so_conf "$1" "$LD_SO_CONF" | xargs echo |
| 87 elif [ -e "$LD_SO_CONF_D" ]; then |
| 88 find "$LD_SO_CONF_D" -maxdepth 1 -name '*.conf' -print -quit |
| 89 if [ $? -eq 0 ]; then |
| 90 for entry in $LD_SO_CONF_D/*.conf; do |
| 91 process_ld_so_conf "$1" "$entry" |
| 92 done | xargs echo |
| 93 fi |
| 94 fi |
OLD | NEW |