summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/move-docs.sh
blob: c819ee12a9c9ba463ee6b1e6a8b7bd5f153dcef5 (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This setup hook moves $out/{man,doc,info} to $out/share; moves
# $out/share/man to $man/share/man; and moves $out/share/doc to
# $man/share/doc.

preFixupHooks+=(_moveDocs)

_moveToShare() {
    forceShare=${forceShare:=man doc info}
    if [ -z "$forceShare" -o -z "$out" ]; then return; fi

    for d in $forceShare; do
        if [ -d "$out/$d" ]; then
            if [ -d "$out/share/$d" ]; then
                echo "both $d/ and share/$d/ exist!"
            else
                echo "moving $out/$d to $out/share/$d"
                mkdir -p $out/share
                mv $out/$d $out/share/
            fi
        fi
    done
}

_moveToOutput() {
    local d="$1"
    local dst="$2"
    if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi
    local output
    for output in $outputs; do
        if [ "${!output}" = "$dst" ]; then continue; fi
        if [ -d "${!output}/$d" ]; then
            echo "moving ${!output}/$d to $dst/$d"
            mkdir -p $dst/share
            mv ${!output}/$d $dst/$d
            break
        fi
    done
}

_moveDocs() {
    _moveToShare
    _moveToOutput share/man "$man"
    _moveToOutput share/info "$info"
    _moveToOutput share/doc "$doc"

    # Remove empty share directory.
    if [ -d "$out/share" ]; then
        rmdir $out/share 2> /dev/null || true
    fi
}