# -*- 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           github 1.0
PortGroup           openssl 1.0

name                sqlcipher
revision            0
categories          databases
license             BSD

maintainers         {gmail.com:ybzhao1989 @z7z8th} openmaintainer

description         An security extesion to the embedded SQL database engine

long_description    SQLCipher extends the SQLite database library to add \
                    security enhancements that make it more suitable for \
                    encrypted local data storage like: \
                     * on-the-fly encryption \
                     * tamper detection \
                     * memory sanitization \
                     * strong key derivation. \
                    \
                    SQLite3 is an SQL database engine in a C library. \
                    Programs that link the SQLite3 library can have SQL \
                    database access without running a separate RDBMS \
                    process. The distribution comes with a standalone \
                    command-line access program (sqlite3) that can be used \
                    to administer an SQLite3 database and which serves as \
                    an example of how to use the SQLite3 library.

homepage            https://www.zetetic.net/sqlcipher/
github.setup        sqlcipher sqlcipher 4.6.1 v
github.tarball_from archive
checksums           rmd160  01890f5230bdb7a08d7f757b34cfa177a2a8596d \
                    sha256  d8f9afcbc2f4b55e316ca4ada4425daf3d0b4aab25f45e11a802ae422b9f53a3 \
                    size    19115004

openssl.configure   build_flags

# enable sqlcipher security enhancements
configure.cppflags-prepend  -DSQLITE_HAS_CODEC

build.type          gnu

# Needed for both subports:
if {${os.major} <= 15} {
    # https://github.com/sqlcipher/sqlcipher/issues/518
    configure.cppflags-prepend \
                    -DSQLCIPHER_OMIT_LOG_DEVICE
}

if {${subport} eq ${name}} {
    depends_lib-append  port:libedit \
                        port:ncurses \
                        port:zlib

    # to enable `--enable-dynamic-extensions', re-genereate configure from configure.ac
    configure.args      --enable-threadsafe \
                        --disable-readline \
                        --enable-editline \
                        --enable-tempstore=yes \
                        AWK=/usr/bin/awk

    if {${os.major} <= 16} {
        configure.args-prepend  --disable-tcl
    }

    # search in worksrcpath for sqlcipher/sqlite3.h first -- don't pick up an installed one!
    configure.cppflags-prepend  -DSQLITE_DISABLE_INTRINSIC \
                                -DSQLITE_ENABLE_COLUMN_METADATA \
                                -DSQLITE_ENABLE_FTS3_PARENTHESIS \
                                -DSQLITE_ENABLE_FTS4 \
                                -DSQLITE_ENABLE_FTS5 \
                                -DSQLITE_ENABLE_JSON1 \
                                -DSQLITE_ENABLE_RTREE \
                                -DSQLITE_SECURE_DELETE \
                                -DSQLITE_ENABLE_STAT4 \
                                -DSQLITE_ENABLE_UNLOCK_NOTIFY \
                                -DSQLITE_SOUNDEX \
                                -I${worksrcpath}

    post-destroot {
        xinstall -m 644 ${worksrcpath}/${name}.1 ${destroot}${prefix}/share/man/man1
    }
}


subport ${name}-tools {
    description               A bundle of command-line tools for managing SQLite \
                              database files

    long_description          ${description}, including the sqldiff program and the \
                              sqlite3_analyzer program.

    conflicts                 sqlite3-tools

    depends_lib-append        port:tcl \
                              port:zlib

    configure.args            --with-tcl=${prefix}/lib \
                              --enable-tempstore=yes

    build.target              sqldiff sqlite3_analyzer
    destroot {
        xinstall -m 0755 ${worksrcpath}/sqldiff ${destroot}${prefix}/bin
        xinstall -m 0755 ${worksrcpath}/sqlite3_analyzer ${destroot}${prefix}/bin
    }
}