summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks
diff options
context:
space:
mode:
authorMaxim Ivanov <ivanov.maxim@gmail.com>2014-05-06 22:41:49 +0100
committerMaxim Ivanov <ivanov.maxim@gmail.com>2014-05-06 22:47:45 +0100
commite2e77950f3f1ca560fbffe4351b98a9e75c4c685 (patch)
tree0d3587a31422bdbdb7d181922cae151e9130f4d5 /pkgs/build-support/setup-hooks
parent5b4006cddb23c82a1d132d273db3833698f3d880 (diff)
downloadnixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar.gz
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar.bz2
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar.lz
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar.xz
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.tar.zst
nixlib-e2e77950f3f1ca560fbffe4351b98a9e75c4c685.zip
Scatter output hook
This hook allows to scatter files in $out to multiple outputs.
For "bin" and "doc" outputs there are prefefined default masks, but
they can be overriden by setting files_<outname>, for example:

files_bin = [ "/bin/*" "/lib/libexec/" ];

To make an effect hook must be specified in buildInputs.
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/scatter_output.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/scatter_output.sh b/pkgs/build-support/setup-hooks/scatter_output.sh
new file mode 100644
index 000000000000..79118392094d
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/scatter_output.sh
@@ -0,0 +1,56 @@
+preFixupPhases+=" scatter_files"
+preDistPhases+=" propagate_bin_input"
+
+SCATTER_BIN_DEFAULT=${SCATTER_BIN_DEFAULT:-"/lib/*.so* /bin/*"}
+SCATTER_DOC_DEFAULT=${SCATTER_DOC_DEFAULT:-"/share/man/* /share/doc/*"}
+
+
+scatter_files() {
+    save_nullglob=$(shopt -p nullglob)
+    for o in $outputs; do
+	[[ "$o" == "out" ]] && continue
+	v=files_${o}
+	
+	#if files_'output' isn't set in derivative, use defualts for some
+	[[ ${!v} ]] || {
+            case $o in
+		bin)
+		    v=SCATTER_BIN_DEFAULT
+		    ;;
+		doc)
+		    v=SCATTER_DOC_DEFAULT
+		    ;;
+		*)
+		    continue
+		    ;;
+	    esac
+        }
+
+	# prepend each path with $out
+	paths=$out${!v// \// $out/}
+        shopt -s nullglob
+	for f in $paths; do
+	    shopt -u nullglob
+	    dist=${!o}${f#$out}
+	    mkdir -p $(dirname $dist)
+	    cp -pr $f $dist
+	    # remove source, not forgetting to clean empty dirs
+	    rm -r $f
+	    rmdir --ignore-fail-on-non-empty $(dirname $f)
+	done
+	find ${!o} -type f -exec /bin/sh -c 'patchelf --set-rpath $(patchelf --print-rpath {} 2>/dev/null):'${!o}'/lib {} 2>/dev/null && patchelf --shrink-rpath {}' \;
+    done
+    eval $save_nullglob
+}
+
+propagate_bin_input() {
+    if [[ -n ${bin:-} ]]; then
+	mkdir -p $out/nix-support
+	echo $bin >> $out/nix-support/propagated-native-build-inputs 
+    fi
+
+    if [[ -n ${bin:-} && -n ${doc:-} ]]; then
+	mkdir -p $bin/nix-support
+	echo $doc >> $bin/nix-support/propagated-user-env-packages
+    fi
+}