# vim: tabstop=8 softtabstop=0 noexpandtab
# Ports collection Makefile for:	jags
# Date created:		21 April 2004
# Whom:			Eric van Gyzen <vangyzen@stat.duke.edu>
#
# $FreeBSD: ports/math/jags/Makefile,v 1.28 2012/01/05 13:16:02 bf Exp $
#

PORTNAME=	mcmc-jags
PORTVERSION=	3.2.0
CATEGORIES=	math
MASTER_SITES=	SF:1,2,3,4
MASTER_SITE_SUBDIR=	mcmc-jags/JAGS/${S}.x/Source/:1 \
		mcmc-jags/Examples/2.x/:2 \
		mcmc-jags/Manuals/2.x/:3 \
		mcmc-jags/Manuals/${S}.x/:4
DISTFILES=	JAGS-${PORTVERSION}${EXTRACT_SUFX}:1
.if !defined(NOPORTDOCS) || make(makesum)
DISTFILES+=	jags_developer_manual.pdf:3 jags_installation_manual.pdf:4 \
		jags_user_manual.pdf:4
.endif
.if !defined(NOPORTEXAMPLES) || make(makesum)
DISTFILES+=	classic-bugs.tar.gz:2
.endif
EXTRACT_ONLY=	${DISTFILES:M*[12]:C|:.*||}

MAINTAINER=	bf@FreeBSD.org
COMMENT=	Just Another Gibbs Sampler

LICENSE=	GPLv2

GNU_CONFIGURE=	yes
USE_BISON=	build
USE_FORTRAN=	yes
USE_LDCONFIG=	yes

DIST_SUBDIR=	${PORTNAME}
WRKSRC=		${WRKDIR}/JAGS-${PORTVERSION}

CPPFLAGS+=	-I${LOCALBASE}/include
LDFLAGS+=	-L${LOCALBASE}/lib
MAN1=		jags.1
OPTIONS=	ATLAS "use ATLAS libraries instead of BLAS and LAPACK" off
PLIST_SUB=	MODULEVERSION=${S}
S=		${PORTVERSION:C|\..*||}

.include <bsd.port.options.mk>

.if defined(WITH_ATLAS)
LIB_DEPENDS+=	atlas.2:${PORTSDIR}/math/atlas
CONFIGURE_ARGS=	--with-lapack="-lalapack -lptcblas" --with-blas="-lptf77blas"
.else
LIB_DEPENDS+=	blas.2:${PORTSDIR}/math/blas
LIB_DEPENDS+=	lapack.4:${PORTSDIR}/math/lapack
CONFIGURE_ARGS=	--with-lapack="-llapack" --with-blas="-lblas"
.endif

.if !defined(NOPORTDOCS)
PORTDOCS=	${DISTFILES:M*[34]:C|:.*||}
.endif

.if !defined(NOPORTEXAMPLES)
PORTEXAMPLES=	*
.endif

post-patch:
	@${REINPLACE_CMD} -e 's|[(]libdir[)]/pkgconfig|(prefix)/libdata/pkgconfig|g' \
		${WRKSRC}/etc/Makefile.in
	@${REINPLACE_CMD} \
		-e '/@WINDOWS_FALSE@bin_SCRIPTS =/s/jags/mcmc-&/' \
		-e '/CLEANFILES =/s/jags/mcmc-&/' \
		-e '/@WINDOWS_FALSE@jags:/s/jags/mcmc-&/' \
		-e '/@WINDOWS_FALSE@.*rm -f jags/s/jags/mcmc-&/' \
		-e '/@WINDOWS_FALSE@.*mv jags.tmp jags/s/jags/mcmc-&/2' \
		${WRKSRC}/src/terminal/Makefile.in
.if !defined(NOPORTEXAMPLES)
	@${SED} -i '' -e '\|JAGS ?=|{s|jags|mcmc-&|;s|/usr/local|${PREFIX}|;}' \
		${WRKDIR}/classic-bugs/vol[12]/Makefile
.endif

post-install:
.if !defined(NOPORTDOCS)
	@${MKDIR} ${DOCSDIR}
	@cd ${_DISTDIR}; ${INSTALL_DATA} ${PORTDOCS} ${DOCSDIR}
.endif
.if !defined(NOPORTEXAMPLES)
	@${MKDIR} ${EXAMPLESDIR}
	@cd ${WRKDIR}/classic-bugs; ${COPYTREE_SHARE} \* ${EXAMPLESDIR}
.endif
	@${ECHO_MSG} ""
	@${CAT} ${PKGMESSAGE}
	@${ECHO_MSG} ""

.if defined(MAINTAINER_MODE)
BUILD_DEPENDS+=	${LOCALBASE}/lib/R/library/coda/R/coda.rdb:${PORTSDIR}/math/R-cran-coda

check test: install
.for i in 1 2
	cd ${WRKDIR}/classic-bugs/vol${i}; ${SETENV} ${MAKE_ENV} \
	${MAKE} ${_MAKE_JOBS} ${MAKE_ARGS} check
.endfor

.endif
.include <bsd.port.mk>
