about summary refs log tree commit diff
path: root/nixpkgs/pkgs/stdenv/darwin/unpack-bootstrap-tools-aarch64.sh
blob: 4bb84f6409cbd44d9c6ac094c9b79932c827d444 (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
set -euo pipefail

# Unpack the bootstrap tools tarball.
echo Unpacking the bootstrap tools...
$mkdir $out
$bzip2 -d < $tarball | (cd $out && $cpio -i)

export PATH=$out/bin

# Fix codesign wrapper paths
sed -i \
  -e "1c\
#!$out/bin/bash" \
  -e "s|[^( ]*\bsigtool\b|$out/bin/sigtool|g" \
  $out/bin/codesign

updateInstallName() {
  local path="$1"

  cp "$path" "$path.new"
  install_name_tool -id "$path" "$path.new"
  # workaround for https://github.com/NixOS/nixpkgs/issues/294518
  # libc++.1.0.dylib contains wrong LC_RPATH
  if [[ ${path} == *libc++.1.0.dylib ]]; then
    install_name_tool -add_rpath @loader_path/.. "${path}.new"
  fi
  codesign -f -i "$(basename "$path")" -s - "$path.new"
  mv -f "$path.new" "$path"
}

find $out

ln -s bash $out/bin/sh
ln -s bzip2 $out/bin/bunzip2

find $out/lib -type f -name '*.dylib' -print0 | while IFS= read -r -d $'\0' lib; do
  updateInstallName "$lib"
done

# Provide a gunzip script.
cat > $out/bin/gunzip <<EOF
#!$out/bin/sh
exec $out/bin/gzip -d "\$@"
EOF
chmod +x $out/bin/gunzip

# Provide fgrep/egrep.
echo "#! $out/bin/sh" > $out/bin/egrep
echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
echo "#! $out/bin/sh" > $out/bin/fgrep
echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep

cat >$out/bin/dsymutil << EOF
#!$out/bin/sh
EOF

chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/dsymutil