Skip to content

Commit 1fd3d5b

Browse files
Freebsd support (#191)
* Add freebsd support * correct path
1 parent 7974851 commit 1fd3d5b

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

docker/base/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ RUN \
8787

8888
ENV PATH /osxcross/target/bin:$PATH
8989

90+
###########################
91+
# FREEBSD TOOLCHAIN BUILD #
92+
###########################
93+
94+
ADD prep_freebsd.sh /prep_freebsd.sh
95+
RUN chmod +x /prep_freebsd.sh && \
96+
/prep_freebsd.sh
97+
98+
ENV PATH /freebsdcross/x86_64-pc-freebsd12/bin:$PATH
99+
90100
# Inject the new Go root distribution downloader and bootstrapper
91101
ADD bootstrap_pure.sh /bootstrap_pure.sh
92102
ENV BOOTSTRAP_PURE /bootstrap_pure.sh

docker/base/bootstrap_pure.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go install std
6060
echo "Bootstrapping windows/386..."
6161
GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go install std
6262

63+
echo "Bootstrapping freebsd/amd64..."
64+
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-pc-freebsd12-gcc go install std
65+
6366
echo "Bootstrapping darwin/amd64..."
6467
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CC=o64-clang go install std
6568

docker/base/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,24 @@ for TARGET in $TARGETS; do
463463
# Remove any automatically injected deployment target vars
464464
unset MACOSX_DEPLOYMENT_TARGET
465465
fi
466+
# Check and build for freebsd targets
467+
if [ "$XGOOS" == "." ] || [[ "$XGOOS" == freebsd* ]]; then
468+
# Build the requested freebsd binaries
469+
if [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "amd64" ]; then
470+
echo "Compiling for freebsd/amd64..."
471+
CC=x86_64-pc-freebsd12-gcc HOST=x86_64-pc-freebsd12 PREFIX=/freebsdcross/x86_64-pc-freebsd12 $BUILD_DEPS /deps "${DEPS_ARGS[@]}"
472+
export PKG_CONFIG_PATH=/freebsdcross/x86_64-pc-freebsd12/lib/pkgconfig
473+
474+
if [[ "$USEMODULES" == false ]]; then
475+
CC=x86_64-pc-freebsd12-gcc CXX=x86_64-pc-freebsd12-g++ GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 go get $V $X "${T[@]}" -d "$PACK_RELPATH"
476+
fi
477+
CC=x86_64-pc-freebsd12-gcc CXX=x86_64-pc-freebsd12-g++ GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 go build $V $X $TP "${MOD[@]}" "${T[@]}" "${LDF[@]}" "${GC[@]}" "${BM[@]}" -o "/build/$NAME-freebsd12-amd64$(extension freebsd)" "$PACK_RELPATH"
478+
fi
479+
if [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "arm64" ]; then
480+
echo "skipping freebsd/arm64... as it is not yet supported"
481+
# TODO: add arm64 support
482+
fi
483+
fi
466484
done
467485

468486
# Clean up any leftovers for subsequent build invocations

docker/base/prep_freebsd.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# big thanks to:
4+
# @mcandre
5+
# @samm-git
6+
# @mcilloni
7+
# @marcelog
8+
# @bijanebrahimi
9+
# for their work on this subject which
10+
# I have been able to expand upon for cgo/golang
11+
12+
freebsd_ver=12
13+
freebsd_full_ver=12.4
14+
binutils_ver=2.39
15+
gmp_ver=6.2.1
16+
mpfr_ver=4.1.1
17+
mpc_ver=1.3.1
18+
gcc_ver=7.5.0
19+
20+
mkdir -p /freebsdcross/x86_64-pc-freebsd${freebsd_ver}
21+
22+
# binutils
23+
mkdir /tmp/freebsdbuild && cd /tmp/freebsdbuild && \
24+
wget https://ftp.gnu.org/gnu/binutils/binutils-${binutils_ver}.tar.xz && \
25+
tar -xf binutils-${binutils_ver}.tar.xz && cd binutils-${binutils_ver} && \
26+
./configure --enable-libssp --enable-gold --enable-ld \
27+
--target=x86_64-pc-freebsd${freebsd_ver} --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && make -j4 && \
28+
make install && \
29+
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild
30+
31+
# freebsd specific lbs
32+
cd /tmp/freebsdbuild && \
33+
wget https://download.freebsd.org/ftp/releases/amd64/${freebsd_full_ver}-RELEASE/base.txz && \
34+
cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \
35+
tar -xf /tmp/freebsdbuild/base.txz ./lib/ ./usr/lib/ ./usr/include/ && \
36+
cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver}/usr/lib && \
37+
find . -xtype l|xargs ls -l|grep ' /lib/' \
38+
| awk '{print "ln -sf /freebsdcross/x86_64-pc-freebsd12"$11 " " $9}' \
39+
| /bin/sh && \
40+
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild
41+
42+
# Compile GMP
43+
cd /tmp/freebsdbuild && \
44+
wget https://ftp.gnu.org/gnu/gmp/gmp-${gmp_ver}.tar.xz && \
45+
tar -xf gmp-${gmp_ver}.tar.xz && \
46+
cd gmp-${gmp_ver} && \
47+
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --enable-shared --enable-static \
48+
--enable-fft --enable-cxx --host=x86_64-pc-freebsd${freebsd_ver} && \
49+
make -j4 && make install && \
50+
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild
51+
52+
# Compile MPFR
53+
cd /tmp/freebsdbuild && \
54+
wget https://ftp.gnu.org/gnu/mpfr/mpfr-${mpfr_ver}.tar.xz && tar -xf mpfr-${mpfr_ver}.tar.xz && \
55+
cd mpfr-${mpfr_ver} && \
56+
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \
57+
--enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \
58+
make -j4 && make install && \
59+
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild
60+
61+
# Compile MPC
62+
cd /tmp/freebsdbuild && \
63+
wget https://ftp.gnu.org/gnu/mpc/mpc-${mpc_ver}.tar.gz && tar -xf mpc-${mpc_ver}.tar.gz && \
64+
cd mpc-${mpc_ver} && \
65+
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \
66+
--enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
67+
--with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \
68+
make -j4 && make install && \
69+
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild
70+
71+
# gcc (change LD_LIBRARY_PATH to /freebsdcross or something)
72+
cd /tmp/freebsdbuild && \
73+
wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.xz && \
74+
tar xf gcc-${gcc_ver}.tar.xz && \
75+
cd gcc-${gcc_ver} && mkdir build && cd build && \
76+
../configure --without-headers --with-gnu-as --with-gnu-ld --disable-nls \
77+
--enable-languages=c,c++ --enable-libssp --enable-gold --enable-ld \
78+
--disable-libitm --disable-libquadmath --target=x86_64-pc-freebsd${freebsd_ver} \
79+
--prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
80+
--with-mpc=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --disable-libgomp \
81+
--with-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
82+
--with-build-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \
83+
cd /tmp/freebsdbuild/gcc-${gcc_ver} && \
84+
echo '#define HAVE_ALIGNED_ALLOC 1' >> libstdc++-v3/config.h.in && \
85+
cd /tmp/freebsdbuild/gcc-${gcc_ver}/build && \
86+
make -j4 && make install && \
87+
rm -rf /tmp/freebsdbuild

0 commit comments

Comments
 (0)