# $Id: Portfile 62651 2010-01-13 14:05:43Z nox@macports.org $

PortSystem      1.0

name            colorer
version         take5.be5
revision        1
license         MPL-1.1 GPL-2.0 LGPL-2.1
categories      textproc devel
platforms       darwin
maintainers     nox openmaintainer
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
distname        Colorer-${version}
use_zip         yes

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

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

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
}

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

build.target colorer
use_parallel_build yes

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

if {[variant_isset universal]} {
    post-patch {
        # Use MacPorts universal flags
        reinplace "/^CPPFLAGS/s:\$: ${configure.universal_cflags}:" \
            ${worksrcpath}/src/shared/makefile.colorer.gcc
        reinplace -E "/^(LIB)?FLAGS/s:\$: ${configure.universal_ldflags}:" \
            ${worksrcpath}/src/colorer/makefile.macos \
            ${worksrcpath}/src/libcolorer/makefile.gcc
    }
}

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