# -*- 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                       legacysupport 1.1
PortGroup                       github 1.0
PortGroup                       php 1.1

# strnlen
legacysupport.newest_darwin_requires_legacy 10

name                            php-sqlsrv
categories-append               databases
maintainers                     {ryandesign @ryandesign} {mathiesen.info:macintosh @BjarneDMat} openmaintainer
license                         MIT

php.branches                    7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5

description                     Microsoft Drivers for PHP for SQL Server (SQLSRV)
long_description \
    The Microsoft Drivers for PHP for SQL Server are PHP extensions \
    that allow for the reading and writing of SQL Server data from within PHP scripts. \
    The SQLSRV extension provides a procedural interface \
    while the PDO_SQLSRV extension implements PDO for accessing data \
    in all editions of SQL Server 2012 and later (including Azure SQL DB). \
    These drivers rely on the Microsoft ODBC Driver for SQL Server \
    to handle the low-level communication with SQL Server. \
    *This package contains only the SQLSRV driver.*

github.tarball_from             archive

if {[vercmp ${php.branch} >= 8.3]} {
    github.setup                microsoft msphpsql 5.13.3 v
    revision                    0
    checksums                   rmd160  eb5abb55571d69bef03baf0d3b0dd5b95917d5bd \
                                sha256  0fa6db7c7df8927ddb816c6184d129026338cfa6fe2721f9db41d91290be2cdc \
                                size    10853229
} elseif {[vercmp ${php.branch} >= 8.1]} {
    github.setup                microsoft msphpsql 5.12.0 v
    revision                    1
    checksums                   rmd160  d741e123d82bdc85a4c40ad27a5ec272e74e60e9 \
                                sha256  c2a67f20a49555243a1b6c45d4a735e58dcbed0bafefbf7de8e196f317544fbc \
                                size    10776978
} elseif {[vercmp ${php.branch} >= 8.0]} {
    github.setup                microsoft msphpsql 5.11.1 v
    revision                    1
    checksums                   rmd160  d9b7f85ae00b5503aa5775c062682ca8e993e839 \
                                sha256  aef6c480bff2e5e8de326fd03c6465006bee6c2aef8b3d5b5e56e4352c7e707f \
                                size    10776759
} elseif {[vercmp ${php.branch} >= 7.4]} {
    github.setup                microsoft msphpsql 5.10.1 v
    revision                    1
    checksums                   rmd160  630d46bffca54d89ff2a5739c81bb985d4eb02a2 \
                                sha256  1e66ce803bd36dbee6c45852ac831e83c0d18dd4d4c5095188f3fa08d4f19724 \
                                size    11091586
} elseif {[vercmp ${php.branch} >= 7.3]} {
    github.setup                microsoft msphpsql 5.9.0 v
    revision                    0
    checksums                   rmd160  640edda514939d44b2684bc90dbee2b12bedfcf5 \
                                sha256  fe960c4c32c83cd98c84fe85c5cdcb145ed0679ee36a3ab6f16132249a4c0d61 \
                                size    10762839
} elseif {[vercmp ${php.branch} >= 7.2]} {
    github.setup                microsoft msphpsql 5.8.1 v
    revision                    0
    checksums                   rmd160  86eed46d32e67169d39f13f83fea54e990bfa816 \
                                sha256  c24e8a267fab06d99ecb639d6195dadb3ca8e4b9a3264b564a9b730fc61d26f5 \
                                size    11030927
} elseif {[vercmp ${php.branch} >= 7.1]} {
    github.setup                microsoft msphpsql 5.6.1 v
    revision                    1
    checksums                   rmd160  e42eb031ee9c0aca5177a493b3ef33ada1575088 \
                                sha256  ff05186ea1d33ecd7b258b3a453896cabaa9e944598e7dddb0d6dbe3c8ef1b48 \
                                size    10858444
} elseif {[vercmp ${php.branch} >= 7.0]} {
    github.setup                microsoft msphpsql 5.3.0 v
    revision                    0
    checksums                   rmd160  cd52cc3276e79f115ce1e011cea0ac2e3f36868c \
                                sha256  2519522891746a02e1c9f4674e379bbb75eb044305aee1522097c2d9923545af \
                                size    10819430
}

if {${subport} ne ${name}} {
    # remove w/ next update
    dist_subdir                 ${name}/${version}_1

    depends_lib-append          port:msodbcsql \
                                port:${php}-pdo_sqlsrv

    if {[vercmp ${version} < 5.9.0]} {
        patchfiles-append       ${php}-deployment_target.patch
    }

    php.build_dirs              [list "${worksrcpath}/source/sqlsrv"]

    post-extract {
        set build_dir           [lindex ${php.build_dirs} 0]
        file link -symbolic     "${build_dir}/shared" "${build_dir}/../shared"
    }

    compiler.cxx_standard       2011
}
