mirror of
https://github.com/dslm4515/BMLFS.git
synced 2025-08-01 19:42:55 +00:00
123 lines
3.8 KiB
Bash
123 lines
3.8 KiB
Bash
#! /bin/bash
|
|
|
|
# Go Compiler
|
|
# Source: https://go.dev/dl/go1.22.3.src.tar.gz
|
|
#
|
|
# $BUILD = Directory to temporarily install
|
|
# $PKGS = Directory to store built packages
|
|
#
|
|
# DEPS
|
|
# Required: golang-1.20.6+
|
|
# Recommended: NONE
|
|
# Optional: NONE
|
|
|
|
# NOTE: go-1.22.x requires at least go 1.20.6 for bootstrap. A recent GCC-go can be used instead.
|
|
|
|
# Per Chimera Linux, drop gold enforcement on linux
|
|
patch -Np1 -i ../patches/go1.21.3-chimera/arm64-no-gold.patch
|
|
|
|
# Per Chimera Linux and Alpine Linux, use the local toolchain by default
|
|
# even if a different version was specified in go.mod
|
|
patch -Np1 -i ../patches/go1.21.3-chimera/disable-auto-go-download.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.21.5 in /usr/lib/go
|
|
export GOROOT_BOOTSTRAP="/usr/lib/go"
|
|
|
|
# Build!
|
|
cd src && ./make.bash -v
|
|
|
|
unset GOROOT GOBIN GOROOT GOROOT_FINAL GO_LDFLAGS GOOS GOPATH GOROOT_BOOTSTRAP
|
|
|
|
# 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 cp -a src $BUILD/usr/lib/go/ && \
|
|
|
|
# Per Archlinux, the go.env needs to be copied.
|
|
# https://github.com/golang/go/issues/57179
|
|
sudo -S install -Dm644 go.env $BUILD/usr/lib/go/go.env
|
|
|
|
# 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.22.3-$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.22.3-${NOPSUFFIX} &&
|
|
sudo -S rm -rf ${BUILD}/*
|
|
unset GOOS GOPATH GOROOT GOBIN GOROOT_FINAL GOROOT_BOOTSTRAP GOARCH
|