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