# -*- 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.00
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  d5d56bd49bf4d973b15302bcfa65779e41732771 \
                    sha256  7f710cd0d2b266a2202c7f6e11758cfdf165e9667ac3aa9fd75854a9d8acdcf8 \
                    size    162020625

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} < 15} {
        pre-fetch {
            ui_error "${name} @${version} requires at least OS X 10.11 El Capitan"
            return -code error "incompatible OS X version"
        }
        known_fail  yes
    }

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

        minimum_xcodeversions   {20 12.2}

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

    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 {
    platform darwin {
        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
        }
    }
}

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.\]+)\\)
