Avoid noise from python bytecompile on non-python pkgs (RhBug:539635)
[platform/upstream/rpm.git] / scripts / brp-compress
1 #!/bin/sh
2
3 # If using normal root, avoid changing anything.
4 if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
5         exit 0
6 fi
7
8 cd $RPM_BUILD_ROOT
9
10 # Compress man pages
11 COMPRESS="gzip -9 -n"
12 COMPRESS_EXT=.gz
13
14 for d in ./usr/man/man* ./usr/man/*/man* ./usr/info \
15         ./usr/share/man/man* ./usr/share/man/*/man* ./usr/share/info \
16         ./usr/kerberos/man ./usr/X11R6/man/man* ./usr/lib/perl5/man/man* \
17         ./usr/share/doc/*/man/man* ./usr/lib/*/man/man*
18 do
19     [ -d $d ] || continue
20     for f in `find $d -type f`
21     do
22         [ -f "$f" ] || continue
23         [ "`basename $f`" = "dir" ] && continue
24
25         case "$f" in
26          *.gz|*.Z)    gunzip  $f; b=`echo $f | sed -e 's/\.\(gz\|Z\)$//'`;;
27          *.bz2)       bunzip2 $f; b=`echo $f | sed -e 's/\.bz2$//'`;;
28          *.xz|*.lzma) unxz    $f; b=`echo $f | sed -e 's/\.\(xz\|lzma\)$//'`;;
29          *) b=$f;;
30         esac
31
32         $COMPRESS $b </dev/null 2>/dev/null || {
33             inode=`ls -i $b | awk '{ print $1 }'`
34             others=`find $d -type f -inum $inode`
35             if [ -n "$others" ]; then
36                 for afile in $others ; do
37                     [ "$afile" != "$b" ] && rm -f $afile
38                 done
39                 $COMPRESS -f $b
40                 for afile in $others ; do
41                     [ "$afile" != "$b" ] && ln $b$COMPRESS_EXT $afile$COMPRESS_EXT
42                 done
43             else
44                 $COMPRESS -f $b
45             fi
46         }
47     done
48
49     for f in `find $d -type l`
50     do
51         l=`ls -l $f | sed -e 's/.* -> //' -e 's/\.\(gz\|Z\|bz2\|xz\|lzma\)$//'`
52         rm -f $f
53         b=`echo $f | sed -e 's/\.\(gz\|Z\|bz2\|xz\|lzma\)$//'`
54         ln -sf $l$COMPRESS_EXT $b$COMPRESS_EXT
55     done
56 done