]> git.donarmstrong.com Git - debhelper.git/blob - dh_strip
r436: more pods
[debhelper.git] / dh_strip
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_strip - strip executables, shared libraries, and some static libraries
6
7 =cut
8
9 use strict;
10 use File::Find;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15   dh_strip [debhelper options] [-Xitem]
16
17 =head1 DESCRIPTION
18
19 dh_strip is a debhelper program that is responsible for stripping
20 executables, shared libraries, and static libraries that are not used for
21 debugging.
22
23 It assumes that files that have names like lib*_g.a are static libraries
24 used in debugging, and will not strip them.
25
26 =head1 OPTIONS
27
28 =over 4
29
30 =item B<-X>I<item>, B<--exclude=>I<item>
31
32 Exclude files that contain "item" anywhere in their filename from being
33 stripped. You may use this option multiple times to build up a list of
34 things to exclude.
35
36 =back
37
38 =head1 NOTES
39
40 If the DEB_BUILD_OPTIONS environement variable contains "nostrip", nothing
41 will be stripped, in accordance with Debian policy.
42
43 =head1 CONFORMS TO
44
45 Debian policy, version 3.0.1
46
47 =cut
48
49 init();
50
51 # This variable can be used to turn off stripping (see Policy).
52 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nostrip/) {
53         exit;
54 }
55
56 # Check if a file is an elf binary, shared library, or static library,
57 # for use by File::Find. It'll fill the following 3 arrays with anything
58 # it finds:
59 my (@shared_libs, @executables, @static_libs);
60 sub testfile {
61         return if -l $_ or -d $_; # Skip directories and symlinks always.
62
63         # See if we were asked to exclude this file.
64         # Note that we have to test on the full filename, including directory.
65         my $fn="$File::Find::dir/$_";
66         foreach my $f (@{$dh{EXCLUDE}}) {
67                 return if ($fn=~m/\Q$f\E/);
68         }
69
70         # Does its filename look like a shared library?
71         if (m/.*\.so.*?/) {
72                 # Ok, do the expensive test.
73                 my $type=`file $_`;
74                 if ($type=~m/.*ELF.*shared.*/) {
75                         push @shared_libs, $fn;
76                         return;
77                 }
78         }
79         
80         # Is it executable? -x isn't good enough, so we need to use stat.
81         my (undef,undef,$mode,undef)=stat(_);
82         if ($mode & 0111) {
83                 # Ok, expensive test.
84                 my $type=`file $_`;
85                 if ($type=~m/.*ELF.*executable.*/) {
86                         push @executables, $fn;
87                         return;
88                 }
89         }
90         
91         # Is it a static library, and not a debug library?
92         if (m/lib.*\.a/ && ! m/.*_g\.a/) {
93                 push @static_libs, $fn;
94                 return;
95         }
96 }
97
98 foreach my $package (@{$dh{DOPACKAGES}}) {
99         my $tmp=tmpdir($package);
100
101         my (@shared_libs, @executables, @static_libs);
102         find(\&testfile,$tmp);
103
104         foreach (@shared_libs) {
105                 # Note that all calls to strip on shared libs
106                 # *must* inclde the --strip-unneeded.
107                 doit("strip","--remove-section=.comment",
108                         "--remove-section=.note","--strip-unneeded",$_);
109         }
110         
111         foreach (@executables) {
112                 doit("strip","--remove-section=.comment",
113                         "--remove-section=.note",$_);
114         }
115
116         foreach (@static_libs) {
117                 doit("strip","--strip-debug",$_);
118         }
119 }
120
121 =head1 SEE ALSO
122
123 L<debhelper(1)>
124
125 This program is a part of debhelper.
126
127 =head1 AUTHOR
128
129 Joey Hess <joeyh@debian.org>
130
131 =cut