-
Notifications
You must be signed in to change notification settings - Fork 381
/
netbsd.sh
executable file
·122 lines (101 loc) · 3.5 KB
/
netbsd.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -x
set -euo pipefail
# shellcheck disable=SC1091
. lib.sh
main() {
local binutils=2.36.1 \
gcc=9.4.0 \
target=x86_64-unknown-netbsd
install_packages bzip2 \
ca-certificates \
curl \
g++ \
make \
patch \
texinfo \
wget \
xz-utils
local td
td="$(mktemp -d)"
mkdir "${td}"/{binutils,gcc}{,-build} "${td}/netbsd"
download_binutils "${binutils}" "bz2"
tar -C "${td}/binutils" --strip-components=1 -xjf "binutils-${binutils}.tar.bz2"
download_gcc "${gcc}" "xz"
tar -C "${td}/gcc" --strip-components=1 -xJf "gcc-${gcc}.tar.xz"
pushd "${td}"
pushd gcc
sed -i -e 's/ftp:/https:/g' ./contrib/download_prerequisites
./contrib/download_prerequisites
local patches=(
https://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/lang/gcc9/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h
https://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/lang/gcc9/patches/patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc
)
local patch
for patch in "${patches[@]}"; do
local patch_file
patch_file="$(mktemp)"
curl --retry 3 -sSfL "${patch}" -o "${patch_file}"
patch -Np0 < "${patch_file}"
rm "${patch_file}"
done
popd
local mirrors=(
"ftp://ftp.netbsd.org"
"https://cdn.NetBSD.org"
)
download_mirrors "pub/NetBSD/NetBSD-9.2/amd64/binary/sets" "base.tar.xz" "${mirrors[@]}"
tar -C "${td}/netbsd" -xJf base.tar.xz ./usr/include ./usr/lib ./lib
download_mirrors "pub/NetBSD/NetBSD-9.2/amd64/binary/sets" "comp.tar.xz" "${mirrors[@]}"
tar -C "${td}/netbsd" -xJf comp.tar.xz ./usr/include ./usr/lib
pushd binutils-build
../binutils/configure \
--target="${target}"
make "-j$(nproc)"
make install
popd
local destdir="/usr/local/${target}"
cp -r "${td}/netbsd/usr/include" "${destdir}"/
ls -all "${td}/netbsd/usr/lib"
cp "${td}/netbsd/lib/libc.so.12.213" "${destdir}/lib"
cp "${td}/netbsd/lib/libm.so.0.12" "${destdir}/lib"
cp "${td}/netbsd/lib/libutil.so.7.24" "${destdir}/lib"
cp "${td}/netbsd/lib/libpthread.so.1.4" "${destdir}/lib"
cp "${td}/netbsd/usr/lib/librt.so.1.1" "${destdir}/lib"
cp "${td}/netbsd/usr/lib"/lib{c,m,pthread}{,_p}.a "${destdir}/lib"
cp "${td}/netbsd/usr/lib"/{crt0,crti,crtn,crtbeginS,crtendS,crtbegin,crtend,gcrt0}.o "${destdir}/lib"
ln -s libc.so.12.213 "${destdir}/lib/libc.so"
ln -s libc.so.12.213 "${destdir}/lib/libc.so.12"
ln -s libm.so.0.12 "${destdir}/lib/libm.so"
ln -s libm.so.0.12 "${destdir}/lib/libm.so.0"
ln -s libpthread.so.1.4 "${destdir}/lib/libpthread.so"
ln -s libpthread.so.1.4 "${destdir}/lib/libpthread.so.1"
ln -s librt.so.1.1 "${destdir}/lib/librt.so"
ln -s libutil.so.7.24 "${destdir}/lib/libutil.so"
ln -s libutil.so.7.24 "${destdir}/lib/libutil.so.7"
pushd gcc-build
../gcc/configure \
--disable-libada \
--disable-libcilkrt \
--disable-libcilkrts \
--disable-libgomp \
--disable-libquadmath \
--disable-libquadmath-support \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-lto \
--disable-multilib \
--disable-nls \
--enable-languages=c,c++ \
--target="${target}"
make "-j$(nproc)"
make install
popd
# clean up
popd
purge_packages
rm -rf "${td}"
rm "${0}"
}
main "${@}"