# $Id: Portfile 50984 2009-05-14 21:08:43Z and.damore@macports.org $

PortSystem			1.0
name				yaws
version				1.76
categories			www
maintainers			kallisys.net:pguyot
platforms			darwin
description			Webserver for dynamic content written in Erlang
long_description	Yaws is a high performance HTTP server for dynamic content \
					written in Erlang. Pages can be dynamic with embedded erlang \
					code. Yaws also features a built-in Wiki.
homepage			http://yaws.hyber.org/
master_sites		http://yaws.hyber.org/download/
checksums			md5 c6072c4dc6664fa8be88e12baa458eaf \
					sha1 a2517bc95bde181561a2214329f5fcc80ded3c38 \
					rmd160 8107c46d7b4b34e1662e7aa585f2722da1d021b2

depends_build		port:erlang

extract.post_args	| tar -xf - --exclude \
					"${name}-${version}/www/testdir/xx*xx.jpg"

patchfiles			patch-man-yaws.1 \
					patch-man-yaws_api.5 \
					patch-man-yaws.conf.5 \
					patch-scripts-Install \
					patch-scripts-Makefile \
					patch-scripts-yaws.conf.template

post-patch {
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/man/yaws.1
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/man/yaws.conf.5
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/man/yaws_api.5
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/scripts/yaws.conf.template
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/src/yaws_config.erl
}

default_variants	+yapp

configure.args		--sysconfdir=${prefix}/etc \
					--localstatedir=${prefix}/var

variant yapp description {Yapp application handler} {
	post-build {
		system "cd ${worksrcpath}/applications/yapp && make && make docs"
	}
	post-destroot {
		system "cd ${worksrcpath}/applications/yapp && make install DESTDIR=${destroot}"
	}
}
					
post-destroot {
	xinstall -d "${destroot}${prefix}/var/log/yaws/"
	system "touch ${destroot}${prefix}/var/log/yaws/.turd"
	file rename "${destroot}${prefix}/etc/yaws.conf" "${destroot}${prefix}/etc/yaws.conf.template"
}

post-install {
	ui_msg "Copy and customize ${prefix}/etc/yaws.conf.template to ${prefix}/etc/yaws.conf"
}

startupitem.create	yes
startupitem.name	yaws
startupitem.start	"${prefix}/bin/yaws --daemon --heart --conf ${prefix}/etc/yaws.conf"
startupitem.stop	"${prefix}/bin/yaws --stop"

livecheck.check	regex
livecheck.url	http://yaws.hyber.org/download/
livecheck.regex	{<address> Yaws (.*) Server at yaws.hyber.org </address>}
