diff -ruN Mk1/Uses/go.mk Mk2/Uses/go.mk --- Mk1/Uses/go.mk 1969-12-31 16:00:00.000000000 -0800 +++ Mk2/Uses/go.mk 2015-12-14 20:02:42.218632000 -0800 @@ -0,0 +1,118 @@ +# $FreeBSD$ +# +# Provide support for NodeJS based projects +# +# Feature: go +# Usage: USES=go +# +# MAINTAINER: portmgr@FreeBSD.org + +# GO_MAIN_PATH : where is the main part of the project, +# main distfile is extracted there and build +# is performed +# GO_EXTRA_PATH : additional directory to perform the build in +# GO_ARGS : arguments to supply to the go command +# GO_TAGS : tags to use with the go command +# GO_PATCH_FLAGS : C/C++ go-files that need to have the CFLAGS or LDFLAGS set +# GO_PATCH_FLAGS_CFLAGS : CFLAGS to supply to GO_PATCH_FLAGS +# GO_PATCH_FLAGS_LDFLAGS : LDFLAGS to supply to GO_PATCH_FLAGS +# +# Port's Makefile should supply these items: +# * base go packages in GO_BASE in the form: commit-tag:package ... +# * (optional) the list of packages from GitHub in GH_TUPLE variable +# account:project:tagname:group:gh (with suffix :gh) +# * (optional) the list of go modules in the form +# account:project:tagname:group:version#:pkg (with suffix :pkg) +# +# Framework installs one executable: ${LOCALBASE}/libexec/${PORTNAME}. +# In post-install port is expected to add symbolic links or services +# that use this executable. +# + +.if !defined(_INCLUDE_USES_GO_MK) +_INCLUDE_USES_GO_MK= yes + +# depends +BUILD_DEPENDS+= go:${PORTSDIR}/lang/go + +# commands +GO_CMD?= ${LOCALBASE}/bin/go + +GO_MAIN_PATH?= github.com/${GH_TUPLE:N*\:*\:*\:*:C@:[^:]+$@@:C@:@/@} +GO_MAIN_BUILD_PATH?= ${GO_MAIN_PATH} + +# internal variables +_GO_DIR?= ${PORTNAME}-${PORTVERSION} +_GO_DO_FAIL?= return 1 +GO_PATCH_FLAGS_CFLAGS?= ${CFLAGS} -I${LOCALBASE}/include +GO_PATCH_FLAGS_LDFLAGS?=${LDFLAGS} -L${LOCALBASE}/lib + +# paths and environment +WRKSRC= ${WRKDIR}/${_GO_DIR} +GOPATH:= ${WRKSRC} +GO_ENV+= GOPATH=${GOPATH} +.for opt in ${OPTIONS_FILE_SET} +GO_TAGS+= ${${opt}_GO_TAGS} +.endfor +.if defined(GO_TAGS) +GO_ARGS+= -tags="${GO_TAGS}" +.endif + +# distfiles +.for _GO_BASE_ONE in ${GO_BASE} +MASTER_SITES+= https://codeload.github.com/golang/${_GO_BASE_ONE:C@.*:@@}/tar.gz/${_GO_BASE_ONE:C@:.*@@}?dummy=/:golang-${_GO_BASE_ONE:C@.*:@@} +DISTFILES+= golang-${_GO_BASE_ONE:C@.*:@@}-${_GO_BASE_ONE:C@:.*@@}.tar.gz:golang-${_GO_BASE_ONE:C@.*:@@} +.endfor + +# targets +_GO_GH_TUPLE_GH= ${GH_TUPLE:M*\:*\:*\:*\:gh:C@:gh@@} +_GO_GH_TUPLE_PKG= ${GH_TUPLE:M*\:pkg:C@:pkg$@@} + +do-extract: + @${MKDIR} ${WRKDIR}/${_GO_DIR} && \ + cd ${WRKDIR}/${_GO_DIR} && \ + ${MKDIR} src/${GO_MAIN_PATH} && \ + ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${DISTDIR}/${DISTFILES:N*\:*} ${EXTRACT_AFTER_ARGS} \ + -C src/${GO_MAIN_PATH} --strip 1 && \ + ${ECHO} ${_GO_GH_TUPLE_GH:M*\:*\:*\:*:C@:@ @g} | xargs -n4 \ + ${SH} -c 'acc=$$0;proj=$$1;h=$$2;grp=$$3; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":$${grp}$$" | ${SED} -e "s/:.*//g"); \ + '"${MKDIR} src/github.com/"'$$acc'"/"'$$proj'"; \ + ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/github.com/"'$$acc'"/"'$$proj'" --strip 1" && \ + ${ECHO} ${_GO_GH_TUPLE_PKG:M*\:*\:*\:*:C@:@ @g} | xargs -n5 \ + ${SH} -c 'acc=$$0;proj=$$1;h=$$2;grp=$$3;vers=$$4; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":$${grp}$$" | ${SED} -e "s/:.*//g"); \ + '"${MKDIR} src/gopkg.in/"'$${proj}.$${vers}'"; \ + ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/gopkg.in/"'$${proj}.$${vers}'" --strip 1" && \ + ${ECHO} ${GO_BASE} | ${SED} -e 's/:/ /g' | xargs -n2 \ + ${SH} -c 'pkg=$$1; df=$$(echo ${DISTFILES} | tr " " "\\n" | grep ":golang-$${pkg}$$" | ${SED} -e "s/:.*//g"); \ + '"${MKDIR} src/golang.org/x/"'$$pkg'"; \ + ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} "'${DISTDIR}/$${df}'" ${EXTRACT_AFTER_ARGS} -C src/golang.org/x/"'$${pkg} --strip 1' + +_USES_patch+= 750:go-patch-cflags +go-patch-cflags: +.for gofile in ${GO_PATCH_FLAGS} + @${AWK} '/^\/\*([^*]|\*[^\/])*$$/ {print;print "#cgo CFLAGS: ${GO_PATCH_FLAGS_CFLAGS}";print "#cgo LDFLAGS: ${GO_PATCH_FLAGS_LDFLAGS}"} /^([^\/]|\/[^*]).*$$/ {print} /^$$/ {print}' \ + < ${WRKSRC}/${gofile} > ${WRKSRC}/${gofile}.new && \ + ${MV} ${WRKSRC}/${gofile}.new ${WRKSRC}/${gofile} +.endfor + +do-build: + @for dir in ${GO_MAIN_BUILD_PATH} ${GO_EXTRA_PATH}; do \ + ${ECHO} "===> Building in the Go directory $$dir" && \ + (cd ${GOPATH}/src/$$dir && \ + ${GO_ENV} ${GO_CMD} build ${GO_ARGS}) || ${_GO_DO_FAIL}; \ + done + +# install: only install when one program is produced in each GO_MAIN_BUILD_PATH + +.if !target(do-install) +.for dir in ${GO_MAIN_BUILD_PATH} +PLIST_FILES+= bin/${dir:C@^.*/@@} +.endfor + +do-install: +.for dir in ${GO_MAIN_BUILD_PATH} + ${INSTALL_PROGRAM} ${WRKSRC}/src/${dir}/${dir:C@^.*/@@} ${STAGEDIR}${LOCALBASE}/bin/ +.endfor + +.endif +.endif