about summary refs log tree commit diff
path: root/pkgs/tools/typesetting/tex/texlive/make-bin-containers.sh
blob: c293970ac7f99c4f0ac89ca6d842f46b1cb9eb3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# load realpath
loadables="$(command -v bash)"
loadables="${loadables%/bin/bash}/lib/bash"
enable -f "$loadables/realpath" realpath
mkdir -p "$out/bin"

# find interpreters
export interpPerl="$(PATH="$HOST_PATH" command -v perl)"
export interpJava="$(PATH="$HOST_PATH" command -v java || :)"
export interpWish="$(PATH="$HOST_PATH" command -v wish || :)"

# prepare sed script
substituteAll "$patchScripts" patch-scripts.sed

for binname in $binfiles ; do
  # binlinks to be created last, after the other binaries are in place
  if [[ " $binlinks " == *" $binname "* ]] ; then
    continue
  fi

  output="$out/bin/$binname"

  # look for existing binary from bin.core or bin.${pname}
  for folder in $binfolders ; do
    target="$folder"/bin/"$binname"
    if [[ -f "$target" && -x "$target" ]] ; then
      ln -s "$(realpath "$target")" "$output"
      continue 2
    fi
  done

  # look for scripts
  # the explicit list of extensions avoid non-scripts such as $binname.cmd, $binname.jar, $binname.pm
  # the order is relevant: $binname.sh is preferred to other $binname.*
  if [[ -n "$scriptsFolder" ]] ; then
    for script in "$scriptsFolder/$binname"{,.sh,.lua,.pl,.py,.rb,.sno,.tcl,.texlua,.tlu}; do
      if [[ -f "$script" ]] ; then
        sed -f patch-scripts.sed \
          -e 's/^scriptname=`basename "\$0"`$/'"scriptname='$(basename "$binname")'/" \
          -e 's/^scriptname=`basename "\$0" .sh`$'"/scriptname='$(basename "$binname" .sh)'/" \
          "$script" > "$output"
        chmod +x "$output"
        continue 2
      fi
    done
  fi

  echo "error: could not find source for 'bin/$binname'" >&2
  exit 1
done

# patch shebangs
patchShebangs "$out/bin"

# generate links
# we canonicalise the source to avoid symlink chains, and to check that it exists
cd "$out"/bin
for alias in $binlinks ; do
  target="${bintargets%% *}"
  bintargets="${bintargets#* }"
  ln -s "$(realpath "$target")" "$out/bin/$alias"
done