I'm attaching two patches, one for dh_installdocs and one for dh_compress.

dh_installdocs.diff implements a new subroutine and uses that to omit
all other files except debian/copyright if "nodocs" is given in
DEB_BUILD_OPTIONS.

dh_compress.diff implements a method to allow the compression of
debian/copyright *even if less than 4k* to allow compression for target
filesystems that use smaller block sizes, like many embedded systems.
The option is only enabled if nodocs is specified to DEB_BUILD_OPTIONS.

These work for me, let me know if there are problems.

In due course, I'd like dh_installman (dh_installmanpages),
dh_installinfo, dh_installexamples and dh_installchangelogs to also
support nodocs with the simple addition:

if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~
/nodocs/) {
        exit;
}

Let me know if you would prefer separate bug reports for each of those,
one for all or none.

A patch may also be needed for dh_link so that dangling symlinks can be
prevented when docs are not included - I'll file a separate bug for that
later.

-- 


Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/

--- debhelper-5.0.62/dh_compress 
+++ debhelper-5.0.62.new/dh_compress 
@@ -58,6 +58,13 @@
 
 =back
 
+=head1 NOTES
+
+If the DEB_BUILD_OPTIONS environment variable contains "nodocs",
+debian/copyright is not excluded from compression.
+
+=cut
+
 =head1 CONFORMS TO
 
 Debian policy, version 3.0
@@ -88,21 +95,32 @@
 		push @files, split(/\n/,`sh $olddir/$compress 2>/dev/null`);
 	}
 	else {
-		# Note that all the excludes of odd things like _z 
+		# if nodocs is used, allow compression of debian/copyright
+		my $nodocs=qq/! -name "copyright"/;
+		$nodocs="" if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nodocs/);
+		# also allow compression of sub 4k copyright files for
+		# embedded filesystems with smaller block/page sizes.
+		my $omitsmall=qq/-size +4k -or/;
+		$omitsmall="" if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nodocs/);
+		# find needs -name before ! -name, so add the copyright file
+		# at the start of the find command.
+		my $addcopy="";
+		$addcopy=qq/ -name "copyright" -or/ if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nodocs/);
+		# Note that all the excludes of odd things like _z
 		# are because gzip refuses to compress such files, assumming
 		# they are zip files. I looked at the gzip source to get the
 		# complete list of such extensions: ".gz", ".z", ".taz", 
 		# ".tgz", "-gz", "-z", "_z"
 		push @files, split(/\n/,`
 			find usr/info usr/share/info usr/man usr/share/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true;
-			find usr/share/doc -type f \\( -size +4k -or -name "changelog*" -or -name "NEWS*" \\) \\
+			find usr/share/doc -type f \\( $omitsmall $addcopy -name "changelog*" -or -name "NEWS*" \\) \\
 				\\( -name changelog.html -or ! -iname "*.htm*" \\) \\
 				! -iname "*.gif" ! -iname "*.png" ! -iname "*.jpg" \\
 				! -iname "*.jpeg" ! -iname "*.gz" ! -iname "*.taz" \\
 				! -iname "*.tgz" ! -iname "*.z" ! -iname "*.bz2" \\
 				! -iname "*-gz"  ! -iname "*-z" ! -iname "*_z" \\
 				! -iname "*.jar" ! -iname "*.zip" ! -iname "*.css" \\
-				! -name "copyright" 2>/dev/null || true;
+				$nodocs 2>/dev/null || true;
 			find usr/X11R6/lib/X11/fonts usr/share/fonts/X11 -type f -name "*.pcf" 2>/dev/null || true;
 		`);
 	}
--- debhelper-5.0.62/dh_installdocs 
+++ debhelper-5.0.62.new/dh_installdocs 
@@ -94,9 +94,50 @@
 between invocations of this command. Otherwise, it may cause multiple
 instances of the same text to be added to maintainer scripts.
 
+If the DEB_BUILD_OPTIONS environment variable contains "nodocs", only the
+copyright file will be installed - all other documentation, .docs file(s),
+README.Debian and TODO files are omitted.
+
 =cut
 
 init();
+
+sub handle_copyright($$)
+{
+	my ($tmp, $package) = @_;
+	# If the "directory" is a dangling symlink, then don't install
+	# the copyright file. This is useful for multibinary packages
+	# that share a doc directory.
+	if (-d "$tmp/usr/share/doc/$package") {
+		# Support debian/package.copyright, but if not present, fall
+		# back on debian/copyright for all packages, not just the
+		# main binary package.
+		my $copyright=pkgfile($package,'copyright');
+		if (! $copyright && -e "debian/copyright") {
+			$copyright="debian/copyright";
+		}
+		if ($copyright && ! excludefile($copyright)) {
+				doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
+					"$tmp/usr/share/doc/$package/copyright");
+		}
+	}
+}
+
+# This variable can be used to exclude all docs.
+if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS} =~ /nodocs/) {
+	foreach my $package (@{$dh{DOPACKAGES}}) {
+		my $tmp=tmpdir($package);
+		next if is_udeb($package);
+		# If this is a symlink, leave it alone.
+		if ( ! -d "$tmp/usr/share/doc/$package" &&
+			 ! -l "$tmp/usr/share/doc/$package") {
+			doit("install","-g",0,"-o",0,"-d","$tmp/usr/share/doc/$package");
+		}
+		# ignore the .docs file(s), just put in copyright
+		&handle_copyright($tmp,$package);
+	}
+	exit;
+}
 
 foreach my $package (@{$dh{DOPACKAGES}}) {
 	next if is_udeb($package);
@@ -169,22 +210,7 @@
 		}
 	}
 
-	# If the "directory" is a dangling symlink, then don't install
-	# the copyright file. This is useful for multibinary packages 
-	# that share a doc directory.
-	if (-d "$tmp/usr/share/doc/$package") {
-		# Support debian/package.copyright, but if not present, fall
-		# back on debian/copyright for all packages, not just the 
-		# main binary package.
-		my $copyright=pkgfile($package,'copyright');
-		if (! $copyright && -e "debian/copyright") {
-			$copyright="debian/copyright";
-		}
-		if ($copyright && ! excludefile($copyright)) {
-				doit("install","-g",0,"-o",0,"-m","644","-p",$copyright,
-					"$tmp/usr/share/doc/$package/copyright");
-		}
-	}
+	&handle_copyright($tmp,$package);
 
 	# Handle doc-base files. There are two filename formats, the usual
 	# plus an extended format (debian/package.*).

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to