# -*- 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 120157 2014-05-17 08:40:31Z mojca@macports.org $

PortSystem          1.0
PortGroup           texlive 1.0

name                asymptote
version             2.31
categories          graphics
maintainers         gmail.com:loshea
description         a vector graphics language
long_description    Asymptote is a powerful descriptive \
                    vector graphics language that provides a natural \
                    coordinate-based framework for technical drawing. \
                    Labels and equations are typeset with LaTeX, for \
                    high-quality PostScript output.
homepage            http://asymptote.sourceforge.net
license             LGPL-3+
platforms           darwin
configure.args      --with-latex=${texlive_texmfports}/tex/latex \
                    --with-context=${texlive_texmfports}/tex/context/third \
                    --mandir=${prefix}/share/man \
                    --disable-offscreen
master_sites        sourceforge
extract.suffix      .src.tgz
checksums           rmd160  be10acd3581e4d79a3d1dc70d3080776a80caa23 \
                    sha256  d40fb1c525c53b064dfd30f09ad1b59b60650601a831615d7651de93dce31afa

# texlive-latex-recommended and texinfo are only used for building the docs
# other relevant packages are:
# - texlive-common
# - texlive-bin
# - texlive-basic
# - texlive-latex
# but they are already a dependency of latex-recommended
#
# one day we could split that into a separate +docs variant
# or fetch the PDF from somewhere
depends_build       port:ghostscript \
                    port:texinfo \
                    port:texlive-latex-recommended

depends_lib         port:readline \
                    port:fftw-3 \
                    port:gsl \
                    port:libsigsegv \
                    port:ncurses \
                    path:lib/libgc.dylib:boehmgc

# Runtime dependencies really depend on user preferences.
# Asy can draw graphics without any TeX or without LaTeX,
# so one might just as well remove all deps (or add more)
#
# The hierarchy of dependencies goes as:
# - texlive-latex-recommended [common, bin, basic, latex]
# - texlive-latex             [common, bin, basic]
# - texlive-basic             [common, bin]
#
# But then asy also supports luatex, context, etc.
depends_run         port:ghostscript \
                    port:texlive-basic

depends_skip_archcheck-append \
                    port:ghostscript \
                    port:texinfo \
                    port:texlive-basic \
                    port:texlive-bin \
                    port:texlive-latex-recommended

post-destroot {
    set python.bin ""
    if {[variant_isset python27]} {
        set python.bin ${prefix}/bin/python2.7
    } elseif {[variant_isset python26]} {
        set python.bin ${prefix}/bin/python2.6
    }
    if {${python.bin} != ""} {
        eval reinplace {"s|#!/usr/bin/env python|#!${python.bin}|"} \
            [glob -directory ${destroot}${prefix}/share/${name}/GUI *.py]
    } else {
        delete ${destroot}${prefix}/bin/xasy
    }
}

post-activate {
  # run `mktexlsr` to make sure the asymptote files are found:
  system "mktexlsr"
}
post-deactivate {
  system "mktexlsr"
}

variant python26 conflicts python27 description {Enable xasy GUI using Python 2.6} {
    depends_lib-append port:py26-tkinter port:py26-pil
}
variant python27 conflicts python26 description {Enable xasy GUI using Python 2.7} {
    depends_lib-append port:py27-tkinter port:py27-pil
}
if {![variant_isset python26]} {
    default_variants +python27
}
