# -*- 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 92979 2012-05-12 16:06:44Z cal@macports.org $

PortSystem              1.0

name                    nxcomp
version                 3.5.0-2

categories              net
platforms               darwin
license                 GPL-2

maintainers             cal openmaintainer

description             nxcomp is the X compression library by NX
long_description        nxcomp is a library compressing X commands to be passed over network \
                        for use with x2go.

homepage                http://www.nomachine.com/
master_sites            http://code.x2go.org/releases/source/nx-libs/nxcomp/
worksrcdir              ${name}
checksums               rmd160  b537b40aedcc0eca6cfac14da8ff702857e04c28 \
                        sha256  30a51228509a083b4196e86596a6efb85b2e75e703f5d842158c9a27abb6ebc6

universal_variant       yes
supported_archs         ppc i386 x86_64

depends_lib             port:libpng \
                        port:jpeg \
                        port:zlib \
                        port:xorg-xproto

livecheck.url           ${master_sites}
livecheck.regex         ${name}-(\[0-9\]+(\\.\[0-9\]+)+(-\[0-9\]+)?)

set major_version [lindex [split ${version} .] 0]
set minor_version [join [lrange [split ${version} .] 0 1] .]
set teeny_version [lindex [split [join [lrange [split ${version} .] 0 2] .] -] 0]

configure.cxxflags-append \
                        -I${prefix}/include

post-configure {
    # the makefile would build a .so bundle, which we can't link against.
    # the following lines make the makefile build a dylib
    reinplace -E "s|LDFLAGS     =|LDFLAGS     = -dynamiclib -install_name ${prefix}/lib/libXcomp.${major_version}.dylib \
        -compatibility_version ${minor_version} -current_version ${teeny_version}|g" ${worksrcpath}/Makefile
    reinplace -E "s|\\.so(\\..*)?\$|\\1.dylib|g" ${worksrcpath}/Makefile
    reinplace -E "s|-bundle$||g" ${worksrcpath}/Makefile

    # Compiling C++ with -Wmissing-declarations generates a warning
    # There's no C source in this project anyway
    reinplace -E "s|-Wmissing-declarations||g" ${worksrcpath}/Makefile

    # Our CFLAGS, CXXFLAGS aren't used if we don't do this
    reinplace -E "s|CXXFLAGS    =|CXXFLAGS    = ${configure.cxxflags}|g" ${worksrcpath}/Makefile
    reinplace -E "s|CCFLAGS     =|CCFLAGS     = ${configure.cflags}|g"   ${worksrcpath}/Makefile

    # Won't build universal without this
    if {[variant_isset universal]} {
        reinplace -E "s|CXXFLAGS    =|CXXFLAGS    = ${configure.universal_cxxflags}|g" ${worksrcpath}/Makefile
        reinplace -E "s|CCFLAGS     =|CCFLAGS     = ${configure.universal_cflags}|g"   ${worksrcpath}/Makefile
    }
}

destroot {
    # the makefile does not provide an install target
    # install headers
    xinstall -d ${destroot}${prefix}/include/${name}
    eval xinstall -m 0644 [glob ${worksrcpath}/NX*.h] ${destroot}${prefix}/include/${name}

    # install libraries
    set libname libXcomp.${teeny_version}.dylib

    xinstall -m 0644 -W ${worksrcpath} libXcomp.a ${destroot}${prefix}/lib/libXcomp.a
    xinstall -m 0755 -W ${worksrcpath} ${libname} ${destroot}${prefix}/lib/${libname}
    ln -s ${libname} ${destroot}${prefix}/lib/libXcomp.${major_version}.dylib
    ln -s ${libname} ${destroot}${prefix}/lib/libXcomp.dylib
}

