PortSystem	1.0

name		ha
version		0.999
revision    1
categories	archivers sysutils
platforms	darwin
license		GPL-2
description	The \"HA\" archiver, based on arithmetic/Markov coder.
maintainers	nomaintainer
homepage	ftp://ftp.kiarchive.ru/pub/unix/arcers/

long_description ${description}

distfiles	ha0999.tgz
master_sites	ftp://ftp.kiarchive.ru/pub/unix/arcers/

checksums   md5 77f3266a451712bec55d60df67f61486 \
            sha1 8dd106748619772f988ee0bce59937a4de1677ed \
            rmd160 41b52392267551f834b58e0a4b69b89e813c8bd6

extract.mkdir   yes

# Fix implicit function declarations
patchfiles-append \
            patch-machine.c.diff

post-patch {
    reinplace -E "s|(malloc.h)|malloc/\\1|" \
        ${worksrcpath}/c/hsc.c \
        ${worksrcpath}/c/asc.c \
        ${worksrcpath}/c/cpy.c
}

configure {
    reinplace -E "/^CFLAGS/s|\$| [join ${configure.cflags} " "]|" ${worksrcpath}/makefile.nix
    reinplace -E "/^LDFLAGS/s|\$| [join ${configure.ldflags} " "]|" ${worksrcpath}/makefile.nix
}

build.target
build.args	-f makefile.nix \
            "CC=${configure.cc}" \
            "CPP=${configure.cpp}"

destroot {
    xinstall ${worksrcpath}/ha ${destroot}${prefix}/bin

    set docdir ${prefix}/share/doc/${name}-${version}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} copying readme ${destroot}${docdir}
}

