#!/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()" } var root = $1 var localpath = $2 echo $localpath | grep -qs '^/' if test $Status -ne 0 { log_error_and_exit $localpath does not start with / } var 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()" } var root = $1 var ld_so_conf = $2 # ld.so.conf may include relative include paths. pushd is a bashism. var 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 { var 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. } global LD_SO_CONF := ""$1/etc/ld.so.conf"" global 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 } } (CommandList children: [ (FuncDef name: log_error_and_exit body: (BraceGroup children: [ (C {(echo)} {($ VSub_Number "$0") (Lit_Other ":")} {($ VSub_At "$@")}) (C {(exit)} {(1)}) ] spids: [33] ) spids: [29 32] ) (FuncDef name: process_entry body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")}) (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Number "$2"))} {(Lit_Other "]")}) ] op_id: Op_DPipe ) terminator: ) ] action: [(C {(log_error_and_exit)} {(DQ ("bad arguments to process_entry()"))})] spids: [-1 83] ) ] spids: [-1 93] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:root) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [98] ) ] spids: [96] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:localpath) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [106] ) ] spids: [104] ) (Pipeline children: [(C {(echo)} {($ VSub_Name "$localpath")}) (C {(grep)} {(-qs)} {(SQ <"^/">)})] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-ne)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(log_error_and_exit)} {($ VSub_Name "$localpath")} {(does)} {(not)} {(start)} {(with)} {(/)} ) ] spids: [-1 141] ) ] spids: [-1 159] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:entry) op: Equal rhs: {(DQ ($ VSub_Name "$root") ($ VSub_Name "$localpath"))} spids: [164] ) ] spids: [162] ) (C {(echo)} {(-L) ($ VSub_Name "$entry")}) (C {(echo)} {(-Wl) (Lit_Comma ",") (-rpath-link) (Lit_Other "=") ($ VSub_Name "$entry")}) ] spids: [55] ) spids: [51 54] ) (FuncDef name: process_ld_so_conf body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "]")}) (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Number "$2"))} {(Lit_Other "]")}) ] op_id: Op_DPipe ) terminator: ) ] action: [(C {(log_error_and_exit)} {(DQ ("bad arguments to process_ld_so_conf()"))})] spids: [-1 220] ) ] spids: [-1 230] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:root) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [235] ) ] spids: [233] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:ld_so_conf) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [243] ) ] spids: [241] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:saved_pwd) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [257 259] ) } spids: [256] ) ] spids: [254] ) (C {(cd)} { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ ($ VSub_Name "$ld_so_conf"))})] ) left_token: spids: [264 270] ) } ) (Pipeline children: [ (C {(cat)} {(DQ ($ VSub_Name "$ld_so_conf"))}) (While cond: [(Sentence child:(C {(read)} {(ENTRY)}) terminator:)] body: (DoGroup children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$ENTRY"))}) (C {(grep)} {(-qs)} {(Lit_Other "^") (include)}) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:included_files) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$ENTRY"))}) (C {(sed)} {(SQ <"s/^include //">)}) ] negated: False ) ] ) left_token: spids: [329 343] ) } spids: [328] ) ] spids: [326] ) (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$included_files"))}) (C {(grep)} {(-qs)} {(Lit_Other "^") (/)}) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [ {(ls)} {($ VSub_Name "$root") ($ VSub_Name "$included_files") } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [385] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [388] ) ] ) terminator: ) ] action: [ (ForEach iter_name: inc_file iter_words: [ {($ VSub_Name "$root") ($ VSub_Name "$included_files") } ] do_arg_iter: False body: (DoGroup children: [ (C {(process_ld_so_conf)} {(DQ ($ VSub_Name "$root"))} {(DQ ($ VSub_Name "$inc_file"))} ) ] spids: [406 420] ) spids: [401 404] ) ] spids: [-1 393] ) ] spids: [-1 423] ) ] spids: [-1 375] ) ] else_action: [ (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [ {(ls)} { (CommandSubPart command_list: (CommandList children: [(C {(pwd)})] ) left_token: spids: [433 435] ) (/) ($ VSub_Name "$included_files") } ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [439] ) (Redir op_id: Redir_GreatAnd fd: 2 arg_word: {(1)} spids: [442] ) ] ) terminator: ) ] action: [ (ForEach iter_name: inc_file iter_words: [ { (CommandSubPart command_list: (CommandList children: [(C {(pwd)})] ) left_token: spids: [456 458] ) (/) ($ VSub_Name "$included_files") } ] do_arg_iter: False body: (DoGroup children: [ (C {(process_ld_so_conf)} {(DQ ($ VSub_Name "$root"))} {(DQ ($ VSub_Name "$inc_file"))} ) ] spids: [463 477] ) spids: [455 461] ) ] spids: [-1 447] ) ] spids: [-1 480] ) ] spids: [426 483] ) (ControlFlow token: ) ] spids: [-1 323] ) ] spids: [-1 489] ) (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$ENTRY"))}) (C {(grep)} {(-qs)} {(Lit_Other "^") (/)}) ] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(process_entry)} {(DQ ($ VSub_Name "$root"))} {(DQ ($ VSub_Name "$ENTRY"))} ) ] spids: [-1 522] ) ] spids: [-1 536] ) ] spids: [291 539] ) ) ] negated: False ) (C {(cd)} {(DQ ($ VSub_Name "$saved_pwd"))}) ] spids: [192] ) spids: [188 191] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(-ne)} {(1)} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(echo)} {(Usage)} {($ VSub_Number "$0")} {(/abspath/to/sysroot)}) (C {(exit)} {(1)}) ] spids: [-1 573] ) ] spids: [-1 589] ) (Pipeline children: [(C {(echo)} {($ VSub_Number "$1")}) (C {(grep)} {(-qs)} {(SQ <" ">)})] negated: False ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [(C {(log_error_and_exit)} {($ VSub_Number "$1")} {(contains)} {(whitespace.)})] spids: [-1 619] ) ] spids: [-1 630] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LD_SO_CONF) op: Equal rhs: {(DQ ($ VSub_Number "$1") (/etc/ld.so.conf))} spids: [633] ) ] spids: [633] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LD_SO_CONF_D) op: Equal rhs: {(DQ ($ VSub_Number "$1") (/etc/ld.so.conf.d))} spids: [639] ) ] spids: [639] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-e)} {(DQ ($ VSub_Name "$LD_SO_CONF"))} {(Lit_Other "]")}) terminator: ) ] action: [ (Pipeline children: [ (C {(process_ld_so_conf)} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Name "$LD_SO_CONF"))}) (C {(xargs)} {(echo)}) ] negated: False ) ] spids: [-1 659] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-e)} {(DQ ($ VSub_Name "$LD_SO_CONF_D"))} {(Lit_Other "]")}) terminator: ) ] action: [ (SimpleCommand words: [ {(find)} {(DQ ($ VSub_Name "$LD_SO_CONF_D"))} {(-maxdepth)} {(1)} {(-name)} {(SQ <"*.conf">)} {(-print)} {(-quit)} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[714])] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [ (Pipeline children: [ (ForEach iter_name: entry iter_words: [{($ VSub_Name "$LD_SO_CONF_D") (/) (Lit_Other "*") (.conf)}] do_arg_iter: False body: (DoGroup children: [ (C {(process_ld_so_conf)} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Name "$entry"))} ) ] spids: [747 761] ) spids: [740 745] ) (C {(xargs)} {(echo)}) ] negated: False ) ] spids: [-1 732] ) ] spids: [-1 770] ) ] spids: [678 691] ) ] spids: [-1 772] ) ] )