2014-08-30 15:53:24 +02:00
|
|
|
# The base package for automatic multiple-output splitting. Used in stdenv as well.
|
2014-08-24 19:05:56 +02:00
|
|
|
preConfigureHooks+=(_multioutConfig)
|
2014-08-25 15:30:46 +02:00
|
|
|
preFixupHooks+=(_multioutDocs)
|
2014-08-27 01:14:09 +02:00
|
|
|
preFixupHooks+=(_multioutDevs)
|
2014-08-25 15:30:46 +02:00
|
|
|
postFixupHooks+=(_multioutPropagateDev)
|
|
|
|
|
2014-08-27 01:14:09 +02:00
|
|
|
# Assign the first string containing nonempty variable to the variable named $1
|
2014-08-24 19:05:56 +02:00
|
|
|
_assignFirst() {
|
|
|
|
local varName="$1"
|
2015-10-25 11:26:51 +01:00
|
|
|
local REMOVE=REMOVE # slightly hacky - we allow REMOVE (i.e. not a variable name)
|
2014-08-24 19:05:56 +02:00
|
|
|
shift
|
2014-08-27 01:14:09 +02:00
|
|
|
while [ $# -ge 1 ]; do
|
|
|
|
if [ -n "${!1}" ]; then eval "${varName}"="$1"; return; fi
|
2014-08-24 19:05:56 +02:00
|
|
|
shift
|
|
|
|
done
|
2015-10-25 11:26:51 +01:00
|
|
|
echo "Error: _assignFirst found no valid variant!"
|
2014-08-24 19:05:56 +02:00
|
|
|
return 1 # none found
|
|
|
|
}
|
2014-08-30 08:43:46 +02:00
|
|
|
# Same as _assignFirst, but only if "$1" = ""
|
|
|
|
_overrideFirst() {
|
|
|
|
if [ -z "${!1}" ]; then
|
|
|
|
_assignFirst "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-08-24 19:05:56 +02:00
|
|
|
|
|
|
|
# Setup chains of sane default values with easy overridability.
|
|
|
|
# The variables are global to be usable anywhere during the build.
|
2015-10-15 13:37:03 +02:00
|
|
|
# Typical usage in package is defining outputBin = "dev";
|
2014-08-27 01:14:09 +02:00
|
|
|
|
2014-08-30 08:43:46 +02:00
|
|
|
_overrideFirst outputDev "dev" "out"
|
|
|
|
_overrideFirst outputBin "bin" "out"
|
2014-08-24 19:05:56 +02:00
|
|
|
|
2014-08-30 08:43:46 +02:00
|
|
|
_overrideFirst outputInclude "$outputDev"
|
2014-08-24 19:05:56 +02:00
|
|
|
|
|
|
|
# so-libs are often among the main things to keep, and so go to $out
|
2014-08-30 08:43:46 +02:00
|
|
|
_overrideFirst outputLib "lib" "out"
|
2014-08-24 19:05:56 +02:00
|
|
|
|
2014-08-30 08:43:46 +02:00
|
|
|
_overrideFirst outputDoc "doc" "out"
|
2015-10-25 11:26:51 +01:00
|
|
|
_overrideFirst outputDocdev "docdev" REMOVE # documentation for developers
|
2014-08-24 19:05:56 +02:00
|
|
|
# man and info pages are small and often useful to distribute with binaries
|
2014-08-30 08:43:46 +02:00
|
|
|
_overrideFirst outputMan "man" "doc" "$outputBin"
|
|
|
|
_overrideFirst outputInfo "info" "doc" "$outputMan"
|
2014-08-27 01:14:09 +02:00
|
|
|
|
2014-08-25 15:30:46 +02:00
|
|
|
|
2014-08-24 19:05:56 +02:00
|
|
|
# Add standard flags to put files into the desired outputs.
|
|
|
|
_multioutConfig() {
|
2014-08-30 15:53:24 +02:00
|
|
|
if [ "$outputs" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi;
|
2014-08-27 01:14:09 +02:00
|
|
|
|
2016-04-18 08:50:34 +02:00
|
|
|
# try to detect share/doc/${shareDocName}
|
|
|
|
# Note: sadly, $configureScript detection comes later in configurePhase,
|
|
|
|
# and reordering would cause more trouble than worth.
|
|
|
|
if [ -z "$shareDocName" ]; then
|
|
|
|
local confScript="$configureScript"
|
|
|
|
if [ -z "$confScript" ] && [ -x ./configure ]; then
|
|
|
|
confScript=./configure
|
|
|
|
fi
|
|
|
|
if [ -f "$confScript" ]; then
|
|
|
|
local shareDocName="$(sed -n "s/^PACKAGE_TARNAME='\(.*\)'$/\1/p" < "$confScript")"
|
|
|
|
fi
|
|
|
|
# PACKAGE_TARNAME sometimes contains garbage.
|
|
|
|
if [ -n "$shareDocName" ] || echo "$shareDocName" | grep -q '[^a-zA-Z-_0-9]'; then
|
|
|
|
shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-08-27 01:14:09 +02:00
|
|
|
configureFlags="\
|
|
|
|
--bindir=${!outputBin}/bin --sbindir=${!outputBin}/sbin \
|
|
|
|
--includedir=${!outputInclude}/include --oldincludedir=${!outputInclude}/include \
|
|
|
|
--mandir=${!outputMan}/share/man --infodir=${!outputInfo}/share/info \
|
2016-04-18 08:50:34 +02:00
|
|
|
--docdir=${!outputDoc}/share/doc/${shareDocName} \
|
2014-08-27 01:14:09 +02:00
|
|
|
--libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \
|
2015-10-15 13:37:03 +02:00
|
|
|
--localedir=${!outputLib}/share/locale \
|
2014-08-27 01:14:09 +02:00
|
|
|
$configureFlags"
|
|
|
|
|
|
|
|
installFlags="\
|
|
|
|
pkgconfigdir=${!outputDev}/lib/pkgconfig \
|
|
|
|
m4datadir=${!outputDev}/share/aclocal aclocaldir=${!outputDev}/share/aclocal \
|
|
|
|
$installFlags"
|
2014-08-24 19:05:56 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 08:50:34 +02:00
|
|
|
|
2014-08-24 19:05:56 +02:00
|
|
|
# Add rpath prefixes to library paths, and avoid stdenv doing it for $out.
|
2014-08-27 01:14:09 +02:00
|
|
|
_addRpathPrefix "${!outputLib}"
|
2014-08-24 19:05:56 +02:00
|
|
|
NIX_NO_SELF_RPATH=1
|
|
|
|
|
2014-08-27 01:14:09 +02:00
|
|
|
|
|
|
|
# Move subpaths that match pattern $1 from under any output/ to the $2 output/
|
2015-10-15 13:37:03 +02:00
|
|
|
# Beware: only globbing patterns are accepted, e.g.: * ? {foo,bar}
|
2015-12-02 10:03:23 +01:00
|
|
|
# A special target "REMOVE" is allowed: moveToOutput foo REMOVE
|
|
|
|
moveToOutput() {
|
2014-08-27 01:14:09 +02:00
|
|
|
local patt="$1"
|
|
|
|
local dstOut="$2"
|
|
|
|
local output
|
|
|
|
for output in $outputs; do
|
2014-08-30 15:53:24 +02:00
|
|
|
if [ "${!output}" = "$dstOut" ]; then continue; fi
|
2014-08-27 01:14:09 +02:00
|
|
|
local srcPath
|
2015-10-25 11:26:51 +01:00
|
|
|
for srcPath in "${!output}"/$patt; do
|
2014-08-27 01:14:09 +02:00
|
|
|
if [ ! -e "$srcPath" ]; then continue; fi
|
2015-10-25 11:26:51 +01:00
|
|
|
|
|
|
|
if [ "$dstOut" = REMOVE ]; then
|
|
|
|
echo "Removing $srcPath"
|
|
|
|
rm -r "$srcPath"
|
|
|
|
else
|
|
|
|
local dstPath="$dstOut${srcPath#${!output}}"
|
|
|
|
echo "Moving $srcPath to $dstPath"
|
|
|
|
|
|
|
|
if [ -d "$dstPath" ] && [ -d "$srcPath" ]
|
|
|
|
then # attempt directory merge
|
|
|
|
# check the case of trying to move an empty directory
|
|
|
|
rmdir "$srcPath" --ignore-fail-on-non-empty
|
|
|
|
if [ -d "$srcPath" ]; then
|
|
|
|
mv -t "$dstPath" "$srcPath"/*
|
|
|
|
rmdir "$srcPath"
|
|
|
|
fi
|
|
|
|
else # usual move
|
|
|
|
mkdir -p "$(readlink -m "$dstPath/..")"
|
|
|
|
mv "$srcPath" "$dstPath"
|
|
|
|
fi
|
2014-08-27 01:14:09 +02:00
|
|
|
fi
|
2015-10-25 11:23:51 +01:00
|
|
|
|
|
|
|
# remove empty directories, printing iff at least one gets removed
|
|
|
|
local srcParent="$(readlink -m "$srcPath/..")"
|
|
|
|
if rmdir "$srcParent"; then
|
|
|
|
echo "Removing empty $srcParent/ and (possibly) its parents"
|
2015-10-25 11:26:51 +01:00
|
|
|
rmdir -p --ignore-fail-on-non-empty "$(readlink -m "$srcParent/..")" \
|
2016-01-02 11:18:27 +01:00
|
|
|
2> /dev/null || true # doesn't ignore failure for some reason
|
2015-10-25 11:23:51 +01:00
|
|
|
fi
|
2014-08-27 01:14:09 +02:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Move documentation to the desired outputs.
|
2014-08-25 15:30:46 +02:00
|
|
|
_multioutDocs() {
|
2015-10-25 11:26:51 +01:00
|
|
|
local REMOVE=REMOVE # slightly hacky - we expand ${!outputFoo}
|
|
|
|
|
2015-12-02 10:03:23 +01:00
|
|
|
moveToOutput share/info "${!outputInfo}"
|
|
|
|
moveToOutput share/doc "${!outputDoc}"
|
|
|
|
moveToOutput share/gtk-doc "${!outputDocdev}"
|
2015-10-15 13:37:03 +02:00
|
|
|
|
|
|
|
# the default outputMan is in $bin
|
2015-12-02 10:03:23 +01:00
|
|
|
moveToOutput share/man "${!outputMan}"
|
|
|
|
moveToOutput share/man/man3 "${!outputDocdev}"
|
2014-08-25 15:30:46 +02:00
|
|
|
}
|
2014-08-27 01:14:09 +02:00
|
|
|
|
|
|
|
# Move development-only stuff to the desired outputs.
|
|
|
|
_multioutDevs() {
|
2014-08-30 15:53:24 +02:00
|
|
|
if [ "$outputs" = "out" ] || [ -z "${moveToDev-1}" ]; then return; fi;
|
2015-12-02 10:03:23 +01:00
|
|
|
moveToOutput include "${!outputInclude}"
|
2015-10-15 13:37:03 +02:00
|
|
|
# these files are sometimes provided even without using the corresponding tool
|
2015-12-02 10:03:23 +01:00
|
|
|
moveToOutput lib/pkgconfig "${!outputDev}"
|
|
|
|
moveToOutput share/pkgconfig "${!outputDev}"
|
|
|
|
moveToOutput lib/cmake "${!outputDev}"
|
|
|
|
moveToOutput share/aclocal "${!outputDev}"
|
2015-10-15 13:37:03 +02:00
|
|
|
# don't move *.la, as libtool needs them in the directory of the library
|
2014-08-30 23:29:23 +02:00
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
for f in "${!outputDev}"/{lib,share}/pkgconfig/*.pc; do
|
|
|
|
echo "Patching '$f' includedir to output ${!outputInclude}"
|
2014-08-30 23:29:23 +02:00
|
|
|
sed -i "/^includedir=/s,=\${prefix},=${!outputInclude}," "$f"
|
|
|
|
done
|
2014-08-25 15:30:46 +02:00
|
|
|
}
|
|
|
|
|
2015-04-18 15:46:00 +02: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.
|
2016-04-19 13:13:27 +02:00
|
|
|
# Note: with current cross-building setup, all packages are "native" if not cross-building;
|
|
|
|
# however, if cross-building, the outputs are non-native. We have to choose the right file.
|
2014-08-25 15:30:46 +02:00
|
|
|
_multioutPropagateDev() {
|
2014-08-30 15:53:24 +02:00
|
|
|
if [ "$outputs" = "out" ]; then return; fi;
|
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
local outputFirst
|
|
|
|
for outputFirst in $outputs; do
|
|
|
|
break
|
|
|
|
done
|
|
|
|
|
|
|
|
# Default value: propagate binaries, includes and libraries
|
2015-12-02 10:03:23 +01:00
|
|
|
if [ -z "${propagatedBuildOutputs+1}" ]; then
|
2015-04-18 15:46:00 +02:00
|
|
|
local po_dirty="$outputBin $outputInclude $outputLib"
|
2015-08-20 01:53:31 +02:00
|
|
|
set +o pipefail
|
2015-12-02 10:03:23 +01:00
|
|
|
propagatedBuildOutputs=`echo "$po_dirty" \
|
2015-04-18 15:46:00 +02:00
|
|
|
| tr -s ' ' '\n' | grep -v -F "$outputFirst" \
|
|
|
|
| sort -u | tr '\n' ' ' `
|
2015-08-20 01:53:31 +02:00
|
|
|
set -o pipefail
|
2015-10-15 13:37:03 +02:00
|
|
|
fi
|
2015-04-18 15:46:00 +02:00
|
|
|
|
2015-10-15 13:37:03 +02:00
|
|
|
# The variable was explicitly set to empty or we resolved it so
|
2015-12-02 10:03:23 +01:00
|
|
|
if [ -z "$propagatedBuildOutputs" ]; then
|
2015-10-15 13:37:03 +02:00
|
|
|
return
|
2014-08-25 15:30:46 +02:00
|
|
|
fi
|
2015-04-18 15:46:00 +02:00
|
|
|
|
|
|
|
mkdir -p "${!outputFirst}"/nix-support
|
2016-04-19 13:13:27 +02:00
|
|
|
local propagatedBuildInputsFile
|
|
|
|
if [ -z "$crossConfig" ]; then
|
|
|
|
propagatedBuildInputsFile=propagated-native-build-inputs
|
|
|
|
else
|
|
|
|
propagatedBuildInputsFile=propagated-build-inputs
|
|
|
|
fi
|
|
|
|
|
2015-12-02 10:03:23 +01:00
|
|
|
for output in $propagatedBuildOutputs; do
|
2016-04-19 13:13:27 +02:00
|
|
|
echo -n " ${!output}" >> "${!outputFirst}"/nix-support/$propagatedBuildInputsFile
|
2015-04-18 15:46:00 +02:00
|
|
|
done
|
2014-08-25 15:30:46 +02:00
|
|
|
}
|
|
|
|
|