# Created by: Julian Stecklina

PORTNAME=	ecl
PORTVERSION=	20.4.24
PORTREVISION=	1
CATEGORIES=	lang lisp
MASTER_SITES=	https://common-lisp.net/project/ecl/static/files/release/

MAINTAINER=	olgeni@FreeBSD.org
COMMENT=	ANSI Common Lisp implementation

LICENSE=	LGPL20

BROKEN_mips=		fails to build: qemu: uncaught target signal 11 (Segmentation fault) - core dumped
BROKEN_mips64=		fails to build: qemu: uncaught target signal 11 (Segmentation fault) - core dumped

BUILD_DEPENDS=	${LOCALBASE}/lib/libatomic_ops.a:devel/libatomic_ops
LIB_DEPENDS=	libgmp.so:math/gmp \
		libgc.so:devel/boehm-gc

MAKE_JOBS_UNSAFE=	yes
USES=		autoreconf gmake localbase perl5 tar:tgz makeinfo
USE_CSTD=	c99
USE_PERL5=	build
GNU_CONFIGURE=	yes
AUTORECONF_WRKSRC=	${WRKSRC}/src
CONFIGURE_ARGS=	--with-system-gmp \
		--with-gmp-prefix=${LOCALBASE} \
		--enable-boehm=system \
		--enable-libatomic=system
USE_LDCONFIG=	yes
INFO=		ecl

OPTIONS_DEFINE=	ASDF DFFI SAGE SOCKETS THREADS X11
OPTIONS_DEFAULT=ASDF DFFI SAGE SOCKETS THREADS

ASDF_DESC=	Enable ASDF building facility
SAGE_DESC=	Build with patches for sage
SOCKETS_DESC=	Enable socket interface
DFFI_DESC=	Dynamic foreign-function support

OPTIONS_SUB=	yes
PLIST_SUB=	VERSION="${PORTVERSION}"

ASDF_CONFIGURE_ON=	--with-asdf=yes
ASDF_CONFIGURE_OFF=	--with-asdf=no

X11_USES=		xorg
X11_USE=		XORG=x11
X11_CONFIGURE_ON=	--with-x=yes
X11_CONFIGURE_OFF=	--with-x=no

SAGE_EXTRA_PATCHES=	${PATCHDIR}/extra-patch-src_aclocal.m4 \
			${PATCHDIR}/extra-patch-src_c_file.d \
			${PATCHDIR}/extra-patch-src_compile.lsp.in \
			${PATCHDIR}/extra-patch-src_configure.ac \
			${PATCHDIR}/extra-patch-src_Makefile.in

SOCKETS_CONFIGURE_ON=	--with-tcp=yes
SOCKETS_CONFIGURE_OFF=	--with-tcp=no

DFFI_LIB_DEPENDS=	libffi.so:devel/libffi
DFFI_CONFIGURE_ON=	--with-dffi=system
DFFI_CONFIGURE_OFF=	--with-dffi=no

THREADS_CONFIGURE_ON=	--enable-threads=yes
THREADS_LDFLAGS=	-lpthread -lgc-threaded
THREADS_LIB_DEPENDS=	libgc-threaded.so:devel/boehm-gc-threaded
THREADS_CONFIGURE_OFF=	--enable-threads=no

post-patch-THREADS-on:
	@${REINPLACE_CMD} -e 's|-lgc|-lgc-threaded|' ${WRKSRC}/src/configure

post-install:
	${RMDIR} ${STAGEDIR}${PREFIX}/include/ecl/gc/private
	${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/libecl.so.${PORTVERSION}
	${LN} -sf ecl-${PORTVERSION} ${STAGEDIR}${PREFIX}/lib/ecl

.include <bsd.port.mk>
