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