Subject: Re: `ldd' functionality
From: [email-masked] (Gary V. Vaughan)

10 Dec 1998 07:42:56 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------20DEF1AD03B29A8C07D133D1"
To: Mumit Khan <[email-masked]>
Cc: [email-masked]

This is a multi-part message in MIME format.
--------------20DEF1AD03B29A8C07D133D1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Thanks for the response:

Mumit Khan wrote:
> 
> On Tue, 8 Dec 1998, Gary V. Vaughan wrote:
> 
> > I am in the process of patching libtool to play nicely on win32,
> > and it turns out that as part of the port I need to do the
> > equivalent to ldd on linux/solaris.
> >
> > Attached is a script which seems to give the right results -- is
> > this the correct approach?  Or is there a cleaner (or less kludgy)
> > way to do it?
> 
> It's a start, but unfortunately not quite enough. It fails to recurse
> into the depdendencies.

Ahh.. I didn't know dll's could depend on one another.  Are these
dependencies encoded into the dependee by cygwin's ld at linktime?

> I suggest you look into cygcheck and wrap that instead.

I want to support b19, which didn't have cygcheck IIRC =(O|

> If that doesn't work for you, I might be able to dig out some old
> code that emulates ldd reasonably well (The reason I didn't pursue it
> is because I had trouble back then building it with GCC due to
> win32api header limitations, but I believe that's been resolved
> since).

libtool is currently one (or three) big shell scripts, so I want to
avoid compiling a program if I can.  I have attached an even uglier
script which does the recursion and displays a bit more info.  Am
I doing the right thing now?

Cheers,
	Gary.
--------------20DEF1AD03B29A8C07D133D1
Content-Type: text/plain; charset=us-ascii;
 name="ldd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ldd"

#! /bin/sh

RE_dll='^	DLL Name: '
to_lower="tr 'A-Z' 'a-z'"

test $# = 1 || { echo "USAGE: ldd <object>"; exit 1; }

OBJDUMP=${OBJDUMP=objdump}
OBJDUMP_FLAGS=${OBJDUMP_FLAGS='-p -j idata'}

exts="exe dll o"		# valid extensions
seen=""				# dependencies visited already
objects=$1			# objects with dependencies to be found

while test -n "$objects"
do
  newobjects=""
  for object in $objects; do

    # search the PATH for each object
    IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=':'
    path=""
    for dir in $PATH; do
      IFS="$save_ifs"
      for ext in $exts; do
        if test -f "$dir/$object.$ext"; then
          path="$dir/$object.$ext"
        fi
      done
      if test -z "$path" && test -f "$dir/$object"; then
        path="$dir/$object"
      fi
    done
    test -n "$path" || path="$object: no such file"

    test "$object" = "$1" || echo "$object	-> $path"
    test -f "$path" || continue

    # extract dependencies from current object
    new=`eval ${OBJDUMP} ${OBJDUMP_FLAGS} "$path" \
	 | grep "$RE_dll"  | sed "s,$RE_dll,,"`
    newobjects="$new $newobjects"
    seen="$seen $object"
  done
  
  # remove any dependencies visited already
  for pending in $seen; do
    pending=`echo $pending|$to_lower`
    newobjects=`echo "$newobjects"|$to_lower|\
	        sed -e "s, $pending\$,,g
		        s,^$pending ,,g
		        s, $pending , ,g
		        /^$pending\$/d"`
  done

  # set the list for the next iteration
  objects="$newobjects"
done

exit 0

--------------20DEF1AD03B29A8C07D133D1--

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".