Changeset View
Changeset View
Standalone View
Standalone View
Mk/Uses/go.mk
# 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), N.NN, devel, modules, no_targets, run | ||||
# | # | ||||
# (none) Setup GOPATH and build in GOPATH mode. | # (none) Setup GOPATH and build in GOPATH mode using default Go version. | ||||
# N.NN | devel Specify Go version | |||||
# 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 and | # GO_ENV, GO_BUILDFLAGS but will not create post-extract and | ||||
# do-{build,install,test} 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. | ||||
Show All 30 Lines | |||||
# 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 | # GO_TESTFLAGS | ||||
# Additional build arguments to be passed to the `go test` command | # Additional build arguments to be passed to the `go test` command | ||||
# | # | ||||
# GO_PORT | |||||
# 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. | |||||
# | |||||
# This variable must not be set by individual ports! | |||||
# | |||||
# MAINTAINER: ports@FreeBSD.org | # MAINTAINER: ports@FreeBSD.org | ||||
.if !defined(_INCLUDE_USES_GO_MK) | .if !defined(_INCLUDE_USES_GO_MK) | ||||
_INCLUDE_USES_GO_MK= yes | _INCLUDE_USES_GO_MK= yes | ||||
. if !empty(go_ARGS:Nmodules:Nno_targets:Nrun) | # When adding a version, please keep the comment in | ||||
IGNORE= USES=go has invalid arguments: ${go_ARGS:Nmodules:Nno_targets:Nrun} | # Mk/bsd.default-versions.mk in sync. | ||||
GO_VALID_VERSIONS= 1.17 1.18 1.19-devel | |||||
# Check arguments sanity | |||||
. if !empty(go_ARGS:N[1-9].[0-9][0-9]:N*-devel:Nmodules:Nno_targets:Nrun) | |||||
IGNORE= USES=go has invalid arguments: ${go_ARGS:N[1-9].[0-9][0-9]:N*-devel:Nmodules:Nno_targets:Nrun} | |||||
. endif | . endif | ||||
# Parse Go version | |||||
GO_VERSION= ${go_ARGS:Nmodules:Nno_targets:Nrun:C/^$/${GO_DEFAULT}/} | |||||
. if empty(GO_VALID_VERSIONS:M${GO_VERSION}) | |||||
IGNORE?= USES=go has invalid version number: ${GO_VERSION} | |||||
. endif | |||||
GO_SUFFIX= ${GO_VERSION:S/.//:C/.*-devel/-devel/} | |||||
GO_PORT= lang/go${GO_SUFFIX} | |||||
# Settable variables | # Settable variables | ||||
GO_PORT?= lang/go | |||||
. if empty(GO_PKGNAME) | . if empty(GO_PKGNAME) | ||||
. 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_TESTTARGET?= ./... | ||||
GO_BUILDFLAGS+= -v -buildmode=exe -trimpath | GO_BUILDFLAGS+= -v -buildmode=exe -trimpath | ||||
. 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 | GO_TESTFLAGS+= -v | ||||
. if ${GO_PORT} != lang/go117 | . if ${GO_VERSION} != 1.17 | ||||
GO_BUILDFLAGS+= -buildvcs=false | GO_BUILDFLAGS+= -buildvcs=false | ||||
GO_TESTFLAGS+= -buildvcs=false | GO_TESTFLAGS+= -buildvcs=false | ||||
. endif | . endif | ||||
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 | ||||
GO_GOPROXY?= https://proxy.golang.org | GO_GOPROXY?= https://proxy.golang.org | ||||
GO_GOSUMDB?= sum.golang.org | GO_GOSUMDB?= sum.golang.org | ||||
# Read-only variables | # Read-only variables | ||||
GO_CMD= ${LOCALBASE}/bin/go | GO_CMD= ${LOCALBASE}/bin/go${GO_SUFFIX} | ||||
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 | ||||
Show All 30 Lines | |||||
GO_GOPATH= ${WRKDIR} | GO_GOPATH= ${WRKDIR} | ||||
GO_WRKSRC= ${WRKDIR}/src/${GO_PKGNAME} | GO_WRKSRC= ${WRKDIR}/src/${GO_PKGNAME} | ||||
GO_ENV+= GOPATH="${GO_GOPATH}" \ | GO_ENV+= GOPATH="${GO_GOPATH}" \ | ||||
GOBIN="" \ | GOBIN="" \ | ||||
GO111MODULE=off | GO111MODULE=off | ||||
. endif | . endif | ||||
BUILD_DEPENDS+= ${GO_CMD}:${GO_PORT} | BUILD_DEPENDS+= ${GO_CMD}:${GO_PORT} | ||||
BINARY_ALIAS+= go=go${GO_SUFFIX} gofmt=gofmt${GO_SUFFIX} | |||||
. if ${go_ARGS:Mrun} | . if ${go_ARGS:Mrun} | ||||
RUN_DEPENDS+= ${GO_CMD}:${GO_PORT} | RUN_DEPENDS+= ${GO_CMD}:${GO_PORT} | ||||
. endif | . endif | ||||
_USES_POST+= go | _USES_POST+= go | ||||
.endif # !defined(_INCLUDE_USES_GO_MK) | .endif # !defined(_INCLUDE_USES_GO_MK) | ||||
.if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_GO_POST_MK) | .if defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_GO_POST_MK) | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |