Chromium Code Reviews| Index: build/linux/sysroot_ld_path.sh |
| =================================================================== |
| --- build/linux/sysroot_ld_path.sh (revision 0) |
| +++ build/linux/sysroot_ld_path.sh (revision 0) |
| @@ -0,0 +1,89 @@ |
| +#!/bin/sh |
|
Sam Clegg
2013/03/19 21:31:14
Are there no bashisms in here?
Lei Zhang
2013/03/19 21:41:01
There are no bashisms. I ran checkbashisms.
|
| +# 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 |
| +# |
| + |
|
Sam Clegg
2013/03/19 21:31:14
Maybe set -x to catch any sub-commands that fail?
Lei Zhang
2013/03/19 21:41:01
Did you mean "set -e" ? If we do that, we can prob
|
| +process_entry() { |
| + if [ -z "$1" ] || [ -z "$2" ]; then |
| + echo "bad arguments to process_entry()" |
| + exit 1 |
| + fi |
| + local root="$1" |
| + local localpath="$2" |
| + |
| + echo $localpath | grep -qs '^/' |
| + if [ $? -ne 0 ]; then |
| + echo $localpath does not start with / |
| + exit 1 |
| + fi |
| + local entry="$root$localpath" |
| + echo -L$entry |
| + echo -Wl,-rpath-link=$entry |
| +} |
| + |
| +process_ld_so_conf() { |
| + if [ -z "$1" ] || [ -z "$2" ]; then |
| + echo "bad arguments to process_ld_so_conf()" |
| + exit 1 |
| + fi |
| + 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; do |
| + echo "$ENTRY" | grep -qs ^include |
| + if [ $? -eq 0 ]; then |
| + local included_files=$(echo "$ENTRY" | sed 's/^include //') |
| + for inc_file in $included_files; do |
| + echo $inc_file | grep -qs ^/ |
| + if [ $? -eq 0 ]; then |
| + process_ld_so_conf "$root" "$root$inc_file" |
| + else |
| + process_ld_so_conf "$root" "$(pwd)/$inc_file" |
| + fi |
| + done |
| + continue |
| + fi |
| + |
| + echo "$ENTRY" | grep -qs ^/ |
| + if [ $? -eq 0 ]; then |
| + process_entry "$root" "$ENTRY" |
| + fi |
| + done |
| + |
| + # popd is a bashism |
| + cd "$saved_pwd" |
| +} |
| + |
| +# Main |
| + |
| +if [ $# -ne 1 ]; then |
| + echo $0 /abspath/to/sysroot |
|
Sam Clegg
2013/03/19 21:31:14
Maybe "Usage: ..."
Lei Zhang
2013/03/19 21:41:01
Done.
Lei Zhang
2013/03/19 21:41:01
Done.
|
| + exit 1 |
| +fi |
| + |
| +echo $1 | grep -qs ' ' |
| +if [ $? -eq 0 ]; then |
| + echo $1 contains whitespace. |
|
Sam Clegg
2013/03/19 21:31:14
Maybe $0 here too so its clean which tools reporti
Lei Zhang
2013/03/19 21:41:01
Done.
Lei Zhang
2013/03/19 21:41:01
Added log_error_and_exit()
|
| + exit 1 |
| +fi |
| + |
| +LD_SO_CONF="$1/etc/ld.so.conf" |
| + |
| +if [ -e "$LD_SO_CONF" ]; then |
| + process_ld_so_conf "$1" "$LD_SO_CONF" | xargs echo |
| +else |
| + for entry in $1//etc/ld.so.conf.d/*.conf; do |
| + process_ld_so_conf "$1" "$entry" |
| + done | xargs echo |
| +fi |
| Property changes on: build/linux/sysroot_ld_path.sh |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |
| Added: svn:executable |
| + * |