# $Id: Portfile,v 1.3 2005/10/21 23:10:52 mww Exp $

PortSystem 1.0
name				htdig
version				3.1.6
categories			www
platforms			darwin freebsd
maintainers			simon@cotsworth.com
description			WWW Search Engine Software

long_description	The ht://Dig system is a complete world wide web indexing and searching system \
			for a domain or intranet. This system is not meant to replace the need for \
			powerful internet-wide search systems like Lycos, Infoseek, Google and AltaVista. \
			Instead it is meant to cover the search needs for a single company, campus, or \
			even a particular sub section of a web site. As opposed to some WAIS-based or \
			web-server based search engines, ht://Dig can easily span several web servers. \
			The type of these different web servers doesn't matter as long as they \
			understand common protocols like HTTP. 

homepage		http://www.htdig.org/
master_sites		${homepage}files/
checksums		md5 7a2f20d8d6149efd8d119bb2ebf55f23
patchfiles		patch-metadate.0 \
			patch-Makefile.0 \
		  	patch-documentation.1 \
			patch-documentation.2 \
			patch-Date-viewing.0 \
			patch-ExternalParser-max_doc_size.0 \
			patch-htnotifyNull.0 \
			patch-JavaScript.0 \
			patch-CONFIG.in

set doc_path		"${prefix}/share/doc/${name}"
set conf_path		"${prefix}/etc/${name}"
set share_path		"${prefix}/share/${name}"
set db_path		"${prefix}/var/${name}"
set cgi_path		""
set httpd_doc_path	""
set httpd_conf_path 	""

destroot.destdir 	prefix=${destroot}${prefix}
variant darwin		{ global cgi_path httpd_conf_path httpd_doc_path
				set cgi_path "/Library/WebServer/CGI-Executables"
				set httpd_doc_path "/Library/WebServer/Documents"
				set httpd_conf_path "/private/etc/httpd"

				# apache darwinport interop
				if {[ file exists ${prefix}/sbin/httpd]} {
					set cgi_path "${prefix}/www/cgi-bin"
					set httpd_doc_path "${prefix}/www/htdocs"
					set httpd_conf_path "${prefix}/etc/apache"
				}
				configure.args	--with-cgi-bin-dir=${destroot}${cgi_path} }

platform darwin 8 {
	configure.env	CC=/usr/bin/gcc-3.3 CPP=/usr/bin/cpp-3.3 CXX=/usr/bin/g++-3.3
}

variant freebsd 	{ global cgi_path httpd_conf_path httpd_doc_path
				set cgi_path "/usr/local/www/cgi-bin"
				set httpd_doc_path "/usr/local/www/data"
				set httpd_conf_path "/usr/local/etc/apache"

				# apache darwinport interop
				if {[ file exists ${prefix}/sbin/httpd]} {
					set cgi_path "${prefix}/www/cgi-bin"
					set httpd_doc_path "${prefix}/www/htdocs"
					set httpd_conf_path "${prefix}/etc/apache"
				}
				configure.args	--with-cgi-bin-dir=${destroot}${cgi_path} }

post-destroot		{ # Empty directory hack
				file mkdir ${destroot}${db_path}
				system "touch ${destroot}${db_path}/.turd"

				# Install documentation
			 	file mkdir ${destroot}${doc_path}
				system "cd ${worksrcpath}/htdoc && \
				  tar -cf - *.html *.gif *.css | \
				  tar -xf - -C ${destroot}${doc_path}"
				system "chown -R `id -u`:`id -g` \
				  ${destroot}${doc_path}"

				# Create symbolic link in web server doc root
				file mkdir ${destroot}${httpd_doc_path}
				system "cd ${destroot}${httpd_doc_path} && \
				  ln -s ${share_path}/search.html"

				# Fix paths in rundig script
				reinplace "s|${destroot}${prefix}|${prefix}|g" \
				  "${destroot}${prefix}/bin/rundig"

				# Fix paths in htdig config file
				reinplace "s|${destroot}${prefix}|${prefix}|g" \
				  "${destroot}${conf_path}/${name}.conf"

				# Make copy of htdig config file
				system "install -m 644 ${destroot}${conf_path}/${name}.conf \
			  	${destroot}${share_path}/${name}.conf.default"

				# Install default htdig apache config file
				file mkdir ${destroot}${httpd_conf_path}
				system "install -m 644 ${portpath}/${filesdir}/httpd.conf \
				  ${destroot}${httpd_conf_path}/httpd_${name}.conf"
				reinplace "s|DP_PREFIX|${prefix}|g" \
				  "${destroot}${httpd_conf_path}/httpd_${name}.conf"
				reinplace "s|NAME|${name}|g" \
				  "${destroot}${httpd_conf_path}/httpd_${name}.conf"
				reinplace "s|VERSION|${version}|g" \
				  "${destroot}${httpd_conf_path}/httpd_${name}.conf"

				# Install contributed scripts
				file mkdir ${destroot}${share_path}/contrib
				system "cd ${worksrcpath}/contrib && \
				  tar -cf - * | \
				  tar -xf - -C ${destroot}${share_path}/contrib"
				system "chown -R `id -u`:`id -g` \
				  ${destroot}${share_path}/contrib" 
}

