]> git.donarmstrong.com Git - debhelper.git/blob - dh_makeshlibs
r1897: * dh_makeshlibs: Fix udeb package name regexp. Closes: #361677
[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 =item B<--add-udeb=>I<udeb>
68
69 Create an additional line for udebs in the shlibs file and use "udeb" as the
70 package name for udebs to depend on instead of the regular library package.
71
72 =back
73
74 =head1 EXAMPLES
75
76 =over 4
77
78 =item dh_makeshlibs
79
80 Assuming this is a package named libfoobar1, generates a shlibs file that
81 looks something like:
82  libfoobar 1 libfoobar1
83
84 =item dh_makeshlibs -V
85
86 Assuming the current version of the package is 1.1-3, generates a shlibs
87 file that looks something like:
88  libfoobar 1 libfoobar1 (>= 1.1)
89
90 =item dh_makeshlibs -V 'libfoobar1 (>= 1.0)'
91
92 Generates a shlibs file that looks something like:
93   libfoobar 1 libfoobar1 (>= 1.0)
94
95 =back
96
97 =cut
98
99 init();
100
101 foreach my $package (@{$dh{DOPACKAGES}}) {
102         next if is_udeb($package);
103         
104         my $tmp=tmpdir($package);
105
106         my %seen;
107         my $need_ldconfig = 0;
108
109         doit("rm", "-f", "$tmp/DEBIAN/shlibs");
110
111         # So, we look for files or links to existing files with names that
112         # match "*.so*". Matching *.so.* is not good enough because of
113         # broken crap like db3. And we only look at real files not
114         # symlinks, so we don't accidentually add shlibs data to -dev
115         # packages. This may have a few false positives, which is ok,
116         # because only if we can get a library name and a major number from
117         # objdump is anything actually added.
118         my $exclude='';
119         my @udeb_lines;
120         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
121                 $exclude="! \\( $dh{EXCLUDE_FIND} \\) ";
122         }
123         open (FIND, "find $tmp -type f \\( -name '*.so' -or -name '*.so.*' \\) $exclude |");
124         while (<FIND>) {
125                 my ($library, $major);
126                 my $objdump=`objdump -p $_`;
127                 if ($objdump=~m/\s+SONAME\s+(.+)\.so\.(.+)/) {
128                         # proper soname format
129                         $library=$1;
130                         $major=$2;
131                 }
132                 elsif ($objdump=~m/\s+SONAME\s+(.+)-(.+)\.so/) {
133                         # idiotic crap soname format
134                         $library=$1;
135                         $major=$2;
136                 }
137
138                 if (defined($dh{M_PARAMS}) && $dh{M_PARAMS} ne '') {
139                         $major=$dh{M_PARAMS};
140                 }
141                 
142                 if (! -d "$tmp/DEBIAN") {
143                         doit("install","-d","$tmp/DEBIAN");
144                 }
145                 my $deps=$package;
146                 if ($dh{V_FLAG_SET}) {
147                         if ($dh{V_FLAG} ne '') {
148                                 $deps=$dh{V_FLAG};
149                         }       
150                         else {
151                                 # Call isnative becuase it sets $dh{VERSION}
152                                 # as a side effect.
153                                 isnative($package);
154                                 my $version = $dh{VERSION};
155                                 # Old compatibility levels include the
156                                 # debian revision, while new do not.
157                                 if (! compat(3)) {
158                                         # Remove debian version, if any.
159                                         $version =~ s/-[^-]+$//;
160                                 }
161                                 $deps="$package (>= $version)";
162                         }
163                 }
164                 if (defined($library) && defined($major) && defined($deps) &&
165                     $library ne '' && $major ne '' && $deps ne '') {
166                         $need_ldconfig=1;
167                         # Prevent duplicate lines from entering the file.
168                         my $line="$library $major $deps";
169                         if (! $seen{$line}) {
170                                 $seen{$line}=1;
171                                 complex_doit("echo '$line' >>$tmp/DEBIAN/shlibs");
172                                 if (defined($dh{SHLIBS_UDEB}) && $dh{SHLIBS_UDEB} ne '') {
173                                         my $udeb_deps = $deps;
174                                         $udeb_deps =~ s/\Q$package\E/$dh{SHLIBS_UDEB}/e;
175                                         $line="udeb: "."$library $major $udeb_deps";
176                                         push @udeb_lines, $line;
177                                 }
178                         }
179                 }
180         }
181         close FIND;
182
183         # Write udeb: lines last.
184         foreach (@udeb_lines) {
185                 complex_doit("echo '$_' >>$tmp/DEBIAN/shlibs");
186         }
187
188         # New as of dh_v3.
189         if (! compat(2) && ! $dh{NOSCRIPTS} && $need_ldconfig) {
190                 autoscript($package,"postinst","postinst-makeshlibs");
191                 autoscript($package,"postrm","postrm-makeshlibs");
192         }
193
194         if (-e "$tmp/DEBIAN/shlibs") {
195                 doit("chmod",644,"$tmp/DEBIAN/shlibs");
196                 doit("chown","0:0","$tmp/DEBIAN/shlibs");
197         }
198 }
199
200 =head1 SEE ALSO
201
202 L<debhelper(7)>
203
204 This program is a part of debhelper.
205
206 =head1 AUTHOR
207
208 Joey Hess <joeyh@debian.org>
209
210 =cut