# $Id: Portfile 91190 2012-03-25 08:43:12Z jeremyhu@macports.org $
PortSystem 1.0

name			libmilter
set major_version	8.14
version			${major_version}.5
categories		mail
maintainers		geeklair.net:dluke
platforms		darwin
description		libmilter library from Sendmail
license			Permissive

long_description	Sendmail's Content Management API (milter) provides \
			third-party programs to access mail messages as they \
			are being processed by the Mail Transfer Agent (MTA), \
			allowing them to examine and modify message content \
			and meta-information. Filtering policies implemented \
			by Milter-conformant filters may then be centrally \
			configured and composed in an end-user's MTA \
			configuration file

homepage		http://www.sendmail.org/doc/sendmail-current/libmilter/docs/
master_sites		ftp://ftp.sendmail.org/pub/sendmail/ \
		http://www.mirrorservice.org/sites/ftp.sendmail.org/pub/sendmail/
distname		sendmail.${version}

checksums	md5	02ccfc331cc81ed00ec8bb5ecfc69018 \
		sha1	86dd2a8ad5eac892cd02cf67792a25efccacc100 \
		rmd160	0961ed4d6bcda73908670c20c8de6c14cac4d0dd

worksrcdir	sendmail-${version}

set arch_flags "${configure.cc_archflags}"
post-patch {
	file copy ${worksrcpath}/devtools/OS/Darwin.10.x \
		${worksrcpath}/devtools/Site/site.config.m4
	reinplace "s|-DDARWIN=100000|-DDARWIN=${os.major}0000|" \
		${worksrcpath}/devtools/Site/site.config.m4
	if [variant_isset universal] {
		reinplace "s|\${Extra_CC_Flags}|${arch_flags}|" \
			${worksrcpath}/devtools/Site/site.config.m4
	}
}

use_configure	no

build	{
		system "cd ${worksrcpath}/${name} && \
			./Build -O ${worksrcpath}/macports"
	
		close [open ${worksrcpath}/include/sm_os.h a]

		system "cd ${worksrcpath}/macports/*/${name} && \
			${configure.cc} ${configure.cflags} ${arch_flags}\
			-fno-common -DNOT_SENDMAIL -Dsm_snprintf=snprintf \
			-D_THREAD_SAFE -DBIND_8_COMPAT -DXP_MT \
			-I${worksrcpath}/include \
			-I${worksrcpath}/sendmail -c *.c"
		
		set x {}
		fs-traverse object ${worksrcpath}/macports {
			if {[file isfile ${object}] && [regexp ".o$" ${object}]} {
				lappend x ${object}
			}
		}

		set objects [join ${x} " "]

		system "${configure.cc} ${configure.cflags} ${arch_flags} -dynamiclib \
			-install_name ${prefix}/lib/${name}.dylib \
			-compatibility_version ${major_version} \
			-current_version ${version} \
			-o ${worksrcpath}/macports/libmilter.dylib ${objects}"
	}

destroot	{
			file copy "${worksrcpath}/macports/libmilter.dylib" \
				"${destroot}${prefix}/lib/"
			file copy "${worksrcpath}/include/${name}" \
				"${destroot}${prefix}/include/"
			file delete "${destroot}${prefix}/include/${name}/milter.h"
		}

variant universal {
	set arch_flags "${configure.universal_cflags}"
}
