# -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 78328 2011-05-03 15:24:40Z macsforever2000@macports.org $

PortSystem	1.0
PortGroup   qt4 1.0

name		py26-pyqt4
version		4.8.4
categories	python devel
platforms	macosx
maintainers     michaelld openmaintainer
description	PyQt4 is a set of Python bindings for the Qt4 toolkit
long_description \
		PyQt4 is a set of Python bindings for the Qt4 toolkit. The \
		bindings are implemented as a set of Python modules: qt, \
		qtcanvas, qtgl, qtnetwork, qtsql, qttable, qtui and qtxml, \
		and contains 300 classes and over 5,750 functions and methods.
homepage	http://www.riverbankcomputing.co.uk/software/pyqt/intro
master_sites	http://www.riverbankcomputing.com/static/Downloads/PyQt4/ \
		http://pyqwt.sourceforge.net/support/
distname	PyQt-mac-gpl-${version}
dist_subdir         python

checksums           md5     c9114258f494cafa87fc2740364fa7f4 \
                    sha1    7fbd01603cb1b203abad6331594d1c4b7a395920 \
                    rmd160  96d7076162ae6b4b0518f91108572558268e529c

set pyversion 2.6
set pyversion_join [join [split ${pyversion} "."] ""]

depends_lib-append port:py${pyversion_join}-sip

# The patch file alters configure.py so that the qtdesigner plugin can link.
# - it ensures that both LFLAGS are included and that the relevant version framework is linked
patchfiles	patch-configure.py
post-patch {
    reinplace "s|@@MACPORTS_PYTHON_FRAMEWORK@@|${frameworks_dir}/Python.framework/Versions/${pyversion}/Python|" ${worksrcpath}/configure.py
}

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

configure.cmd	"${prefix}/bin/python${pyversion} configure.py \
		-q ${qt_qmake_cmd} --verbose --confirm-license"
configure.pre_args
configure.post_args	LFLAGS="-F${frameworks_dir} -L${prefix}/lib"

variant universal {
	configure.universal_args
	configure.post_args	LFLAGS="-F${frameworks_dir} -L${prefix}/lib \
								${configure.universal_ldflags}"
	configure.post_args-append	CFLAGS="${configure.universal_cflags}"
	configure.post_args-append	CXXFLAGS="${configure.universal_cxxflags}"
}

post-configure {
	if {[variant_isset universal]} {
		set conflags ""
		foreach arch ${configure.universal_archs} {
			if {${arch} == "i386"} {append conflags "x86 "} else {
				if {${arch} == "ppc64"} {append conflags "ppc_64 "} else {
					append conflags ${arch} " "
				}
			}
		}

		set profiles [exec find ${worksrcpath} -name "*.pro"]
		foreach profile ${profiles} {
			reinplace -E "s|^(CONFIG\[ \\t].*)|\\1 ${conflags}|" ${profile}
		
		# Cures an isolated case
		system "cd ${worksrcpath}/designer && \
			${qt_qmake_cmd} -spec ${qt_mkspecs_dir}/macx-g++ -macx \
				-o Makefile python.pro"
		}
	}
}

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

build.target    all
use_parallel_build yes

test.run	yes
test.cmd	cd qt && ${prefix}/bin/python${pyversion} -c 'import PyQt4'

post-destroot {
    ln -s ${frameworks_dir}/Python.framework/Versions/${pyversion}/bin/pyrcc4 ${destroot}${prefix}/bin/pyrcc4-${pyversion}
    ln -s ${frameworks_dir}/Python.framework/Versions/${pyversion}/bin/pyuic4 ${destroot}${prefix}/bin/pyuic4-${pyversion}

	xinstall -m 755 -d ${destroot}${prefix}/share/doc
	file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${name}
	file copy ${worksrcpath}/examples \
		${destroot}${prefix}/share/doc/${name}
	xinstall -m 644 -W ${worksrcpath} \
		GPL_EXCEPTION.TXT GPL_EXCEPTION_ADDENDUM.TXT \
		LICENSE-MERGED-GPL2-GPL3 LICENSE.GPL2 LICENSE.GPL3 OPENSOURCE-NOTICE.TXT NEWS README \
		THANKS \
		${destroot}${prefix}/share/doc/${name}

    # rename Qt4 specific files
    # (a) designer plugin
    set old_name libpythonplugin.dylib
    set new_name libpython${pyversion_join}plugin.dylib

    move ${destroot}${qt_plugins_dir}/designer/${old_name} \
        ${destroot}${qt_plugins_dir}/designer/${new_name}
    system "install_name_tool -id ${new_name} \
        ${destroot}${qt_plugins_dir}/designer/${new_name}"

    # (b) Qsci API file, if it exists (if Qsci is installed at build time)
    if {[file exists ${destroot}${qt_data_dir}/qsci/api/python/PyQt4.api]} {
        move ${destroot}${qt_data_dir}/qsci/api/python/PyQt4.api \
            ${destroot}${qt_data_dir}/qsci/api/python/PyQt4-Python${pyversion}.api
    }
}

variant debug description "Build debug libraries" {
    configure.cmd-append --debug
}

livecheck.type   regex
livecheck.url    http://www.riverbankcomputing.co.uk/software/pyqt/download
livecheck.regex  "PyQt-mac-gpl-(\[0-9.\]\\.\[0-9.\]\\.\[0-9.\]).tar.gz"
