1 # This hook ensures that we do the following in post-fixup:
2 # * wrap any installed executables with a wrapper that configures TCLLIBPATH
3 # * write a setup hook that extends the TCLLIBPATH of any anti-dependencies
5 tclWrapperArgs
=( ${tclWrapperArgs-} )
7 # Add a directory to TCLLIBPATH, provided that it exists
10 if [[ -z "$tclPkg" ]]; then
14 if [[ ! -d "$tclPkg" ]]; then
15 >&2 echo "can't add $tclPkg to TCLLIBPATH; that directory doesn't exist"
19 if [[ "$tclPkg" == *" "* ]]; then
23 if [[ -z "${TCLLIBPATH-}" ]]; then
24 export TCLLIBPATH
="$tclPkg"
26 if [[ "$TCLLIBPATH" != *"$tclPkg "* && "$TCLLIBPATH" != *"$tclPkg" ]]; then
27 export TCLLIBPATH
="${TCLLIBPATH} $tclPkg"
32 # Locate any directory containing an installed pkgIndex file
33 findInstalledTclPkgs
() {
34 local -r newLibDir
="${!outputLib}/lib"
35 if [[ ! -d "$newLibDir" ]]; then
36 >&2 echo "Assuming no loadable tcl packages installed ($newLibDir does not exist)"
39 echo "$(find "$newLibDir" -name pkgIndex.tcl -exec dirname {} \;)"
42 # Wrap any freshly-installed binaries and set up their TCLLIBPATH
44 if [ "$dontWrapTclBinaries" ]; then return; fi
46 if [[ -z "${TCLLIBPATH-}" ]]; then
47 echo "skipping automatic Tcl binary wrapping (nothing to do)"
51 local -r tclBinsDir
="${!outputBin}/bin"
52 if [[ ! -d "$tclBinsDir" ]]; then
53 echo "No outputBin found, not using any TCLLIBPATH wrapper"
57 tclWrapperArgs
+=(--prefix TCLLIBPATH
' ' "$TCLLIBPATH")
59 find "$tclBinsDir" -type f
-executable -print |
60 while read -r someBin
; do
61 echo "Adding TCLLIBPATH wrapper for $someBin"
62 wrapProgram
"$someBin" "${tclWrapperArgs[@]}"
66 # Generate hook to adjust TCLLIBPATH in anti-dependencies
67 writeTclLibPathHook
() {
68 local -r hookPath
="${!outputLib}/nix-support/setup-hook"
69 mkdir
-p "$(dirname "$hookPath")"
71 typeset
-f _addToTclLibPath
>> "$hookPath"
72 local -r tclPkgs
=$
(findInstalledTclPkgs
)
73 while IFS
= read -r tclPkg
; do
74 echo "_addToTclLibPath \"$tclPkg\"" >> "$hookPath"
75 _addToTclLibPath
"$tclPkg" true
79 postFixupHooks
+=(writeTclLibPathHook
)
80 postFixupHooks
+=(wrapTclBins
)