# Created by: Franz Glasner <freebsd-dev@dom66.de>
# $FreeBSD$

PORTNAME=	local-bsdtools
DISTVERSION=	0.5
CATEGORIES=	sysutils
MASTER_SITES=	# none
DISTFILES=	# none

MAINTAINER=	freebsd-dev@dom66.de
COMMENT=	Collection of private system management tools

LICENSE=	BSD3CLAUSE

BUILD_DEPENDS=	hg:devel/mercurial
RUN_DEPENDS=	pkg:ports-mgmt/pkg

NO_ARCH=	yes
NO_BUILD=	yes
WRKSRC=		${WRKDIR}/local-bsdtools

SRC=		${.CURDIR}

HGCANONICALPATH?=	default
HGREVISION=	${:!hg id -R "${SRC}" -q!}
HGDATE=		${:!hg log -R "${SRC}" -r "${HGREVISION:S/+//}" --template '{date|isodatesec}'!}
HGAUTHOR=	${:!hg log -R "${SRC}" -r "${HGREVISION:S/+//}" --template '{author|person}' | ${TR} ' ' '+'!}
HGPATH=		${:!hg --config ui.paginate=never path -R "${SRC}" ${HGCANONICALPATH} || echo "file://\$$\(hg root)"!}
HGPHASE=	${:!hg phase!:[2]}

do-extract:
	${MKDIR} ${WRKSRC}/bin
.for _rp in bin/check-ports
	${CP} -v ${SRC}/${_rp} ${WRKSRC}/${_rp}
	${SED} -i "" -E -e "s|\\\$$Date\\\$$|\$$Date: ${HGDATE} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -E -e "s|\\\$$Revision\\\$$|\$$Revision: ${HGREVISION} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -E -e "s|\\\$$Author\\\$$|\$$Author: ${HGAUTHOR} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|\\\$$HGpath\\\$$|\$$HGpath: ${HGPATH} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|\\\$$HGsource\\\$$|\$$HGsource: ${HGPATH}/${_rp} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|\\\$$Header\\\$$|\$$Header: ${_rp} ${HGREVISION} ${HGDATE} ${HGAUTHOR} ${HGPHASE} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|\\\$$HGid\\\$$|\$$HGid: ${HGPATH}/${_rp} ${HGREVISION} ${HGDATE} ${HGAUTHOR} ${HGPHASE} \$$|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|@@VERSION@@|${PORTVERSION}|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|@@ETCDIR@@|${ETCDIR}|" ${WRKSRC}/${_rp}
	${SED} -i "" -e "s|@@INDEXFILE@@|${INDEXFILE}|" ${WRKSRC}/${_rp}
.endfor
	${MKDIR} ${WRKSRC}/etc
.for _ef in etc/package-mapping.conf.sample
	${CP} -v ${SRC}/${_ef} ${WRKSRC}/${_ef}
	${SED} -i "" -e "s|\\\$$HGid\\\$$|\$$HGid: ${HGPATH}/${_ef} ${HGREVISION} ${HGDATE} ${HGAUTHOR} ${HGPHASE} \$$|" ${WRKSRC}/${_ef}
.endfor

do-install:
.for _rp in bin/check-ports
	${INSTALL_SCRIPT} ${WRKSRC}/${_rp} ${STAGEDIR}${PREFIX}/${_rp}
.endfor
	${MKDIR} ${STAGEDIR}${ETCDIR}
.for _ef in package-mapping.conf.sample
	${INSTALL_DATA} ${WRKSRC}/etc/${_ef} ${STAGEDIR}${ETCDIR}/${_ef}
.endfor

.include <bsd.port.mk>
