File: build.sh

package info (click to toggle)
moor 2.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,960 kB
  • sloc: sh: 229; ansic: 12; xml: 6; makefile: 5
file content (36 lines) | stat: -rwxr-xr-x 1,257 bytes parent folder | download
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
#!/bin/bash

set -e -o pipefail

if [ -z ${CI+x} ]; then
    # Local build, not in CI, format source
    gofmt -s -w .
fi

VERSION="$(git describe --tags --dirty --always)"

BINARY="moor"
if [ -n "${GOOS}${GOARCH}" ]; then
    EXE=""
    if [ "${GOOS}" = "windows" ]; then
        EXE=".exe"
    fi
    BINARY="releases/${BINARY}-${VERSION}-${GOOS}-${GOARCH}${EXE}"
fi

# Linker flags version number trick below from here:
# https://www.reddit.com/r/golang/comments/4cpi2y/question_where_to_keep_the_version_number_of_a_go/d1kbap7?utm_source=share&utm_medium=web2x

# Linker flags -s and -w strips debug data, but keeps whatever is needed for
# proper panic backtraces, this makes binaries smaller:
# https://boyter.org/posts/trimming-golang-binary-fat/

# This line must be last in the script so that its return code
# propagates properly to its caller
#
# Note that ${RACE} must *not* be quoted, we want it to disappear if empty.
# shellcheck disable=SC2086
go build ${RACE} -trimpath -ldflags="-s -w -X main.versionString=${VERSION}" -o "${BINARY}" ./cmd/moor

# Alternative build line, if you want to attach to the running process in the Go debugger:
# go build -ldflags="-X main.versionString=${VERSION}" -gcflags="all=-N -l" -o "${BINARY}" ./cmd/moor