]> git.donarmstrong.com Git - debhelper.git/blob - dh_strip
r366: * dh_strip: now knows about the DEB_BUILD_OPTIONS=nostrip thing.
[debhelper.git] / dh_strip
1 #!/usr/bin/perl -w
2 #
3 # Strip files.
4
5 use File::Find;
6 use Debian::Debhelper::Dh_Lib;
7 init();
8
9 # This variable can be used to turn off stripping (see Policy).
10 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nostrip/) {
11         exit;
12 }
13
14 # Check if a file is an elf binary, shared library, or static library,
15 # for use by File::Find. It'll fill the following 3 arrays with anything
16 # it finds:
17 my (@shared_libs, @executables, @static_libs);
18 sub testfile {
19         return if -l $_ or -d $_; # Skip directories and symlinks always.
20
21         # See if we were asked to exclude this file.
22         # Note that we have to test on the full filename, including directory.
23         $fn="$File::Find::dir/$_";
24         foreach $f (@{$dh{EXCLUDE}}) {
25                 return if ($fn=~m/\Q$f\E/);
26         }
27
28         # Does its filename look like a shared library?
29         if (m/.*\.so.*?/) {
30                 # Ok, do the expensive test.
31                 my $type=`file $_`;
32                 if ($type=~m/.*ELF.*shared.*/) {
33                         push @shared_libs, $fn;
34                         return;
35                 }
36         }
37         
38         # Is it executable? -x isn't good enough, so we need to use stat.
39         (undef,undef,$mode,undef)=stat(_);
40         if ($mode & 0111) {
41                 # Ok, expensive test.
42                 my $type=`file $_`;
43                 if ($type=~m/.*ELF.*executable.*/) {
44                         push @executables, $fn;
45                         return;
46                 }
47         }
48         
49         # Is it a static library, and not a debug library?
50         if (m/lib.*\.a/ && ! m/.*_g\.a/) {
51                 push @static_libs, $fn;
52                 return;
53         }
54 }
55
56 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
57         $TMP=tmpdir($PACKAGE);
58
59         @shared_libs=@executables=@static_libs=();
60         find(\&testfile,$TMP);
61
62         foreach (@shared_libs) {
63                 # Note that all calls to strip on shared libs
64                 # *must* inclde the --strip-unneeded.
65                 doit("strip","--remove-section=.comment","--remove-section=.note","--strip-unneeded",$_);
66         }
67         
68         foreach (@executables) {
69                 doit("strip","--remove-section=.comment","--remove-section=.note",$_);
70         }
71
72         foreach (@static_libs) {
73                 doit("strip","--strip-debug",$_);
74         }
75 }