[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to determine header dependencies for -dev packages



>>>>> On 19 May 1998 22:13:11 -0500, Manoj Srivastava <srivasta@datasync.com> said:

 Manoj> Hi,
 >>> "Shaleh" == Shaleh <shaleh@livenet.net> writes:

 Shaleh> Is there an easy way to determine header dependencies?
 Shaleh> Anyone header could include many others.  Or do I have to
 Shaleh> open up each header and track down which package it is
 Shaleh> included in?

 Manoj> 	Well, one may script this -- there are scripts out
 Manoj> 	there that
 Manoj>  can print a recursive tree of included dependencies
 Manoj>  (unfortunately, most scripts do not deal well with cpp
 Manoj>  conditionals); one just needs grab ths list of headers, and
 Manoj>  then do a dpkg -S on them. Not likely to be fast, but it'll
 Manoj>  work.

(taking from Manoj's suggestion) How about:

#! /usr/bin/perl -w

use strict;

my @headers = <list of headers>; @ maybe `find . -name '*.h' -print`

my $tmp_file = <some secure method of getting a temp file>;

open(TMP_FILE, $tmp_file);
foreach (@headers) {
  print TMP_FILE "#include <$_>\n"; #maybe should be "$_" instead
}
print TMP_FILE "main(){}"
close(TMP_FILE);

my $deps = `gcc -I. -M $tmp_file`; # need the approriate -I directives
                               # here.  At least -I.

my @deps = split(/\s+/, $deps); # this may not work.  Maybe need a m
                                # on the regexp

my @all_deps;

foreach (@deps) {
  if(-f $_) {
    my $one_dep = `dpkg -S $_`;
    $one_dep =~ s/:.*//;
    # and it'd probably be faster to do something like (but not the
    # best of ideas)
    # my $one_dep = `grep -l $_ /var/lib/dpkg/info/*.list`;
    # $one_dep =~ s{/var/lib/dpkg/info}{};
  }
  push(@all_deps, $one_dep) if $one_dep !~ m/dpkg.*not found/;
  # since dpkg doesn't return an error code like it should here (IMO
  # of course) this check is a little annoying.  Should just be
  # $? == 0 
}

print "@all_deps";

exit 0;

----------------------------------------------------------------------
All of the above is off the top of my head and mostly untested, but it
should be close to working.

Unfortunately there is another cute problem:

Many packages use a config.h file to determine which things get
included.  Assuming you are doing this at the same time (with the same 
config.h file) as when you compiled the library, then it should work
OK, but that is important.

Also, really, libraries should be linked with the appropriate
libraries they depend on (which really tells you which dependancies
they have since it is a rare header file that doesn't refer to
functions in a library).

Dres
-- 
@James LewisMoss <dres@dimensional.com> |  Blessed Be!
@    http://www.dimensional.com/~dres   |  Linux is kewl!
@"Argue for your limitations and sure enough, they're yours." Bach


--
To UNSUBSCRIBE, email to debian-mentors-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: