# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 80157 2011-07-05 16:49:12Z ryandesign@macports.org $

PortSystem      1.0

name            scite
version         2.27
categories      editors
platforms       darwin
maintainers     nomaintainer
description     SciTE is a SCIntilla based Text Editor.

long_description \
    Originally built to demonstrate Scintilla, it has grown to be a generally \
    useful editor with facilities for building and running programs. It is best \
    used for jobs with simple configurations.

homepage        http://scintilla.sourceforge.net/SciTE.html
master_sites    sourceforge:scintilla
distname        ${name}[strsed ${version} {g/\.//}]
extract.suffix  .tgz

depends_build   port:pkgconfig
depends_lib     port:gtk2

checksums       sha1    d248394fe09dc1d111d1afe5c89320b67c01e9f0 \
                rmd160  f61251b8d451ef05bedef55836b483bbf188c761

worksrcdir      ${name}

patch.dir       ${workpath}

patchfiles      patch-scite-makefile.diff

use_configure   no

build.dir       ${worksrcpath}/gtk

build.args      prefix=${prefix} GTK2=yes

use_parallel_build  yes

pre-build {
    foreach {badport badfile} "tidy ${prefix}/include/platform.h" {
        if {[file exists ${badfile}]} {
            ui_error "${name} cannot be built while ${badport} is active."
            ui_error "Please deactivate ${badport} and try again."
            ui_error "You can reactivate ${badport} again later."
            return -code error "${badport} is installed"
        }
    }

    if {[variant_isset universal]} {
        set lipo_args {}
        set sysrootflags ""
        if {${configure.sdkroot} != ""} {
            set sysrootflags "-isysroot ${configure.sdkroot} "
        }

        foreach arch ${configure.universal_archs} {
            system "make -C ${workpath}/scintilla/gtk \
                GTK2=yes UNIVERSAL_CFLAGS=\"${sysrootflags}-arch ${arch}\""

            file mkdir ${workpath}/scintilla/bin/${arch}
            move ${workpath}/scintilla/bin/scintilla.a ${workpath}/scintilla/bin/${arch}/scintilla.a

            system "make -C ${workpath}/scintilla/gtk \
                clean"

            lappend lipo_args -arch ${arch} ${workpath}/scintilla/bin/${arch}/scintilla.a
        }

        system "lipo -create [join ${lipo_args}] -output ${workpath}/scintilla/bin/scintilla.a"
    } else {
        system "make -C ${workpath}/scintilla/gtk \
            GTK2=yes"
    }
}

destroot.destdir    prefix=${destroot}${prefix}

post-destroot {
    xinstall -m 444 ${worksrcpath}/doc/scite.1 ${destroot}${prefix}/share/man/man1
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${workpath}/scite License.txt README ${destroot}${docdir}
}

variant universal {
    post-patch {
        reinplace -E "/^CXXBASEFLAGS/s|\$| \$(UNIVERSAL_CFLAGS)|" \
            ${workpath}/scintilla/gtk/makefile
        reinplace -E "/^CXXBASEFLAGS/s|\$| ${configure.universal_cflags}|" \
            ${build.dir}/makefile
    }

    build.args-append   "UNIVERSAL_LDFLAGS=\"${configure.universal_ldflags}\""
}

livecheck.distname  SciTE
