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