Files
BMLFS/build-scripts/golang.build
2023-05-27 21:06:36 -05:00

127 lines
4.1 KiB
Bash

#! /bin/bash
# Go Compiler
# Source: https://go.dev/dl/go1.20.4.src.tar.gz
#
# $BUILD = Directory to temporarily install
# $PKGS = Directory to store built packages
#
# DEPS
# Required: golang-1.17.8
# Recommended: NONE
# Optional: NONE
# NOTE: go-1.20.x requires at least go 1.17 for bootstrap. A recent GCC-go can be used instead.
# Apply patches from Alpine Linux
patch -Np1 -i ../patches/golang-alpine/0001-cmd-link-load-host-archive-libc_nonshared.a-for-fsta.patch
patch -Np1 -i ../patches/golang-alpine/0002-cmd-link-check-for-libssp_nonshared.a-instead-of-lib.patch
patch -Np1 -i ../patches/golang-alpine/0003-cmd-link-always-check-for-__stack_chk_fail_local-ref.patch
# if running tests, apply these patches too:
patch -Np1 -i ../patches/golang-alpine/tests-filter-overflow-gid.patch
patch -Np1 -i ../patches/golang-alpine/tests-unset-GCCGO.patch
patch -Np1 -i ../patches/golang-alpine/tests-unshare-enosys.patch
# For AMD64/x86_64
export GOARCH="amd64"
# For i686
# export GOARCH=386
# For arch64
# export GOARCH=arm64
# For armv7
# export GOARCH="arm" GOARM=7
# For armhf
# export GOARCH="arm" GOARM=6
# compile go itself as a PIE on supported arches.
case $(uname -m) in
x86_64|s390x|aarch64) export GO_LDFLAGS=-buildmode=pie ;;
esac
export GOOS="linux"
export GOPATH="/src"
export GOROOT="/src/go"
export GOBIN="$GOROOT"/bin
export GOROOT_FINAL=/usr/lib/go
# go-bootstrap is too old. Build and use go-1.17.8 in /usr/lib/go
#for p in /usr/lib/go-bootstrap /usr/lib/go-linux-$GOARCH-bootstrap /usr/lib/go; do
# if [ -d "$p" ]; then
# export GOROOT_BOOTSTRAP="$p"
# break
# fi
#done
export GOROOT_BOOTSTRAP="/usr/lib/go"
# Build!
cd src && ./make.bash -v
# Install
cd .. && \
sudo -S mkdir -pv $BUILD/usr/bin $BUILD/usr/lib/go/bin $BUILD/usr/share/doc/go &&
for binary in go gofmt; do
sudo -S install -Dm755 bin/"$binary" $BUILD/usr/lib/go/bin/"$binary"
sudo -S ln -sv ../../usr/lib/go/bin/"$binary" $BUILD/usr/bin/
done
sudo -S cp -av pkg lib $BUILD/usr/lib/go && \
sudo -S cp -rv doc misc $BUILD/usr/share/doc/go && \
sudo -S rm -rfv $BUILD/usr/lib/go/pkg/obj && \
sudo -S rm -rfv $BUILD/usr/lib/go/pkg/bootstrap && \
sudo -S rm -fv $BUILD/usr/lib/go/pkg/tool/*/api && \
sudo -S mkdir -pv $BUILD/usr/lib/go/ && \
sudo -S cp -a src $BUILD/usr/lib/go/ && \
# Per Alpine Linux
# Remove tests from /usr/lib/go/src to reduce package size,
# these should not be needed at run-time by any program.
find $BUILD/usr/lib/go/src \( -type f -a -name "*_test.go" \) \
-exec sudo -S rm -rf \{\} \+
find $BUILD/usr/lib/go/src \( -type d -a -name "testdata" \) \
-exec sudo -S rm -rf \{\} \+
# Per Alpine Linux
# Remove rc (plan 9) and bat scripts (windows) to reduce package
#
# See: https://gitlab.alpinelinux.org/alpine/aports/issues/11091
find $BUILD/usr/lib/go/src -type f -a \( -name "*.rc" -o -name "*.bat" \) \
-exec sudo -S rm -rf \{\} \+
cd $BUILD && sudo -S mkdir -v ${BUILD}/install &&
cat > /tmp/slack-desc << "EOF"
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
golang: golang
golang:
golang: Go programming language compiler
golang:
golang: https://go.dev/
golang:
EOF
sudo -S mv -v /tmp/slack-desc install/ &&
sudo -S mkdir -pv /BMAN/install /BMAN/usr && \
sudo mv $BUILD/usr/share /BMAN/usr/ && \
sudo -S makepkg -l y -c n $PKGS/golang-1.20.4-$PSUFFIX &&
cd /BMAN && \
cat > /tmp/slack-desc << "EOF"
golang-doc: Documentation for golang
golang-doc:
golang-doc: Go programming language compiler
golang-doc:
golang-doc: https://go.dev/
golang-doc:
EOF
sudo -S mv -v /tmp/slack-desc install/ && \
sudo -S makepkg -l y -c n $PKGS/golang-doc-1.20.4-${NOPSUFFIX} &&
sudo -S rm -rf ${BUILD}/*
unset GOOS GOPATH GOROOT GOBIN GOROOT_FINAL GOROOT_BOOTSTRAP GOARCH