about summary refs log tree commit diff
path: root/pkgs/development/libraries/qt-5/hooks
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@mailbox.org>2017-10-24 06:39:54 -0500
committerThomas Tuegel <ttuegel@mailbox.org>2017-11-07 07:18:46 -0600
commitfe0ab944db2176e6757ae89aeebea16ab8dc69d0 (patch)
tree9a9c8962bc6a3083900770c980a5b87666f89688 /pkgs/development/libraries/qt-5/hooks
parent4866f16fbadd2fcc702102944b990ff578379b0a (diff)
downloadnixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.gz
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.bz2
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.lz
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.xz
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.tar.zst
nixlib-fe0ab944db2176e6757ae89aeebea16ab8dc69d0.zip
qt5: factor out common definitions and remove symlink farm
The module definitions are factored out and shared between qt56 and qt59. The
symlink farm which was created during builds is no longer needed.
Diffstat (limited to 'pkgs/development/libraries/qt-5/hooks')
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh64
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh43
-rw-r--r--pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh32
-rw-r--r--pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh34
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qmake-hook.sh18
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh87
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh1
7 files changed, 279 insertions, 0 deletions
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh
new file mode 100644
index 000000000000..4ca11a223de2
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-builtin-paths.sh
@@ -0,0 +1,64 @@
+# fixQtBuiltinPaths
+#
+# Usage: fixQtBuiltinPaths _dir_ _pattern_
+#
+# Fix Qt builtin paths in files matching _pattern_ under _dir_.
+#
+fixQtBuiltinPaths() {
+    local dir="$1"
+    local pattern="$2"
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local doc="${!outputDoc}"
+    local lib="${!outputLib}"
+
+    if [ -d "$dir" ]; then
+        find "$dir" -name "$pattern" | while read pr_; do
+            if grep -q '\$\$\[QT_' "${pr_:?}"; then
+                echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${pr_:?}'..."
+                sed -i "${pr_:?}" \
+                    -e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
+                    -e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
+                    -e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
+                    -e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
+            fi
+        done
+    elif [ -e "$dir" ]; then
+        if grep -q '\$\$\[QT_' "${dir:?}"; then
+            echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${dir:?}'..."
+            sed -i "${dir:?}" \
+                -e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
+                -e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
+                -e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
+                -e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
+        fi
+    else
+        echo "fixQtBuiltinPaths: Warning: \`$dir' does not exist"
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh
new file mode 100644
index 000000000000..916981b5299f
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-module-paths.sh
@@ -0,0 +1,43 @@
+# fixQtModulePaths
+#
+# Usage: fixQtModulePaths _dir_
+#
+# Find Qt module definitions in directory _dir_ and patch the module paths.
+#
+fixQtModulePaths () {
+    local dir="$1"
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local lib="${!outputLib}"
+
+    if [ -d "$dir" ]; then
+        find "$dir" -name 'qt_*.pri' | while read pr; do
+            if grep -q '\$\$QT_MODULE_' "${pr:?}"; then
+                echo "fixQtModulePaths: Fixing module paths in \`${pr:?}'..."
+                sed -i "${pr:?}" \
+                    -e "s|\\\$\\\$QT_MODULE_LIB_BASE|$dev/lib|g" \
+                    -e "s|\\\$\\\$QT_MODULE_HOST_LIB_BASE|$dev/lib|g" \
+                    -e "s|\\\$\\\$QT_MODULE_INCLUDE_BASE|$dev/include|g" \
+                    -e "s|\\\$\\\$QT_MODULE_BIN_BASE|$dev/bin|g"
+            fi
+        done
+    elif [ -e "$dir" ]; then
+        echo "fixQtModulePaths: Warning: \`$dir' is not a directory"
+    else
+        echo "fixQtModulePaths: Warning: \`$dir' does not exist"
+    fi
+
+    if [ "z$dev" != "z$lib" ]; then
+        if [ -d "$lib/lib" ]; then
+            mkdir -p "$dev/lib"
+            lndir -silent "$lib/lib" "$dev/lib"
+        fi
+    fi
+
+    if [ "z$bin" != "z$dev" ]; then
+        if [ -d "$bin/bin" ]; then
+            mkdir -p "$dev/bin"
+            lndir -silent "$bin/bin" "$dev/bin"
+        fi
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh b/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh
new file mode 100644
index 000000000000..2a20e77e7ba7
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/fix-qt-static-libs.sh
@@ -0,0 +1,32 @@
+# fixQtStaticLibs
+#
+# Usage: fixQtStaticLibs _lib_ _dev_
+#
+# Find static Qt libraries in output _lib_ and move them to the corresponding
+# path in output _dev_. Any QMake library definitions (*.prl files) are also
+# moved and library paths are patched.
+#
+fixQtStaticLibs() {
+    local lib="$1"
+    local dev="$2"
+
+    pushd "$lib"
+    if [ -d "lib" ]; then
+        find lib \( -name '*.a' -o -name '*.la' -o -name '*.prl' \) -print0 | \
+            while read -r -d $'\0' file; do
+                mkdir -p "$dev/$(dirname "$file")"
+                mv "$lib/$file" "$dev/$file"
+            done
+    fi
+    popd
+
+    if [ -d "$dev" ]; then
+        find "$dev" -name '*.prl' | while read prl; do
+            echo "fixQtStaticLibs: Fixing built-in paths in \`$prl'..."
+            sed -i "$prl" \
+                -e '/^QMAKE_PRL_BUILD_DIR =/d' \
+                -e '/^QMAKE_PRO_INPUT =/d' \
+                -e "s|-L\\\$\\\$NIX_OUTPUT_OUT/lib|-L$lib/lib -L$dev/lib|g"
+        done
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh b/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh
new file mode 100644
index 000000000000..85489c85105b
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/move-qt-dev-tools.sh
@@ -0,0 +1,34 @@
+updateToolPath() {
+    local tool="$1"
+    local target="$2"
+    local original="${!outputBin}/$tool"
+    local actual="${!outputDev}/$tool"
+    if grep -q "$original" "$target"; then
+        echo "updateToolPath: Updating \`$original' in \`$target\'..."
+        sed -i "$target" -e "s|$original|$actual|"
+    fi
+}
+
+moveQtDevTools() {
+    if [ -n "$devTools" ]; then
+        for tool in $devTools; do
+            moveToOutput "$tool" "${!outputDev}"
+        done
+
+        if [ -d "${!outputDev}/mkspecs" ]; then
+            find "${!outputDev}/mkspecs" -name '*.pr?' | while read pr_; do
+                for tool in $devTools; do
+                    updateToolPath "$tool" "$pr_"
+                done
+            done
+        fi
+
+        if [ -d "${!outputDev}/lib/cmake" ]; then
+            find "${!outputDev}/lib/cmake" -name '*.cmake' | while read cmake; do
+                for tool in $devTools; do
+                    updateToolPath "$tool" "$cmake"
+                done
+            done
+        fi
+    fi
+}
diff --git a/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh b/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh
new file mode 100644
index 000000000000..17d3db65849e
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qmake-hook.sh
@@ -0,0 +1,18 @@
+qmakeConfigurePhase() {
+    runHook preConfigure
+
+    qmake PREFIX=$out \
+          NIX_OUTPUT_OUT=$out \
+          NIX_OUTPUT_DEV=${!outputDev} \
+          NIX_OUTPUT_BIN=${!outputBin} \
+          NIX_OUTPUT_DOC=${!outputDev}/${qtDocPrefix:?} \
+          NIX_OUTPUT_QML=${!outputBin}/${qtQmlPrefix:?} \
+          NIX_OUTPUT_PLUGIN=${!outputBin}/${qtPluginPrefix:?} \
+          $qmakeFlags
+
+    runHook postConfigure
+}
+
+if [ -z "$dontUseQmakeConfigure" -a -z "$configurePhase" ]; then
+    configurePhase=qmakeConfigurePhase
+fi
diff --git a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
new file mode 100644
index 000000000000..258b2d09f20b
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
@@ -0,0 +1,87 @@
+qtPluginPrefix=@qtPluginPrefix@
+qtQmlPrefix=@qtQmlPrefix@
+qtDocPrefix=@qtDocPrefix@
+
+. @fix_qt_builtin_paths@
+. @fix_qt_module_paths@
+. @fix_qt_static_libs@
+
+providesQtRuntime() {
+    [ -d "$1/$qtPluginPrefix" ] || [ -d "$1/$qtQmlPrefix" ]
+}
+
+# Build tools are often confused if QMAKE is unset.
+QMAKE=@dev@/bin/qmake
+export QMAKE
+
+QMAKEPATH=
+export QMAKEPATH
+
+QMAKEMODULES=
+export QMAKEMODULES
+
+addToQMAKEPATH() {
+    if [ -d "$1/mkspecs" ]; then
+        QMAKEMODULES="${QMAKEMODULES}${QMAKEMODULES:+:}/mkspecs"
+        QMAKEPATH="${QMAKEPATH}${QMAKEPATH:+:}$1"
+    fi
+}
+
+# Propagate any runtime dependency of the building package.
+# Each dependency is propagated to the user environment and as a build
+# input so that it will be re-propagated to the user environment by any
+# package depending on the building package. (This is necessary in case
+# the building package does not provide runtime dependencies itself and so
+# would not be propagated to the user environment.)
+qtCrossEnvHook() {
+    addToQMAKEPATH "$1"
+    if providesQtRuntime "$1"; then
+        if [ "z${!outputBin}" != "z${!outputDev}" ]; then
+            propagatedBuildInputs+=" $1"
+        fi
+        propagatedUserEnvPkgs+=" $1"
+    fi
+}
+crossEnvHooks+=(qtCrossEnvHook)
+
+qtEnvHook() {
+    addToQMAKEPATH "$1"
+    if providesQtRuntime "$1"; then
+        if [ "z${!outputBin}" != "z${!outputDev}" ]; then
+            propagatedNativeBuildInputs+=" $1"
+        fi
+        if [ -z "$crossConfig" ]; then
+        propagatedUserEnvPkgs+=" $1"
+        fi
+    fi
+}
+envHooks+=(qtEnvHook)
+
+postPatchMkspecs() {
+    local bin="${!outputBin}"
+    local dev="${!outputDev}"
+    local doc="${!outputDoc}"
+    local lib="${!outputLib}"
+
+    moveToOutput "mkspecs" "$dev"
+
+    if [ -d "$dev/mkspecs/modules" ]; then
+        fixQtModulePaths "$dev/mkspecs/modules"
+    fi
+
+    if [ -d "$dev/mkspecs" ]; then
+        fixQtBuiltinPaths "$dev/mkspecs" '*.pr?'
+    fi
+}
+if [ -z "$dontPatchMkspecs" ]; then
+    postPhases="${postPhases}${postPhases:+ }postPatchMkspecs"
+fi
+
+postMoveQtStaticLibs() {
+    if [ "z${!outputLib}" != "z${!outputDev}" ]; then
+        fixQtStaticLibs "${!outputLib}" "${!outputDev}"
+    fi
+}
+if [ -z "$dontMoveQtStaticLibs" ]; then
+    postPhases="${postPhases}${postPhases:+ }postMoveQtStaticLibs"
+fi
diff --git a/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh
new file mode 100644
index 000000000000..b09cf5f46c9c
--- /dev/null
+++ b/pkgs/development/libraries/qt-5/hooks/qttools-setup-hook.sh
@@ -0,0 +1 @@
+qmakeFlags="$qmakeFlags${qmakeFlags:+ }QMAKE_LRELEASE=@dev@/bin/lrelease"