# -*- 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 91679 2012-04-07 20:05:25Z snc@macports.org $

PortSystem          1.0

name                lilypond-devel
set my_name         lilypond
version             2.15.36
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          textproc
maintainers         snc openmaintainer
license             GPL-3+
description         An automated engraving system for typesetting sheet music.
long_description    Lilypond is a unix-based automated engraving system that \
                    generates beautiful sheet music from input files. Lilypond \
                    uses its own input format, .ly, which in many ways is \
                    similar to LaTeX. Lilypond can export sheet music to PDF, \
                    EPS, SVG, and PNG formats, and can also create MIDI files.

homepage            http://lilypond.org/
conflicts           lilypond
platforms           darwin
master_sites        http://download.linuxaudio.org/lilypond/sources/v${branch}/
distname            ${my_name}-${version}
dist_subdir         ${name}/${version}_${revision}
checksums           rmd160  a63f7029b60cdc6999790319670b136f9fdf355c \
                    sha256  cc84b6539b73b45fc24ff353a11f03a45006944934dc950ca0e064e9cecd0183


depends_build       port:t1utils \
                    port:texi2html \
                    port:pkgconfig
depends_lib         port:fontforge \
                    port:ghostscript \
                    port:mftrace \
                    port:guile \
                    port:texinfo \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:flex \
                    port:t1utils \
                    port:texlive-metapost \
                    port:dblatex \
                    port:urw-fonts
depends_run-append  bin:python2.7:python27

patchfiles          patch-scripts-build-mf2pt1.pl.diff
post-patch {
    reinplace s|__vector|lily_vector|g ${worksrcpath}/flower/include/std-vector.hh
    set files {Documentation/cs/usage/setup.itely \
        Documentation/de/usage/setup.itely \
        scripts/auxiliar/check_texi_refs.py \
        scripts/auxiliar/check_translation.py \
        scripts/auxiliar/coverage.py \
        scripts/auxiliar/find-superfluous-includes.py \
        scripts/auxiliar/fixcc.py \
        scripts/auxiliar/makelsr.py \
        scripts/auxiliar/musicxml_generate_intervals.py \
        scripts/auxiliar/musicxml_generate_keys.py \
        scripts/auxiliar/musicxml_generate_timesignatures.py \
        scripts/auxiliar/node-menuify.py \
        scripts/auxiliar/prepare-web-media.py \
        scripts/auxiliar/readlink.py \
        scripts/auxiliar/strip-whitespace.py \
        scripts/auxiliar/tely-gettext.py \
        scripts/auxiliar/texi-langutils.py \
        scripts/auxiliar/texi-skeleton-update.py \
        scripts/auxiliar/translations-status.py \
        scripts/auxiliar/update-snippets.py \
        python/auxiliar/manuals_definitions.py \
        scripts/build/pytt.py}
    
    foreach file ${files} {
        reinplace {s|env python|env python2.7|} ${worksrcpath}/$file
        reinplace s|/usr/bin/python|/usr/bin/env\ python2.7| ${worksrcpath}/$file
    }
}

# 17 casting errors similar to:
# accidental-engraver.cc:501:1: error: cannot cast from type 'void (Accidental_engraver::*)(Grob_info)' to pointer type 'Engraver_void_function_engraver_grob_info' (aka 'void (*)(Engraver *, Grob_info)')
if {${configure.compiler} == "clang"} {
    configure.compiler llvm-gcc-4.2
}
#configure.cflags-append --std=gnu89

configure.args-append  --with-ncsb-dir=${prefix}/share/fonts/urw-fonts \
    --disable-documentation

configure.env       LTDL_LIBRARY_PATH=${prefix}/lib

build.env           LTDL_LIBRARY_PATH=${prefix}/lib

destroot.env        LTDL_LIBRARY_PATH=${prefix}/lib
post-destroot {
    move ${destroot}${prefix}/bin/lilypond \
        ${destroot}${prefix}/libexec/lilypond-bin
    xinstall -m 755 ${filespath}/lilypond.in ${destroot}${prefix}/bin/lilypond
    reinplace "s|@@PREFIX@@|${prefix}|g" ${destroot}${prefix}/bin/lilypond
}

default_variants +docs

variant docs description {Build documentation files} {
    configure.args-delete   --disable-documentation
    configure.args-append   --enable-documentation
    depends_lib-append      port:netpbm
}

livecheck.type  regex
livecheck.url   ${homepage}/development.html
livecheck.regex ${my_name}-(\\d+(\\.\\d+)+)
