#!/bin/sh # Copyright (c) 2013 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. # Reads etc/ld.so.conf and/or etc/ld.so.conf.d/*.conf and returns the # appropriate linker flags. # # sysroot_ld_path.sh /abspath/to/sysroot # proc log_error_and_exit { echo $0: $ifsjoin(Argv) exit 1 } proc process_entry { if test -z $1 || test -z $2 { log_error_and_exit "bad arguments to process_entry()" } local root="$1" local localpath="$2" echo $localpath | grep -qs '^/' if test $Status -ne 0 { log_error_and_exit $localpath does not start with / } local entry="$root$localpath" echo -L$entry echo -Wl,-rpath-link=$entry } proc process_ld_so_conf { if test -z $1 || test -z $2 { log_error_and_exit "bad arguments to process_ld_so_conf()" } local root="$1" local ld_so_conf="$2" # ld.so.conf may include relative include paths. pushd is a bashism. local saved_pwd=$[pwd] cd $[dirname $ld_so_conf] cat $ld_so_conf | \ while read ENTRY { echo $ENTRY | grep -qs ^include if test $Status -eq 0 { local included_files=$[echo $ENTRY | sed 's/^include //] echo $included_files | grep -qs ^/ if test $Status -eq 0 { if ls $root$included_files >/dev/null !2 > !1 { for inc_file in [$root$included_files] { process_ld_so_conf $root $inc_file } } } else { if ls $[pwd]/$included_files >/dev/null !2 > !1 { for inc_file in [$[pwd]/$included_files] { process_ld_so_conf $root $inc_file } } } continue } echo $ENTRY | grep -qs ^/ if test $Status -eq 0 { process_entry $root $ENTRY } } # popd is a bashism cd $saved_pwd } # Main if test $Argc -ne 1 { echo Usage $0 /abspath/to/sysroot exit 1 } echo $1 | grep -qs ' ' if test $Status -eq 0 { log_error_and_exit $1 contains whitespace. } setglobal LD_SO_CONF = ""$1/etc/ld.so.conf"" setglobal LD_SO_CONF_D = ""$1/etc/ld.so.conf.d"" if test -e $LD_SO_CONF { process_ld_so_conf $1 $LD_SO_CONF | xargs echo } elif test -e $LD_SO_CONF_D { find $LD_SO_CONF_D -maxdepth 1 -name '*.conf' -print -quit > /dev/null if test $Status -eq 0 { for entry in [$LD_SO_CONF_D/*.conf] { process_ld_so_conf $1 $entry } | xargs echo } }