PORTNAME=	gforth
PORTVERSION=	0.7.3
PORTREVISION=	15
CATEGORIES=	lang
MASTER_SITES=	http://www.complang.tuwien.ac.at/forth/gforth/ \
		GNU

PATCH_SITES=	https://cgit.git.savannah.gnu.org/cgit/gforth.git/patch/?id=e664cb01&dummy=/:c1 \
		https://cgit.git.savannah.gnu.org/cgit/gforth.git/patch/?id=4284a265&dummy=/:c2
PATCHFILES=	gforth-git-e664cb01.patch:-p1:c1 gforth-git-4284a265.patch:-p1:c2

MAINTAINER=	danfe@FreeBSD.org
COMMENT=	Fast and portable ANS Forth 94 implementation
WWW=		https://www.gnu.org/software/gforth/gforth.html

LICENSE=	GPLv3+
LICENSE_FILE=	${WRKSRC}/COPYING

LIB_DEPENDS=	libavcall.so:devel/libffcall \
		libffi.so:devel/libffi \
		libltdl.so:devel/libltdl

USES=		gmake libtool:build localbase makeinfo
USE_GCC=	yes
USE_LDCONFIG=	${PREFIX}/lib/gforth/${PORTVERSION}/libcc-named
GNU_CONFIGURE=	yes
CONFIGURE_ENV=	GFORTHHIST=${WRKSRC}
MAKE_ENV=	GFORTHHIST=${WRKSRC}
ALL_TARGET=	kernel/version.fs more info
TEST_TARGET=	check
MAKE_JOBS_UNSAFE=	/bin/sh: ./gforth: not found

STRIP=		#none

PLIST_SUB=	PORTVERSION=${PORTVERSION} \
		WORDSIZE=${WORDSIZE} BYTEORDER=${BYTEORDER}

PORTDOCS=	AUTHORS BUGS Benchres COPYING COPYING.DOC \
		INSTALL INSTALL.BINDIST NEWS README \
		NEWS.vmgen README.vmgen ToDo

INFO=		gforth vmgen

OPTIONS_DEFINE=	DOCS

.include <bsd.port.pre.mk>

.if ${ARCH} == i386 || ${ARCH} == powerpc || ${ARCH} == armv6 || ${ARCH} == armv7
WORDSIZE=32
.else
WORDSIZE=64
.endif

.if ${ARCH} == powerpc || ${ARCH} == powerpc64
BYTEORDER=b
.else
BYTEORDER=l
.endif

post-patch:
	${REINPLACE_CMD} 's:@CC@:& -I${LOCALBASE}/include -L${LOCALBASE}/lib:' \
		 ${WRKSRC}/envos.fs.in
	${REINPLACE_CMD} '/ checkone/d' ${WRKSRC}/Makefile.in

post-install: install-doc remove-empty-files remove-empty-dirs

install-doc:
.if ${PORT_OPTIONS:MDOCS}
	@${MKDIR} ${STAGEDIR}${DOCSDIR}
. for filename in ${PORTDOCS}
	${INSTALL_DATA} ${WRKSRC}/${filename} ${STAGEDIR}${DOCSDIR}
. endfor
.endif

# Remove unused file
remove-empty-files:
	@${RM} ${STAGEDIR}${DATADIR}/site-forth/siteinit.fs

# Remove unused directories
remove-empty-dirs:
	@${FIND} -d ${STAGEDIR}${DATADIR}/${PORTVERSION}/arch/ -type d -empty -delete

.include <bsd.port.post.mk>
