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

PortSystem          1.0

name                msieve
version             1.53
categories          math
license             public-domain Apache-2 zlib BSD
maintainers         {nicos @NicosPavlov} openmaintainer
description         A library for factoring large integers
long_description    {*}${description}

conflicts           ${name}-devel

homepage            https://sourceforge.net/projects/msieve/
master_sites        sourceforge:project/msieve/msieve/Msieve%20v${version}

distfiles           ${name}[string map {. ""} ${version}]_src${extract.suffix}
checksums           rmd160  81170f6ee363140c44bd07b9937cab0ab8c75f1a \
                    sha256  c5fcbaaff266a43aa8bca55239d5b087d3e3f138d1a95d75b776c04ce4d93bb4 \
                    size 976135

depends_lib         port:gmp

patchfiles          patch-Makefile.diff \
                    patch-time.diff

post-patch {
    reinplace "s|@VER@|${version}|g" ${worksrcpath}/Makefile
    reinplace "s|@CC@|${configure.cc}|g" ${worksrcpath}/Makefile
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/Makefile
    reinplace "s|-march=native||g" ${worksrcpath}/Makefile
}

subport ${name}-devel {
    conflicts       ${name}

    fetch.type      svn
    svn.url         https://svn.code.sf.net/p/msieve/code/trunk/
    version         1045
    revision        0

    patchfiles-delete \
                    patch-Makefile.diff

    patchfiles-append \
                    patch-Makefile-trunk.diff
}

use_configure       no
build.env           CFLAGS=${configure.cflags} \
                    CPATH=${compiler.cpath} \
                    LIBRARY_PATH=${compiler.library_path} \
                    MACHINE_FLAGS=${configure.cc_archflags}

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/include/msieve \
        ${destroot}${prefix}/share/doc/${name} \
        ${destroot}${prefix}/share/${name}/demo
    xinstall -m 755 ${worksrcpath}/msieve ${destroot}${prefix}/bin
    xinstall -m 644 {*}[glob ${worksrcpath}/libmsieve.*] ${destroot}${prefix}/lib
    ln -s ${prefix}/lib/libsieve.${version}.dylib ${destroot}${prefix}/lib/libsieve.1.dylib
    ln -s ${prefix}/lib/libsieve.${version}.dylib ${destroot}${prefix}/lib/libsieve.dylib
    xinstall -m 644 {*}[glob ${worksrcpath}/include/*] \
        ${destroot}${prefix}/include/msieve
    xinstall -m 644 -W ${worksrcpath} Readme Readme.qs Readme.nfs \
        ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} demo.c \
        ${destroot}${prefix}/share/${name}/demo
}

variant ecm description "Use elliptic curve method for factorisation" {
    depends_lib-append  port:gmp-ecm
    build.args          ECM=1
}

livecheck.type      regex
livecheck.url       http://sourceforge.net/projects/${name}/files/
livecheck.regex     {Msieve v([0-9.]+)}
