# -*- 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: Portfile 119541 2014-04-29 21:38:47Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               qt4 1.0

name                    KeePassX
version                 2.0-alpha6
categories              security aqua
maintainers             nomaintainer

description             KeePassX is a password manager compatiable with KeePass
long_description        KeePassX is an application for people with extremely \
                        high demands on secure personal data management. It \
                        has a light interface and is cross platform. KeePassX \
                        saves many different types of information including \
                        user names, passwords, URLs, attachments and comments \
                        in one single database.

platforms               darwin
license                 GPL-2 LGPL-2 LGPL-3 BSD permissive
license_noconflict      openssl

notes "
BEWARE, THIS IS AN ALPHA RELEASE AND NOT INTENDED TO BE USED IN A PRODUCTION\
ENVIRONMENT.
"

homepage                https://www.keepassx.org/
master_sites            https://www.keepassx.org/dev/attachments/download/69
distname                keepassx-${version}

checksums               md5     7c1c3a42aff63abd8db3bc8df6c963f6 \
                        rmd160  ef46208dd0654e9046e048c2a91c285d1fb14001 \
                        sha256  592f9995b13c4f84724fb24a0078162246397eedccd467daaf0fd3608151f2b0

depends_lib-append      port:libgcrypt \
                        port:zlib

depends_build-append    port:cmake

worksrcdir              build

post-extract {
    file mkdir ${worksrcpath}
    reinplace "s|zlib.h|${prefix}/include/zlib.h|" ../${distname}/CMakeLists.txt
    platform darwin {
        if {${os.major} >= 13} {
            reinplace "s|-stack-protector-buffer-size=4||g" \
                      ../${distname}/CMakeLists.txt
            reinplace "s|-mllvm||g" \
                      ../${distname}/CMakeLists.txt
        }
    }
}

configure.cmd           cmake
configure.pre_args      -DCMAKE_INSTALL_PREFIX=${applications_dir} \
                        -DZLIB_ROOT=${prefix}
configure.args          ${qt_cmake_defines} ../${distname}

platform darwin {
    if {${os.major} < 13} {
        # Build fails with clang: unsupported -stack-protector-buffer-size=4
        # (even though clang -help lists option)
        compiler.blacklist          clang
    } else {
        configure.pre_args-append   -DWITH_CXX11=On
    }
}

# Don't make copies of all the QT4 libraries etc... (MUCH smaller install)
post-configure {
    reinplace "s/FIXUP_QT4_EXECUTABLE.*//" src/cmake_install.cmake
}

post-destroot {
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -W ${workpath}/${distname} COPYING LICENSE.BSD LICENSE.CC0 \
             LICENSE.GPL-2 LICENSE.LGPL-2.1 LICENSE.LGPL-3 \
             LICENSE.NOKIA-LGPL-EXCEPTION \
             ${destroot}${prefix}/share/doc/${name}
}

livecheck.type          regex
livecheck.url           ${homepage}dev/projects/keepassx/files
livecheck.regex         keepassx-(\[-alphabet\\d\.\]+).tar.gz
