# $Id: Portfile 112479 2013-10-24 09:36:43Z ryandesign@macports.org $

PortSystem      1.0

name            colorer
version         take5.be5
revision        1
license         MPL-1.1 GPL-2 LGPL-2.1
categories      textproc devel
platforms       darwin
maintainers     nomaintainer
description     A library that provides source text syntax highlighting services

long_description \
    Colorer take5 is a syntax highlighting and text parsing library, that \
    provides services of text parsing in host editor systems in real-time and \
    transforming results into colored text. Result information allows to \
    search and build outlined lists of functions, structures, and to search \
    and indent programming language constructions (brackets, paired tags).

homepage        http://colorer.sourceforge.net/
master_sites    sourceforge:project/colorer/Library%20sources/Colorer-${version}
distname        Colorer-${version}
use_zip         yes

checksums       md5     075ede3afc260766fe13c71850a5e6c0 \
                sha1    53cd454779621c09954ce70b6d06a4e1903ed6af \
                rmd160  87c9ad2b99343c19e74211e658eb73ebcf0bcea9

post-extract {
    copy \
        ${worksrcpath}/src/libcolorer/linux/Makefile.in \
        ${worksrcpath}
}

variant universal {}

patchfiles      patch-Makefile.in.diff

post-patch {
    # Use makefile.macos for colorer
    reinplace {/\/colorer/s/gcc/macos/} ${worksrcpath}/Makefile.in

    # error: cast from 'int*' to 'int' loses precision
    reinplace s/int(/bool(/ ${worksrcpath}/src/shared/unicode/BitArray.cpp

    # Libraries extension is ".dylib" on Darwin, not ".so"
    reinplace {s/\.so/.dylib/} \
        ${worksrcpath}/Makefile.in \
        ${worksrcpath}/src/libcolorer/makefile.gcc

    # The flag to build dynamic libraries on Darwin is -dynamiclib
    # Furthermore we need to write down libcolorer install name
    reinplace \
        "s:-shared:-dynamiclib -install_name ${prefix}/lib/\$(TARGET):" \
        ${worksrcpath}/src/libcolorer/makefile.gcc

    # Do not force installation as root
    reinplace {s/-g 0 -o 0//} ${worksrcpath}/Makefile.in

    # Install documentation in an unversioned directory
    reinplace s:doc/colorer-take5:doc/colorer: ${worksrcpath}/Makefile.in

    reinplace "/^CPPFLAGS/s:\$: [get_canonical_archflags cc]:" \
        ${worksrcpath}/src/shared/makefile.colorer.gcc
    reinplace -E "/^(LIB)?FLAGS/s:\$: [get_canonical_archflags ld]:" \
        ${worksrcpath}/src/colorer/makefile.macos \
        ${worksrcpath}/src/libcolorer/makefile.gcc
}

# error: taking the address of a temporary object of type 'DString'
compiler.blacklist *clang*

configure.cmd   sh src/libcolorer/linux/configure
configure.args  --srcdir=.

build.target colorer
# Yes, this build system uses "CPP" for the C compiler and "LINK" for the C++ compiler.
build.args          CPP=${configure.cc} \
                    LINK=${configure.cxx}
use_parallel_build yes

destroot.destdir    prefix=${destroot}${prefix}
destroot.args       -B

livecheck.type  regex
livecheck.url   ${homepage}whatsnew/history.html
livecheck.regex {<h2>([^,]*), Latest}
