PORTNAME=	java-simple-serial-connector
PORTVERSION=	2.8.0
PORTREVISION=	4
DISTVERSIONPREFIX=	v
CATEGORIES=	comms java

MAINTAINER=	kevans@FreeBSD.org
COMMENT=	Library for working with serial ports from Java
WWW=		https://github.com/scream3r/java-simple-serial-connector

LICENSE=	LGPL3

USES=		java:ant,build
USE_GITHUB=	yes
GH_ACCOUNT=	scream3r

MAJOR_MINOR=	${PORTVERSION:C/(.*)\.[0-9]*/\\1/}
ALL_TARGET=	dist
CXXFLAGS+=	-I${JAVA_HOME}/include -I${JAVA_HOME}/include/freebsd
WRKSRC_LIBS=	${WRKSRC}/src/java/libs

PLIST_FILES=	${JAVAJARDIR}/jssc-${PORTVERSION}.jar

.include <bsd.port.pre.mk>

.if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7
JSSC_ARCH=		arm
.else
JSSC_ARCH=		${ARCH}
.endif

post-extract:
	@${CP} ${FILESDIR}/build.xml.in ${WRKSRC}/build.xml
	@${REINPLACE_CMD} -e 's|%%PORTVERSION%%|${PORTVERSION}|' ${WRKSRC}/build.xml

pre-build:
	${RM} -r ${WRKSRC_LIBS}/*
	${MKDIR} ${WRKSRC_LIBS}/freebsd
	(cd ${WRKSRC}/src/cpp/_nix_based && ${CXX} ${CXXFLAGS} ${CPPFLAGS} -shared -fPIC -o ${WRKSRC_LIBS}/freebsd/libjSSC-${MAJOR_MINOR}_${JSSC_ARCH}.so jssc.cpp)
	${STRIP_CMD} ${WRKSRC_LIBS}/freebsd/libjSSC-${MAJOR_MINOR}_${JSSC_ARCH}.so

do-install:
	${INSTALL_DATA} ${WRKSRC}/build/jssc-${PORTVERSION}.jar ${STAGEDIR}${JAVAJARDIR}/

.include <bsd.port.post.mk>
