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