# -*- 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

PortSystem          1.0

name                john
conflicts           john-jumbo
version             1.9.0
revision            1
categories          sysutils security
maintainers         nomaintainer
license             {GPL-2+ OpenSSLException}

description         Featureful Unix password cracker
long_description    John the Ripper is a UNIX password cracker, currently available for \
                    UNIX (tested with Linux x86, FreeBSD x86, Solaris 2.x SPARC, OSF/1 \
                    Alpha), DOS, WinNT/Win95.
homepage            https://www.openwall.com/john/
platforms           darwin
master_sites        http://www.openwall.com/${name}/k/

use_xz              yes

checksums           rmd160  16114db2fe5004ce4044a2d56b46ef209b941dc4 \
                    sha256  0b266adcfef8c11eed690187e71494baea539efbd632fe221181063ba09508df \
                    size    8944932

patchfiles          patch-src-params.h.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/src/params.h
}

use_configure       no

use_parallel_build  no

build.dir           ${worksrcpath}/src
build.args          CC=${configure.cc}
build.target        clean
switch ${configure.build_arch} {
    i386 {
        build.target-append macosx-x86-sse2
    }
    x86_64 {
        # x86_64 is only supported on Leopard and up
        if {${os.major} >= 9} {
            build.target-append macosx-x86-64
        } else {
            configure.build_arch i386
            build.target-append macosx-x86-sse2
        }
    }
    ppc {
        # Use altivec if available
        if {![catch {sysctl hw.vectorunit} result] && $result == 1} {
            build.target-append macosx-ppc32-altivec
        } else {
            build.target-append macosx-ppc32
        }
    }
    ppc64 {
        build.target-append macosx-ppc64
    }
}

destroot {
    file copy ${worksrcpath}/run ${destroot}${prefix}/share/john
    system "chmod -R a+rX ${destroot}${prefix}/share/john"
    system "ln -s ${prefix}/share/john/john ${destroot}${prefix}/bin/john"
    xinstall -d ${destroot}${prefix}/share/doc
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/john
    system "chmod -R a+rX ${destroot}${prefix}/share/doc/john"
}


subport john-jumbo {
    conflicts           john
    version             1.9.0
    revision            1
    set jumbo_patchlvl  1
    license             GPL-2 GPL-3+ Apache-2 Restrictive
    master_sites        https://www.openwall.com/john/k/

    # note: according to https://www.openwall.com/john/
    # developement appears to have moved to github
    # https://github.com/magnumripper/JohnTheRipper

    depends_lib-append  path:lib/libssl.dylib:openssl

    distname            ${name}-${version}-jumbo-${jumbo_patchlvl}

    checksums           rmd160  ea75c464d211691f00db7aec66e0503c1177866b \
                        sha256  f5d123f82983c53d8cc598e174394b074be7a77756f5fb5ed8515918c81e7f3b \
                        size    33638768

    use_configure       yes
    configure.dir       ${worksrcpath}/src

    # error We need minimum OpenCL 1.2 to build with OpenCL support. 
    if {${os.platform} eq "darwin" && ${os.major} <= 11} {
        configure.args-append      --disable-opencl
    }

    build.dir           ${worksrcpath}/src
    build.target        default
    build.env-append    CC=${configure.cc} \
                        "CFLAGS=${configure.cflags} [get_canonical_archflags cc]" \
                        "LDFLAGS=${configure.ldflags} [get_canonical_archflags ld]"

}

notes "You'll find the john files under ${prefix}/share/john/"

livecheck.type      regex
livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}