# Template file for 'ytnef'
pkgname=ytnef
version=1.9.2
revision=1
build_style=gnu-configure
hostmakedepends="automake libtool"
short_desc="Yerase's TNEF Stream Reader"
maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
license="GPL-2"
homepage="https://github.com/Yeraze/ytnef"
distfiles="https://github.com/Yeraze/ytnef/archive/v${version}.tar.gz>${pkgname}-${version}.tar.gz"
checksum=48f7d7272ba74b267d3f98a1b14c81fef54cfb53460346d7c36a9604df1f95ad

pre_configure() {
	./autogen.sh
}

do_build() {
	if [ -n "$CROSS_BUILD" ]; then
		configure_args+=" --host=${XBPS_TARGET_MACHINE}"
		export ac_cv_func_malloc_0_nonnull=yes
	fi
	cd ${wrksrc}/lib
	make ${makejobs} DESTDIR="${DESTDIR}" install
	if [ -d "${DESTDIR}/usr/lib32" ]; then
		mv "${DESTDIR}/usr/lib32" "${DESTDIR}/usr/lib"
	fi
	export CFLAGS+=" -I${DESTDIR}/usr/include"
	export LDFLAGS+=" -L${DESTDIR}/usr/lib"
	cd ${wrksrc}
	make ${makejobs}
}

do_install() {
	cd ${wrksrc}/ytnef
	make DESTDIR="${DESTDIR}" install
	# Cross compiling for some reason installs to /usr/local/bin
	if [ -d "${DESTDIR}/usr/local/bin" ]; then
		mv "${DESTDIR}/usr/local/bin" "${DESTDIR}/usr"
	fi
}

ytnef-devel_package() {
	short_desc+=" - development files"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/*.a
		vmove usr/lib/*.so
	}
}
