# -*- 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           xcode 1.0
PortGroup           xcodeversion 1.0

name                TeXShop
version             5.21
revision            0

set major           [lindex [split ${version} .] 0]
categories          aqua editors
license             GPL-2+
maintainers         {mps @Schamschula} openmaintainer
description         TeX previewer for Mac OS X
long_description   \
    TeXShop is a TeX previewer for Mac OS X, written in Cocoa.  \
    Since pdf is a native file format on OS X, TeXShop uses     \
    "pdftex" and "pdflatex" rather than "tex" and "latex" to    \
    typeset, these programs in the standard teTeX distribution  \
    of TeX produce pdf output instead of dvi output.
homepage            http://pages.uoregon.edu/koch/texshop
master_sites        ${homepage}/texshop-64
use_zip             yes

distname            texshopsource[strsed ${version} {/\.//}]
dist_subdir         TeXShop/
worksrcdir          ${name}-${version}

checksums           rmd160  ceb1e0720486ccd92cf24550a432160780824430 \
                    sha256  517bf8fbff87e11d49e13c11c5094590286dd80d8463e1fa60f910bce8cd0513 \
                    size    217317273

minimum_xcodeversions   {21 13.4}

# This is a temporary kludge. The new Xcode build system fails to
# destroot this for reasons that are poorly understood.
# Remove this when a better fix is known.
if {[vercmp ${xcodeversion} 10.0] >= 0} {
    build.pre_args      -UseNewBuildSystem=NO
    destroot.pre_args   -UseNewBuildSystem=NO
}

configure.cxx_stdlib    libstdc++

platform darwin {
    if {${os.major} > 20} {
        # Don't build Sparkle
        # See: https://trac.macports.org/ticket/66382
        patchfiles  patch-Sources-UseSparkle.h.diff \
                    patch-TeXShop.xcodeproj-project.pbxproj.diff

        post-patch {
            delete ${worksrcpath}/Sparkle.framework
        }
    }

    if {${os.major} == 20} {
        version     4.79
        revision    1
        checksums   rmd160  ba6ff730a0ab391b039bdac315c41404cd99959c \
                    sha256  dfa9f54b93502a6487c31adf39c47051483a4b4bd1f974d8b35e66a90c6c660d \
                    size    158553155

        minimum_xcodeversions   {20 12.2}

        distname    texshopsource[strsed ${version} {/\.//}]
        worksrcdir  ${name}-${version}

        # Don't build Sparkle
        # See: https://trac.macports.org/ticket/66382
        patchfiles  patch-TeXShop-4.79.xcodeproj-project.pbxproj.diff \
                    patch-TeXShop-4.79-Sources-TSPreferences.diff

        post-patch {
            delete ${worksrcpath}/Sparkle.framework
        }

        livecheck.type  none
    }

    if {${os.major} < 20} {
        version     4.44
        revision    0
        checksums   rmd160  bcbccbd35ecbf9f09d38e43a7bc5392f1e0f419c \
                    sha256  e73f79a87cb02faa37b080fbdddec5edc384b7e80ff5b1d3828f86a3160da032 \
                    size    151971878

        minimum_xcodeversions   {13 6.2}

        distname    texshopsource[strsed ${version} {/\.//}]
        worksrcdir  ${distname}

        post-patch {
            if {${os.major} < 17} {
                reinplace "s|#define HIGHSIERRAORHIGHER|// #define HIGHSIERRAORHIGHER|g" ${worksrcpath}/Sources/globals.h
            }
            if {${os.major} < 18} {
                reinplace "s|#define MOJAVEORHIGHER|// #define MOJAVEORHIGHER|g" ${worksrcpath}/Sources/globals.h
            }
        }

        livecheck.type  none
    }

    platforms {darwin >= 15}
}

build.target            ${name}

xcode.project           ${name}.xcodeproj
xcode.configuration     Release
xcode.build.settings    FRAMEWORK_SEARCH_PATHS=${worksrcpath} \
                        CONFIGURATION_BUILD_DIR=${worksrcpath}/build \
                        CODE_SIGN_IDENTITY=

xcode.destroot.settings INSTALL_MODE_FLAG=755 {*}${xcode.build.settings}

post-destroot {
    file delete -force ${destroot}${applications_dir}/TeX.mdimporter
}

livecheck.type      regex
livecheck.regex     TeXShop \\(v (${major}\.\[0-9.\]+)\\)
