|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +declare -r workdir="${PWD}" |
| 6 | +declare -r temporary_directory='/tmp/netbsd-sysroot' |
| 7 | + |
| 8 | +declare -ra targets=( |
| 9 | + # 'hpcsh' |
| 10 | + # 'vax' |
| 11 | + # 'emips' |
| 12 | + # 'evbppc' |
| 13 | + # 'hppa' |
| 14 | + 'amd64' |
| 15 | + 'i386' |
| 16 | + # 'alpha' |
| 17 | + # 'sparc' |
| 18 | + # 'sparc64' |
| 19 | + 'evbarm-aarch64' |
| 20 | + # 'evbarm-earmv7hf' |
| 21 | + # 'evbarm-earmv6hf' |
| 22 | +) |
| 23 | + |
| 24 | +[ -d "${temporary_directory}" ] || mkdir "${temporary_directory}" |
| 25 | + |
| 26 | +cd "${temporary_directory}" |
| 27 | + |
| 28 | +for target in "${targets[@]}"; do |
| 29 | + case "${target}" in |
| 30 | + amd64) |
| 31 | + declare triplet='x86_64-unknown-netbsd';; |
| 32 | + i386) |
| 33 | + declare triplet='i386-unknown-netbsdelf';; |
| 34 | + emips) |
| 35 | + declare triplet='mips-unknown-netbsd';; |
| 36 | + alpha) |
| 37 | + declare triplet='alpha-unknown-netbsd';; |
| 38 | + hppa) |
| 39 | + declare triplet='hppa-unknown-netbsd';; |
| 40 | + sparc) |
| 41 | + declare triplet='sparc-unknown-netbsdelf';; |
| 42 | + sparc64) |
| 43 | + declare triplet='sparc64-unknown-netbsd';; |
| 44 | + vax) |
| 45 | + declare triplet='vax-unknown-netbsdelf';; |
| 46 | + hpcsh) |
| 47 | + declare triplet='shle-unknown-netbsdelf';; |
| 48 | + evbppc) |
| 49 | + declare triplet='powerpc-unknown-netbsd';; |
| 50 | + evbarm-aarch64) |
| 51 | + declare triplet='aarch64-unknown-netbsd';; |
| 52 | + evbarm-earmv7hf) |
| 53 | + declare triplet='armv7-unknown-netbsdelf-eabihf';; |
| 54 | + evbarm-earmv6hf) |
| 55 | + declare triplet='armv6-unknown-netbsdelf-eabihf';; |
| 56 | + esac |
| 57 | + |
| 58 | + declare netbsd_version='10.1' |
| 59 | + |
| 60 | + declare url="https://ftp.netbsd.org/pub/NetBSD/NetBSD-${netbsd_version}/${target}/binary/sets" |
| 61 | + |
| 62 | + declare extension='.tar.xz' |
| 63 | + |
| 64 | + if [ "${target}" = 'i386' ]; then |
| 65 | + extension='.tgz' |
| 66 | + fi |
| 67 | + |
| 68 | + declare base_url="${url}/base${extension}" |
| 69 | + declare comp_url="${url}/comp${extension}" |
| 70 | + |
| 71 | + declare base_output="${temporary_directory}/$(basename "${base_url}")" |
| 72 | + declare comp_output="${temporary_directory}/$(basename "${comp_url}")" |
| 73 | + |
| 74 | + declare sysroot_directory="${workdir}/${triplet}" |
| 75 | + declare tarball_filename="${sysroot_directory}.tar.xz" |
| 76 | + |
| 77 | + [ -d "${sysroot_directory}" ] || mkdir "${sysroot_directory}" |
| 78 | + |
| 79 | + echo "- Generating sysroot for ${triplet}" |
| 80 | + |
| 81 | + if [ -f "${tarball_filename}" ]; then |
| 82 | + echo "+ Already exists. Skip" |
| 83 | + continue |
| 84 | + fi |
| 85 | + |
| 86 | + echo "- Fetching data from ${base_url}" |
| 87 | + |
| 88 | + curl \ |
| 89 | + --url "${base_url}" \ |
| 90 | + --retry '30' \ |
| 91 | + --retry-all-errors \ |
| 92 | + --retry-delay '0' \ |
| 93 | + --retry-max-time '0' \ |
| 94 | + --location \ |
| 95 | + --silent \ |
| 96 | + --output "${base_output}" |
| 97 | + |
| 98 | + echo "- Unpacking ${base_output}" |
| 99 | + |
| 100 | + tar \ |
| 101 | + --directory="${sysroot_directory}" \ |
| 102 | + --strip=2 \ |
| 103 | + --extract \ |
| 104 | + --file="${base_output}" \ |
| 105 | + './usr/lib' \ |
| 106 | + './usr/include' |
| 107 | + |
| 108 | + tar \ |
| 109 | + --directory="${sysroot_directory}" \ |
| 110 | + --extract \ |
| 111 | + --file="${base_output}" \ |
| 112 | + './lib' |
| 113 | + |
| 114 | + echo "- Fetching data from ${base_url}" |
| 115 | + |
| 116 | + curl \ |
| 117 | + --url "${comp_url}" \ |
| 118 | + --retry '30' \ |
| 119 | + --retry-all-errors \ |
| 120 | + --retry-delay '0' \ |
| 121 | + --retry-max-time '0' \ |
| 122 | + --location \ |
| 123 | + --silent \ |
| 124 | + --output "${comp_output}" |
| 125 | + |
| 126 | + echo "- Unpacking ${comp_output}" |
| 127 | + |
| 128 | + tar \ |
| 129 | + --directory="${sysroot_directory}" \ |
| 130 | + --strip=2 \ |
| 131 | + --extract \ |
| 132 | + --file="${comp_output}" \ |
| 133 | + './usr/lib' \ |
| 134 | + './usr/include' |
| 135 | + |
| 136 | + # Update permissions |
| 137 | + while read name; do |
| 138 | + if [ -f "${name}" ]; then |
| 139 | + chmod 644 "${name}" |
| 140 | + elif [ -d "${name}" ]; then |
| 141 | + chmod 755 "${name}" |
| 142 | + fi |
| 143 | + done <<< "$(find "${sysroot_directory}/include" "${sysroot_directory}/lib")" |
| 144 | + |
| 145 | + echo "- Creating tarball at ${tarball_filename}" |
| 146 | + |
| 147 | + tar --directory="$(dirname "${sysroot_directory}")" --create --file=- "$(basename "${sysroot_directory}")" | xz --threads='0' --extreme --compress -9 --memlimit-compress='100%' > "${tarball_filename}" |
| 148 | + sha256sum "${tarball_filename}" | sed "s|$(dirname "${sysroot_directory}")/||" > "${tarball_filename}.sha256" |
| 149 | + |
| 150 | + rm --force --recursive "${sysroot_directory}" |
| 151 | + rm --force --recursive "${temporary_directory}/"* |
| 152 | +done |
0 commit comments