2014-08-30 13:53:24 +00:00
|
|
|
# The base package for automatic multiple-output splitting. Used in stdenv as well.
|
2014-08-24 17:05:56 +00:00
|
|
|
preConfigureHooks+=(_multioutConfig)
|
2014-08-25 13:30:46 +00:00
|
|
|
preFixupHooks+=(_multioutDocs)
|
2014-08-26 23:14:09 +00:00
|
|
|
preFixupHooks+=(_multioutDevs)
|
2014-08-25 13:30:46 +00:00
|
|
|
postFixupHooks+=(_multioutPropagateDev)
|
|
|
|
|
2023-01-15 19:54:48 +00:00
|
|
|
# _assignFirst varName otherVarNames*
|
|
|
|
#
|
|
|
|
# Set the value of the variable named $varName to the first of otherVarNames
|
|
|
|
# that refers to a non-empty variable name.
|
|
|
|
#
|
|
|
|
# If none of otherVarNames refers to a non-empty variable, the error message is
|
|
|
|
# specific to this function's use case, which is setting up the output variables.
|
2014-08-24 17:05:56 +00:00
|
|
|
_assignFirst() {
|
|
|
|
local varName="$1"
|
2023-02-26 08:57:00 +00:00
|
|
|
local _var
|
2015-10-25 10:26:51 +00:00
|
|
|
local REMOVE=REMOVE # slightly hacky - we allow REMOVE (i.e. not a variable name)
|
2014-08-24 17:05:56 +00:00
|
|
|
shift
|
2023-02-26 08:55:45 +00:00
|
|
|
for _var in "$@"; do
|
|
|
|
if [ -n "${!_var-}" ]; then eval "${varName}"="${_var}"; return; fi
|
2014-08-24 17:05:56 +00:00
|
|
|
done
|
2023-01-15 19:54:48 +00:00
|
|
|
echo
|
2023-02-26 08:57:19 +00:00
|
|
|
echo "error: _assignFirst: could not find a non-empty variable whose name to assign to ${varName}."
|
2023-01-16 22:26:23 +00:00
|
|
|
echo " The following variables were all unset or empty:"
|
|
|
|
echo " $*"
|
2023-01-15 19:54:48 +00:00
|
|
|
if [ -z "${out:-}" ]; then
|
|
|
|
echo ' If you do not want an "out" output in your derivation, make sure to define'
|
|
|
|
echo ' the other specific required outputs. This can be achieved by picking one'
|
2023-01-16 22:26:23 +00:00
|
|
|
echo " of the above as an output."
|
2023-01-15 19:54:48 +00:00
|
|
|
echo ' You do not have to remove "out" if you want to have a different default'
|
2023-01-16 22:26:23 +00:00
|
|
|
echo ' output, because the first output is taken as a default.'
|
2023-01-15 19:54:48 +00:00
|
|
|
echo
|
|
|
|
fi
|
2014-08-24 17:05:56 +00:00
|
|
|
return 1 # none found
|
|
|
|
}
|
2016-09-20 15:39:11 +00:00
|
|
|
|
2014-08-30 06:43:46 +00:00
|
|
|
# Same as _assignFirst, but only if "$1" = ""
|
|
|
|
_overrideFirst() {
|
2019-10-29 23:42:31 +00:00
|
|
|
if [ -z "${!1-}" ]; then
|
2014-08-30 06:43:46 +00:00
|
|
|
_assignFirst "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-08-24 17:05:56 +00:00
|
|
|
|
|
|
|
# Setup chains of sane default values with easy overridability.
|
|
|
|
# The variables are global to be usable anywhere during the build.
|
2015-10-15 11:37:03 +00:00
|
|
|
# Typical usage in package is defining outputBin = "dev";
|
2014-08-26 23:14:09 +00:00
|
|
|
|
2014-08-30 06:43:46 +00:00
|
|
|
_overrideFirst outputDev "dev" "out"
|
|
|
|
_overrideFirst outputBin "bin" "out"
|
2014-08-24 17:05:56 +00:00
|
|
|
|
2014-08-30 06:43:46 +00:00
|
|
|
_overrideFirst outputInclude "$outputDev"
|
2014-08-24 17:05:56 +00:00
|
|
|
|
|
|
|
# so-libs are often among the main things to keep, and so go to $out
|
2014-08-30 06:43:46 +00:00
|
|
|
_overrideFirst outputLib "lib" "out"
|
2014-08-24 17:05:56 +00:00
|
|
|
|
2014-08-30 06:43:46 +00:00
|
|
|
_overrideFirst outputDoc "doc" "out"
|
2016-09-20 14:51:51 +00:00
|
|
|
_overrideFirst outputDevdoc "devdoc" REMOVE # documentation for developers
|
2014-08-24 17:05:56 +00:00
|
|
|
# man and info pages are small and often useful to distribute with binaries
|
2017-07-11 09:05:31 +00:00
|
|
|
_overrideFirst outputMan "man" "$outputBin"
|
2016-09-20 15:39:11 +00:00
|
|
|
_overrideFirst outputDevman "devman" "devdoc" "$outputMan"
|
2017-07-11 11:13:18 +00:00
|
|
|
_overrideFirst outputInfo "info" "$outputBin"
|
2014-08-26 23:14:09 +00:00
|
|
|
|
2014-08-25 13:30:46 +00:00
|
|
|
|
2014-08-24 17:05:56 +00:00
|
|
|
# Add standard flags to put files into the desired outputs.
|
|
|
|
_multioutConfig() {
|
2022-05-31 21:34:59 +00:00
|
|
|
if [ "$(getAllOutputNames)" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi;
|
2014-08-26 23:14:09 +00:00
|
|
|
|
2016-04-18 06:50:34 +00:00
|
|
|
# try to detect share/doc/${shareDocName}
|
|
|
|
# Note: sadly, $configureScript detection comes later in configurePhase,
|
|
|
|
# and reordering would cause more trouble than worth.
|
2023-07-28 14:30:50 +00:00
|
|
|
if [ -z "${shareDocName:-}" ]; then
|
|
|
|
local confScript="${configureScript:-}"
|
2016-04-18 06:50:34 +00:00
|
|
|
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.
|
2020-06-22 09:32:57 +00:00
|
|
|
if [ -z "$shareDocName" ] || echo "$shareDocName" | grep -q '[^a-zA-Z0-9_-]'; then
|
2016-04-18 06:50:34 +00:00
|
|
|
shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-05-31 21:34:59 +00:00
|
|
|
prependToVar 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/"${shareDocName}" \
|
|
|
|
--libdir="${!outputLib}"/lib --libexecdir="${!outputLib}"/libexec \
|
|
|
|
--localedir="${!outputLib}"/share/locale
|
|
|
|
|
|
|
|
prependToVar installFlags \
|
|
|
|
pkgconfigdir="${!outputDev}"/lib/pkgconfig \
|
|
|
|
m4datadir="${!outputDev}"/share/aclocal aclocaldir="${!outputDev}"/share/aclocal
|
2014-08-24 17:05:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 06:50:34 +00:00
|
|
|
|
2014-08-24 17:05:56 +00:00
|
|
|
# Add rpath prefixes to library paths, and avoid stdenv doing it for $out.
|
2014-08-26 23:14:09 +00:00
|
|
|
_addRpathPrefix "${!outputLib}"
|
2014-08-24 17:05:56 +00:00
|
|
|
NIX_NO_SELF_RPATH=1
|
|
|
|
|
2014-08-26 23:14:09 +00:00
|
|
|
|
|
|
|
# Move subpaths that match pattern $1 from under any output/ to the $2 output/
|
2022-07-17 21:44:52 +00:00
|
|
|
# Beware: only globbing patterns are accepted, e.g.: * ? [abc]
|
2015-12-02 09:03:23 +00:00
|
|
|
# A special target "REMOVE" is allowed: moveToOutput foo REMOVE
|
|
|
|
moveToOutput() {
|
2014-08-26 23:14:09 +00:00
|
|
|
local patt="$1"
|
|
|
|
local dstOut="$2"
|
|
|
|
local output
|
2022-05-31 21:34:59 +00:00
|
|
|
for output in $(getAllOutputNames); do
|
2014-08-30 13:53:24 +00:00
|
|
|
if [ "${!output}" = "$dstOut" ]; then continue; fi
|
2014-08-26 23:14:09 +00:00
|
|
|
local srcPath
|
2015-10-25 10:26:51 +00:00
|
|
|
for srcPath in "${!output}"/$patt; do
|
2016-11-26 09:25:20 +00:00
|
|
|
# apply to existing files/dirs, *including* broken symlinks
|
|
|
|
if [ ! -e "$srcPath" ] && [ ! -L "$srcPath" ]; then continue; fi
|
2015-10-25 10:26:51 +00: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-26 23:14:09 +00:00
|
|
|
fi
|
2015-10-25 10:23:51 +00:00
|
|
|
|
|
|
|
# remove empty directories, printing iff at least one gets removed
|
|
|
|
local srcParent="$(readlink -m "$srcPath/..")"
|
2023-03-02 14:23:34 +00:00
|
|
|
if [ -n "$(find "$srcParent" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
|
2015-10-25 10:23:51 +00:00
|
|
|
echo "Removing empty $srcParent/ and (possibly) its parents"
|
2023-03-02 14:23:34 +00:00
|
|
|
rmdir -p --ignore-fail-on-non-empty "$srcParent" \
|
2016-01-02 10:18:27 +00:00
|
|
|
2> /dev/null || true # doesn't ignore failure for some reason
|
2015-10-25 10:23:51 +00:00
|
|
|
fi
|
2014-08-26 23:14:09 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Move documentation to the desired outputs.
|
2014-08-25 13:30:46 +00:00
|
|
|
_multioutDocs() {
|
2015-10-25 10:26:51 +00:00
|
|
|
local REMOVE=REMOVE # slightly hacky - we expand ${!outputFoo}
|
|
|
|
|
2015-12-02 09:03:23 +00:00
|
|
|
moveToOutput share/info "${!outputInfo}"
|
|
|
|
moveToOutput share/doc "${!outputDoc}"
|
2016-09-20 14:51:51 +00:00
|
|
|
moveToOutput share/gtk-doc "${!outputDevdoc}"
|
2017-11-23 19:21:32 +00:00
|
|
|
moveToOutput share/devhelp/books "${!outputDevdoc}"
|
2015-10-15 11:37:03 +00:00
|
|
|
|
|
|
|
# the default outputMan is in $bin
|
2015-12-02 09:03:23 +00:00
|
|
|
moveToOutput share/man "${!outputMan}"
|
2016-09-20 15:39:11 +00:00
|
|
|
moveToOutput share/man/man3 "${!outputDevman}"
|
2014-08-25 13:30:46 +00:00
|
|
|
}
|
2014-08-26 23:14:09 +00:00
|
|
|
|
|
|
|
# Move development-only stuff to the desired outputs.
|
|
|
|
_multioutDevs() {
|
2022-05-31 21:34:59 +00:00
|
|
|
if [ "$(getAllOutputNames)" = "out" ] || [ -z "${moveToDev-1}" ]; then return; fi;
|
2015-12-02 09:03:23 +00:00
|
|
|
moveToOutput include "${!outputInclude}"
|
2015-10-15 11:37:03 +00:00
|
|
|
# these files are sometimes provided even without using the corresponding tool
|
2015-12-02 09:03:23 +00:00
|
|
|
moveToOutput lib/pkgconfig "${!outputDev}"
|
|
|
|
moveToOutput share/pkgconfig "${!outputDev}"
|
|
|
|
moveToOutput lib/cmake "${!outputDev}"
|
|
|
|
moveToOutput share/aclocal "${!outputDev}"
|
2015-10-15 11:37:03 +00:00
|
|
|
# don't move *.la, as libtool needs them in the directory of the library
|
2014-08-30 21:29:23 +00:00
|
|
|
|
2015-04-18 13:46:00 +00:00
|
|
|
for f in "${!outputDev}"/{lib,share}/pkgconfig/*.pc; do
|
|
|
|
echo "Patching '$f' includedir to output ${!outputInclude}"
|
2014-08-30 21:29:23 +00:00
|
|
|
sed -i "/^includedir=/s,=\${prefix},=${!outputInclude}," "$f"
|
|
|
|
done
|
2014-08-25 13:30:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-24 03:21:45 +00:00
|
|
|
# Make the "dev" propagate other outputs needed for development.
|
2014-08-25 13:30:46 +00:00
|
|
|
_multioutPropagateDev() {
|
2022-05-31 21:34:59 +00:00
|
|
|
if [ "$(getAllOutputNames)" = "out" ]; then return; fi;
|
2014-08-30 13:53:24 +00:00
|
|
|
|
2015-04-18 13:46:00 +00:00
|
|
|
local outputFirst
|
2022-05-31 21:34:59 +00:00
|
|
|
for outputFirst in $(getAllOutputNames); do
|
2015-04-18 13:46:00 +00:00
|
|
|
break
|
|
|
|
done
|
2016-01-24 03:21:45 +00:00
|
|
|
local propagaterOutput="$outputDev"
|
|
|
|
if [ -z "$propagaterOutput" ]; then
|
|
|
|
propagaterOutput="$outputFirst"
|
|
|
|
fi
|
2015-04-18 13:46:00 +00:00
|
|
|
|
|
|
|
# Default value: propagate binaries, includes and libraries
|
2015-12-02 09:03:23 +00:00
|
|
|
if [ -z "${propagatedBuildOutputs+1}" ]; then
|
2015-04-18 13:46:00 +00:00
|
|
|
local po_dirty="$outputBin $outputInclude $outputLib"
|
2015-08-19 23:53:31 +00:00
|
|
|
set +o pipefail
|
2015-12-02 09:03:23 +00:00
|
|
|
propagatedBuildOutputs=`echo "$po_dirty" \
|
2016-01-24 03:21:45 +00:00
|
|
|
| tr -s ' ' '\n' | grep -v -F "$propagaterOutput" \
|
2015-04-18 13:46:00 +00:00
|
|
|
| sort -u | tr '\n' ' ' `
|
2015-08-19 23:53:31 +00:00
|
|
|
set -o pipefail
|
2015-10-15 11:37:03 +00:00
|
|
|
fi
|
2015-04-18 13:46:00 +00:00
|
|
|
|
2015-10-15 11:37:03 +00:00
|
|
|
# The variable was explicitly set to empty or we resolved it so
|
2015-12-02 09:03:23 +00:00
|
|
|
if [ -z "$propagatedBuildOutputs" ]; then
|
2015-10-15 11:37:03 +00:00
|
|
|
return
|
2014-08-25 13:30:46 +00:00
|
|
|
fi
|
2015-04-18 13:46:00 +00:00
|
|
|
|
2016-01-24 03:21:45 +00:00
|
|
|
mkdir -p "${!propagaterOutput}"/nix-support
|
2015-12-02 09:03:23 +00:00
|
|
|
for output in $propagatedBuildOutputs; do
|
2017-11-17 18:26:21 +00:00
|
|
|
echo -n " ${!output}" >> "${!propagaterOutput}"/nix-support/propagated-build-inputs
|
2015-04-18 13:46:00 +00:00
|
|
|
done
|
2014-08-25 13:30:46 +00:00
|
|
|
}
|