# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id$

PortSystem              1.0
PortGroup               muniversal 1.0

name                    wget
version                 1.18
revision                1
categories              net www
maintainers             ryandesign openmaintainer
license                 GPL-3+
homepage                http://www.gnu.org/software/wget/
platforms               darwin freebsd
use_parallel_build      yes
master_sites            gnu
use_xz                  yes

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               rmd160  4fdf9c523b434050eeccfbd14b98c90c591d7ce4 \
                        sha256  b5b55b75726c04c06fe253daec9329a6f1a3c0c1878e3ea76ebfebc139ea9cc1

configure.args \
    --without-ssl

# use a specific MacPorts perl version
# older system perl versions (10.6 and earlier) do not support pod2man --utf8
# https://trac.macports.org/ticket/50164

set perl_version        5.24

depends_build           bin:makeinfo:texinfo \
                        port:perl${perl_version} \
                        port:pkgconfig

depends_lib \
    port:libidn \
    port:gettext \
    port:nettle \
    port:pcre

patchfiles              nawk.patch \
                        prefix.patch

configure.perl          ${prefix}/bin/perl${perl_version}
configure.env-append    POD2MAN=${prefix}/bin/pod2man-${perl_version}

# Ensure libuuid doesn't get used even if the ossp-uuid port is installed.
configure.args-append       ac_cv_header_uuid_uuid_h=no

# Remove test variant and use depends_test when that becomes available (#38208)
pre-test {
    if {![variant_isset test]} {
        ui_error "To run the tests, you must select the +test variant."
        return -code error "+test variant not selected"
    }
}
variant test description {Add dependencies needed to run tests} {
    depends_build-append    port:p${perl_version}-libwww-perl \
                            port:p${perl_version}-io-socket-ssl
    test.run                yes
    test.target             check
}

variant ssl description {Build with SSL support using GnuTLS} {
    depends_lib-append      port:gnutls
    configure.args-delete   --without-ssl
}

default_variants        +ssl

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}
    xinstall -d ${docdir}
    xinstall -W ${worksrcpath} -m 0644 AUTHORS COPYING ChangeLog MAILING-LIST NEWS README ${docdir}
    
    # 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
}

notes "
To customize wget, you can copy ${prefix}/etc/wgetrc.sample to\
${prefix}/etc/wgetrc and then make changes.
"