5 dh_strip - strip executables, shared libraries, and some static libraries
11 use Debian::Debhelper::Dh_Lib;
15 B<dh_strip> [S<I<debhelper options>>] [B<-X>I<item>] [item]
19 dh_strip is a debhelper program that is responsible for stripping
20 executables, shared libraries, and static libraries that are not used for
23 It assumes that files that have names like lib*_g.a are static libraries
24 used in debugging, and will not strip them.
30 =item B<-X>I<item>, B<--exclude=>I<item>
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
40 If the DEB_BUILD_OPTIONS environment variable contains "nostrip", nothing
41 will be stripped, in accordance with Debian policy.
45 Debian policy, version 3.0.1
51 # This variable can be used to turn off stripping (see Policy).
52 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nostrip/) {
56 # I could just use `file $_[0]`, but this is safer
59 open (FILE, '-|') # handle all filenames safely
60 || exec('file', $file)
61 || die "can't exec file: $!";
67 # Check if a file is an elf binary, shared library, or static library,
68 # for use by File::Find. It'll fill the following 3 arrays with anything
70 my (@shared_libs, @executables, @static_libs);
72 return if -l $_ or -d $_; # Skip directories and symlinks always.
74 # See if we were asked to exclude this file.
75 # Note that we have to test on the full filename, including directory.
76 my $fn="$File::Find::dir/$_";
77 foreach my $f (@{$dh{EXCLUDE}}) {
78 return if ($fn=~m/\Q$f\E/);
81 # Does its filename look like a shared library?
83 # Ok, do the expensive test.
84 my $type=get_file_type($_);
85 if ($type=~m/.*ELF.*shared.*/) {
86 push @shared_libs, $fn;
91 # Is it executable? -x isn't good enough, so we need to use stat.
92 my (undef,undef,$mode,undef)=stat(_);
95 my $type=get_file_type($_);
96 if ($type=~m/.*ELF.*(executable|shared).*/) {
97 push @executables, $fn;
102 # Is it a static library, and not a debug library?
103 if (m/lib.*\.a$/ && ! m/.*_g\.a$/) {
104 push @static_libs, $fn;
109 foreach my $package (@{$dh{DOPACKAGES}}) {
110 my $tmp=tmpdir($package);
112 find(\&testfile,$tmp);
114 foreach (@shared_libs) {
115 # Note that all calls to strip on shared libs
116 # *must* inclde the --strip-unneeded.
117 doit("strip","--remove-section=.comment",
118 "--remove-section=.note","--strip-unneeded",$_);
121 foreach (@executables) {
122 doit("strip","--remove-section=.comment",
123 "--remove-section=.note",$_);
126 foreach (@static_libs) {
127 doit("strip","--strip-debug",$_);
135 This program is a part of debhelper.
139 Joey Hess <joeyh@debian.org>