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