# Template file for 'libmilter'
pkgname=libmilter
version=1.0.2
revision=4
_pkgname=sendmail
_version=8.15.2
wrksrc="${_pkgname}-${_version}"
hostmakedepends="m4"
short_desc="Implementation of the sendmail Mail Filter API"
maintainer="John Regan <john@jrjrtech.com>"
license="Sendmail"
homepage="https://www.milter.org/developers/api/"
distfiles="ftp://ftp.mirrorservice.org/sites/ftp.sendmail.org/pub/${_pkgname}/${_pkgname}.${_version}.tar.gz"
checksum=24f94b5fd76705f15897a78932a5f2439a32b1a2fdc35769bb1a5f5d9b4db439

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	makedepends+=" musl-legacy-compat"
fi

pre_build() {
	cp "${FILESDIR}/site.config.m4" devtools/Site/site.config.m4
	cat >> devtools/Site/site.config.m4 <<EOF
define(\`confCC',\`${CC}')
define(\`confLD',\`${LD}')
define(\`confCCOPTS',\`${CFLAGS} ${CPPFLAGS}')
define(\`confLDOPTS',\`${LDFLAGS}')
define(\`confRANLIB',\`${RANLIB}')
APPENDDEF(\`conf_libmilter_ENVDEF',\`-DNETINET6=1')
EOF
	case "$XBPS_TARGET_MACHINE" in
	  *-musl)
		echo "APPENDDEF(\`confLIBSEARCH', \`crypt')" >> devtools/Site/site.config.m4
		echo "APPENDDEF(\`conf_libmilter_ENVDEF',\`-DNEEDSGETIPNODE=1')" >> devtools/Site/site.config.m4
		;;
	  *)
		echo "APPENDDEF(\`confLIBSEARCH', \`crypt nsl')" >> devtools/Site/site.config.m4
		;;
	esac
}

do_build() {
	make -j1 -C libmilter MILTER_SOVER=${version}
}

do_install() {
	install -d "${DESTDIR}/usr/lib"
	make -j1 -C libmilter MILTER_SOVER=${version} DESTDIR="${DESTDIR}" install
}

post_install() {
	vlicense LICENSE
}

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