# -*- 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
PortGroup               wxWidgets 1.0
PortGroup               gpg_verify 1.0

name                    VeraCrypt
version                 1.24
revision                1
categories              security aqua
maintainers             nomaintainer

homepage                https://www.veracrypt.fr/
description             A free open source disk encryption software.
long_description        ${description}

platforms               darwin
license                 Apache-2 Permissive

master_sites            https://launchpad.net/veracrypt/trunk/${version}/+download/
distname                VeraCrypt_${version}_Source
use_bzip2               yes

distfiles-append        ${distname}${extract.suffix}.sig

checksums               ${distname}${extract.suffix} \
                        rmd160  2d3f2191306442718407669198f31b03fb3c8d23 \
                        sha256  23a66eee2438b98c05fc9254ec31fdf9d0266fa37ecc8a105e6b1d95a43b64cf \
                        size    23422992 \
                        ${distname}${extract.suffix}.sig \
                        size    566

gpg_verify.use_gpg_verification \
                        yes

if {[option gpg_verify.use_gpg_verification]} {
    post-checksum {
        # The public key is downloaded from [1], and the key ID is listed on [2].
        # [1] https://www.idrix.fr/VeraCrypt/VeraCrypt_PGP_public_key.asc
        # [2] https://www.veracrypt.fr/en/Downloads.html
        set gpg_keyid 680D16DE

        gpg_verify.verify_gpg_signature \
            ${filespath}/keyid-${gpg_keyid}.txt \
            ${distpath}/[lindex ${distfiles} 0].sig \
            ${distpath}/[lindex ${distfiles} 0]
    }
}

wxWidgets.use           wxWidgets-3.0

depends_build-append    port:pkgconfig \
                        port:yasm
depends_lib-append      port:${wxWidgets.port} \
                        port:osxfuse

worksrcdir
build.dir               ${worksrcpath}/src

patchfiles              patch-makefiles.diff \
                        patch-allow-macports-osxfuse.diff

post-extract {
    system -W ${workpath} "chmod -R u+w ."
}

post-patch {
    reinplace "s|@ARCH_FLAGS@|-arch ${build_arch}|g" ${build.dir}/Makefile
    reinplace "s|@PREFIX@|${prefix}|" ${build.dir}/Core/Unix/MacOSX/CoreMacOSX.cpp
}

use_configure           no

if {${configure.sdkroot} ne ""} {
    set sdkroot ${configure.sdkroot}
} else {
    set sdkroot /
}

build.target
build.args              CC=${configure.cc} CXX=${configure.cxx} VERBOSE=1 \
                        VC_OSX_TARGET=${configure.sdk_version} \
                        VC_OSX_SDK=${sdkroot} \
                        WX_CONFIG=${wxWidgets.wxconfig} \
                        APPDIR=${applications_dir} \
                        AS=${prefix}/bin/yasm

destroot.dir            ${build.dir}
destroot.args           {*}${build.args}

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}

    xinstall ${worksrcpath}/License.txt ${docdir}
}