]> git.donarmstrong.com Git - debhelper.git/blobdiff - dh_compress
r102: Initial Import
[debhelper.git] / dh_compress
index 4626ed09a180f131799986ea4bbbca7b547c14fb..7d6e4979ade9cef8456959980e5ded3e035e386e 100755 (executable)
@@ -6,38 +6,60 @@
 PATH=debian:$PATH:/usr/lib/debhelper
 . dh_lib
 
+# Returns a list of all the files that we want to compress,
+# (ignoring any files we were asked to exclude on the command
+# line). Assummes we are already in the temp directory.
+filelist () {
+       if [ "$compress" ]; then
+               # The config file is a sh script that outputs the files to be compressed
+               # (typically using find).
+               sh $olddir/$compress 2>/dev/null || true
+       else
+               # By default fall back on what the policy manual says to compress.
+               find usr/info usr/man usr/X11*/man -type f ! -name "*.gz" 2>/dev/null || true
+               find usr/doc -type f \( -size +4k -or -name "changelog*" \) \
+                       ! -name "*.htm*" ! -name "*.gif" ! -name "*.gz" \
+                       ! -name "copyright" 2>/dev/null || true
+       fi
+}
+
+# Returns a list of all the files we want to compress,
+# after taking command line exclusions into account.
+# Call only if DH_EXCLUDE_GREP is non-empty.
+filelist_excluded () {
+       # Use grep -F so we don't have to worry about regexp's.
+       (filelist | grep -v -F \
+               "`echo "$DH_EXCLUDE_GREP" | tr "|" "\n"`") || true
+}
+
 for PACKAGE in $DH_DOPACKAGES; do
        TMP=`tmpdir $PACKAGE`
-       EXT=`pkgext $PACKAGE`
+       compress=`pkgfile $PACKAGE compress`
 
-       # Run the file name gatering commands from within the directory
+       # Run the file name gathering commands from within the directory
        # structure that will be effected.
        olddir=`pwd`
-       doit "cd $TMP"
+       # Can't use doit here, that breaks --no-act mode.
+       verbose_echo "cd $TMP"
+       cd "$TMP"
 
-       if [ -f $olddir/debian/${EXT}compress ]; then
-               # The config file is a sh script that outputs the files to be compressed
-               # (typically using find).
-               files=`sh $olddir/debian/${EXT}compress 2>/dev/null`
+       # Get the list of files to compress.
+       if [ "$DH_EXCLUDE_GREP" ]; then
+               files=`filelist_excluded`
        else
-               # By default fall back on what the policy manual says to compress.
-               files=`
-                       find usr/info usr/man usr/X11*/man -type f 2>/dev/null ;
-                       find usr/doc -type f \( -size +4k -or -name "changelog*" \) \
-                               ! -name "*.htm*" ! -name "*.gif" \
-                               ! -name "copyright" 2>/dev/null
-                       `
+               files=`filelist`
        fi
 
        if [ "$files" ]; then
                # This is just a cosmetic fix.
-               files=`echo $files | tr "\n" " "`       
+               files=`echo $files | tr "\n" " "`
        
-               doit "gzip -9 $files" || true
+               doit "gzip -f9 $files" || true
        fi
 
        # Change back to old pwd.
-       doit "cd $olddir"
+       verbose_echo "cd $olddir"
+       cd "$olddir"
 
        # Fix up symlinks that were pointing to the uncompressed files.
        for file in `find $TMP -type l`; do