View | Details | Raw Unified | Return to bug 205282 | Differences between
and this patch

Collapse All | Expand All

(-)Mk2/Uses/go.mk (+118 lines)
Line 0 Link Here
1
# $FreeBSD$
2
#
3
# Provide support for NodeJS based projects
4
#
5
# Feature:	go
6
# Usage:	USES=go
7
#
8
# MAINTAINER: portmgr@FreeBSD.org
9
10
# GO_MAIN_PATH           : where is the main part of the project,
11
#                          main distfile is extracted there and build
12
#                          is performed
13
# GO_EXTRA_PATH          : additional directory to perform the build in
14
# GO_ARGS                : arguments to supply to the go command
15
# GO_TAGS                : tags to use with the go command
16
# GO_PATCH_FLAGS         : C/C++ go-files that need to have the CFLAGS or LDFLAGS set
17
# GO_PATCH_FLAGS_CFLAGS  : CFLAGS to supply to GO_PATCH_FLAGS
18
# GO_PATCH_FLAGS_LDFLAGS : LDFLAGS to supply to GO_PATCH_FLAGS
19
#
20
# Port's Makefile should supply these items:
21
# * base go packages in GO_BASE in the form: commit-tag:package ...
22
# * (optional) the list of packages from GitHub in GH_TUPLE variable
23
#   account:project:tagname:group:gh (with suffix :gh)
24
# * (optional) the list of go modules in the form
25
#   account:project:tagname:group:version#:pkg (with suffix :pkg)
26
#
27
# Framework installs one executable: ${LOCALBASE}/libexec/${PORTNAME}.
28
# In post-install port is expected to add symbolic links or services
29
# that use this executable.
30
#
31
32
.if !defined(_INCLUDE_USES_GO_MK)
33
_INCLUDE_USES_GO_MK=	yes
34
35
# depends
36
BUILD_DEPENDS+=		go:${PORTSDIR}/lang/go
37
38
# commands
39
GO_CMD?=		${LOCALBASE}/bin/go
40
41
GO_MAIN_PATH?=		github.com/${GH_TUPLE:N*\:*\:*\:*:C@:[^:]+$@@:C@:@/@}
42
GO_MAIN_BUILD_PATH?=	${GO_MAIN_PATH}
43
44
# internal variables
45
_GO_DIR?=		${PORTNAME}-${PORTVERSION}
46
_GO_DO_FAIL?=		return 1
47
GO_PATCH_FLAGS_CFLAGS?=	${CFLAGS} -I${LOCALBASE}/include
48
GO_PATCH_FLAGS_LDFLAGS?=${LDFLAGS} -L${LOCALBASE}/lib
49
50
# paths and environment
51
WRKSRC=			${WRKDIR}/${_GO_DIR}
52
GOPATH:=		${WRKSRC}
53
GO_ENV+=		GOPATH=${GOPATH}
54
.for opt in ${OPTIONS_FILE_SET}
55
GO_TAGS+=		${${opt}_GO_TAGS}
56
.endfor
57
.if defined(GO_TAGS)
58
GO_ARGS+=		-tags="${GO_TAGS}"
59
.endif
60
61
# distfiles
62
.for _GO_BASE_ONE in ${GO_BASE}
63
MASTER_SITES+=		https://codeload.github.com/golang/${_GO_BASE_ONE:C@.*:@@}/tar.gz/${_GO_BASE_ONE:C@:.*@@}?dummy=/:golang-${_GO_BASE_ONE:C@.*:@@}
64
DISTFILES+=		golang-${_GO_BASE_ONE:C@.*:@@}-${_GO_BASE_ONE:C@:.*@@}.tar.gz:golang-${_GO_BASE_ONE:C@.*:@@}
65
.endfor
66
67
# targets
68
_GO_GH_TUPLE_GH=	${GH_TUPLE:M*\:*\:*\:*\:gh:C@:gh@@}
69
_GO_GH_TUPLE_PKG=	${GH_TUPLE:M*\:pkg:C@:pkg$@@}
70
71
do-extract:
72
	@${MKDIR} ${WRKDIR}/${_GO_DIR} && \
73
	cd ${WRKDIR}/${_GO_DIR} && \
74
	${MKDIR} src/${GO_MAIN_PATH} && \
75
	${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/${DISTFILES:N*\:*} ${EXTRACT_AFTER_ARGS} \
76
	  -C src/${GO_MAIN_PATH} --strip 1 && \
77
	${ECHO} ${_GO_GH_TUPLE_GH:M*\:*\:*\:*:C@:@ @g} | xargs -n4 \
78
	  ${SH} -c 'acc=$$0;proj=$$1;h=$$2;grp=$$3; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":$${grp}$$" | ${SED} -e "s/:.*//g"); \
79
	    '"${MKDIR} src/github.com/"'$$acc'"/"'$$proj'"; \
80
	    ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/github.com/"'$$acc'"/"'$$proj'" --strip 1" && \
81
	${ECHO} ${_GO_GH_TUPLE_PKG:M*\:*\:*\:*:C@:@ @g} | xargs -n5 \
82
	  ${SH} -c 'acc=$$0;proj=$$1;h=$$2;grp=$$3;vers=$$4; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":$${grp}$$" | ${SED} -e "s/:.*//g"); \
83
	    '"${MKDIR} src/gopkg.in/"'$${proj}.$${vers}'"; \
84
	    ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/gopkg.in/"'$${proj}.$${vers}'" --strip 1" && \
85
	${ECHO} ${GO_BASE} | ${SED} -e 's/:/ /g' | xargs -n2 \
86
	  ${SH} -c 'pkg=$$1; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":golang-$${pkg}$$" | ${SED} -e "s/:.*//g"); \
87
	    '"${MKDIR} src/golang.org/x/"'$$pkg'"; \
88
	    ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/golang.org/x/"'$${pkg} --strip 1'
89
90
_USES_patch+= 750:go-patch-cflags
91
go-patch-cflags:
92
.for gofile in ${GO_PATCH_FLAGS}
93
	@${AWK} '/^\/\*([^*]|\*[^\/])*$$/ {print;print "#cgo CFLAGS: ${GO_PATCH_FLAGS_CFLAGS}";print "#cgo LDFLAGS: ${GO_PATCH_FLAGS_LDFLAGS}"} /^([^\/]|\/[^*]).*$$/ {print} /^$$/ {print}' \
94
	< ${WRKSRC}/${gofile} > ${WRKSRC}/${gofile}.new && \
95
	${MV} ${WRKSRC}/${gofile}.new ${WRKSRC}/${gofile}
96
.endfor
97
98
do-build:
99
	@for dir in ${GO_MAIN_BUILD_PATH} ${GO_EXTRA_PATH}; do \
100
	  ${ECHO} "===>  Building in the Go directory $$dir" && \
101
	  (cd ${GOPATH}/src/$$dir && \
102
	   ${GO_ENV} ${GO_CMD} build ${GO_ARGS}) || ${_GO_DO_FAIL}; \
103
	done
104
105
# install: only install when one program is produced in each GO_MAIN_BUILD_PATH
106
107
.if !target(do-install)
108
.for dir in ${GO_MAIN_BUILD_PATH}
109
PLIST_FILES+=		bin/${dir:C@^.*/@@}
110
.endfor
111
112
do-install:
113
.for dir in ${GO_MAIN_BUILD_PATH}
114
	${INSTALL_PROGRAM} ${WRKSRC}/src/${dir}/${dir:C@^.*/@@} ${STAGEDIR}${LOCALBASE}/bin/
115
.endfor
116
117
.endif
118
.endif

Return to bug 205282