# $Id: Portfile 101438 2013-01-11 01:38:53Z ryandesign@macports.org $
PortSystem      1.0

name                    blt
version                 2.4z
revision                5
categories              x11
license                 MIT
maintainers             markd
description             BLT is an extension to the Tk toolkit, adding new widgets, \
			geometry managers, and miscellaneous commands.
long_description        ${description}
  
homepage                http://blt.sourceforge.net/
platforms               darwin

master_sites            sourceforge
distname		BLT${version}
worksrcdir		blt${version}
checksums               md5 aa2ed73080f3005d9c2a3b5e57ab1eff

depends_build           port:xorg-libX11 \
			port:tcl \
			port:tk

use_parallel_build      no

configure.optflags      -O3
configure.cflags-append -fno-common -DUSE_INTERP_RESULT

configure.args		--exec_prefix=${prefix} \
			--bindir=${prefix}/bin \
			--includedir=${prefix}/include \
			--libdir=${prefix}/lib \
                        --mandir=${prefix}/share/man \
			--with-tcllibs=${prefix}/lib \
			--with-tklibs=${prefix}/lib \
			--with-tclincls=${prefix}/include \
			--with-tkincls=${prefix}/include \
                        --with-tcl=${prefix} \
                        --with-tk=${prefix}

patchfiles		patch-configure \
			patch-Makefile.in \
			patch-library-Makefile.in \
			patch-src-Makefile.in \
			patch-src-shared-Makefile.in \
			patch-library-pkgIndex.tcl.in \
			patch-demos-Makefile.in \
			blt-2.4z-tcl8.5-fix.patch \
			blt2.4z-noexactversion.patch \
                        blt-x86_64.patch \
                        patch-tk-8.6 \
                        patch-man-Makefile.in

post-patch {
        reinplace "s|__DESTROOT__|${destroot}|g" \
                ${worksrcpath}/Makefile.in \
		${worksrcpath}/src/Makefile.in \
		${worksrcpath}/src/shared/Makefile.in \
                        ${worksrcpath}/demos/Makefile.in \
                        ${worksrcpath}/library/Makefile.in \
                        ${worksrcpath}/man/Makefile.in

	eval reinplace "s|../src/bltwish|${prefix}/bin/bltwish|g" \
                [glob ${worksrcpath}/demos/*.tcl] \
		[glob ${worksrcpath}/demos/scripts/*.tcl]
}

post-destroot {
	system "cd ${destroot}${prefix}/lib && ln -sf libBLT.2.4.dylib libBLT.2.dylib"
	system "cd ${destroot}${prefix}/lib && ln -sf libBLT.2.4.dylib libBLT.dylib"
	system "cd ${destroot}${prefix}/lib && ln -sf libBLTlite.2.4.dylib libBLTlite.2.dylib"
	system "cd ${destroot}${prefix}/lib && ln -sf libBLTlite.2.4.dylib libBLTlite.dylib"
    
    # These manpages conflict with those installed by tk.
    # blt's busy.n and tk's busy.n appear to describe the same function so I don't mind deleting blt's.
    delete ${destroot}${prefix}/share/man/mann/busy.n
    # blt's bitmap.n and tk's bitmap.n don't appear to be related at all so I'm keeping and renaming blt's.
    move ${destroot}${prefix}/share/man/mann/bitmap.n ${destroot}${prefix}/share/man/mann/blt-bitmap.n
}

pre-activate {
    # blt 2.4z_4 and earlier installed some items directly to ${prefix}; remove them if found.
    # To be removed after January 2014.
    foreach file {
        lib/blt2.4/bltCanvEps.pro
        lib/blt2.4/bltGraph.pro
        lib/blt2.4/dnd.tcl
        lib/blt2.4/dragdrop.tcl
        lib/blt2.4/graph.tcl
        lib/blt2.4/hierbox.tcl
        lib/blt2.4/pkgIndex.tcl
        lib/blt2.4/tabnotebook.tcl
        lib/blt2.4/tabset.tcl
        lib/blt2.4/tclIndex
        lib/blt2.4/treeview.tcl
        lib/blt2.4/treeview.xbm
        lib/blt2.4/treeview_m.xbm
        lib/blt2.4/dd_protocols/dd-color.tcl
        lib/blt2.4/dd_protocols/dd-file.tcl
        lib/blt2.4/dd_protocols/dd-number.tcl
        lib/blt2.4/dd_protocols/dd-text.tcl
        lib/blt2.4/dd_protocols/tclIndex
        man/man3/Blt_Tree.3
        man/man3/Blt_TreeCreate.3
        man/man3/Blt_TreeCreateNode.3
        man/man3/Blt_TreeDeleteNode.3
        man/man3/Blt_TreeExists.3
        man/man3/Blt_TreeGetNode.3
        man/man3/Blt_TreeGetToken.3
        man/man3/Blt_TreeName.3
        man/man3/Blt_TreeNodeId.3
        man/man3/Blt_TreeReleaseToken.3
        man/mann/BLT.n
        man/mann/barchart.n
        man/mann/beep.n
        man/mann/bgexec.n
        man/mann/bitmap.n
        man/mann/bltdebug.n
        man/mann/busy.n
        man/mann/container.n
        man/mann/cutbuffer.n
        man/mann/dragdrop.n
        man/mann/eps.n
        man/mann/graph.n
        man/mann/hierbox.n
        man/mann/hiertable.n
        man/mann/htext.n
        man/mann/spline.n
        man/mann/stripchart.n
        man/mann/table.n
        man/mann/tabset.n
        man/mann/tile.n
        man/mann/tree.n
        man/mann/treeview.n
        man/mann/vector.n
        man/mann/watch.n
        man/mann/winop.n
    } {
        set filepath ${prefix}/${file}
        if {[file exists ${filepath}] && [registry_file_registered ${filepath}] == "0"} {
            if {[catch {delete ${filepath}}]} {
                ui_warn "Cannot delete ${filepath}; please remove it manually"
            }
        }
    }
}
