# -*- 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

PortSystem          1.0
PortGroup           qt4 1.0

name                qtscriptgenerator
version             0.2.0
revision            1
categories          devel kde4
license             LGPL-2.1
maintainers         {michaelld @michaelld} openmaintainer
description         QtScript bindings generator.
long_description    Qt Script Generator is a tool that generates \
    Qt bindings for Qt Script. With the generated bindings you get \
    access to substantial portions of the Qt API from within Qt Script.
platforms           darwin
homepage            http://labs.trolltech.com/page/Projects/QtScript/Generator
distname            ${name}-src-${version}
master_sites        http://qtscriptgenerator.googlecode.com/files/
checksums           md5     9f82b0aa212f7938de37df46cd27165c \
                    sha1    4c1078f26b196156e857c17c9d11a66cfea66f00 \
                    rmd160  01c8ce3b4c8e9ebb3bc3c2d7b319846f34baee04 

depends_build-append port:automoc
depends_lib-append  port:phonon

patchfiles          patch-generator.diff \
                    patch-qtbindings.diff \
                    patch-generator_typesystem_phonon-qtscript.xml.diff \
                    patch-generator_typesystem_phonon.xml.diff \
                    debian_drop_extra_linkage_fix.diff \
                    debian_qs_eval_globalize.diff \
                    upstream_memory_alignment_fix.diff \
                    upstream_support_later_phonon.diff \
                    remove-QtScriptFutureIterator.diff \
                    patch-include-everything.diff \
                    patch-build-system-for-MacPorts.diff

# check for +debug variant of this port, and make sure phonon was
# installed with +debug as well; if not, error out.  phonon checks to
# make sure Qt was installed with +debug, so it is OK if this stage
# overrides that provided in the qt4 portgroup.
pre-extract {
    if {[variant_exists debug] && \
        [variant_isset debug] && \
       ![info exists building_qt4]} {
        if {![file exists ${prefix}/lib/libphonon_debug.dylib]} {
            return -code error "\n\nERROR:\n\
In order to install this port as +debug,
Phonon \(and Qt4\) must also be installed with +debug.\n"
        }
    }
}

post-patch {
    # copy the QMake build script into place
    copy ${filespath}/qtsg.pro ${worksrcpath}

    reinplace "s|@QT_FRAMEWORKS_DIR@|${qt_frameworks_dir}|g" \
        ${worksrcpath}/generator/main.h
    reinplace -W ${worksrcpath} "s|@QT_INCLUDES_DIR@|${qt_includes_dir}|g" \
        generator/main.h \
        generator/generator.pri \
        qtbindings/qtbindingsbase.pri
    reinplace -W ${worksrcpath} "s|@PREFIX@|${prefix}|g" \
        generator/main.h \
        generator/generator.pri \
        qtbindings/qtbindingsbase.pri
    reinplace "s|@CC@|${configure.cc}|g" \
        ${worksrcpath}/qtsg.pro
    reinplace "s|@CXX@|${configure.cxx}|g" \
        ${worksrcpath}/qtsg.pro

    # allow for universal and non-native building if just the
    # qtbinding scripts, not the generator (which is solely used for
    # generating the scripts)
    reinplace "s/@ARCHES@/${qt_arch_types}/" \
        ${worksrcpath}/qtbindings/qtbindingsbase.pri

    # fix up qtbindings QMake build file to handle debug and release
    set build_type "release"
    if {[variant_isset debug]} {
        set build_type "debug_and_release build_all"
    }
    reinplace "s/@BUILD_TYPE@/${build_type}/" \
        ${worksrcpath}/qtbindings/qtbindingsbase.pri
}

# set up to use the installed QMake files
configure.cmd       ${qt_qmake_cmd}
configure.pre_args
configure.args      "-o Makefile qtsg.pro"
configure.post_args
configure.universal_args
configure.env-delete \
                    QTDIR=${qt_dir}
build.env-delete    QTDIR=${qt_dir}
# used by generator/generator:
build.env-append    QTFRAMEWORKS=${qt_frameworks_dir}

# allow ccache, if specified by the user
pre-build {
    if {[tbool configure.ccache]} {
        build.post_args "CCACHE=ccache"
    }
}

variant docs description {installs the documentation} {}

post-destroot {
    xinstall -m 755 ${build.dir}/generator/generator ${destroot}${prefix}/bin/qs_generator
    xinstall -m 755 ${build.dir}/qtbindings/qs_eval/qs_eval ${destroot}${prefix}/bin/qs_eval
    xinstall -m 755 -d ${destroot}${prefix}/share/man/man1
    xinstall -m 644 ${filespath}/qs_eval.1 ${destroot}${prefix}/share/man/man1/qs_eval.1
    reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${prefix}/share/man/man1/qs_eval.1
    if {[variant_isset docs]} {
        xinstall -m 755 -d ${destroot}${prefix}/share/doc/qtscriptgenerator
        foreach d [glob -nocomplain ${build.dir}/doc/*] {
            file copy ${d} ${destroot}${prefix}/share/doc/qtscriptgenerator
        }
    }
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/qtscriptgenerator
    file copy ${build.dir}/examples ${destroot}${prefix}/share/doc/qtscriptgenerator
}

variant debug description "Build release and debug versions" {}

# just disable for now
livecheck.type      none
