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