# Template file for 'marvin'
pkgname=marvin
version=20.20.0
revision=1
depends="openjdk11"
short_desc="Skeletal structure drawing program by ChemAxon"
maintainer="Brenton Horne <brentonhorne77@gmail.com>"
license="custom:Marvin"
_filename="marvin_linux_${version%.*}_openjdk11.deb"
homepage="https://chemaxon.com/products/marvin"
distfiles="https://dl.chemaxon.com/marvin/${version}/${_filename}"
checksum=b8afb058331a5ec19bce11def803aeab1eff6f7ebc7abee7fa844ce3f72fe411
repository=nonfree
restricted=yes
nostrip=yes

do_extract() {
	bsdtar xf ${XBPS_SRCDISTDIR}/${pkgname}-${version}/${_filename}
	bsdtar xf data.tar.gz
}

do_patch() {
	local _file
	rm -rf opt/chemaxon/marvinsuite/jre
	rm -rf opt/chemaxon/marvinsuite/legal/OpenJDK11
	for _file in cxcalc cxtrain evaluate msketch mview
	do
		vsed -i -e '/^# INSTALL4J_JAVA_HOME_OVERRIDE=/{
			s,#,,;
			s,=.*,=/usr/lib/jvm/openjdk11,
		}' opt/chemaxon/marvinsuite/bin/$_file
	done
	vsed -i -e 's,JAVACMD="java",JAVACMD=/usr/lib/jvm/openjdk11/bin/java,' \
		-e 's,which java,: "${JAVA_HOME:=/usr/lib/jvm/openjdk11}",' \
		opt/chemaxon/marvinsuite/bin/molconvert
}

do_install() {
	cp -r opt ${DESTDIR}
	mkdir -p ${DESTDIR}/usr/{bin,share/pixmaps}
	ln -sf /opt/chemaxon/marvinsuite/.install4j/Marvin{Sketch,View}.png ${DESTDIR}/usr/share/pixmaps/

	vinstall ${FILESDIR}/MarvinSketch.desktop 755 usr/share/applications
	vinstall ${FILESDIR}/MarvinView.desktop 755 usr/share/applications

	ln -sf /opt/chemaxon/marvinsuite/MarvinSketch ${DESTDIR}/usr/bin/
	ln -sf /opt/chemaxon/marvinsuite/MarvinView ${DESTDIR}/usr/bin/
	vlicense opt/chemaxon/marvinsuite/EULA.txt
}
