2014-08-30 17:53:24 +04:00
|
|
|
# The base package for automatic multiple-output splitting. Used in stdenv as well.
|
|
|
|
|
2014-08-24 21:05:56 +04:00
|
|
|
preConfigureHooks+=(_multioutConfig)
|
2014-08-25 17:30:46 +04:00
|
|
|
preFixupHooks+=(_multioutDocs)
|
2014-08-27 03:14:09 +04:00
|
|
|
preFixupHooks+=(_multioutDevs)
|
2014-08-25 17:30:46 +04:00
|
|
|
postFixupHooks+=(_multioutPropagateDev)
|
|
|
|
|
2014-08-27 03:14:09 +04:00
|
|
|
# Assign the first string containing nonempty variable to the variable named $1
|
2014-08-24 21:05:56 +04:00
|
|
|
_assignFirst() {
|
|
|
|
local varName="$1"
|
|
|
|
shift
|
2014-08-27 03:14:09 +04:00
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
if [ -n "${!1}" ]; then eval "${varName}"="$1"; return; fi
|
2014-08-24 21:05:56 +04:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
return 1 # none found
|
|
|
|
}
|
2014-08-30 10:43:46 +04:00
|
|
|
# Same as _assignFirst, but only if "$1" = ""
|
|
|
|
_overrideFirst() {
|
|
|
|
if [ -z "${!1}" ]; then
|
|
|
|
_assignFirst "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-08-24 21:05:56 +04:00
|
|
|
|
|
|
|
# Setup chains of sane default values with easy overridability.
|
|
|
|
# The variables are global to be usable anywhere during the build.
|
2014-08-27 03:14:09 +04:00
|
|
|
|
2014-08-30 10:43:46 +04:00
|
|
|
_overrideFirst outputDev "dev" "out"
|
|
|
|
_overrideFirst outputBin "bin" "out"
|
2014-08-24 21:05:56 +04:00
|
|
|
|
2014-08-30 10:43:46 +04:00
|
|
|
_overrideFirst outputInclude "$outputDev"
|
2014-08-24 21:05:56 +04:00
|
|
|
|
|
|
|
# so-libs are often among the main things to keep, and so go to $out
|
2014-08-30 10:43:46 +04:00
|
|
|
_overrideFirst outputLib "lib" "out"
|
2014-08-24 21:05:56 +04:00
|
|
|
|
2014-08-30 10:43:46 +04:00
|
|
|
_overrideFirst outputDoc "doc" "out"
|
2014-08-24 21:05:56 +04:00
|
|
|
# man and info pages are small and often useful to distribute with binaries
|
2014-08-30 10:43:46 +04:00
|
|
|
_overrideFirst outputMan "man" "doc" "$outputBin"
|
|
|
|
_overrideFirst outputInfo "info" "doc" "$outputMan"
|
2014-08-27 03:14:09 +04:00
|
|
|
|
2014-08-25 17:30:46 +04:00
|
|
|
|
2014-08-24 21:05:56 +04:00
|
|
|
# Add standard flags to put files into the desired outputs.
|
|
|
|
_multioutConfig() {
|
2014-08-30 17:53:24 +04:00
|
|
|
if [ "$outputs" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi;
|
2014-08-27 03:14:09 +04:00
|
|
|
|
|
|
|
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"
|
2014-08-24 21:05:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add rpath prefixes to library paths, and avoid stdenv doing it for $out.
|
2014-08-27 03:14:09 +04:00
|
|
|
_addRpathPrefix "${!outputLib}"
|
2014-08-24 21:05:56 +04:00
|
|
|
NIX_NO_SELF_RPATH=1
|
|
|
|
|
2014-08-27 03:14:09 +04:00
|
|
|
|
|
|
|
# Move subpaths that match pattern $1 from under any output/ to the $2 output/
|
2015-04-18 16:46:00 +03:00
|
|
|
# Beware: only * ? [..] patterns are accepted.
|
2014-08-27 03:14:09 +04:00
|
|
|
_moveToOutput() {
|
|
|
|
local patt="$1"
|
|
|
|
local dstOut="$2"
|
|
|
|
local output
|
|
|
|
for output in $outputs; do
|
2014-08-30 17:53:24 +04:00
|
|
|
if [ "${!output}" = "$dstOut" ]; then continue; fi
|
2014-08-27 03:14:09 +04:00
|
|
|
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.
|
2014-08-25 17:30:46 +04:00
|
|
|
_multioutDocs() {
|
2014-08-30 17:53:24 +04:00
|
|
|
if [ "$outputs" = "out" ]; then return; fi;
|
2014-08-27 03:14:09 +04:00
|
|
|
echo "Looking for documentation to move between outputs"
|
|
|
|
_moveToOutput share/man "${!outputMan}"
|
|
|
|
_moveToOutput share/info "${!outputInfo}"
|
|
|
|
_moveToOutput share/doc "${!outputDoc}"
|
2015-10-03 14:33:13 +03:00
|
|
|
# outputs TODO: perhaps have outputDevDoc for developer docs
|
|
|
|
# and maybe allow _moveToOutput move to "/dev/trash" or similar
|
|
|
|
_moveToOutput share/gtk-doc "${!outputDoc}"
|
2014-08-25 17:30:46 +04:00
|
|
|
|
|
|
|
# Remove empty share directory.
|
|
|
|
if [ -d "$out/share" ]; then
|
2015-10-03 14:33:13 +03:00
|
|
|
rmdir "$out/share" --ignore-fail-on-non-empty
|
2014-08-25 17:30:46 +04:00
|
|
|
fi
|
|
|
|
}
|
2014-08-27 03:14:09 +04:00
|
|
|
|
|
|
|
# Move development-only stuff to the desired outputs.
|
|
|
|
_multioutDevs() {
|
2014-08-30 17:53:24 +04:00
|
|
|
if [ "$outputs" = "out" ] || [ -z "${moveToDev-1}" ]; then return; fi;
|
2015-04-18 16:46:00 +03:00
|
|
|
echo "Looking for development-only stuff to move to $outputDev"
|
2014-08-27 03:14:09 +04:00
|
|
|
_moveToOutput include "${!outputInclude}"
|
|
|
|
_moveToOutput lib/pkgconfig "${!outputDev}"
|
2015-04-18 16:46:00 +03:00
|
|
|
_moveToOutput share/pkgconfig "${!outputDev}"
|
|
|
|
|
|
|
|
# don't move libtool files yet
|
|
|
|
#_moveToOutput "lib/*.la" "${!outputDev}"
|
2014-08-31 01:29:23 +04:00
|
|
|
|
2015-04-18 16:46:00 +03:00
|
|
|
for f in "${!outputDev}"/{lib,share}/pkgconfig/*.pc; do
|
|
|
|
echo "Patching '$f' includedir to output ${!outputInclude}"
|
2014-08-31 01:29:23 +04:00
|
|
|
sed -i "/^includedir=/s,=\${prefix},=${!outputInclude}," "$f"
|
|
|
|
done
|
2014-08-25 17:30:46 +04:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:00 +03:00
|
|
|
# Make the first output (typically "dev") propagate other outputs needed for development.
|
|
|
|
# Take the first, because that's what one gets when putting the package into buildInputs.
|
2014-08-27 03:14:09 +04:00
|
|
|
# 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.
|
2014-08-25 17:30:46 +04:00
|
|
|
_multioutPropagateDev() {
|
2014-08-30 17:53:24 +04:00
|
|
|
if [ "$outputs" = "out" ]; then return; fi;
|
|
|
|
|
2015-04-18 16:46:00 +03:00
|
|
|
local outputFirst
|
|
|
|
for outputFirst in $outputs; do
|
|
|
|
break
|
|
|
|
done
|
|
|
|
|
|
|
|
# Default value: propagate binaries, includes and libraries
|
2015-08-23 21:29:00 +03:00
|
|
|
if [ -z "${propagatedOutputs+1}" ]; then
|
2015-04-18 16:46:00 +03:00
|
|
|
local po_dirty="$outputBin $outputInclude $outputLib"
|
2015-08-20 02:53:31 +03:00
|
|
|
set +o pipefail
|
2015-04-18 16:46:00 +03:00
|
|
|
propagatedOutputs=`echo "$po_dirty" \
|
|
|
|
| tr -s ' ' '\n' | grep -v -F "$outputFirst" \
|
|
|
|
| sort -u | tr '\n' ' ' `
|
2015-08-20 02:53:31 +03:00
|
|
|
set -o pipefail
|
2015-04-18 16:46:00 +03:00
|
|
|
|
|
|
|
elif [ -z "$propagatedOutputs" ]; then
|
|
|
|
return # variable was explicitly set to empty
|
2014-08-25 17:30:46 +04:00
|
|
|
fi
|
2015-04-18 16:46:00 +03:00
|
|
|
|
|
|
|
mkdir -p "${!outputFirst}"/nix-support
|
|
|
|
for output in $propagatedOutputs; do
|
|
|
|
echo -n " ${!output}" >> "${!outputFirst}"/nix-support/propagated-native-build-inputs
|
|
|
|
done
|
2014-08-25 17:30:46 +04:00
|
|
|
}
|
|
|
|
|