2015-02-21 13:38:37 +01:00
|
|
|
#
|
|
|
|
# This helper is for templates for Go packages.
|
|
|
|
#
|
|
|
|
|
2017-11-24 14:05:29 -08:00
|
|
|
do_configure() {
|
2018-09-18 19:29:24 -05:00
|
|
|
# $go_import_path must be set, or we can't link $PWD into $GOSRCPATH
|
2018-12-19 17:01:04 -08:00
|
|
|
# nor build from modules
|
2018-09-18 19:29:24 -05:00
|
|
|
if [ -z "$go_import_path" ]; then
|
|
|
|
msg_error "\"\$go_import_path\" not set on $pkgname template.\n"
|
|
|
|
fi
|
|
|
|
|
2018-09-18 21:41:08 -03:00
|
|
|
# This isn't really configuration, but its needed by packages
|
|
|
|
# that do unusual things with the build where the expect to be
|
|
|
|
# able to cd into the $GOSRCPATH
|
2019-06-18 19:37:27 -07:00
|
|
|
if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then
|
2018-12-19 17:01:04 -08:00
|
|
|
# Skip GOPATH symlink for Go modules
|
|
|
|
msg_normal "Building $pkgname using Go modules.\n"
|
2021-02-19 17:24:28 -03:00
|
|
|
else
|
2019-04-13 17:42:53 -03:00
|
|
|
mkdir -p ${GOSRCPATH%/*}/
|
2019-06-18 19:37:27 -07:00
|
|
|
ln -fs "$PWD" "${GOSRCPATH}"
|
2017-09-15 19:18:31 +02:00
|
|
|
fi
|
2017-11-24 14:05:29 -08:00
|
|
|
}
|
2017-09-15 19:18:31 +02:00
|
|
|
|
2017-11-24 14:05:29 -08:00
|
|
|
do_build() {
|
2022-08-10 03:18:17 -04:00
|
|
|
# remove -s and -w from go_ldflags, we should let xbps-src strip binaries itself
|
|
|
|
for wd in $go_ldflags; do
|
|
|
|
if [ "$wd" == "-s" ] || [ "$wd" == "-w" ]; then
|
|
|
|
msg_error "$pkgname: remove -s and -w from go_ldflags\n"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-04-17 18:18:35 +02:00
|
|
|
go_package=${go_package:-$go_import_path}
|
2018-12-19 17:01:04 -08:00
|
|
|
# Build using Go modules if there's a go.mod file
|
2019-06-18 19:37:27 -07:00
|
|
|
if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then
|
|
|
|
if [ -z "${go_mod_mode}" ] && [ -d vendor ]; then
|
2018-12-19 17:01:04 -08:00
|
|
|
msg_normal "Using vendor dir for $pkgname Go dependencies.\n"
|
|
|
|
go_mod_mode=vendor
|
2019-06-18 19:37:27 -07:00
|
|
|
elif [ "${go_mod_mode}" = "default" ]; then
|
2018-12-19 17:01:04 -08:00
|
|
|
# Allow templates to explicitly opt into the go tool's
|
|
|
|
# default behavior.
|
|
|
|
go_mod_mode=
|
|
|
|
fi
|
2019-06-18 19:37:27 -07:00
|
|
|
go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
|
2018-12-19 17:01:04 -08:00
|
|
|
else
|
|
|
|
# Otherwise, build using GOPATH
|
2019-06-18 19:37:27 -07:00
|
|
|
go get -p "$XBPS_MAKEJOBS" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
|
2018-12-19 17:01:04 -08:00
|
|
|
fi
|
2015-02-21 13:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do_install() {
|
2019-11-11 13:49:02 +07:00
|
|
|
for f in ${GOPATH}/bin/* ${GOPATH}/bin/**/*; do
|
|
|
|
if [ -f "$f" ] && [ -x "$f" ]; then
|
|
|
|
vbin "$f"
|
|
|
|
fi
|
2015-05-04 13:39:15 +02:00
|
|
|
done
|
2015-02-21 13:38:37 +01:00
|
|
|
}
|