+
+=head1 SYNOPSIS
+
+B<dh_strip> [S<I<debhelper options>>] [B<-X>I<item>] [B<--dbg-package=>I<package>] [B<--keep-debug>]
+
+=head1 DESCRIPTION
+
+B<dh_strip> is a debhelper program that is responsible for stripping
+executables, shared libraries, and static libraries that are not used for
+debugging.
+
+This program examines your package build directories and works out what
+to strip on its own. It uses L<file(1)> and file permissions and filenames
+to figure out what files are shared libraries (F<*.so>), executable binaries,
+and static (F<lib*.a>) and debugging libraries (F<lib*_g.a>, F<debug/*.so>), and
+strips each as much as is possible. (Which is not at all for debugging
+libraries.) In general it seems to make very good guesses, and will do the
+right thing in almost all cases.
+
+Since it is very hard to automatically guess if a file is a
+module, and hard to determine how to strip a module, B<dh_strip> does not
+currently deal with stripping binary modules such as F<.o> files.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-X>I<item>, B<--exclude=>I<item>
+
+Exclude files that contain I<item> anywhere in their filename from being
+stripped. You may use this option multiple times to build up a list of
+things to exclude.
+
+=item B<--dbg-package=>I<package>
+
+Causes B<dh_strip> to save debug symbols stripped from the packages it acts on
+as independent files in the package build directory of the specified debugging
+package.
+
+For example, if your packages are libfoo and foo and you want to include a
+I<foo-dbg> package with debugging symbols, use B<dh_strip --dbg-package=>I<foo-dbg>.
+
+Note that this option behaves significantly different in debhelper
+compatibility levels 4 and below. Instead of specifying the name of a debug
+package to put symbols in, it specifies a package (or packages) which
+should have separated debug symbols, and the separated symbols are placed
+in packages with B<-dbg> added to their name.
+
+=item B<-k>, B<--keep-debug>
+
+Debug symbols will be retained, but split into an independent
+file in F<usr/lib/debug/> in the package build directory. B<--dbg-package>
+is easier to use than this option, but this option is more flexible.
+
+=back
+
+=head1 NOTES
+
+If the B<DEB_BUILD_OPTIONS> environment variable contains B<nostrip>, nothing
+will be stripped, in accordance with Debian policy (section 10.1
+"Binaries").
+
+=head1 CONFORMS TO
+
+Debian policy, version 3.0.1
+
+=cut
+
+init(options => {
+ "keep-debug" => \$dh{K_FLAG},
+});
+
+# This variable can be used to turn off stripping (see Policy).
+if (get_buildoption('nostrip')) {
+ exit;
+}
+
+my $objcopy = cross_command("objcopy");
+my $strip = cross_command("strip");
+
+# I could just use `file $_[0]`, but this is safer
+sub get_file_type {
+ my $file=shift;
+ open (FILE, '-|') # handle all filenames safely
+ || exec('file', $file)
+ || die "can't exec file: $!";
+ my $type=<FILE>;
+ close FILE;
+ return $type;
+}