# -*- 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 84550 2011-09-27 21:05:11Z snc@macports.org $

PortSystem          1.0
PortGroup           qt4 1.0

name                qtscriptgenerator
version             0.1.0
revision            4
categories          devel kde4
maintainers         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     ca4046ad4bda36cd4e21649d4b98886d \
                    sha1    eeae733106369e289f257b754822bc372fd6ba75 \
                    rmd160  a02ce6fea2fbc3d3a6ae9e51c6b563ef4bcd51f3 

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

patchfiles          patch-generator.diff \
                    patch-qtbindings.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}

    # 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

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

universal_variant   yes

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