summary refs log tree commit diff
path: root/pkgs/development/libraries/qt-5/5.5/qmake-hook.sh
blob: 2669a396280f456b60753234b95df45adaea3f56 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
if [[ -z "$QMAKE" ]]; then

_qtLinkDependencyDir() {
    @lndir@/bin/lndir -silent "$1/$2" "$qtOut/$2"
    if [ -n "$NIX_QT_SUBMODULE" ]; then
        find "$1/$2" -printf "$2/%P\n" >> "$out/nix-support/qt-inputs"
    fi
}

_qtLinkModule() {
    if [ -d "$1/mkspecs" ]; then
        # $1 is a Qt module
        _qtLinkDependencyDir "$1" mkspecs

        for dir in bin include lib share; do
            if [ -d "$1/$dir" ]; then
                _qtLinkDependencyDir "$1" "$dir"
            fi
        done
    fi
}

_qtRmModules() {
    cat "$out/nix-support/qt-inputs" | while read file; do
      if [ -h "$out/$file" ]; then
        rm "$out/$file"
      fi
    done

    cat "$out/nix-support/qt-inputs" | while read file; do
      if [ -d "$out/$file" ]; then
        rmdir --ignore-fail-on-non-empty -p "$out/$file"
      fi
    done

    rm "$out/nix-support/qt-inputs"
}

_qtRmQmake() {
    rm "$qtOut/bin/qmake" "$qtOut/bin/qt.conf"
}

_qtSetQmakePath() {
    export PATH="$qtOut/bin${PATH:+:}$PATH"
}

_qtMultioutModuleDevs() {
    # We cannot simply set these paths in configureFlags because libQtCore retains
    # references to the paths it was built with.
    moveToOutput "bin" "${!outputDev}"
    moveToOutput "include" "${!outputDev}"

    # The destination directory must exist or moveToOutput will do nothing
    mkdir -p "${!outputDev}/share"
    moveToOutput "share/doc" "${!outputDev}"

    # Move libtool archives and qmake project files to $dev/lib
    if [ "z${!outputLib}" != "z${!outputDev}" ]; then
        pushd "${!outputLib}"
        if [ -d "lib" ]; then
            find lib \( -name '*.a' -o -name '*.la' -o -name '*.prl' -print0 \) | \
                while read -r -d $'\0' file; do
                    mkdir -p "${!outputDev}/$(dirname "$file")"
                    mv "${!outputLib}/$file" "${!outputDev}/$file"
                done
        fi
        popd
    fi
}

qmakeConfigurePhase() {
    runHook preConfigure

    qmake PREFIX=$out $qmakeFlags

    runHook postConfigure
}

qtOut=""
if [[ -z "$NIX_QT_SUBMODULE" ]]; then
    qtOut=`mktemp -d`
else
    qtOut=$out
fi

mkdir -p "$qtOut/bin" "$qtOut/mkspecs" "$qtOut/include" "$qtOut/nix-support" "$qtOut/lib" "$qtOut/share"

cp "@qt_dev@/bin/qmake" "$qtOut/bin"
cat >"$qtOut/bin/qt.conf" <<EOF
[Paths]
Prefix = $qtOut
Plugins = lib/qt5/plugins
Imports = lib/qt5/imports
Qml2Imports = lib/qt5/qml
Documentation = share/doc/qt5
EOF

export QMAKE="$qtOut/bin/qmake"

envHooks+=(_qtLinkModule)
# Set PATH to find qmake first in a preConfigure hook
# It must run after all the envHooks!
postHooks+=(_qtSetQmakePath)

if [ -z "$dontUseQmakeConfigure" -a -z "$configurePhase" ]; then
    configurePhase=qmakeConfigurePhase
fi

if [ -n "$NIX_QT_SUBMODULE" ]; then
    postInstallHooks+=(_qtRmQmake _qtRmModules)
    preFixupHooks+=(_qtMultioutModuleDevs)
fi

fi