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>]
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 This program examines your package build directories and works out what
24 to strip on its own. It uses L<file(1)> and file permisions and filenames
25 to figure out what files are shared libraries (*.so), executable binaries,
26 and static (lib*.a) and debugging libraries (lib*_g.a, debug/*.so), and
27 strips each as much as is possible. (Which is not at all for debugging
28 libraries.) In general it seems to make very good guesses, and will do the
29 right thing in almost all cases.
31 Since it is very hard to automatically guess if a file is a
32 module, and hard to determine how to strip a module, dh_strip does not
33 currently deal with stripping binary modules such as .o files.
39 =item B<-X>I<item>, B<--exclude=>I<item>
41 Exclude files that contain "item" anywhere in their filename from being
42 stripped. You may use this option multiple times to build up a list of
49 If the DEB_BUILD_OPTIONS environment variable contains "nostrip", nothing
50 will be stripped, in accordance with Debian policy.
54 Debian policy, version 3.0.1
60 # This variable can be used to turn off stripping (see Policy).
61 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nostrip/) {
65 # I could just use `file $_[0]`, but this is safer
68 open (FILE, '-|') # handle all filenames safely
69 || exec('file', $file)
70 || die "can't exec file: $!";
76 # Check if a file is an elf binary, shared library, or static library,
77 # for use by File::Find. It'll fill the following 3 arrays with anything
79 my (@shared_libs, @executables, @static_libs);
81 return if -l $_ or -d $_; # Skip directories and symlinks always.
83 # See if we were asked to exclude this file.
84 # Note that we have to test on the full filename, including directory.
85 my $fn="$File::Find::dir/$_";
86 foreach my $f (@{$dh{EXCLUDE}}) {
87 return if ($fn=~m/\Q$f\E/);
90 # Is it a debug library in a debug subdir?
91 return if $fn=~m/debug\/.*\.so/;
93 # Does its filename look like a shared library?
95 # Ok, do the expensive test.
96 my $type=get_file_type($_);
97 if ($type=~m/.*ELF.*shared.*/) {
98 push @shared_libs, $fn;
103 # Is it executable? -x isn't good enough, so we need to use stat.
104 my (undef,undef,$mode,undef)=stat(_);
106 # Ok, expensive test.
107 my $type=get_file_type($_);
108 if ($type=~m/.*ELF.*(executable|shared).*/) {
109 push @executables, $fn;
114 # Is it a static library, and not a debug library?
115 if (m/lib.*\.a$/ && ! m/.*_g\.a$/) {
116 push @static_libs, $fn;
121 foreach my $package (@{$dh{DOPACKAGES}}) {
122 my $tmp=tmpdir($package);
124 find(\&testfile,$tmp);
126 foreach (@shared_libs) {
127 # Note that all calls to strip on shared libs
128 # *must* inclde the --strip-unneeded.
129 doit("strip","--remove-section=.comment",
130 "--remove-section=.note","--strip-unneeded",$_);
133 foreach (@executables) {
134 doit("strip","--remove-section=.comment",
135 "--remove-section=.note",$_);
138 foreach (@static_libs) {
139 doit("strip","--strip-debug",$_);
147 This program is a part of debhelper.
151 Joey Hess <joeyh@debian.org>