summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/multiple-outputs.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/setup-hooks/multiple-outputs.sh')
-rw-r--r--pkgs/build-support/setup-hooks/multiple-outputs.sh125
1 files changed, 78 insertions, 47 deletions
diff --git a/pkgs/build-support/setup-hooks/multiple-outputs.sh b/pkgs/build-support/setup-hooks/multiple-outputs.sh
index ac83a7cca3d..b3274c88cd7 100644
--- a/pkgs/build-support/setup-hooks/multiple-outputs.sh
+++ b/pkgs/build-support/setup-hooks/multiple-outputs.sh
@@ -1,14 +1,15 @@
 preConfigureHooks+=(_multioutConfig)
 preFixupHooks+=(_multioutDocs)
+preFixupHooks+=(_multioutDevs)
 postFixupHooks+=(_multioutPropagateDev)
 
 
-# Assign the first nonempty string to variable named $1
+# Assign the first string containing nonempty variable to the variable named $1
 _assignFirst() {
     local varName="$1"
     shift
-    while [ $# -ge 0 ]; do
-        if [ -n "$1" ]; then eval "${varName}"="$1"; return; fi
+    while [ $# -ge 1 ]; do
+        if [ -n "${!1}" ]; then eval "${varName}"="$1"; return; fi
         shift
     done
     return 1 # none found
@@ -18,78 +19,108 @@ _assignFirst() {
 # The variables are global to be usable anywhere during the build.
 # ToDo: I was unable to get rid of the double-name redundancy (I hate bash eval ways)
 
-_assignFirst outputDev "$outputDev" "$dev" "$out"
-_assignFirst outputBin "$outputBin" "$bin" "$out"
+# ToDo: easy way of overriding from withing mkDerivation attrset
+
+_assignFirst outputDev "$outputDev" "dev" "out"
+_assignFirst outputBin "$outputBin" "bin" "out"
 
 _assignFirst outputInclude "$outputInclude" "$outputDev"
 
 # so-libs are often among the main things to keep, and so go to $out
-_assignFirst outputLib "$outputLib" "$lib" "$out"
+_assignFirst outputLib "$outputLib" "lib" "out"
 
-_assignFirst outputDoc "$outputDoc" "$doc" "$out"
+_assignFirst outputDoc "$outputDoc" "doc" "out"
 # man and info pages are small and often useful to distribute with binaries
-_assignFirst outputMan "$outputMan" "$man" "$outputBin"
-_assignFirst outputInfo "$outputInfo" "$info" "$outputMan"
+_assignFirst outputMan "$outputMan" "man" "doc" "$outputBin"
+_assignFirst outputInfo "$outputInfo" "info" "doc" "$outputMan"
+
+# Make stdenv put propagated*BuildInputs into $outputDev instead of $out
+propagateIntoOutput="${!outputDev}"
 
-# put propagated*BuildInputs into $outputDev instead of $out
-propagateIntoOutput="$outputDev"
 
 # Add standard flags to put files into the desired outputs.
 _multioutConfig() {
-    if [ -n "${setOutputFlags-1}" ]; then
-        configureFlags="\
-            --bindir=$outputBin/bin --sbindir=$outputBin/sbin \
-            --includedir=$outputInclude/include --oldincludedir=$outputInclude/include \
-            --mandir=$outputMan/share/man --infodir=$outputInfo/share/info --docdir=$outputDoc/share/doc \
-            --libdir=$outputLib/lib --libexecdir=$outputLib/libexec \
-            $configureFlags"
-
-        installFlags="\
-            pkgconfigdir=$outputDev/lib/pkgconfig \
-            m4datadir=$outputDev/share/aclocal aclocaldir=$outputDev/share/aclocal \
-            $installFlags"
-    fi
+    if [ -z "${setOutputFlags-1}" ]; then return; fi;
+
+    configureFlags="\
+        --bindir=${!outputBin}/bin --sbindir=${!outputBin}/sbin \
+        --includedir=${!outputInclude}/include --oldincludedir=${!outputInclude}/include \
+        --mandir=${!outputMan}/share/man --infodir=${!outputInfo}/share/info \
+        --docdir=${!outputDoc}/share/doc \
+        --libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \
+        $configureFlags"
+
+    installFlags="\
+        pkgconfigdir=${!outputDev}/lib/pkgconfig \
+        m4datadir=${!outputDev}/share/aclocal aclocaldir=${!outputDev}/share/aclocal \
+        $installFlags"
 }
 
 # Add rpath prefixes to library paths, and avoid stdenv doing it for $out.
-_addRpathPrefix "$outputLib"
+_addRpathPrefix "${!outputLib}"
 NIX_NO_SELF_RPATH=1
 
-# Move documentation into the desired outputs.
+
+# Move subpaths that match pattern $1 from under any output/ to the $2 output/
+_moveToOutput() {
+    local patt="$1"
+    local dstOut="$2"
+    echo "XXX: m2o '$1' '$2'"
+    local output
+    for output in $outputs; do
+        echo "XXX: output='$output'"
+        if [ "${output}" = "$dstOut" ]; then continue; fi
+        local srcPath
+        for srcPath in ${!output}/$patt; do
+            if [ ! -e "$srcPath" ]; then continue; fi
+            local dstPath="$dstOut${srcPath#${!output}}"
+            echo "moving $srcPath to $dstPath"
+
+            if [ -d "$dstPath" ] && [ -d "$srcPath" ]
+            then # attempt directory merge
+                mv -t "$dstPath" "$srcPath"/*
+                rmdir "$srcPath"
+            else # usual move
+                mkdir -p $(readlink -m "$dstPath/..") # create the parent for $dstPath
+                mv "$srcPath" "$dstPath"
+            fi
+        done
+    done
+}
+
+# Move documentation to the desired outputs.
 _multioutDocs() {
-    _moveToOutput share/man "$outputMan"
-    _moveToOutput share/info "$outputInfo"
-    _moveToOutput share/doc "$outputDoc"
+    echo "Looking for documentation to move between outputs"
+    _moveToOutput share/man "${!outputMan}"
+    _moveToOutput share/info "${!outputInfo}"
+    _moveToOutput share/doc "${!outputDoc}"
 
     # Remove empty share directory.
     if [ -d "$out/share" ]; then
         rmdir "$out/share" 2> /dev/null || true
     fi
 }
-_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
+
+# Move development-only stuff to the desired outputs.
+_multioutDevs() {
+    if [ -z "${moveToDev-1}" ]; then return; fi;
+    echo "Looking for development-only stuff to move between outputs"
+    _moveToOutput include "${!outputInclude}"
+    _moveToOutput lib/pkgconfig "${!outputDev}"
+    _moveToOutput "lib/*.la" "${!outputDev}"
 }
 
+# Make ${!outputDev} propagate other outputs needed for development
+# Note: during the build, probably only the "native" development packages are useful.
+# With current cross-building setup, all packages are "native" if not cross-building.
 _multioutPropagateDev() {
-    if [ "$outputInclude" != "$propagateIntoOutput" ]; then
+    if [ "${!outputInclude}" != "$propagateIntoOutput" ]; then
         mkdir -p "$propagateIntoOutput"/nix-support
-        echo -n " $outputInclude" >> "$propagateIntoOutput"/nix-support/propagated-native-build-inputs
+        echo -n " ${!outputInclude}" >> "$propagateIntoOutput"/nix-support/propagated-native-build-inputs
     fi
-    if [ "$outputLib" != "$propagateIntoOutput" ]; then
+    if [ "${!outputLib}" != "$propagateIntoOutput" ]; then
         mkdir -p "$propagateIntoOutput"/nix-support
-        echo -n " $outputLib" >> "$propagateIntoOutput"/nix-support/propagated-native-build-inputs
+        echo -n " ${!outputLib}" >> "$propagateIntoOutput"/nix-support/propagated-native-build-inputs
     fi
 }