Changeset View
Changeset View
Standalone View
Standalone View
Mk/Uses/go.mk
Show All 14 Lines | |||||
# GO_ENV, GO_BUILDFLAGS but will not create post-extract, do-build | # GO_ENV, GO_BUILDFLAGS but will not create post-extract, do-build | ||||
# and do-install targets. | # and do-install 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 is | # The name of the package when building in GOPATH mode. This is | ||||
# the directory that will be created in GOPATH/src and seen by the | # the directory that will be created in GOPATH/src and seen by the | ||||
# `go` command. When building in modules-aware mode, no directories | # `go` command. If not set explicitly and GH_SUBDIR or GL_SUBDIR | ||||
# will be created and GO_PKGNAME value will be only used as a default | # is present, GO_PKGNAME will be inferred from it. | ||||
# for GO_TARGET. If not set explicitly and GH_SUBDIR is present, | # Not needed when building in modules-aware mode. | ||||
# GO_PKGNAME will be inferred from GH_SUBDIR. | |||||
# | # | ||||
# GO_TARGET | # GO_TARGET | ||||
# The names of the package(s) to build. If not set explicitly, | # The names of the package(s) to build. If not set explicitly, | ||||
# defaults to GO_PKGNAME. | # defaults to GO_PKGNAME. GO_TARGET can also be a tuple in the form | ||||
# package:output which will instruct Go to write resulting executable | |||||
# to ${GO_WRKDIR_BIN}/${output} instead of the default behaviour of | |||||
# naming executable using the last component of the package name. | |||||
# | # | ||||
# CGO_CFLAGS | # CGO_CFLAGS | ||||
# Addional 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 | ||||
# Addional 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 install` command | # Additional build arguments to be passed to the `go install` 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: dg@syrec.org | # MAINTAINER: dg@syrec.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) | .if !empty(go_ARGS:Nmodules:Nno_targets:Nrun) | ||||
IGNORE= USES=go has invalid arguments: ${go_ARGS:Nmodules:Nno_targets:Nrun} | IGNORE= USES=go has invalid arguments: ${go_ARGS:Nmodules:Nno_targets:Nrun} | ||||
.endif | .endif | ||||
# Settable variables | # Settable variables | ||||
.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) | |||||
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_BUILDFLAGS+= -v -buildmode=exe | GO_BUILDFLAGS+= -v -buildmode=exe | ||||
CGO_ENABLED?= 1 | CGO_ENABLED?= 1 | ||||
CGO_CFLAGS+= -I${LOCALBASE}/include | CGO_CFLAGS+= -I${LOCALBASE}/include | ||||
Show All 39 Lines | |||||
post-extract: | post-extract: | ||||
@${MKDIR} ${GO_WRKSRC:H} | @${MKDIR} ${GO_WRKSRC:H} | ||||
@${LN} -sf ${WRKSRC} ${GO_WRKSRC} | @${LN} -sf ${WRKSRC} ${GO_WRKSRC} | ||||
.endif | .endif | ||||
.if !target(do-build) && empty(go_ARGS:Mno_targets) | .if !target(do-build) && empty(go_ARGS:Mno_targets) | ||||
do-build: | do-build: | ||||
(cd ${GO_WRKSRC}; \ | (cd ${GO_WRKSRC}; \ | ||||
${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} install ${GO_BUILDFLAGS} ${GO_TARGET:S/^${PORTNAME}$/./}) | for t in ${GO_TARGET}; do \ | ||||
out=$$(${BASENAME} $$(${ECHO_CMD} $${t} | \ | |||||
${SED} -Ee 's/^[^:]*:([^:]+).*$$/\1/' -e 's/^\.$$/${PORTNAME}/')); \ | |||||
pkg=$$(${ECHO_CMD} $${t} | \ | |||||
${SED} -Ee 's/^([^:]*).*$$/\1/' -e 's/^${PORTNAME}$$/./'); \ | |||||
${ECHO_CMD} "===> Building $${out} from $${pkg}"; \ | |||||
tobik: Since this is a message from the framework use `${ECHO_MSG}` here. | |||||
${SETENV} ${MAKE_ENV} ${GO_ENV} ${GO_CMD} build ${GO_BUILDFLAGS} \ | |||||
-o ${GO_WRKDIR_BIN}/$${out} \ | |||||
$${pkg}; \ | |||||
done) | |||||
.endif | .endif | ||||
.if !target(do-install) && empty(go_ARGS:Mno_targets) | .if !target(do-install) && empty(go_ARGS:Mno_targets) | ||||
do-install: | do-install: | ||||
.for _TARGET in ${GO_TARGET} | for t in ${GO_TARGET}; do \ | ||||
${INSTALL_PROGRAM} ${GO_WRKDIR_BIN}/${_TARGET:T:S/^.$/${PORTNAME}/} ${STAGEDIR}${PREFIX}/bin | out=$$(${BASENAME} $$(${ECHO_CMD} $${t} | \ | ||||
.endfor | ${SED} -Ee 's/^[^:]*:([^:]+).*$$/\1/' -e 's/^\.$$/${PORTNAME}/')); \ | ||||
${INSTALL_PROGRAM} ${GO_WRKDIR_BIN}/$${out} ${STAGEDIR}${PREFIX}/bin; \ | |||||
Done Inline ActionsI feel like this should somehow also support installing the binaries into a different path altogether like ${PREFIX}/sbin or ${PREFIX}/libexec. Example ports that would benefit are net/gobgp, www/gitea, www/webhook, ... GO_TARGET= ./bsondump/main:${PREFIX}/sbin/bsondump where the short form of GO_TARGET= ./bsondump/main:bsondump would still just install it as ${PREFIX}/bin/bsondump tobik: I feel like this should somehow also support installing the binaries into a different path… | |||||
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 ${_MODULES2TUPLE_CMD} > /dev/null 2>&1; then \ | @if type ${_MODULES2TUPLE_CMD} > /dev/null 2>&1; then \ | ||||
cd ${WRKSRC}; ${GO_CMD} mod vendor; \ | cd ${WRKSRC}; ${GO_CMD} mod vendor; \ | ||||
[ -r vendor/modules.txt ] && ${_MODULES2TUPLE_CMD} vendor/modules.txt; \ | [ -r vendor/modules.txt ] && ${_MODULES2TUPLE_CMD} vendor/modules.txt; \ | ||||
else \ | else \ | ||||
${ECHO_MSG} "===> Please install \"ports-mgmt/modules2tuple\""; \ | ${ECHO_MSG} "===> Please install \"ports-mgmt/modules2tuple\""; \ | ||||
fi | fi | ||||
.endif | .endif | ||||
.endif # defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_GO_POST_MK) | .endif # defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_GO_POST_MK) |
Since this is a message from the framework use ${ECHO_MSG} here.