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