# -*- 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
# $Id: Portfile 64468 2010-03-06 21:01:02Z snc@macports.org $

PortSystem      1.0
PortGroup       xcode 1.0

name            TeXShop
version         2.33
categories      aqua editors
license         GPLv2+
maintainers     snc 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://www.uoregon.edu/~koch/texshop/texshop.html
master_sites    http://www.uoregon.edu/~koch/texshop
use_zip         yes
distname        texshopsource
dist_subdir     ${name}/${version}
worksrcdir      texshop${version}
checksums           md5     aa466417c45e2d990c83bf1e84889e65 \
                    sha1    8af77bf6db75e0588488e7c1d795cfc50559f7b0 \
                    rmd160  30f2d219c4079f857a4e4f632a396bca1ec7ead7

# force 32-bit, ticket #20291
if {$build_arch == "x86_64"} {
    configure.build_arch i386
} elseif {$build_arch == "ppc64"} {
    configure.build_arch ppc
}
post-extract    {
    reinplace "s/defaultConfigurationName = Debug/defaultConfigurationName = Release/" ${worksrcpath}/${name}.xcodeproj/project.pbxproj
    
    set sparkle "Sparkle.framework/Versions/A/Sparkle"
    set ogrekit "OgreKit.framework/Versions/A/OgreKit"
    if {![variant_isset universal]} {
        # thin the bundled frameworks
        system "cd ${worksrcpath} && lipo -thin ${configure.build_arch} $sparkle -output $sparkle"
        system "cd ${worksrcpath} && lipo -thin ${configure.build_arch} $ogrekit -output $ogrekit"
    } elseif {${os.major} == 8} {
        # Tiger chokes on the x86_64
        system "cd ${worksrcpath} && lipo -remove x86_64 $sparkle -output $sparkle"
    }
}

build.target    ${name}

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

destroot.target     ${name}
eval xcode.destroot.settings INSTALL_MODE_FLAG=755 ${xcode.build.settings}
post-destroot        {
    file delete -force ${destroot}${applications_dir}/TeX.mdimporter

    xinstall -m 755 ${filespath}/lilypond.engine ${destroot}${applications_dir}/${name}.app/Contents/Resources/${name}/Engines/Lilypond.engine
    reinplace s|@@PREFIX@@|${prefix}|g ${destroot}${applications_dir}/${name}.app/Contents/Resources/${name}/Engines/Lilypond.engine
}

notes "If you intend to use the Lilypond engine, please copy ${applications_dir}/${name}.app/Contents/Resources/${name}/Engines/Lilypond.engine to ~/Library/${name}/Engines/Lilypond.engine"

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "${name} (\\d+\\.\\d+)"
