# -*- 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

name                libreoffice
version             7.6.4.1
revision            1
categories          office aqua
license             {LGPL-3 MPL-1.1}
platforms           macosx
maintainers         {gmail.com:audvare @Tatsh} openmaintainer
description         Free, open source office suite.
long_description    LibreOffice is a free and powerful office suite, and a successor to \
                    OpenOffice.org (commonly known as OpenOffice). Its clean interface and \
                    feature-rich tools help you unleash your creativity and enhance your \
                    productivity.
homepage            https://www.libreoffice.org

set short_version   [string range $version 0 end-2]
set main_uri        https://download.documentfoundation.org/${name}/src/${short_version}/
set addons_uri      https://dev-www.libreoffice.org/src/
set extern_uri      https://dev-www.libreoffice.org/extern/
use_xz              yes
set main_distfile   ${name}-${version}${extract.suffix}

livecheck.type      regex
livecheck.url       https://downloadarchive.documentfoundation.org/${name}/old/latest/src/
livecheck.regex     "${name}-((?:\\d+\\.\\d+\\.\\d+)(?:\\.\\d+))?${extract.suffix}</a></td>"

extract.only        ${main_distfile} \
                    ${name}-dictionaries-${version}.tar.xz \
                    ${name}-translations-${version}.tar.xz
master_sites        ${main_uri}:main \
                    ${extern_uri}:opens \
                    ${addons_uri}:dtoa \
                    ${addons_uri}:nss \
                    ${main_uri}:dicts \
                    ${main_uri}:translations \
                    ${addons_uri}:libcmis \
                    ${addons_uri}:skia
distfiles           ${main_distfile}:main \
                    ${name}-dictionaries-${version}.tar.xz:dicts \
                    ${name}-translations-${version}.tar.xz:translations \
                    dtoa-20180411.tgz:dtoa \
                    f543e6e2d7275557a839a164941c0a86e5f2c3f2a0042bfc434c88c6dde9e140-opens___.ttf:opens \
                    libcmis-0.6.1.tar.xz:libcmis \
                    skia-m111-a31e897fb3dcbc96b2b40999751611d029bf5404.tar.xz:skia \
                    nss-3.90-with-nspr-4.35.tar.gz:nss

patch.pre_args-replace  -p0 -p1
patchfiles-append   6a2b1d9.diff

checksums           ${name}-${version}.tar.xz \
                    rmd160  dff03f1a5280abeda7179014e54b30d98fb75250 \
                    sha256  13fea7b8f24c776313b9e08628aa590390bea45064be73bc70ee7b1b70aa6a1e \
                    size    281547116 \
                    ${name}-dictionaries-${version}.tar.xz \
                    rmd160  27198d9e7fc6a8b969d357104b6bf0f3d758765b \
                    sha256  36c0526e4c12ab38dd1e1766cd878118dd5692578b80411b9b443e389e3712fa \
                    size    53057396 \
                    ${name}-translations-${version}.tar.xz \
                    rmd160  971154d22f41145be68c971469f33d8db09d0d5f \
                    sha256  3a5a0dbe40abdc55cdd9994895f6577d7e547d26a36b20641f32f3640a3b7679 \
                    size    216976788 \
                    dtoa-20180411.tgz \
                    rmd160  8d1bba737d8b58c3fb09533f35af2a03e05d9849 \
                    sha256  0082d0684f7db6f62361b76c4b7faba19e0c7ce5cb8e36c4b65fea8281e711b4 \
                    size    48893 \
                    f543e6e2d7275557a839a164941c0a86e5f2c3f2a0042bfc434c88c6dde9e140-opens___.ttf \
                    rmd160  b9e2cc0c836faa59eca3bfc0f24e1b790646b112 \
                    sha256  f543e6e2d7275557a839a164941c0a86e5f2c3f2a0042bfc434c88c6dde9e140 \
                    size    207992 \
                    libcmis-0.6.1.tar.xz \
                    rmd160  bcfe41a5d7db5507c72662393341225ee0e68d71 \
                    sha256  d54d19d86153dbc88e2d468f7136269a2cfe71b73227e12fded01d29ac268074 \
                    size    490296 \
                    skia-m111-a31e897fb3dcbc96b2b40999751611d029bf5404.tar.xz \
                    rmd160  b730395b16ba71dfba25ba0af221beb9e4f70fc5 \
                    sha256  0d08a99ed46cde43b5ad2672b5d8770c8eb85d0d26cb8f1f85fd9befe1e9ceb9 \
                    size    10693272 \
                    nss-3.90-with-nspr-4.35.tar.gz \
                    rmd160  dc93cab2c41c7c8bd7f284689b173e7724085886 \
                    sha256  f78ab1d911cae8bbc94758fb3bd0f731df4087423a4ff5db271ba65381f6b739 \
                    size    73739964

depends_build-append \
    port:autoconf \
    port:automake \
    port:bison \
    port:cppunit \
    port:dragonbox \
    port:flex \
    port:frozen \
    port:gettext \
    port:gmake \
    port:gpatch \
    port:gperf \
    port:mesa \
    port:pkgconfig \
    port:ucpp \
    port:unixODBC
depends_lib-append  \
    port:box2d \
    port:bzip2 \
    port:clucene \
    port:curl \
    port:expat \
    port:gdbm \
    port:gettext \
    port:graphite2 \
    path:lib/pkgconfig/harfbuzz.pc:harfbuzz \
    path:lib/pkgconfig/harfbuzz-icu.pc:harfbuzz-icu \
    port:hunspell \
    port:hyphen \
    path:lib/pkgconfig/icu-uc.pc:icu \
    path:include/turbojpeg.h:libjpeg-turbo \
    port:lcms2 \
    port:libabw \
    port:libcdr-0.1 \
    port:libcuckoo \
    port:libe-book \
    port:libepoxy \
    port:libepubgen \
    port:libetonyek \
    port:libexttextcat \
    port:libfreehand \
    port:libiconv \
    port:liblangtag \
    port:libmspub \
    port:libmwaw \
    port:libnumbertext \
    port:libodfgen \
    port:libpagemaker \
    port:libpng \
    port:libqxp \
    port:librevenge \
    port:libstaroffice \
    port:libvisio-0.1 \
    port:libwpd-0.10 \
    port:libwpg-0.3 \
    port:libwps \
    port:libxml2 \
    port:libxslt \
    port:libzmf \
    port:mdds-2.1 \
    port:mythes \
    port:ncurses \
    port:neon \
    port:nspr \
    port:nss \
    port:orcus-0.18 \
    port:ossp-uuid \
    port:raptor2 \
    port:readline \
    port:redland \
    port:sqlite3 \
    port:webp \
    port:xmlsec \
    port:xz \
    port:zlib
# Try to keep this in sync with the Python portgroup.
set pyver 3.11
set python_version [join [split ${pyver} "."] ""]
depends_run-append \
    port:python${python_version} \
    port:py${python_version}-lxml

if {${os.platform} eq "darwin" && ${os.major} < 20} {
    known_fail yes
    depends_build
    depends_lib
    depends_run
    pre-fetch {
        ui_error "Building ${name} @${version} requires macOS 11 or later."
        ui_error ""
        ui_error "Consider downloading a version from LibreOffice's website:"
        ui_error "https://www.libreoffice.org/download/download/"
        ui_error ""
        return -code error "incompatible OS X version"
    }
}

set product_name LibreOffice

pre-configure {
    system "cd ${worksrcpath} && env NOCONFIGURE=1 ./autogen.sh"
}

use_xcode               yes
compiler.cxx_standard   2017
# CMS_NO_REGISTER_KEYWORD required for C++17 or newer compiler.
# PYTHON_CFLAGS and PYTHON_LIBS have to be non-empty
configure.cxxflags-append -std=gnu++17
configure.env-append  \
    "LCMS2_CFLAGS=-I${prefix}/include -DCMS_NO_REGISTER_KEYWORD=1" \
    PYTHON=${prefix}/bin/python${pyver} \
    PYTHON_CFLAGS=-I${frameworks_dir}/Python.framework/Versions/${pyver}/include/python${pyver} \
    "PYTHON_LIBS=-L${frameworks_dir}/Python.framework/Versions/${pyver}/lib -lpython${pyver} -ldl -framework CoreFoundation"

# Most arguments are from
# https://wiki.documentfoundation.org/LibreOffice_Vanilla_for_Mac#LibreOffice_Vanilla
configure.args-append  \
    --disable-breakpad \
    --disable-bundle-mariadb \
    --disable-ccache \
    --disable-coinmp \
    --disable-epm \
    --disable-ext-numbertext \
    --disable-fetch-external \
    --disable-firebird-sdbc \
    --disable-ldap \
    --disable-lotuswordpro \
    --disable-lpsolve \
    --disable-odk \
    --disable-online-update \
    --disable-openssl \
    --disable-pdfimport \
    --disable-pdfium \
    --disable-postgresql-sdbc \
    --disable-report-builder \
    --disable-zxing \
    --enable-bogus-pkg-config \
    --enable-cups \
    --enable-extension-integration \
    --enable-mpl-subset \
    --enable-python=system \
    --enable-readonly-installset \
    --enable-release-build \
    --enable-symbols \
    --with-boost=[boost::install_area] \
    --with-external-tar=${distpath} \
    --with-gnu-patch=${prefix}/bin/gpatch \
    --with-myspell-dicts \
    --with-package-version=${version} \
    --with-parallelism=${build.jobs} \
    --with-product-name=${product_name} \
    --with-system-clucene \
    --with-system-cuckoo \
    --with-system-dragonbox \
    --with-system-epoxy \
    --with-system-gpgmepp \
    --with-system-frozen \
    --with-system-headers \
    --with-system-hunspell \
    --with-system-jars \
    --with-system-libabw \
    --with-system-libebook \
    --with-system-libepubgen \
    --with-system-libexttextcat \
    --with-system-libmwaw \
    --with-system-libnumbertext \
    --with-system-libqxp \
    --with-system-libs \
    --with-system-libstaroffice \
    --with-system-libzmf \
    --with-system-mdds \
    --with-system-mythes \
    --with-system-orcus \
    --with-system-ucpp \
    --with-system-xmlsec \
    --with-theme=colibre \
    --with-tls=nss \
    --with-vendor=MacPorts \
    --without-doxygen \
    --without-fonts \
    --without-java \
    --without-package-format \
    --without-system-dicts \
    --without-system-libcmis \
    --without-system-libfixmath \
    --without-system-sane \
    --without-webdav \
    \"--with-lang=bg br ca ca-valencia cy cs da de el en-US en-GB es et eu fi fr ga gd gl hr hu id is it ja km lt lv nb nl nn pl pt pt-BR ro ru sk sl sv ta tr uk zh-CN zh-TW\"
configure.env-append \
    GNUMAKE=${prefix}/bin/gmake

build.target    build
build.cmd       ${prefix}/bin/gmake

destroot.keepdirs ${destroot}${applications_dir}/${product_name}.app/Contents/Resources/en.lproj
destroot {
    copy ${worksrcpath}/instdir/${product_name}.app ${destroot}${applications_dir}
}
