# -*- 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           cmake 1.1
PortGroup           compiler_blacklist_versions 1.0

github.setup        lensfun lensfun 0.3.4 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
epoch               2

categories          graphics
license             GPL-3 LGPL-3 CC-BY-SA
maintainers         {mascguy @mascguy} openmaintainer

description         Library for fixing lens geometry distortion
long_description    Provides a database of photographic lenses and a library \
                    that allows advanced access to the database including \
                    functions to correct images based on intimate knowledge \
                    of lens characteristics and calibration data.

homepage            https://lensfun.github.io/

checksums           rmd160  6894e8cf7cb5f3c6cb46952bd9f26a5917e9a3a6 \
                    sha256  6364369eea5d90e2a678bc5bbd1e6cf9612add3b7f50c6f0ab2495c332bf75c4 \
                    size    1058856

# With 0.3.0 and gcc-4.2:
#    #error "I don't know how to change symbol visibility for your compiler"
compiler.blacklist-append *gcc-3.* *gcc-4.* {clang < 100}

set python_branch   3.12
set python_version  [join [split ${python_branch} "."] ""]

depends_build-append \
                    port:py${python_version}-setuptools \
                    port:pkgconfig \
                    port:gettext

depends_lib-append \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:libpng \
                    port:zlib

# installs python3 helper scripts lensfun-add-adapter lensfun-update-data
depends_run-append \
                    port:python${python_version}

# Specify path to Python executable
patchfiles-append   patch-cmake-apps-python-path.diff

# Specify install path
patchfiles-append   patch-cmake-apps-install-path.diff

# Specify name of executable for 'rst2man'
patchfiles-append   patch-cmake-docs-rst2man-bin.diff

post-patch {
                    reinplace "s|^#!.*|#!${prefix}/bin/python${python_branch}|" \
                         ${worksrcpath}/apps/lensfun-add-adapter \
                         ${worksrcpath}/apps/lensfun-update-data
                    reinplace "s|@@PYTHON_VERSION@@|${python_branch}|" \
                         ${worksrcpath}/docs/CMakeLists.txt \
                         ${worksrcpath}/apps/CMakeLists.txt
}

# Clear optflags; controlled by project, via cmake build type
configure.optflags

if {[variant_isset debug]} {
    cmake.build_type    RelWithDebInfo
} else {
    cmake.build_type    Release
}

configure.args-append \
                    -DBUILD_LENSTOOL=ON \
                    -DINSTALL_HELPER_SCRIPTS=ON \
                    -DSETUP_PY_INSTALL_PREFIX=${frameworks_dir}/Python.framework/Versions/${python_branch}

# turn off -msse -msse2 if arch is powerpc
platform darwin powerpc {
    configure.args-append \
                    -DBUILD_FOR_SSE=OFF \
                    -DBUILD_FOR_SSE2=OFF
}

variant doc description {Build API and man documentation using doxygen, rst2man} {
    depends_build-append \
                    path:bin/doxygen:doxygen \
                    port:py${python_version}-docutils

    configure.args-append \
                    -DBUILD_DOC=ON
}

# Ignore double-digit RC releases
github.livecheck.regex {([0-9]\.[0-9]\.[0-9])}