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