# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 63537 2010-02-08 00:27:42Z ryandesign@macports.org $

PortSystem 1.0
name              lighttpd
version           1.4.26
set branch        [join [lrange [split ${version} .] 0 1] .]
categories        www
platforms         darwin
maintainers       ryandesign
license           BSD
description       A secure, fast, compliant and flexible web-server
long_description  lighttpd is a secure, fast, compliant and very flexible\
                  web-server which has been optimized for high-performance\
                  environments. It has a very low memory footprint\
                  compared to other webservers and takes care of cpu-load.
homepage          http://www.lighttpd.net/
master_sites      http://download.lighttpd.net/lighttpd/releases-${branch}.x/
use_bzip2         yes

checksums         md5     a682c8efce47a2f4263a247ba0813c9b \
                  sha1    f9710da0152792d83c223a1248345a2d145d6f32 \
                  rmd160  2d294083fbcd4040dc8efec06090cf1c1bf66bbf

depends_lib       port:pcre \
                  port:spawn-fcgi \
                  port:zlib
patchfiles        patch-doc-lighttpd.conf.diff

post-patch {
    reinplace "s|__PREFIX|${prefix}|g" "${worksrcpath}/doc/lighttpd.conf"
}

# Startup item.
set lighttpd_config_name   lighttpd.conf
set lighttpd_config        ${prefix}/etc/${name}/${lighttpd_config_name}

startupitem.create  yes
startupitem.executable ${prefix}/sbin/lighttpd -D -f ${lighttpd_config}

destroot.keepdirs   ${destroot}${prefix}/var/log/lighttpd \
                    ${destroot}${prefix}/www/htdocs \
                    ${destroot}${prefix}/var/run/lighttpd \
                    ${destroot}${prefix}/var/lib/lighttpd \
                    ${destroot}${prefix}/var/cache/lighttpd/compress
post-destroot {
   file mkdir "${destroot}${prefix}/etc/${name}/"
   xinstall -m 644 -v "${worksrcpath}/doc/lighttpd.conf" \
                      "${destroot}${lighttpd_config}.default"
   set docdir ${destroot}${prefix}/share/doc/${name}
   xinstall -d ${docdir}
   xinstall -m 644 -W ${worksrcpath} \
       AUTHORS \
       COPYING \
       NEWS \
       README \
       ${docdir}
}

install.asroot      yes

post-install {
  ui_msg "\n Before starting lighttpd it must be configured.\n\
    Lighttpd is configured by editing ${lighttpd_config}\n\
    There's a sample config file at ${lighttpd_config}.default."
}


variant mysql4 {
   depends_lib-append    port:mysql4
   configure.args-append --with-mysql=${prefix}/bin/mysql_config

   post-configure {
      reinplace "s|<mysql/mysql.h>|\"${prefix}/include/mysql/mysql.h\"|g" \
                "${worksrcpath}/src/mod_mysql_vhost.c"
   }
}

variant mysql5 {
   depends_lib-append    path:bin/mysql_config5:mysql5
   configure.args-append --with-mysql=${prefix}/bin/mysql_config5

   post-configure {
      reinplace "s|<mysql/mysql.h>|\"${prefix}/include/mysql5/mysql/mysql.h\"|g" \
                "${worksrcpath}/src/mod_mysql_vhost.c"
   }
}

variant ssl {
   depends_lib-append   port:openssl
   configure.args-append --with-openssl=${prefix}/include/openssl
}

variant cml {
   depends_lib-append   port:lua \
                        port:libmemcache \
                        port:memcached \
                        port:pkgconfig
                        
   configure.args-append --with-lua \
                         --with-memcache
}

variant davprops {
   depends_lib-append   port:libxml2 \
                        port:sqlite3 \
                        port:pkgconfig
                        
   configure.args-append --with-webdav-props
}
