0
Files
slackbuilds/google-go-lang/google-go-lang.SlackBuild
2024-07-24 22:24:21 +03:00

210 lines
5.8 KiB
Bash

#!/bin/sh
# Slackware build script for google-go-lang
# Written by Eric Schultz eric at schultzter.ca
# Taken over by Vincent Batts vbatts@hashbangbash.com
# Picked by Sergei Fedosoff <eleksir@gmail.com>
# Copyright (c) 2021 Sergei Fedosoff
# Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018 Vincent Batts
# Copyright (c) 2012 Eric Schultz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
PRGNAM=google-go-lang
VERSION=${VERSION:-1.22.5}
BOOTSTRAP1_VERSION=1.18.10
BOOTSTRAP2_VERSION=1.21.12
BOOTSTRAP3_VERSION=1.22.5
BUILD=${BUILD:-1}
TAG=${TAG:-_EXs}
RELEASE=${RELEASE:-linux}
RUN_TEST=${RUN_TEST:-false}
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=$( uname -m ) ;;
esac
fi
if [ "$ARCH" = "i586" ]; then
LIBDIRSUFFIX=""
GOARCH="386"
elif [ "$ARCH" = "x86_64" ]; then
LIBDIRSUFFIX="64"
GOARCH="amd64"
elif [ "$ARCH" = "arm" ]; then
LIBDIRSUFFIX=""
GOARCH="arm"
export GOARM="6" # can be '5' as well, to use soft float instead of hardware
else
LIBDIRSUFFIX=""
GOARCH=386
fi
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
BOOTSTRAP1_DIR="${TMP}/bootstrap-go${BOOTSTRAP1_VERSION}"
BOOTSTRAP2_DIR="${TMP}/bootstrap-go${BOOTSTRAP2_VERSION}"
BOOTSTRAP3_DIR="${TMP}/bootstrap-go${BOOTSTRAP3_VERSION}"
set -e
rm -rf $PKG
mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/go${VERSION} $OUTPUT
cd $PKG/usr/lib${LIBDIRSUFFIX}/go${VERSION}
tar xf $CWD/go${VERSION}.src.tar.gz
cd go
chown -R root:root .
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \+ -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \+
ORIG_PATH="${PATH}"
echo ""
echo "Building 1-st bootstrap compiler, ${BOOTSTRAP1_VERSION}"
mkdir -p "${BOOTSTRAP1_DIR}"
pushd "${BOOTSTRAP1_DIR}"
tar xf $CWD/go${BOOTSTRAP1_VERSION}.src.tar.gz
pushd go
chown -R root:root .
unset GOBIN GOPATH GOOS GOARCH CGO_ENABLED
export GOROOT_BOOTSTRAP="/usr" # gcc 5+ is go1.4 API, so we'll bootstrap with it
export GOROOT="$(pwd)"
export GOROOT_FINAL="${BOOTSTRAP1_DIR}/go"
pushd src
LC_ALL=C ./make.bash
$GOROOT/bin/go install std
popd
popd
popd
# Time to build 2-nd bootstrap compiler
echo ""
echo "Building 2-nd bootstrap compiler, ${BOOTSTRAP2_VERSION}"
mkdir -p "${BOOTSTRAP2_DIR}"
pushd "$BOOTSTRAP2_DIR"
tar xf "${CWD}/go${BOOTSTRAP2_VERSION}.src.tar.gz"
pushd go
chown -R root:root .
export PATH="${BOOTSTRAP1_DIR}/go/bin:${ORIG_PATH}"
unset GOBIN GOPATH GOOS GOARCH CGO_ENABLED
export GOROOT_BOOTSTRAP="$BOOTSTRAP1_DIR/go"
export GOROOT="$(pwd)"
export GOROOT_FINAL="${BOOTSTRAP2_DIR}/go"
pushd src
LC_ALL=C ./make.bash
$GOROOT/bin/go install std
popd
popd
popd
# Time to build 3-rd bootstrap compiler
echo ""
echo "Building 3-rd bootstrap compiler, ${BOOTSTRAP3_VERSION}"
mkdir -p "${BOOTSTRAP3_DIR}"
pushd "$BOOTSTRAP3_DIR"
tar xf "${CWD}/go${BOOTSTRAP3_VERSION}.src.tar.gz"
pushd go
chown -R root:root .
export PATH="${BOOTSTRAP2_DIR}/go/bin:${ORIG_PATH}"
unset GOBIN GOPATH GOOS GOARCH CGO_ENABLED
export GOROOT_BOOTSTRAP="$BOOTSTRAP2_DIR/go"
export GOROOT="$(pwd)"
export GOROOT_FINAL="${BOOTSTRAP3_DIR}/go"
pushd src
LC_ALL=C ./make.bash
$GOROOT/bin/go install std
popd
popd
popd
# Time to build target compiler
echo ""
echo "Building target compiler, ${BOOTSTRAP3_VERSION}"
export PATH="${BOOTSTRAP3_DIR}/go/bin:${PATH}"
cd "$PKG/usr/lib${LIBDIRSUFFIX}/go${VERSION}/go"
unset GOBIN GOPATH GOOS GOARCH CGO_ENABLED
export GOROOT_BOOTSTRAP="$BOOTSTRAP3_DIR/go"
export GOROOT="$(pwd)"
export GOROOT_FINAL="/usr/lib${LIBDIRSUFFIX}/go${VERSION}/go"
export GO_LDFLAGS="-s -w"
export GO_GCFLAGS="-trimpath"
cd src
if [ "${RUN_TEST}" = "true" ] ; then
LC_ALL=C \
./all.bash
else
LC_ALL=C \
./make.bash
fi
# As of go1.5, golang supports shared libraries, so generate them for use.
$GOROOT/bin/go install -buildmode=shared std
cd ..
# remove Go build cache
rm -rf pkg/obj/go-build/*
# remove the doc Makefile
rm -f doc/Makefile
# Put the profile scripts for setting PATH and env variables
mkdir -p $PKG/etc/profile.d
cat > $PKG/etc/profile.d/go.csh << EOF
#!/bin/csh
setenv GOROOT ${GOROOT_FINAL}
setenv PATH \${GOROOT}/bin:\${PATH}
EOF
cat > $PKG/etc/profile.d/go.sh << EOF
#!/bin/sh
export GOROOT="${GOROOT_FINAL}"
export PATH="\${GOROOT}/bin:\${PATH}"
EOF
chmod 0755 $PKG/etc/profile.d/go.csh
chmod 0755 $PKG/etc/profile.d/go.sh
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
CONTRIBUTING.md LICENSE PATENTS README.md VERSION \
$PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}