5 dh_strip - strip executables, shared libraries, and some static libraries
11 use Debian::Debhelper::Dh_Lib;
15 dh_strip [debhelper options] [-Xitem]
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 environement 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 # 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
59 my (@shared_libs, @executables, @static_libs);
61 return if -l $_ or -d $_; # Skip directories and symlinks always.
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/);
70 # Does its filename look like a shared library?
72 # Ok, do the expensive test.
74 if ($type=~m/.*ELF.*shared.*/) {
75 push @shared_libs, $fn;
80 # Is it executable? -x isn't good enough, so we need to use stat.
81 my (undef,undef,$mode,undef)=stat(_);
85 if ($type=~m/.*ELF.*executable.*/) {
86 push @executables, $fn;
91 # Is it a static library, and not a debug library?
92 if (m/lib.*\.a/ && ! m/.*_g\.a/) {
93 push @static_libs, $fn;
98 foreach my $package (@{$dh{DOPACKAGES}}) {
99 my $tmp=tmpdir($package);
101 my (@shared_libs, @executables, @static_libs);
102 find(\&testfile,$tmp);
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",$_);
111 foreach (@executables) {
112 doit("strip","--remove-section=.comment",
113 "--remove-section=.note",$_);
116 foreach (@static_libs) {
117 doit("strip","--strip-debug",$_);
125 This program is a part of debhelper.
129 Joey Hess <joeyh@debian.org>