# as of 7.8.0, the version of modernc.org/sqlite used doesn't seem
# to support other archs
ONLY_FOR_ARCHS =	amd64 aarch64
# https://gitlab.com/cznic/libc/-/issues/34
BROKEN =		syscall(2) removal

COMMENT-main =	open source Slack-alternative
COMMENT-mmctl =	command-line tool for managing Mattermost

V =		9.2.2
# mattermost-server-vendored distfile generated by fetching archive from
# https://github.com/mattermost/mattermost-server/archive/refs/tags/v{$V}.tar.gz
# and running from the server directory "go mod tidy" + "go mod vendor" +
# "rm -rf vendor/github.com/mattermost/mattermost"
DISTNAME =		mattermost-server-vendored-${V}
FULLPKGNAME-main =	mattermost-server-${V}
FULLPKGPATH-main =	net/mattermost-server,-main
FULLPKGNAME-mmctl =	mmctl-${V}
FULLPKGPATH-mmctl =	net/mattermost-server,-mmctl

SITES =		https://distfiles.tristero.se/
SITES.a =	https://releases.mattermost.com/${V}/

DISTFILES +=	${DISTNAME}${EXTRACT_SUFX}
DISTFILES.a += 	mattermost-${V}-linux-amd64${EXTRACT_SUFX}

CATEGORIES =	net
HOMEPAGE =	https://mattermost.com/

MAINTAINER =	Pavel Korovin <pvk@openbsd.org>

# MIT
PERMIT_PACKAGE =	Yes

MULTI_PACKAGES =	-main -mmctl

WANTLIB += 	c pthread

MODULES =	lang/go
ALL_TARGET =    github.com/mattermost/mattermost
MODGO_LDFLAGS = -X github.com/mattermost/mattermost/server/public/model.BuildNumber=${V}

NO_TEST =	Yes

post-extract:
	cp ${WRKDIR}/mattermost/config/config.json ${WRKDIST}/server/config/

pre-configure:
	${SUBST_CMD} ${WRKDIST}/server/channels/utils/fileutils/fileutils.go \
	${WRKDIST}/server/config/{config.json,file.go}

do-build:
	cd ${WRKSRC}/server && ${MODGO_BUILD_CMD} ./cmd/...

do-install:
	${INSTALL_PROGRAM} ${MODGO_WORKSPACE}/bin/{mattermost,mmctl} \
		${PREFIX}/bin/
	${INSTALL_DATA_DIR} ${PREFIX}/share/mattermost/
	${INSTALL_DATA_DIR} ${PREFIX}/share/examples/mattermost/
	cp ${WRKSRC}/server/config/config.json \
		${PREFIX}/share/examples/mattermost/
.for _d in client fonts i18n templates
	cp -Rp ${WRKDIR}/mattermost/${_d} ${PREFIX}/share/mattermost/
.endfor

.include <bsd.port.mk>
