]> git.donarmstrong.com Git - debhelper.git/blob - dh_strip
r338: * Patch from Jorgen `forcer' Schaefer <forcer at mindless.com> (much
[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 # Check if a file is an elf binary, shared library, or static library,
10 # for use by File::Find. It'll fill the following 3 arrays with anything
11 # it finds:
12 my (@shared_libs, @executables, @static_libs);
13 sub testfile {
14         return if -l $_ or -d $_; # Skip directories and symlinks always.
15
16         # See if we were asked to exclude this file.
17         # Note that we have to test on the full filename, including directory.
18         $fn="$File::Find::dir/$_";
19         foreach $f (@{$dh{EXCLUDE}}) {
20                 return if ($fn=~m/\Q$f\E/);
21         }
22
23         # Does its filename look like a shared library?
24         if (m/.*\.so.*?/) {
25                 # Ok, do the expensive test.
26                 my $type=`file $_`;
27                 if ($type=~m/.*ELF.*shared.*/) {
28                         push @shared_libs, $fn;
29                         return;
30                 }
31         }
32         
33         # Is it executable? -x isn't good enough, so we need to use stat.
34         (undef,undef,$mode,undef)=stat(_);
35         if ($mode & 0111) {
36                 # Ok, expensive test.
37                 my $type=`file $_`;
38                 if ($type=~m/.*ELF.*executable.*/) {
39                         push @executables, $fn;
40                         return;
41                 }
42         }
43         
44         # Is it a static library, and not a debug library?
45         if (m/lib.*\.a/ && ! m/.*_g\.a/) {
46                 push @static_libs, $fn;
47                 return;
48         }
49 }
50
51 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
52         $TMP=tmpdir($PACKAGE);
53
54         @shared_libs=@executables=@static_libs=();
55         find(\&testfile,$TMP);
56
57         foreach (@shared_libs) {
58                 # Note that all calls to strip on shared libs
59                 # *must* inclde the --strip-unneeded.
60                 doit("strip","--remove-section=.comment","--remove-section=.note","--strip-unneeded",$_);
61         }
62         
63         foreach (@executables) {
64                 doit("strip","--remove-section=.comment","--remove-section=.note",$_);
65         }
66
67         foreach (@static_libs) {
68                 doit("strip","--strip-debug",$_);
69         }
70 }