summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Sindholt <opensource@zhasha.com>2019-08-17 16:05:34 +0200
committerJoakim Sindholt <opensource@zhasha.com>2019-08-17 16:28:33 +0200
commit715b72ced54af4d7dbae13019c96ab9d6a8dfa2f (patch)
treeb6089bb668186100dcdc9b8ebeb2315e93c416bf
parent531cac64074a37b7e279f063bd77383d3c9268a5 (diff)
p9l: recursively check for all autolink dependencies
-rw-r--r--bin/p9l.sh57
1 files changed, 33 insertions, 24 deletions
diff --git a/bin/p9l.sh b/bin/p9l.sh
index 0b7bdf3..7d0732e 100644
--- a/bin/p9l.sh
+++ b/bin/p9l.sh
@@ -104,12 +104,10 @@ else
done
fi
-autolinks() {
- for f in "$@"; do
- nm "$f" 2>/dev/null | grep '__p9l_autolink_' | while read ln; do
- echo "${ln##*__p9l_autolink_}"
- done
- done
+join() {
+ local IFS="$1"
+ shift
+ echo "$*"
}
LIBDIR="$DIR/../$objtype/lib"
@@ -117,28 +115,39 @@ LIBDIR="$DIR/../$objtype/lib"
saveifs="$IFS"
IFS=$':\n'
SEARCH=("." "$LIBDIR" $(clang -print-search-dirs 2>/dev/null | awk 'match($0, /^libraries\s*:\s*=\s*/) { print substr($0, RSTART + RLENGTH) }'))
-IFS=$'\n'
-AUTOLINKS=($(autolinks "$@" | sort | uniq))
IFS="$saveifs"
-for ln in "${AUTOLINKS[@]}"; do
- # sort away the global libs that are asked to be linked locally
- haslib=false
- for lib in "$@"; do
- if [[ "${lib##*/}" == "$O.lib${ln}.a" ]]; then
- haslib=true
- break
+ALCHECKED=()
+ALFILES=("$@")
+while [[ ${#ALFILES} > 0 ]]; do
+ IFS=$'\n'
+ AUTOLINKS=($(nm "${ALFILES[@]}" 2>/dev/null | awk 'match($0, /__p9l_autolink_[^ \t]+/){print substr($0, RSTART + 15, RLENGTH - 15)}' | sort | uniq))
+ AUTOLINKS=($(join $'\n' "${AUTOLINKS[@]}" "${ALCHECKED[@]}" "${ALCHECKED[@]}" | sort | uniq -u))
+ IFS="$saveifs"
+
+ NEWLIBS=()
+ for ln in "${AUTOLINKS[@]}"; do
+ # sort away the global libs that are asked to be linked locally
+ haslib=false
+ for lib in "$@"; do
+ if [[ "${lib##*/}" == "$O.lib${ln}.a" ]]; then
+ haslib=true
+ break
+ fi
+ done
+ # or find the lib in the search path
+ if [[ $haslib == false ]]; then
+ lib=$(find "${SEARCH[@]}" -maxdepth 1 -type f -name "lib$ln.a" | sed 1q)
+ if [[ "$lib" == "" ]]; then
+ echo "can't find lib$ln.a" >&2
+ exit 1
+ fi
+ NEWLIBS+=("$lib")
fi
done
- # or find the lib in the search path
- if [[ $haslib == false ]]; then
- lib=$(find "${SEARCH[@]}" -maxdepth 1 -type f -name "lib$ln.a" | sed 1q)
- if [[ "$lib" == "" ]]; then
- echo "can't find lib$ln.a" >&2
- exit 1
- fi
- LIBS+=("$lib")
- fi
+ ALCHECKED+=("${AUTOLINKS[@]}")
+ ALFILES=("${NEWLIBS[@]}")
+ LIBS+=("${NEWLIBS[@]}")
done
# add compiler-rt regardless