summaryrefslogtreecommitdiffstats
path: root/development/google-go-lang/google-go-lang.SlackBuild
blob: 690221583a5e01edb1a4558bffac0483e1269f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash

# Slackware build script for google-go-lang

# Written by Eric Schultz eric at schultzter.ca
# Taken over by Vincent Batts vbatts@hashbangbash.com

# 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.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=google-go-lang
VERSION=${VERSION:-1.22.1}
BOOTSTRAP_VERSION=${BOOTSTRAP_VERSION:-1.19.13}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

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="7" # can be '5' as well, to use soft float instead of hard float
elif [ "$ARCH" = "aarch64" ]; then
  LIBDIRSUFFIX="64"
  GOARCH="arm64"
else
  LIBDIRSUFFIX=""
  GOARCH=386
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG

CGO_MINOR_VERSION="$(/usr/bin/go version | awk '{ print $3 }' | sed 's/go//' | awk -F. '{ print $2 }')"
if [[ $CGO_MINOR_VERSION -lt 18 ]] ; then
  mkdir -p $TMP $PKG/usr/lib${LIBDIRSUFFIX}/go${BOOTSTRAP_VERSION} $OUTPUT
  cd $PKG/usr/lib${LIBDIRSUFFIX}/go${BOOTSTRAP_VERSION}
  tar xvf $CWD/go${BOOTSTRAP_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 {} \;

  # as of >= go1.5, the cross-compiler does not need to be bootstrap, so the
  # compiler need only be compiled for the host OS, which it detects
  unset GOBIN GOPATH GOOS GOARCH

  # Not sure why, but this causes run.bash to fail --rworkman
  unset BASH_ENV

  # gcc 5+ is go1.4 API, so we'll bootstrap with it
  export GOROOT_BOOTSTRAP="/usr"

  # Default GOROOT is the parent directory of all.bash,
  # which is the current directory we're in.
  # Defining it here means we can use it below when building
  # shared libraries
  GOROOT="$(pwd)"
  export GOROOT

  # The value of GOROOT once the package is installed
  export GOROOT_FINAL="/usr/lib${LIBDIRSUFFIX}/go${BOOTSTRAP_VERSION}/go"

  case "$ARCH" in
    arm|i?86) export GOMAXPROCS=1 ;;
  esac

  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

  mkdir -p $PKG$GOROOT_FINAL
fi

mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/go${VERSION} $OUTPUT
cd $PKG/usr/lib${LIBDIRSUFFIX}/go${VERSION}
tar xvf $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 {} \;

# as of >= go1.5, the cross-compiler does not need to be bootstrap, so the
# compiler need only be compiled for the host OS, which it detects
unset GOBIN GOPATH GOOS GOARCH

# Not sure why, but this causes run.bash to fail --rworkman
unset BASH_ENV

# gcc 5+ is go1.4 API, so we'll bootstrap with it
if [[ $CGO_MINOR_VERSION -lt 18 ]] ; then
  export GOROOT_BOOTSTRAP="$PKG/usr/lib${LIBDIRSUFFIX}/go${BOOTSTRAP_VERSION}/go"
else
  export GOROOT_BOOTSTRAP="/usr"
fi

# Default GOROOT is the parent directory of all.bash,
# which is the current directory we're in.
# Defining it here means we can use it below when building
# shared libraries
GOROOT="$(pwd)"
export GOROOT

# The value of GOROOT once the package is installed
export GOROOT_FINAL="/usr/lib${LIBDIRSUFFIX}/go${VERSION}/go"

case "$ARCH" in
  arm|i?86) export GOMAXPROCS=1 ;;
esac

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

find $PKG/$GOROOT_FINAL -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
find $PKG/$GOROOT_FINAL -type f -name "*.so" -exec chmod +x {} \; 2> /dev/null || true

cd ..

# remove Go build cache
rm -rf pkg/obj/go-build/*

# remove the doc Makefile
rm -f doc/Makefile

# remove tests, nothing needs these at runtime
find $PKG/$GOROOT_FINAL/src -type d -name "testdata" -exec rm -rf {} +
find $PKG/$GOROOT_FINAL/src -type f -name "*_test.go" -exec rm -rf {} +

mkdir -p $PKG$GOROOT_FINAL

# remove bootstrap
if [[ $CGO_MINOR_VERSION -lt 18 ]] ; then
  rm -rf $PKG/usr/lib$LIBDIRSUFFIX/go$BOOTSTRAP_VERSION
fi

# 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 SECURITY.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