# -*- 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 75404 2011-01-24 16:15:56Z macsforever2000@macports.org $

PortSystem      1.0

name            py27-sip
version         4.12.1
categories      python devel
maintainers     nomaintainer
platforms       macosx

description     create Python bindings for C and C++ libraries
long_description \
    SIP is a tool that makes it very easy to create \
    Python bindings for C and C++ libraries. \
    It was originally developed to create PyQt, \
    the Python bindings for the Qt toolkit, \
    but can be used to create bindings for any \
    C or C++ library.

homepage        http://www.riverbankcomputing.co.uk/software/sip/intro
master_sites \
    http://www.riverbankcomputing.com/static/Downloads/sip4/ \
    http://gentoo.mirrors.easynews.com/linux/gentoo/distfiles/ \
    http://gentoo.osuosl.org/distfiles/ \
    http://www.gtlib.gatech.edu/pub/gentoo/distfiles/

distname        sip-${version}
checksums           md5     0f8e8305b14c1812191de2e0ee22fea9 \
                    sha1    f54a94f25c9756ea365ee28a9dfdfc292a658cee \
                    rmd160  c570c9789ce3832b5d39b22af04d810265e4589b

dist_subdir python

set pyversion 2.7
depends_lib-append port:python[strsed ${pyversion} {g/[.]//}]
set pybin ${prefix}/bin/python${pyversion}

# fix to allow for correct parsing of "X = Y $$X" in QMake files
patchfiles    patch-siputils.py.diff

configure.cmd ${pybin} configure.py

pre-configure {
    # Ensure correct compilers are used
    reinplace "s| cc\$| ${configure.cc}|" \
        ${worksrcpath}/specs/macx-g++
    reinplace "s| c++\$| ${configure.cxx}|" \
        ${worksrcpath}/specs/macx-g++
}

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}"
}

# By default, everything gets installed in the Python Frameworks directory
configure.pre_args-delete  --prefix=${prefix}

test.run    yes
test.cmd    cd siplib && ${pybin} -c 'import sip'

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

    # Install documentation
    xinstall -m 755 -d ${destroot}${prefix}/share/doc
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} LICENSE LICENSE-GPL2 LICENSE-GPL3 NEWS README \
        ${destroot}${prefix}/share/doc/${name}

    system "${prefix}/bin/python${pyversion} ${frameworks_dir}/Python.framework/Versions/${pyversion}/lib/python${pyversion}/compileall.py ${destroot}${prefix}"
    system "${prefix}/bin/python${pyversion} -O ${frameworks_dir}/Python.framework/Versions/${pyversion}/lib/python${pyversion}/compileall.py ${destroot}${prefix}"
}

livecheck.type   regex
livecheck.url    http://www.riverbankcomputing.co.uk/software/sip/download
livecheck.regex  {sip-(\d+(?:\.\d+)*)\.}
