diff --git a/pkgs/build-support/setup-hooks/multiple-outputs.sh b/pkgs/build-support/setup-hooks/multiple-outputs.sh new file mode 100644 index 00000000000..72cef7cf032 --- /dev/null +++ b/pkgs/build-support/setup-hooks/multiple-outputs.sh @@ -0,0 +1,51 @@ +preConfigureHooks+=(_multioutConfig) + +# Assign the first nonempty string to variable named $1 +_assignFirst() { + local varName="$1" + shift + while [ $# -ge 0 ]; do + if [ -n "$1" ]; then eval "${varName}"="$1"; return; fi + shift + done + return 1 # none found +} + +# Setup chains of sane default values with easy overridability. +# 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" + +_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 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" + +# Add standard flags to put files into the desired outputs. +_multioutConfig() { + if [ -n "${setOutputFlags-1}" ]; then + configureFlags="\ + --bindir=$outputBin/bin --sbindir=$outputBin/sbin --libexecdir=$outputBin/libexec \ + --includedir=$outputInclude/include --oldincludedir=$outputInclude/include \ + --mandir=$outputMan/share/man --infodir=$outputInfo/share/info --docdir=$outputDoc/share/doc \ + --libdir=$outputLib/lib \ + $configureFlags" + + installFlags="\ + pkgconfigdir=$outputDev/lib/pkgconfig \ + m4datadir=$outputDev/share/aclocal aclocaldir=$outputDev/share/aclocal \ + $installFlags" + fi +} + +# Add rpath prefixes to library paths, and avoid stdenv doing it for $out. +_addRpathPrefix "$outputLib" +NIX_NO_SELF_RPATH=1 + diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index ae308a01536..29f9f49a928 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -206,6 +206,12 @@ let inherit overrides; inherit gcc; + + # extra useful hooks, so we do not need to pass them as package arguments + hookLib = { + multiout = ../../build-support/setup-hooks/multiple-outputs.sh; + #ToDo: add also autoreconf = pkgs.autoreconfHook + }; } # Propagate any extra attributes. For instance, we use this to diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 5da7f773732..6291f4a367b 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -259,16 +259,19 @@ for i in $crossPkgs; do done -# Add the output as an rpath. ToDo: multiple-output? -if [ "$NIX_NO_SELF_RPATH" != 1 ]; then - export NIX_LDFLAGS="-rpath $out/lib $NIX_LDFLAGS" - if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then - export NIX_LDFLAGS="-rpath $out/lib64 $NIX_LDFLAGS" +# Add $1/lib* into rpaths. +_addRpathPrefix() { + if [ "$NIX_NO_SELF_RPATH" != 1 ]; then + export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS" + if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then + export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS" + fi + if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then + export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS" + fi fi - if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then - export NIX_LDFLAGS="-rpath $out/lib32 $NIX_LDFLAGS" - fi -fi +} +_addRpathPrefix "$out" # Set the TZ (timezone) environment variable, otherwise commands like