]> git.donarmstrong.com Git - debhelper.git/blob - dh_shlibdeps
Move many command-specific options to only be accepted by the command that uses them.
[debhelper.git] / dh_shlibdeps
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_shlibdeps - calculate shared library dependencies
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 dependencies 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 dependencies 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 With recent versions of dpkg-shlibdeps, this option is generally not
46 needed.
47
48 Before dpkg-shlibdeps is run, LD_LIBRARY_PATH will have added to it the 
49 specified directory (or directories -- separate with colons). With recent
50 versions of dpkg-shlibdeps, this is mostly only useful for packages that
51 build multiple flavors of the same library, or other situations where
52 the library is installed into a directory not on the regular library search
53 path.
54
55 =item B<-L>I<package>, B<--libpackage=>I<package>
56
57 With recent versions of dpkg-shlibdeps, this option is generally not
58 needed, unless your package builds multiple flavors of the same library.
59
60 It tells dpkg-shlibdeps (via its -S parameter) to look first in the package
61 build directory for the specified package, when searching for libraries,
62 symbol files, and shlibs files.
63
64 =back
65
66 =head1 EXAMPLES
67
68 Suppose that your source package produces libfoo1, libfoo-dev, and
69 libfoo-bin binary packages. libfoo-bin links against libfoo1, and should
70 depend on it. In your rules file, first run dh_makeshlibs, then dh_shlibdeps:
71
72         dh_makeshlibs
73         dh_shlibdeps
74
75 This will have the effect of generating automatically a shlibs file for
76 libfoo1, and using that file and the libfoo1 library in the
77 debian/libfoo1/usr/lib directory to calculate shared library dependency
78 information.
79
80 If a libbar1 package is also produced, that is an alternate build of
81 libfoo, and is installed into /usr/lib/bar/, you can make libfoo-bin depend
82 on libbar1 as follows:
83
84         dh_shlibdeps -Llibbar1 -l/usr/lib/bar
85         
86 =cut
87
88 init(options => {
89         "L|libpackage=s" => \$dh{LIBPACKAGE},
90         "add-udeb=s" => \$dh{SHLIBS_UDEB},
91         "dpkg-shlibdeps-params=s", => \$dh{U_PARAMS},
92         "l=s", => \$dh{L_PARAMS},
93 });
94
95 if ($dh{L_PARAMS}) {
96         my @paths=();
97         # Add to existing paths, if set.
98         push @paths, $ENV{'LD_LIBRARY_PATH'}
99                 if exists $ENV{'LD_LIBRARY_PATH'};
100         foreach (split(/:/, $dh{L_PARAMS})) {
101                 # Force the path absolute.
102                 if (m:^/:) {
103                         push @paths, $_;
104                 }
105                 else {
106                         push @paths, "/$_";
107                 }
108         }
109         $dh{L_PARAMS}=join(':', @paths);
110 }
111
112 foreach my $package (@{$dh{DOPACKAGES}}) {
113         my $tmp=tmpdir($package);
114         my $ext=pkgext($package);
115
116         my @filelist;
117         my $ff;
118
119         # Generate a list of ELF binaries in the package, ignoring any
120         # we were told to exclude.
121         my $find_options='';
122         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
123                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
124         }
125         foreach my $file (split(/\n/,`find $tmp -type f \\( -perm +111 -or -name "*.so*" \\) $find_options -print`)) {
126                 # Prune directories that contain separated debug symbols.
127                 next if $file=~m!^\Q$tmp\E/usr/lib/debug/(lib|lib64|usr|bin|sbin|opt|dev|emul)/!;
128                 # TODO this is slow, optimize. Ie, file can run once on
129                 # multiple files..
130                 $ff=`file "$file"`;
131                 if ($ff=~m/ELF/ && $ff!~/statically linked/) {
132                         push @filelist,$file;
133                 }
134         }
135
136         if (@filelist) {
137                 my @opts;
138                 if (defined $dh{LIBPACKAGE} && length $dh{LIBPACKAGE}) {
139                         @opts=("-S".tmpdir($dh{LIBPACKAGE}));
140                 }
141                 
142                 push @opts, "-tudeb" if is_udeb($package);
143                 
144                 my $ld_library_path_orig=$ENV{LD_LIBRARY_PATH};
145                 if ($dh{L_PARAMS}) {
146                         $ENV{LD_LIBRARY_PATH}=$dh{L_PARAMS};
147                         verbose_print("LD_LIBRARY_PATH=$dh{L_PARAMS}");
148                 }
149                 
150                 doit("dpkg-shlibdeps","-Tdebian/${ext}substvars",
151                         @opts,@{$dh{U_PARAMS}},@filelist);
152
153                 if ($dh{L_PARAMS}) {
154                         if (defined $ld_library_path_orig) {
155                                 $ENV{LD_LIBRARY_PATH}=$ld_library_path_orig;
156                         }
157                         else {
158                                 delete $ENV{LD_LIBRARY_PATH};
159                         }
160                 }
161         }
162 }
163
164 =head1 SEE ALSO
165
166 L<debhelper(7)>, L<dpkg-shlibdeps(1)>
167
168 This program is a part of debhelper.
169
170 =head1 AUTHOR
171
172 Joey Hess <joeyh@debian.org>
173
174 =cut