2 # ignore-tidy-linelength
7 binutils_version
=2.25.1
9 triple
=$arch-unknown-freebsd10
10 sysroot
=/usr
/local
/$triple
15 echo ERROR: An error was encountered with the build.
20 bash
-c "while true; do sleep 30; echo \$(date) - building ...; done" &
21 local ping_loop_pid
=$
!
28 # First up, build binutils
31 curl https
://ftp.gnu.org
/gnu
/binutils
/binutils-
${binutils_version}.
tar.bz2 |
tar xjf
-
34 hide_output ..
/binutils-
${binutils_version}/configure \
35 --target="$triple" --with-sysroot="$sysroot"
36 hide_output
make -j"$(getconf _NPROCESSORS_ONLN)"
37 hide_output
make install
41 # Next, download the FreeBSD libraries and header files
44 (x86_64
) freebsd_arch
=amd64
;;
45 (i686
) freebsd_arch
=i386
;;
52 # Try to unpack only the libraries the build needs, to save space.
53 for lib
in c cxxrt gcc_s m thr util
; do
54 files_to_extract
=("${files_to_extract[@]}" "./lib/lib${lib}.*" "./usr/lib/lib${lib}.*")
56 for lib
in c
++ c_nonshared compiler_rt execinfo gcc pthread rt ssp_nonshared
; do
57 files_to_extract
=("${files_to_extract[@]}" "./usr/lib/lib${lib}.*")
60 # Originally downloaded from:
61 # https://download.freebsd.org/ftp/releases/${freebsd_arch}/${freebsd_version}-RELEASE/base.txz
62 URL
=https
://ci-mirrors.rust-lang.org
/rustc
/2019-04-04-freebsd-${freebsd_arch}-${freebsd_version}-RELEASE-base.txz
63 curl
"$URL" |
tar xJf
- -C "$sysroot" --wildcards "${files_to_extract[@]}"
65 # Fix up absolute symlinks from the system image. This can be removed
66 # for FreeBSD 11. (If there's an easy way to make them relative
67 # symlinks instead, feel free to change this.)
69 find "$sysroot" -type l |
while read symlink_path
; do
70 symlink_target
=$
(readlink
"$symlink_path")
71 case $symlink_target in
73 echo "Fixing symlink ${symlink_path} -> ${sysroot}${symlink_target}" >&2
74 ln -nfs "${sysroot}${symlink_target}" "${symlink_path}" ;;
79 # Clang can do cross-builds out of the box, if we give it the right
80 # flags. (The local binutils seem to work, but they set the ELF
81 # header "OS/ABI" (EI_OSABI) field to SysV rather than FreeBSD, so
82 # there might be other problems.)
84 # The --target option is last because the cross-build of LLVM uses
85 # --target without an OS version ("-freebsd" vs. "-freebsd10"). This
86 # makes Clang default to libstdc++ (which no longer exists), and also
87 # controls other features, like GNU-style symbol table hashing and
88 # anything predicated on the version number in the __FreeBSD__
90 for tool
in clang clang
++; do
91 tool_path
=/usr
/local
/bin
/${triple}-${tool}
92 cat > "$tool_path" <<EOF
94 exec $tool --sysroot=$sysroot --prefix=${sysroot}/bin "\$@" --target=$triple