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