# $Id: Portfile 91766 2012-04-10 04:43:39Z jeremyhu@macports.org $

PortSystem 1.0

name			xfig
version			3.2.5b
revision		4
categories		graphics x11
license			Permissive
maintainers		nomaintainer
description		Facility for Interactive Generation of figures under X11
long_description	\
				Xfig is a menu-driven tool that allows the user to draw and \
				manipulate objects interactively in an X window.  The \
				resulting pictures can be saved, printed on PostScript \
				printers or converted to a variety of other formats (e.g. to \
				allow inclusion in LaTeX documents).
homepage		http://xfig.org/
platforms		darwin
master_sites	sourceforge:mcj
distname		${name}.${version}
distfiles		${distname}.full${extract.suffix}
checksums		md5     499b0ce103a6b353453bf7e327f9a3b9 \
				sha1    0730d7e6bc217c0de02682efb0078821512bb542 \
				rmd160  aad4cfd808c116d34218e9890a898652e4f52ab6
depends_lib		port:Xaw3d \
				port:xorg-libXi \
				port:libpng \
				port:jpeg \
				port:zlib
depends_run		port:ghostscript \
				port:transfig
use_xmkmf		yes
xmkmf.args-append	\
				-DUseSeparateConfDir=NO -DBuildHtmlManPages=NO
patchfiles		patch-Imakefile \
				patch-fig.h \
                patch-f_util.c \
				patch-w_keyboard.c\
				patch-f_readeps.c

post-extract {
	foreach d "${worksrcpath}/Doc ${worksrcpath}/Libraries" {
		fs-traverse x ${d} {
			if {[file isdirectory ${x}]} {
				file attributes ${x} -permissions 0755
			} else {
				file attributes ${x} -permissions 0644
			}
		}
	}
}

post-patch {
	reinplace "s|__PREFIX|${prefix}|g" ${worksrcpath}/Imakefile
	reinplace "s|__DESTROOT|${destroot}|g" ${worksrcpath}/Imakefile
}
destroot.target	install.all install.man
post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    eval xinstall -m 644 -W ${worksrcpath} \
        CHANGES \
        Doc/TODO \
        [glob ${worksrcpath}/Doc/FORMAT*] \
        FIGAPPS \
        README \
        ${docdir}
}

# https://trac.macports.org/ticket/25935
if {[string match "*gcc-4.2" ${configure.compiler}]} {
	# Fix font selection bug when w_fontpanel.o is compiled with optimization by gcc 4.2
	pre-build {
		system -W ${worksrcpath} "${build.cmd} CDEBUGFLAGS=-O0 w_fontpanel.o"
	}
}

# https://trac.macports.org/ticket/31504
if {${configure.compiler} == "clang"} {
    configure.compiler llvm-gcc-4.2
}

livecheck.type	regex
livecheck.regex	{>Xfig/Transfig (.*) Download</a>}
