From owner-svn-src-head@FreeBSD.ORG Sun Dec 15 07:05:00 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9E4CBD6D; Sun, 15 Dec 2013 07:05:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7E8ED1F6E; Sun, 15 Dec 2013 07:05:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBF7508t079113; Sun, 15 Dec 2013 07:05:00 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBF750Oa079112; Sun, 15 Dec 2013 07:05:00 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201312150705.rBF750Oa079112@svn.freebsd.org> From: Luigi Rizzo Date: Sun, 15 Dec 2013 07:05:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r259410 - head/release/picobsd/build X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Dec 2013 07:05:00 -0000 Author: luigi Date: Sun Dec 15 07:04:59 2013 New Revision: 259410 URL: http://svnweb.freebsd.org/changeset/base/259410 Log: revise the helper functions to lookup binaries and their shared libraries. Modified: head/release/picobsd/build/picobsd Modified: head/release/picobsd/build/picobsd ============================================================================== --- head/release/picobsd/build/picobsd Sun Dec 15 04:28:20 2013 (r259409) +++ head/release/picobsd/build/picobsd Sun Dec 15 07:04:59 2013 (r259410) @@ -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 +# 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