# -*- 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           boost 1.0
PortGroup           github 1.0
PortGroup           active_variants 1.1

github.setup        pemsley coot 1.2 Release-
github.tarball_from archive
conflicts           coot-devel
revision            0

categories          science
license             GPL-3
maintainers         {reneeotten @reneeotten} openmaintainer

description         Coot - Crystallographic Object-Oriented Toolkit
long_description    Coot is for macromolecular model building, model completion and validation, \
                    particularly suitable for protein modelling using X-ray data.

homepage            https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot

set monomer_distfile    refmac-monomer-library.tar.gz
set structures_distfile reference-structures.tar.gz

master_sites        https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/dependencies:monomer_source \
                    https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/dependencies:structures_source

distfiles           ${monomer_distfile}:monomer_source \
                    ${structures_distfile}:structures_source

checksums           ${monomer_distfile} \
                    rmd160  226d42e3fe16a540da13948e262aacef346c1ba2 \
                    sha256  03562eec612103a48bd114cfe0d171943e88f94b84610d16d542cda138e5f36b \
                    size    37439851 \
                    ${structures_distfile} \
                    rmd160  811e7eb4fcd768721e89d82c12135f9bfff0091b \
                    sha256  44db38506f0f90c097d4855ad81a82a36b49cd1e3ffe7d6ee4728b15109e281a \
                    size    6728787

subport coot-devel {
    github.setup    pemsley coot 30337b8ac7c018d3cdb075f1f68581a2fa8af738
    github.tarball_from archive
    version         20260503-[string range ${github.version} 0 7]
    conflicts       coot
    revision        0
}

if {${subport} eq "coot-devel"} {
    set coot_distfile \
                    ${github.version}${extract.suffix}
    master_sites-append \
                    ${github.homepage}/archive/${git.branch}:coot_source
    distfiles-append \
                    ${coot_distfile}:coot_source
    checksums-append \
                    ${coot_distfile} \
                    rmd160  341470a3d0a2a2b0a82ffccf2663704d24dc575f \
                    sha256  3a17e947e8c4fdb5375e2338b7a9688573f1c280c26d306b1a9cdf6d7b670e1e \
                    size    121745996
    github.livecheck.branch main
} else {
    set coot_distfile \
                    Release-${version}${extract.suffix}
    master_sites-append \
                    ${github.homepage}/archive/refs/tags:coot_source
    distfiles-append \
                    ${coot_distfile}:coot_source
    checksums-append \
                    ${coot_distfile} \
                    rmd160  c89b8dcfddc7779c70adb3cb81e8f77ec246259f \
                    sha256  ebf19951382151a53ed9c176aea0cf732994235478c64be611cd3f6fc0bdc9ea \
                    size    113151492
    # FIXME, setting "worksrcdir" does not seem to work, neither does "extract.rename" since
    # there is more than one directory
    post-extract {
        move {*}[glob ${workpath}/${github.project}-*] ${workpath}/${name}-${version}
    }
}

set python_version  3.14
set pver_nodot      [string map {. {}} ${python_version}]
set python_prefix   ${frameworks_dir}/Python.framework/Versions/${python_version}

boost.version       1.88
require_active_variants boost python${pver_nodot}

patchfiles-append   patch-RDKIT_LIBS-configure.ac.diff \
                    patch-FFTW-MoleculesToTriangles_CXXSurface_CXXFFTSolventMap.diff

post-patch {
    reinplace "s|@@BOOST_LIBS@@|[boost::lib_dir]|g" ${worksrcpath}/configure.ac
}

use_autoreconf      yes
autoreconf.cmd      ./autogen-mac.sh

compiler.cxx_standard 2020

configure.python    ${prefix}/bin/python${python_version}
configure.pkg_config_path-append \
                    ${python_prefix}/lib/pkgconfig

configure.cxxflags-append \
                    "-I${python_prefix}/include/python${python_version}/pygobject"

configure.args-append \
                    --disable-silent-rules \
                    --with-boost=[boost::install_area] \
                    --with-boost-libdir=[boost::lib_dir] \
                    --with-boost-python="boost_python${pver_nodot}" \
                    --with-backward \
                    --with-glm=${prefix} \
                    --with-rdkit-prefix=${prefix} \
                    --with-fftw-prefix=${prefix} \
                    -with-gemmi=${prefix}

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    path:bin/pkg-config:pkgconfig \
                    port:swig \
                    port:swig-python \
                    port:swig-guile \
                    port:glm

depends_lib-append  port:adwaita-icon-theme \
                    port:clipper \
                    port:gemmi \
                    port:libccp4 \
                    port:mmdb2 \
                    port:ssm \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:coordgen \
                    port:freetype \
                    port:gdk-pixbuf2 \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gmp \
                    port:graphene \
                    port:gsl \
                    path:lib/pkgconfig/gtk4.pc:gtk4 \
                    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
                    port:libepoxy \
                    port:libpng \
                    port:librsvg \
                    port:py${pver_nodot}-numpy \
                    path:lib/libopenblas.dylib:OpenBLAS \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:py${pver_nodot}-cairo \
                    port:py${pver_nodot}-gobject3 \
                    port:python${pver_nodot} \
                    port:rdkit \
                    port:sqlite3 \
                    port:fftw-single \
                    port:freeglut \
                    port:goocanvas \
                    port:gtkglext \
                    port:libgnomecanvas \
                    port:zlib \
                    port:curl
