SUMMARY="A native serial library for java serial communication"
DESCRIPTION="RXTX is a Java library, using a native implementation (via JNI), \
providing serial and parallel communication for the Java Development Toolkit \
(JDK). All deliverables are under the GNU LGPL license. It is based on the \
specification for Sun Java Communications API, though while many of the class \
descriptions are the same the package used it not, since gnu.io is used \
instead. A certain amount of compatibility is intended with API, though this \
project should be considered as a fork and therefore compatible in spirit, \
but not in implementation."
HOMEPAGE="http://rxtx.qbang.org"
COPYRIGHT="1998-2006 Keane Jarvi"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="git+https://github.com/arduino/RXTX#84a009c"
PATCHES="rxtx-2.2_haiku-support.patch"

ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	# x86_gcc2 is fine as primary target architecture as long as we're building
	# for a different secondary architecture.
	ARCHITECTURES="$ARCHITECTURES x86_gcc2"
else
	ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	rxtx$secondaryArchSuffix = $portVersion
	lib:librxtxSerial$secondaryArchSuffix = 0.0.0 compat >= 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	openjdk${secondaryArchSuffix}
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	openjdk${secondaryArchSuffix}
	"
BUILD_PREREQUIRES="
	openjdk${secondaryArchSuffix}
	cmd:aclocal
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:javac
	cmd:javah
	cmd:libtoolize
	cmd:make
	cmd:find	
	"

BUILD()
{
	sed -i 's/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' configure.in
	libtoolize --force --copy --install
	aclocal
	autoconf
	runConfigure ./configure CPPFLAGS="-I/boot/system/lib/x86/openjdk/include/haiku"
	make
}

INSTALL()
{
	mkdir -p $libDir/openjdk/jre/lib/i386	
	cp i586-pc-haiku/.libs/librxtxSerial-2.2.so $libDir/openjdk/jre/lib/i386
	cp i586-pc-haiku/.libs/librxtxSerial.so $libDir/openjdk/jre/lib/i386

	mkdir -p $libDir/openjdk/jre/lib/ext
	cp RXTXcomm.jar $libDir/openjdk/jre/lib/ext	
}
