]> git.donarmstrong.com Git - debhelper.git/blob - dh_makeshlibs
Typo. Closes: #653339
[debhelper.git] / dh_makeshlibs
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_makeshlibs - automatically create shlibs file and call dpkg-gensymbols
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_makeshlibs> [S<I<debhelper options>>] [B<-m>I<major>] [B<-V>I<[dependencies]>] [B<-n>] [B<-X>I<item>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
18 B<dh_makeshlibs> is a debhelper program that automatically scans for shared
19 libraries, and generates a shlibs file for the libraries it finds.
20
21 It also adds a call to ldconfig in the F<postinst> and F<postrm> scripts (in
22 v3 mode and above only) to any packages in which it finds shared libraries.
23
24 Packages that support multiarch are detected, and
25 a Pre-Dependency on multiarch-support is set in ${misc:Pre-Depends} ;
26 you should make sure to put that token into an appropriate place in your
27 debian/control file for packages supporting multiarch.
28
29 =head1 FILES
30
31 =over 4
32
33 =item debian/I<package>.symbols
34
35 =item debian/I<package>.symbols.I<arch>
36
37 These symbols files, if present, are passed to L<dpkg-gensymbols(1)> to
38 be processed and installed. Use the I<arch> specific names if you need
39 to provide different symbols files for different architectures.
40
41 =back
42
43 =head1 OPTIONS
44
45 =over 4
46
47 =item B<-m>I<major>, B<--major=>I<major>
48
49 Instead of trying to guess the major number of the library with objdump,
50 use the major number specified after the -m parameter. This is much less
51 useful than it used to be, back in the bad old days when this program
52 looked at library filenames rather than using objdump.
53
54 =item B<-V>, B<-V>I<dependencies>
55
56 =item B<--version-info>, B<--version-info=>I<dependencies>
57
58 By default, the shlibs file generated by this program does not make packages
59 depend on any particular version of the package containing the shared
60 library. It may be necessary for you to add some version dependency
61 information to the shlibs file. If B<-V> is specified with no dependency
62 information, the current upstream version of the package is plugged into a
63 dependency that looks like "I<packagename> B<(E<gt>>= I<packageversion>B<)>". Note that in
64 debhelper compatibility levels before v4, the Debian part of the package
65 version number is also included. If B<-V> is specified with parameters, the
66 parameters can be used to specify the exact dependency information needed
67 (be sure to include the package name).
68
69 Beware of using B<-V> without any parameters; this is a conservative setting
70 that always ensures that other packages' shared library dependencies are at
71 least as tight as they need to be (unless your library is prone to changing
72 ABI without updating the upstream version number), so that if the
73 maintainer screws up then they won't break. The flip side is that packages
74 might end up with dependencies that are too tight and so find it harder to
75 be upgraded.
76
77 =item B<-n>, B<--noscripts>
78
79 Do not modify F<postinst>/F<postrm> scripts.
80
81 =item B<-X>I<item>, B<--exclude=>I<item>
82
83 Exclude files that contain I<item> anywhere in their filename or directory 
84 from being treated as shared libraries.
85
86 =item B<--add-udeb=>I<udeb>
87
88 Create an additional line for udebs in the shlibs file and use I<udeb> as the
89 package name for udebs to depend on instead of the regular library package.
90
91 =item B<--> I<params>
92
93 Pass I<params> to L<dpkg-gensymbols(1)>.
94
95 =back
96
97 =head1 EXAMPLES
98
99 =over 4
100
101 =item B<dh_makeshlibs>
102
103 Assuming this is a package named F<libfoobar1>, generates a shlibs file that
104 looks something like:
105  libfoobar 1 libfoobar1
106
107 =item B<dh_makeshlibs -V>
108
109 Assuming the current version of the package is 1.1-3, generates a shlibs
110 file that looks something like:
111  libfoobar 1 libfoobar1 (>= 1.1)
112
113 =item B<dh_makeshlibs -V 'libfoobar1 (E<gt>= 1.0)'>
114
115 Generates a shlibs file that looks something like:
116   libfoobar 1 libfoobar1 (>= 1.0)
117
118 =back
119
120 =cut
121
122 init(options => {
123         "m=s", => \$dh{M_PARAMS},
124         "major=s" => \$dh{M_PARAMS},
125         "version-info:s" => \$dh{V_FLAG},
126         "add-udeb=s" => \$dh{SHLIBS_UDEB},
127 });
128
129 my $objdump=cross_command("objdump");
130 my $multiarch=dpkg_architecture_value("DEB_HOST_MULTIARCH");
131
132 foreach my $package (@{$dh{DOPACKAGES}}) {
133         next if is_udeb($package);
134         
135         my $tmp=tmpdir($package);
136
137         my %seen;
138         my $need_ldconfig = 0;
139         my $is_multiarch = 0;
140
141         doit("rm", "-f", "$tmp/DEBIAN/shlibs");
142
143         # So, we look for files or links to existing files with names that
144         # match "*.so.*". And we only look at real files not
145         # symlinks, so we don't accidentually add shlibs data to -dev
146         # packages. This may have a few false positives, which is ok,
147         # because only if we can get a library name and a major number from
148         # objdump is anything actually added.
149         my $exclude='';
150         my (@udeb_lines, @lib_files);
151         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
152                 $exclude="! \\( $dh{EXCLUDE_FIND} \\) ";
153         }
154         open (FIND, "find $tmp -type f \\( -name '*.so' -or -name '*.so.*' \\) $exclude |");
155         while (<FIND>) {
156                 my ($library, $major);
157                 push @lib_files, $_;
158                 if (defined $multiarch && $multiarch ne '' && m,/$multiarch/,) {
159                         $is_multiarch=1;
160                 }
161                 my $ret=`$objdump -p $_`;
162                 if ($ret=~m/\s+SONAME\s+(.+)\.so\.(.+)/) {
163                         # proper soname format
164                         $library=$1;
165                         $major=$2;
166                 }
167                 elsif ($ret=~m/\s+SONAME\s+(.+)-(.+)\.so/) {
168                         # idiotic crap soname format
169                         $library=$1;
170                         $major=$2;
171                 }
172
173                 if (defined($dh{M_PARAMS}) && $dh{M_PARAMS} ne '') {
174                         $major=$dh{M_PARAMS};
175                 }
176                 
177                 if (! -d "$tmp/DEBIAN") {
178                         doit("install","-d","$tmp/DEBIAN");
179                 }
180                 my $deps=$package;
181                 if ($dh{V_FLAG_SET}) {
182                         if ($dh{V_FLAG} ne '') {
183                                 $deps=$dh{V_FLAG};
184                         }       
185                         else {
186                                 # Call isnative becuase it sets $dh{VERSION}
187                                 # as a side effect.
188                                 isnative($package);
189                                 my $version = $dh{VERSION};
190                                 # Old compatibility levels include the
191                                 # debian revision, while new do not.
192                                 if (! compat(3)) {
193                                         # Remove debian version, if any.
194                                         $version =~ s/-[^-]+$//;
195                                 }
196                                 $deps="$package (>= $version)";
197                         }
198                 }
199                 if (defined($library) && defined($major) && defined($deps) &&
200                     $library ne '' && $major ne '' && $deps ne '') {
201                         $need_ldconfig=1;
202                         # Prevent duplicate lines from entering the file.
203                         my $line="$library $major $deps";
204                         if (! $seen{$line}) {
205                                 $seen{$line}=1;
206                                 complex_doit("echo '$line' >>$tmp/DEBIAN/shlibs");
207                                 if (defined($dh{SHLIBS_UDEB}) && $dh{SHLIBS_UDEB} ne '') {
208                                         my $udeb_deps = $deps;
209                                         $udeb_deps =~ s/\Q$package\E/$dh{SHLIBS_UDEB}/e;
210                                         $line="udeb: "."$library $major $udeb_deps";
211                                         push @udeb_lines, $line;
212                                 }
213                         }
214                 }
215         }
216         close FIND;
217
218         # Write udeb: lines last.
219         foreach (@udeb_lines) {
220                 complex_doit("echo '$_' >>$tmp/DEBIAN/shlibs");
221         }
222
223         # New as of dh_v3.
224         if (! compat(2) && ! $dh{NOSCRIPTS} && $need_ldconfig) {
225                 autoscript($package,"postinst","postinst-makeshlibs");
226                 autoscript($package,"postrm","postrm-makeshlibs");
227         }
228
229         if (-e "$tmp/DEBIAN/shlibs") {
230                 doit("chmod",644,"$tmp/DEBIAN/shlibs");
231                 doit("chown","0:0","$tmp/DEBIAN/shlibs");
232         }
233
234         # dpkg-gensymbols files
235         my $symbols=pkgfile($package, "symbols");
236         if (-e $symbols) {
237                 my @liblist;
238                 if (! compat(7)) {
239                         @liblist=map { "-e$_" } @lib_files;
240                 }
241                 # -I is used rather than using dpkg-gensymbols
242                 # own search for symbols files, since that search
243                 # is not 100% compatible with debhelper. (For example,
244                 # this supports --ignore being used.)
245                 doit("dpkg-gensymbols", "-p$package", "-I$symbols",
246                         "-P$tmp",
247                         @liblist,
248                         @{$dh{U_PARAMS}});
249                 if (-s "$tmp/DEBIAN/symbols" == 0) {
250                         doit("rm", "-f", "$tmp/DEBIAN/symbols");
251                 }
252         }
253         if ($is_multiarch) {
254                 addsubstvar($package, "misc:Pre-Depends", "multiarch-support");
255         }
256 }
257
258 =head1 SEE ALSO
259
260 L<debhelper(7)>
261
262 This program is a part of debhelper.
263
264 =head1 AUTHOR
265
266 Joey Hess <joeyh@debian.org>
267
268 =cut