AdGuardHome/scripts/make/go-build.sh
Ainar Garipov 5d0d32b926 Pull request: all: support multiple dns hosts
Updates #1401.

Squashed commit of the following:

commit a18c3f062a88ad7d7fbfacaedb893f1ca660b6dc
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Mar 22 21:55:26 2021 +0300

    home: imp code

commit 2b4a28cbf379fbc5fb168af6d8d078cab2b8bd64
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Mar 22 20:55:08 2021 +0300

    all: rm unused field

commit 5766a97dafff4acff6b909eb6303459f7991c81e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Mar 22 16:40:14 2021 +0300

    all: support multiple dns hosts
2021-03-23 12:32:07 +03:00

100 lines
2.6 KiB
Bash

#!/bin/sh
# AdGuard Home Build Script
#
# The commentary in this file is written with the assumption that the
# reader only has superficial knowledge of the POSIX shell language and
# alike. Experienced readers may find it overly verbose.
# The default verbosity level is 0. Show every command that is run and
# every package that is processed if the caller requested verbosity
# level greater than 0. Also show subcommands if the requested
# verbosity level is greater than 1. Otherwise, do nothing.
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '1' ]
then
env
set -x
readonly v_flags='-v'
readonly x_flags='-x'
elif [ "$verbose" -gt '0' ]
then
set -x
readonly v_flags='-v'
readonly x_flags=''
else
set +x
readonly v_flags=''
readonly x_flags=''
fi
# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u
# Allow users to set the Go version.
go="${GO:-go}"
# Require the channel to be set and validate the value.
channel="$CHANNEL"
case "$channel"
in
('development'|'edge'|'beta'|'release')
# All is well, go on.
;;
(*)
echo "invalid channel '$channel', supported values are\
'development', 'edge', 'beta', and 'release'" 1>&2
exit 1
;;
esac
# Require the version to be set.
#
# TODO(a.garipov): Additional validation?
version="$VERSION"
# Set the linker flags accordingly: set the release channel and the
# current version as well as goarm and gomips variable values, if the
# variables are set and are not empty.
readonly version_pkg='github.com/AdguardTeam/AdGuardHome/internal/version'
ldflags="-s -w -X ${version_pkg}.version=${version}"
ldflags="${ldflags} -X ${version_pkg}.channel=${channel}"
if [ "${GOARM:-}" != '' ]
then
ldflags="${ldflags} -X ${version_pkg}.goarm=${GOARM}"
elif [ "${GOMIPS:-}" != '' ]
then
ldflags="${ldflags} -X ${version_pkg}.gomips=${GOMIPS}"
fi
# Allow users to limit the build's parallelism.
readonly parallelism="${PARALLELISM:-}"
if [ "$parallelism" != '' ]
then
readonly par_flags="-p ${parallelism}"
else
readonly par_flags=''
fi
# Allow users to specify a different output name.
readonly out="${OUT:-}"
if [ "$out" != '' ]
then
readonly out_flags="-o ${out}"
else
readonly out_flags=''
fi
# Don't use cgo. Use modules.
export CGO_ENABLED='0' GO111MODULE='on'
readonly build_flags="${BUILD_FLAGS:-$out_flags $par_flags\
$v_flags $x_flags}"
# Don't use quotes with flag variables to get word splitting.
"$go" generate $v_flags $x_flags ./main.go
# Don't use quotes with flag variables to get word splitting.
"$go" build --ldflags "$ldflags" $build_flags