]> git.donarmstrong.com Git - debhelper.git/blob - dh_shlibdeps
r1655: * Added udeb support, as pioneered by di-packages-build. Understands
[debhelper.git] / dh_shlibdeps
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_shlibdeps - calculate shared library dependancies
6
7 =cut
8
9 use strict;
10 use Cwd;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15 B<dh_shlibdeps> [S<I<debhelper options>>] [B<-L>I<package>] [B<-l>I<directory>] [B<-X>I<item>] [S<B<--> I<params>>]
16
17 =head1 DESCRIPTION
18
19 dh_shlibdeps is a debhelper program that is responsible for calculating
20 shared library dependancies for packages.
21
22 This program is merely a wrapper around L<dpkg-shlibdeps(1)> that calls it
23 once for each package listed in the control file, passing it
24 a list of ELF executables and shared libraries it has found.
25
26 =head1 OPTIONS
27
28 =over 4
29
30 =item B<-u>I<params>, B<--dpkg-shlibdeps-params=>I<params>
31
32 =item B<--> I<params>
33
34 Pass "params" to L<dpkg-shlibdeps(1)>.
35
36 =item B<-X>I<item>, B<--exclude=>I<item>
37
38 Exclude files that contain "item" anywhere in their filename from being
39 passed to dpkg-shlibdeps. This will make their dependancies be ignored.
40 This may be useful in some situations, but use it with caution. This option
41 may be used more than once to exclude more than one thing.
42
43 =item B<-l>I<directory>[:directory:directory:..]
44
45 Before dpkg-shlibdeps is run, LD_LIBRARY_PATH will have added to it the 
46 specified directory (or directories -- separate with colons). This is
47 useful for multi-binary packages where a library is built in one
48 package and another package contains binaries linked against said
49 library. Relative paths will be made absolute for the benefit of
50 dpkg-shlibdeps.
51
52 Note that the directory given should be the complete or relative path to
53 a directory that contains the library. See example below.
54
55 =item B<-L>I<package>, B<--libpackage=>I<package>
56
57 Use the shlibs file automatically generated by dh_makeshlibs for the named
58 package as a kind of automatically generated shlibs.local file. You can use
59 this switch in concert with the -l switch to make dpkg-shlibdeps find a
60 library built as part of the current package, and get the shlibs information.
61 See example below.
62
63 =back
64
65 =head1 EXAMPLES
66
67 Suppose that your source package produces libfoo1, libfoo-dev, and
68 libfoo-bin binary packages. libfoo-bin links against libfoo1, and should
69 depend on it. In your rules file, first run dh_makeshlibs, then dh_shlibdeps:
70
71         dh_makeshlibs
72         dh_shlibdeps -L libfoo1 -l debian/libfoo1/usr/lib
73
74 This will have the effect of generating automatically a shlibs file for
75 libfoo1, and using that file and the libfoo1 library in the
76 debian/libfoo1/usr/lib directory to calculate shared library dependency
77 information.
78
79 =cut
80
81 init();
82
83 # Add directory to library search path.
84 if ($dh{L_PARAMS}) {
85         my @paths=();
86         # Add to existing paths, if set.
87         push @paths, $ENV{'LD_LIBRARY_PATH'}
88                 if exists $ENV{'LD_LIBRARY_PATH'};
89         foreach (split(/:/, $dh{L_PARAMS})) {
90                 # Force the path absolute.
91                 if (m:^/:) {
92                         push @paths, $_;
93                 }
94                 else {
95                         push @paths, getcwd()."/$_";
96                 }
97         }
98         $dh{L_PARAMS}=join(':', @paths);
99         $ENV{'LD_LIBRARY_PATH'}=$dh{L_PARAMS};
100         verbose_print("LD_LIBRARY_PATH=$dh{L_PARAMS}");
101 }
102
103 foreach my $package (@{$dh{DOPACKAGES}}) {
104         next if is_udeb($package);
105         
106         my $tmp=tmpdir($package);
107         my $ext=pkgext($package);
108
109         my @filelist;
110         my $ff;
111
112         # Generate a list of ELF binaries in the package, ignoring any
113         # we were told to exclude.
114         my $find_options='';
115         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
116                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
117         }
118         foreach my $file (split(/\n/,`find $tmp -path $tmp/usr/lib/debug -prune -or -type f \\( -perm +111 -or -name "*.so*" \\) $find_options -print`)) {
119                 # TODO this is slow, optimize. Ie, file can run once on
120                 # multiple files..
121                 $ff=`file "$file"`;
122                 if ($ff=~m/ELF/ && $ff!~/statically linked/) {
123                         push @filelist,$file;
124                 }
125         }
126
127         if (@filelist) {
128                 my @opts;
129                 if (defined $dh{LIBPACKAGE} && length $dh{LIBPACKAGE}) {
130                         @opts=("-L".tmpdir($dh{LIBPACKAGE}."/DEBIAN/shlibs"));
131                 }
132                 doit("dpkg-shlibdeps","-Tdebian/${ext}substvars",
133                         @opts,@{$dh{U_PARAMS}},@filelist);
134         }
135 }
136
137 =head1 SEE ALSO
138
139 L<debhelper(7)>
140
141 This program is a part of debhelper.
142
143 =head1 AUTHOR
144
145 Joey Hess <joeyh@debian.org>
146
147 =cut