Changeset View
Changeset View
Standalone View
Standalone View
head/Mk/Uses/go.mk
# $FreeBSD$ | # $FreeBSD$ | ||||
# | # | ||||
# This file contains logic to ease porting of Go binaries using the | # This file contains logic to ease porting of Go binaries using the | ||||
# `go` command. | # `go` command. | ||||
# | # | ||||
# Feature: go | # Feature: go | ||||
# Usage: USES=go | # Usage: USES=go | ||||
# Valid ARGS: (none), modules, no_targets, run | # Valid ARGS: (none), modules, no_targets, run | ||||
# | # | ||||
# (none) Setup GOPATH and build in GOPATH mode. | # (none) Setup GOPATH and build in GOPATH mode. | ||||
# modules If the upstream uses Go modules, this can be set to build | # modules If the upstream uses Go modules, this can be set to build | ||||
# in modules-aware mode. | # in modules-aware mode. | ||||
# no_targets Indicates that Go is needed at build time as a part of | # no_targets Indicates that Go is needed at build time as a part of | ||||
# make/CMake build. This will setup build environment like | # make/CMake build. This will setup build environment like | ||||
# GO_ENV, GO_BUILDFLAGS but will not create post-extract, do-build | # GO_ENV, GO_BUILDFLAGS but will not create post-extract and | ||||
# and do-install targets. | # do-{build,install,test} targets. | ||||
# run Indicates that Go is needed at run time and adds it to | # run Indicates that Go is needed at run time and adds it to | ||||
# RUN_DEPENDS. | # RUN_DEPENDS. | ||||
# | # | ||||
# You can set the following variables to control the process. | # You can set the following variables to control the process. | ||||
# | # | ||||
# GO_PKGNAME | # GO_PKGNAME | ||||
# The name of the package when building in GOPATH mode. This | # The name of the package when building in GOPATH mode. This | ||||
# is the directory that will be created in GOPATH/src and seen | # is the directory that will be created in ${GOPATH}/src. If not set | ||||
# by the `go` command. If not set explicitly and GH_SUBDIR or | # explicitly and GH_SUBDIR or GL_SUBDIR is present, GO_PKGNAME will | ||||
# GL_SUBDIR is present, GO_PKGNAME will be inferred from it. | # be inferred from it. | ||||
# It is not needed when building in modules-aware mode. | # It is not needed when building in modules-aware mode. | ||||
# | # | ||||
# GO_TARGET | # GO_TARGET | ||||
# The packages to build. If not set explicitly, defaults to | # The packages to build. The default value is ${GO_PKGNAME}. | ||||
# GO_PKGNAME. GO_TARGET can also be a tuple in the form | # GO_TARGET can also be a tuple in the form package:path where path can be | ||||
# package:path where path can be either a simple filename or a | # either a simple filename or a full path starting with ${PREFIX}. | ||||
# full path starting with ${PREFIX}. Specifying a full path | |||||
# like ${PREFIX}/sbin/binary will install the resulting binary | |||||
# as ${PREFIX}/sbin/binary. Using just simple filename is a | |||||
# shortcut to installing it as ${PREFIX}/bin/filename. | |||||
# | # | ||||
# GO_TESTTARGET | |||||
# The packages to test. The default value is `./...` (the current package | |||||
# and all subpackages). | |||||
# | |||||
# CGO_CFLAGS | # CGO_CFLAGS | ||||
# Additional CFLAGS variables to be passed to the C compiler by the `go` | # Additional CFLAGS variables to be passed to the C compiler by the `go` | ||||
# command | # command | ||||
# | # | ||||
# CGO_LDFLAGS | # CGO_LDFLAGS | ||||
# Additional LDFLAGS variables to be passed to the C compiler by the `go` | # Additional LDFLAGS variables to be passed to the C compiler by the `go` | ||||
# command | # command | ||||
# | # | ||||
# GO_BUILDFLAGS | # GO_BUILDFLAGS | ||||
# Additional build arguments to be passed to the `go build` command | # Additional build arguments to be passed to the `go build` command | ||||
# | # | ||||
# GO_TESTFLAGS | |||||
# Additional build arguments to be passed to the `go test` command | |||||
# | |||||
# GO_PORT | # GO_PORT | ||||
# The Go port to use. By default this is lang/go but can be set | # The Go port to use. By default this is lang/go but can be set | ||||
# to lang/go-devel in make.conf for testing with future Go versions. | # to lang/go-devel in make.conf for testing with future Go versions. | ||||
# | # | ||||
# This variable must not be set by individual ports! | # This variable must not be set by individual ports! | ||||
# | # | ||||
# MAINTAINER: dmgk@FreeBSD.org | # MAINTAINER: dmgk@FreeBSD.org | ||||
Show All 10 Lines | |||||
. if !empty(GH_SUBDIR) | . if !empty(GH_SUBDIR) | ||||
GO_PKGNAME= ${GH_SUBDIR:S|^src/||} | GO_PKGNAME= ${GH_SUBDIR:S|^src/||} | ||||
. elif !empty(GL_SUBDIR) | . elif !empty(GL_SUBDIR) | ||||
GO_PKGNAME= ${GL_SUBDIR:S|^src/||} | GO_PKGNAME= ${GL_SUBDIR:S|^src/||} | ||||
. else | . else | ||||
GO_PKGNAME= ${PORTNAME} | GO_PKGNAME= ${PORTNAME} | ||||
. endif | . endif | ||||
.endif | .endif | ||||
GO_TARGET?= ${GO_PKGNAME} | GO_TARGET?= ${GO_PKGNAME} | ||||
GO_TESTTARGET?= ./... | |||||
GO_BUILDFLAGS+= -v -buildmode=exe | GO_BUILDFLAGS+= -v -buildmode=exe | ||||
.if !defined(WITH_DEBUG) && empty(GO_BUILDFLAGS:M-ldflags*) | .if !defined(WITH_DEBUG) && empty(GO_BUILDFLAGS:M-ldflags*) | ||||
GO_BUILDFLAGS+= -ldflags=-s | GO_BUILDFLAGS+= -ldflags=-s | ||||
.endif | .endif | ||||
GO_TESTFLAGS+= -v | |||||
CGO_ENABLED?= 1 | CGO_ENABLED?= 1 | ||||
CGO_CFLAGS+= -I${LOCALBASE}/include | CGO_CFLAGS+= -I${LOCALBASE}/include | ||||
CGO_LDFLAGS+= -L${LOCALBASE}/lib | CGO_LDFLAGS+= -L${LOCALBASE}/lib | ||||
.if ${ARCH} == armv6 || ${ARCH} == armv7 | .if ${ARCH} == armv6 || ${ARCH} == armv7 | ||||
GOARM?= ${ARCH:C/armv//} | GOARM?= ${ARCH:C/armv//} | ||||
.endif | .endif | ||||
# Read-only variables | # Read-only variables | ||||
GO_CMD= ${LOCALBASE}/bin/go | GO_CMD= ${LOCALBASE}/bin/go | ||||
GO_WRKDIR_BIN= ${WRKDIR}/bin | GO_WRKDIR_BIN= ${WRKDIR}/bin | ||||
GO_ENV+= CGO_ENABLED=${CGO_ENABLED} \ | GO_ENV+= CGO_ENABLED=${CGO_ENABLED} \ | ||||
CGO_CFLAGS="${CGO_CFLAGS}" \ | CGO_CFLAGS="${CGO_CFLAGS}" \ | ||||
CGO_LDFLAGS="${CGO_LDFLAGS}" \ | CGO_LDFLAGS="${CGO_LDFLAGS}" \ | ||||
GOARM=${GOARM} | GOARM=${GOARM} | ||||
.if ${go_ARGS:Mmodules} | .if ${go_ARGS:Mmodules} | ||||
GO_BUILDFLAGS+= -mod=vendor | GO_BUILDFLAGS+= -mod=vendor | ||||
GO_TESTFLAGS+= -mod=vendor | |||||
GO_WRKSRC= ${WRKSRC} | GO_WRKSRC= ${WRKSRC} | ||||
GO_ENV+= GOPATH="" \ | GO_ENV+= GOPATH="" \ | ||||
GOBIN="${GO_WRKDIR_BIN}" | GOBIN="${GO_WRKDIR_BIN}" | ||||
.else | .else | ||||
GO_WRKDIR_SRC= ${WRKDIR}/src | GO_WRKSRC= ${WRKDIR}/src/${GO_PKGNAME} | ||||
GO_WRKSRC= ${GO_WRKDIR_SRC}/${GO_PKGNAME} | |||||
GO_ENV+= GOPATH="${WRKDIR}" \ | GO_ENV+= GOPATH="${WRKDIR}" \ | ||||
GOBIN="" | GOBIN="" | ||||
.endif | .endif | ||||
# Tentatively enable package building for Go ports on aarch64 to catch regressions early. | # Tentatively enable package building for Go ports on aarch64 to catch regressions early. | ||||
# Can be removed after go1.14 is officially released in Jan 2020 and lang/go is updated to 1.14 | # Can be removed after go1.14 is officially released in Jan 2020 and lang/go is updated to 1.14 | ||||
GO_PORT_aarch64= lang/go-devel | GO_PORT_aarch64= lang/go-devel | ||||
GO_PORT?= ${GO_PORT_${ARCH}:Ulang/go} | GO_PORT?= ${GO_PORT_${ARCH}:Ulang/go} | ||||
Show All 38 Lines | for t in ${GO_TARGET}; do \ | ||||
src=$$(${BASENAME} $${dst}); \ | src=$$(${BASENAME} $${dst}); \ | ||||
case $${dst} in \ | case $${dst} in \ | ||||
/*) dst=${STAGEDIR}$${dst}; ${MKDIR} $$(${DIRNAME} $${dst}) ;; \ | /*) dst=${STAGEDIR}$${dst}; ${MKDIR} $$(${DIRNAME} $${dst}) ;; \ | ||||
*) dst=${STAGEDIR}${PREFIX}/bin/$${src} ;; \ | *) dst=${STAGEDIR}${PREFIX}/bin/$${src} ;; \ | ||||
esac; \ | esac; \ | ||||
${ECHO_MSG} "===> Installing $${src} as $${dst}"; \ | ${ECHO_MSG} "===> Installing $${src} as $${dst}"; \ | ||||
${INSTALL_PROGRAM} ${GO_WRKDIR_BIN}/$${src} $${dst}; \ | ${INSTALL_PROGRAM} ${GO_WRKDIR_BIN}/$${src} $${dst}; \ | ||||
done | done | ||||
.endif | |||||
.if !target(do-test) && empty(go_ARGS:Mno_targets) | |||||
do-test: | |||||
(cd ${GO_WRKSRC}; \ | |||||
for t in ${GO_TESTTARGET}; do \ | |||||
${ECHO_MSG} "===> Testing $${t}"; \ | |||||
${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} test ${GO_TESTFLAGS} $${t}; \ | |||||
done) | |||||
.endif | .endif | ||||
# Helper targets for port maintainers | # Helper targets for port maintainers | ||||
.if ${go_ARGS:Mmodules} | .if ${go_ARGS:Mmodules} | ||||
_MODULES2TUPLE_CMD= modules2tuple | _MODULES2TUPLE_CMD= modules2tuple | ||||
gomod-vendor: patch | gomod-vendor: patch | ||||
@if type ${GO_CMD} > /dev/null 2>&1; then \ | @if type ${GO_CMD} > /dev/null 2>&1; then \ | ||||
Show All 12 Lines |