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