summaryrefslogtreecommitdiffstats
path: root/release/picobsd/build
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2013-12-15 07:04:59 +0000
committerluigi <luigi@FreeBSD.org>2013-12-15 07:04:59 +0000
commit352a463ebfa3f78f69edeb0942d282c6195097d1 (patch)
tree3301b359e59323555335fbce527a2ece1154739b /release/picobsd/build
parent6bec98d39501079ca7e61109c4d337b5e6981e4d (diff)
downloadFreeBSD-src-352a463ebfa3f78f69edeb0942d282c6195097d1.zip
FreeBSD-src-352a463ebfa3f78f69edeb0942d282c6195097d1.tar.gz
revise the helper functions to lookup binaries and their
shared libraries.
Diffstat (limited to 'release/picobsd/build')
-rwxr-xr-xrelease/picobsd/build/picobsd107
1 files changed, 63 insertions, 44 deletions
diff --git a/release/picobsd/build/picobsd b/release/picobsd/build/picobsd
index 8d5caa8..26e1b08 100755
--- a/release/picobsd/build/picobsd
+++ b/release/picobsd/build/picobsd
@@ -91,7 +91,7 @@ log() { # message
# unconditionally log and wait for input
logverbose() { # message
local foo
- printf "\n*** %s\n" "$*"
+ printf "\n*** %s\n" "$*" >&2
read -p "=== Press enter to continue" foo
return 0
}
@@ -570,71 +570,89 @@ do_links() { # rootdir varname
# cp -p ${u_progs} ${dst}/libexec # ignore errors
# }
+# find programs and required libraries. Accept -L libs -P path <progs>
+# if no argument default to objdir/SHLIBDIRPREFIX for both
find_progs() { # programs
- local pass i old_libs="" tmp o=""
- if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
- o="-P $2"; shift; shift
- fi
- # Result returned in global variables
- u_libs="" ; u_progs="`find_progs_helper $*`"
+ # logverbose "find_progs: called with $*"
+ local i=`realpath ${o_objdir:-${_SHLIBDIRPREFIX}/..}`
+ # default values for -L and -P
+ local dir="-P $i"
+ local ldir="-L $i"
+
+ while [ "$1" != "" ] ; do
+ if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
+ ldir="-L $2"; shift; shift
+ elif [ x"$1" = "x-P" -a -d "$2" ] ; then # set prog search path
+ dir="-P $2"; shift; shift
+ else
+ break
+ fi
+ done
+
+ # Results are returned in global variables
+ u_libs=""
+ u_progs="`find_progs_helper $dir $*`"
[ -z "${u_progs}" ] && return 1 # not found, error
- # use objdump to find libraries. Iterate to fetch recursive
- # dependencies.
- tmp="${u_progs}" ; pass=1
+
+ # use objdump to find libraries.
+ # Iterate to fetch recursive dependencies.
+ local tmp="${u_progs}"
+ local old_libs=""
+ local pass=1
while [ $pass -lt 10 ] ; do
pass=$(($pass + 1))
i="`objdump -x ${tmp} | \
- awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
+ awk '$1 == "NEEDED" { print $2 }' | sort | uniq | tr '\n' ' '`"
if [ "$old_libs" = "$i" ] ; then
- log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
- log "--- done find_progs ---"
+ # logverbose "find_progs: have `echo ${u_libs} | wc -w`/`echo ${i} | wc -w` libraries for: $my_progs ($u_progs)"
+ # logverbose "they are ($i) $u_libs"
return 0
else
# logverbose "old--- $old_libs --- new +++ $i +++"
fi
- u_libs="`find_progs_helper $o $i`"
+ u_libs="`find_progs_helper $ldir $i`"
old_libs="$i"
tmp="$tmp $u_libs"
done
log "WARNING: Too many passes, giving up"
}
-find_progs_helper() { # programs
- local dir=${o_objdir:-${_SHLIBDIRPREFIX}/..}
- local ldir=""
- if [ x"$1" = "x-P" -a -d "$2" ] ; then # set path
- ldir=$2; shift; shift
- fi
- local progs="$*"
- local subdirs=". local/bin local/sbin local/lib local/libexec \
- bin sbin usr.bin usr.sbin libexec lib \
- gnu/usr.bin gnu/lib \
- secure/usr.bin secure/usr.sbin secure/libexec secure/lib"
- local names="" # files to search
- local o=""
+# prints to stdout files and libs in the search paths
+find_progs_helper() { # first arg is either -P or -L
+ local ty=$1 dir=$2 ; shift; shift
+ local progs="`echo $* | tr ' ' '\n' | sort -u | tr '\n' ' '`"
+ # first, extract absolute pathnames or files in this directory
+
+ # accumulate others in $names
+ local names=""
local i
for i in $progs ; do
- # full pathnames are just listed
- [ -f "$i" ] && echo $i && continue
- names="${names} ${o} -name $i"
- o="-o"
+ [ -f "$i" ] && echo `realpath $i` && continue
+ names="${names} $i"
done
+ # if nothing left, we are done
[ -z "${names}" ] && return 0
- local places="" # places to search
- for i in $subdirs ; do
- [ -d "${dir}/${i}" ] && places="${places} ${dir}/${i}"
- done
- if [ -n "${ldir}" ] ; then
- for i in $subdirs ; do
- [ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}"
- done
+
+ local depth p
+ local places="" # places to search
+ if [ x-P = "x$ty" ] ; then # search programs
+ depth=2
+ p=". local/bin local/sbin local/libexec \
+ bin sbin usr/bin usr/sbin libexec gnu/usr.bin \
+ secure/usr.bin secure/usr.sbin secure/libexec "
+ else
+ depth=3
+ p="lib usr/lib gnu/lib secure/lib"
fi
- for i in $progs ; do
- # full pathnames are just listed
- [ -f "$i" ] && echo $i && continue
- find ${places} -maxdepth 3 -type f -name ${i} | head -1
+ for i in $p ; do
+ i="${dir}/${i}"
+ [ -d "${i}" ] && places="${places} `realpath ${i}`"
+ done
+ # logverbose "--- looking into $places"
+ places=`echo ${places} | tr ' ' '\n' | sort -u`
+ for i in $names ; do
+ find ${places} -maxdepth $depth -type f -name ${i} | head -1
done
- # use maxdepth 3 because some libs are way down
}
# Populate the memory filesystem with binaries and non-variable
@@ -746,6 +764,7 @@ populate_mfs_tree() {
fi
log "for a shared 'crunch' take libraries and dynamic loader as well"
+ # /stand/crunch is our main binary, we extract its libs
find_progs ${dst}/stand/crunch
if [ -n "${u_libs}" ] ; then
mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib
OpenPOWER on IntegriCloud