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