5 dh_compress - compress files and fix symlinks in package build directories
11 use Debian::Debhelper::Dh_Lib;
15 B<dh_compress> [S<I<debhelper options>>] [B<-X>I<item>] [B<-A>] [S<I<file ...>>]
19 dh_compress is a debhelper program that is responsible for compressing
20 the files in package build directories, and makes sure that any symlinks
21 that pointed to the files before they were compressed are updated to point
24 By default, dh_compress compresses files that debian policy mandates should
25 be compressed, namely all files in usr/share/info, usr/share/man,
26 usr/X11R6/man, files in usr/share/doc that are larger than 4k in size,
27 (except the copyright file, .html files, and files that appear to be already
28 compressed based on their extensions), and all changelog files.
30 If a debian/package.compress file exists, however, it will be ran as a shell
31 script, and all filenames that the shell script outputs will be compressed
32 instead of the default files. The shell script will be run from
33 inside the package build directory. Note though that using -X is a much
34 better idea in general; you should only use a debian/package.compress file
35 if you really have to.
41 =item B<-X>I<item>, B<--exclude=>I<item>
43 Exclude files that contain "item" anywhere in their filename from being
44 compressed. For example, -X.jpeg will exclude jpeg's from compression.
45 You may use this option multiple times to build up a list of things to
46 exclude. You can accomplish the same thing by using a debian/compress file,
51 Compress all files specified by command line parameters in ALL packages
56 Add these files to the list of files to compress.
62 Debian policy, version 3.0
68 foreach my $package (@{$dh{DOPACKAGES}}) {
69 my $tmp=tmpdir($package);
70 my $compress=pkgfile($package,"compress");
72 # Run the file name gathering commands from within the directory
73 # structure that will be effected.
75 verbose_print("cd $tmp");
76 chdir($tmp) || error("Can't cd to $tmp: $!");
78 # Figure out what files to compress.
80 # First of all, deal with any files specified right on the command line.
81 if (($package eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
85 # The config file is a sh script that outputs the files to be compressed
86 # (typically using find).
87 push @files, split(/\n/,`sh $olddir/$compress 2>/dev/null`);
90 # Note that all the excludes of odd things like _z
91 # are because gzip refuses to compress such files, assumming
92 # they are zip files. I looked at the gzip source to get the
93 # complete list of such extensions: ".gz", ".z", ".taz",
94 # ".tgz", "-gz", "-z", "_z"
95 push @files, split(/\n/,`
96 find usr/info usr/share/info usr/man usr/share/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true;
97 find usr/doc usr/share/doc -type f \\( -size +4k -or -name "changelog*" \\) \\
98 \\( -name changelog.html -or ! -iname "*.htm*" \\) \\
99 ! -iname "*.gif" ! -iname "*.png" ! -iname "*.jpg" \\
100 ! -iname "*.jpeg" ! -iname "*.gz" ! -iname "*.taz" \\
101 ! -iname "*.tgz" ! -iname "*.z" ! -iname "*.bz2" \\
102 ! -iname "*-gz" ! -iname "*-z" ! -iname "*_z" \\
103 ! -iname "*.jar" ! -iname "*.zip" \\
104 ! -name "copyright" 2>/dev/null || true
108 # Exclude files from compression.
109 if (@files && defined($dh{EXCLUDE}) && $dh{EXCLUDE}) {
113 foreach my $x (@{$dh{EXCLUDE}}) {
124 # Look for files with hard links. If we are going to compress both,
125 # we can preserve the hard link across the compression and save
131 my ($dev, $inode, undef, $nlink)=stat($_);
133 if (! $seen{"$inode.$dev"}) {
134 $seen{"$inode.$dev"}=$_;
138 # This is a hardlink.
139 $hardlinks{$_}=$seen{"$inode.$dev"};
148 # Make executables not be anymore.
149 xargs(\@f,"chmod","a-x");
151 xargs(\@f,"gzip","-9f");
154 # Now change over any files we can that used to be hard links so
156 foreach (keys %hardlinks) {
158 doit("rm","-f","$_");
160 doit("ln","$hardlinks{$_}.gz","$_.gz");
163 verbose_print("cd '$olddir'");
166 # Fix up symlinks that were pointing to the uncompressed files.
167 open (FIND,"find $tmp -type l |");
170 my ($directory)=m:(.*)/:;
171 my $linkval=readlink($_);
172 if (! -e "$directory/$linkval" && -e "$directory/$linkval.gz") {
174 doit("ln","-sf","$linkval.gz","$_.gz");
183 This program is a part of debhelper.
187 Joey Hess <joeyh@debian.org>