# $Id: Portfile 58284 2009-09-25 04:20:31Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               muniversal 1.0

name                    wget
version                 1.12
categories              net www
maintainers             ryandesign
license                 GPLv3
homepage                http://www.gnu.org/software/wget/
platforms               darwin freebsd
use_parallel_build      yes
master_sites            gnu

description \
    internet file retriever

long_description \
    GNU Wget is a free software package for retrieving files using HTTP, \
    HTTPS and FTP, the most widely-used Internet protocols. It is a \
    non-interactive commandline tool, so it may easily be called from \
    scripts, cron jobs, terminals without Xsupport, etc.

checksums \
    md5     141461b9c04e454dc8933c9d1f2abf83 \
    sha1    50d4ed2441e67db7aa5061d8a4dde41ee0e94248 \
    rmd160  232d0aa6fb36731c162d2b7374aa9ab59e671b7d

configure.args \
    --with-libssl-prefix=${prefix}

depends_build \
    bin:makeinfo:texinfo \
    bin:pod2man:perl5

depends_lib \
    port:libidn \
    port:openssl \
    port:gettext

# So that +universal can use gettext and openssl on Tiger; see #18276.
configure.ldflags-append        -liconv -lintl
if {![variant_isset no_ssl]} {
    depends_build-append        port:pkgconfig
    pre-configure {
        configure.ldflags-append    [exec ${prefix}/bin/pkg-config --libs libssl]
    }
}

variant test {
    depends_build-append    port:p5-libwww-perl \
                            port:p5-io-socket-ssl
    test.run                yes
    test.target             check
}

variant no_ssl description {Build without SSL support} {
    depends_lib-delete      port:openssl
    configure.args-append   --without-ssl
    configure.args-delete   --with-libssl-prefix=${prefix}
}

patchfiles \
    patch-prefix.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/ChangeLog \
        ${worksrcpath}/README \
        ${worksrcpath}/NEWS \
        ${worksrcpath}/doc/sample.wgetrc \
        ${worksrcpath}/doc/wget.texi
}

post-destroot {
    # Install documentation.
    set docdir ${destroot}${prefix}/share/doc/${name}-${version}
    xinstall -d ${docdir}
    foreach docfile {AUTHORS COPYING MAILING-LIST NEWS README} {
        xinstall -W ${worksrcpath} -m 0644 ${docfile} ${docdir}/${docfile}.txt
    }
    xinstall -W ${worksrcpath} -m 0644 ChangeLog ${docdir}/ChangeLog.txt
    foreach changelog {doc src} {
        xinstall -W ${worksrcpath} -m 0644 ${changelog}/ChangeLog ${docdir}/ChangeLog-${changelog}.txt
    }
    
    # Rename sample wgetrc file so we don't clobber a user's real config file on upgrade.
    move ${destroot}${prefix}/etc/wgetrc ${destroot}${prefix}/etc/wgetrc.sample
}

post-activate {
    if {![file exists ${prefix}/etc/wgetrc]} {
        ui_msg "To customize wget, you can copy wgetrc.sample to wgetrc"
        ui_msg "in ${prefix}/etc and then make changes."
    }
}
