summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/setup-hooks/compress-man-pages.sh
blob: 77b2eb2d83fa4cb7234789c5d7d62593785a9380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fixupOutputHooks+=('if [ -z "${dontGzipMan-}" ]; then compressManPages "$prefix"; fi')

compressManPages() {
    local dir="$1"

    if [ -L "$dir"/share ] || [ -L "$dir"/share/man ] || [ ! -d "$dir/share/man" ]
        then return
    fi
    echo "gzipping man pages under $dir/share/man/"

    # Compress all uncompressed manpages.  Don't follow symlinks, etc.
    # gzip -f is needed to not error out on hard links.
    find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \
        | xargs -0 -n1 -P "$NIX_BUILD_CORES" gzip -n -f

    # Point symlinks to compressed manpages.
    find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \
        | sort -z \
        | while IFS= read -r -d $'\0' f
    do
        local target
        target="$(readlink -f "$f")"
        if [ -f "$target".gz ]; then
            ln -sf "$target".gz "$f".gz && rm "$f"
        fi
    done
}