# $Id: Portfile 91839 2012-04-11 19:00:31Z jeremyhu@macports.org $

PortSystem 1.0

name			doxygen
version			1.8.0
revision		0
categories		textproc devel
maintainers		css
license			GPL-2
description		Documentation system for several programming languages
long_description \
	It can generate an on-line documentation browser (in HTML) and/or an \
	off-line reference manual from a set of documented source files. \
	There is also support for generating output in RTF (MS-Word), \
	PostScript, hyperlinked PDF, compressed HTML, and Unix man pages. The \
	documentation is extracted directly from the sources, which makes it \
	much easier to keep the documentation consistent with the source code. \
	You can configure doxygen to extract the code structure from \
	undocumented source files. This is very useful to quickly find your \
	way in large source distributions. You can also visualize the \
	relations between the various elements by means of include dependency \
	graphs, inheritance diagrams, and collaboration diagrams, which are \
	all generated automatically.

platforms		darwin

homepage		http://www.doxygen.org/
master_sites		http://ftp.stack.nl/pub/users/dimitri/ \
			ftp://ftp.stack.nl/pub/users/dimitri/
distfiles		${distname}.src${extract.suffix}

checksums           ${distname}.src${extract.suffix} \
                    md5     5ff66c50ca9288d9a3d695a031f6950c \
                    sha1    7f4348418dc3efefd357b32a2b5c8010211ab284 \
                    rmd160  b93293f6bbea725382e5ee10f40fd5a84f7df0ec

depends_build-append	bin:perl:perl5 bin:flex:flex bin:bison:bison
depends_lib		port:libpng path:bin/dot:graphviz port:libiconv

#patchfiles	lion.patch

patch.post_args     -p1
configure.universal_args-delete --disable-dependency-tracking

configure.pre_args	--prefix ${prefix}
configure.args		--docdir ${prefix}/share/doc --dot ${prefix}/bin/dot

post-extract {
	# Use our flex
	file delete ${worksrcpath}/src/ce_lex.cpp
	file delete ${worksrcpath}/src/code.cpp
	file delete ${worksrcpath}/src/commentcnv.cpp
	file delete ${worksrcpath}/src/commentscan.cpp
	file delete ${worksrcpath}/src/config.cpp
	file delete ${worksrcpath}/src/declinfo.cpp
	file delete ${worksrcpath}/src/defargs.cpp
	file delete ${worksrcpath}/src/doctokenizer.cpp
	file delete ${worksrcpath}/src/fortrancode.cpp
	file delete ${worksrcpath}/src/fortranscanner.cpp
	file delete ${worksrcpath}/src/pre.cpp
	file delete ${worksrcpath}/src/pycode.cpp
	file delete ${worksrcpath}/src/pyscanner.cpp
	file delete ${worksrcpath}/src/scanner.cpp
	file delete ${worksrcpath}/src/tclscanner.cpp
	file delete ${worksrcpath}/src/vhdlcode.cpp
	file delete ${worksrcpath}/src/vhdlscanner.cpp

	# Use our bison
	file delete ${worksrcpath}/src/ce_parse.cpp
	file delete ${worksrcpath}/src/ce_parse.h
	file delete ${worksrcpath}/src/vhdlparser.cpp
	file delete ${worksrcpath}/src/vhdlparser.h
}

post-patch {
	# ensure correct compilers and compiler options are used
	reinplace "/^TMAKE_CC\[\[:space:\]\]/s%=.*%= ${configure.cc} ${configure.cppflags} ${arch_flags}%" ${tmake_conf}
	reinplace "/^TMAKE_CXX\[\[:space:\]\]/s%=.*%= ${configure.cxx} ${configure.cppflags} ${arch_flags}%" ${tmake_conf}
	reinplace "/^TMAKE_LINK\[\[:space:\]\]/s%=.*%= ${configure.cxx} ${configure.ldflags} ${arch_flags}%" ${tmake_conf}
	reinplace "/^TMAKE_LINK_SHLIB\[\[:space:\]\]/s%=.*%= ${configure.cxx} ${arch_flags}%" ${tmake_conf}

	# may not be strictly necessary, but remove trailing '/' from DESTDIR
	reinplace "s|\$(DESTDIR)/|\$(DESTDIR)|g" ${worksrcpath}/Makefile.in

	# link with doxygen's libmd5, avoiding a libwww port conflict
	reinplace "s|-lmd5|../lib/libmd5.a|" ${worksrcpath}/src/doxygen.pro.in

	# do not require GNU install; BSD install suffices
	reinplace "s,-n \"`\$j/\$i --version 2>/dev/null \| grep utils`\",-x \"\$j/\$i\",g" ${worksrcpath}/configure
}

build.target		all

destroot.target		install
destroot.args		INSTALL=${prefix} \
			DOCDIR=${prefix}/share/doc/doxygen \
			MAN1DIR=share/man/man1

variant docs description {Include the doxygen PDF documentation and LaTeX} requires {latex} {
  destroot.target-append  install_docs
  build.target-append     pdf
  use_parallel_build      no
}

variant latex description {Support LaTeX/PDF doxygen output} {
  depends_build-append  bin:pdflatex:texlive \
                        bin:gs:ghostscript \
                        port:texlive-latex-extra
}

variant wizard description {Include the GUI wizard based on Qt4} {
    # use the Qt4 PortGroup, which provides a bunch of variables
    # and defines for how Qt4 was installed
    PortGroup qt4 1.0

    # tell configure to make the wizard app
    configure.args-append	--with-doxywizard

	# on Macs, qmake builds .app directories; when installing, copy
	# this directory to the correct location (via the reinplace below).
    patchfiles-append       patch-addon_doxywizard_Makefile.in.diff

    post-patch {
        # allow for universal building, if desired
        reinplace "/CONFIG/s@x86 ppc@${qt_arch_types}@" \
            ${worksrcpath}/addon/doxywizard/doxywizard.pro.in

        # give doxywizard the more mac-like name of DoxyWizard
        reinplace "/^TARGET\[\[:space:\]\]/s%=.*%= DoxyWizard%" \
            ${worksrcpath}/addon/doxywizard/doxywizard.pro.in

        # fix final install location
        reinplace "s|__APPLICATIONS_DIR__|${applications_dir}|" \
            ${worksrcpath}/addon/doxywizard/Makefile.in

        # allow DESTROOT to work
        reinplace "s|\$(INSTALL)|\$(DESTDIR)\$(INSTALL)|g" \
            ${worksrcpath}/addon/doxywizard/Makefile.in

        # use the correct QMAKE command; the other should work, but
        # this one is guaranteed to.
        reinplace "s|QMAKE=qmake|QMAKE=${qt_qmake_cmd}|g" \
            ${worksrcpath}/addon/doxywizard/Makefile.in
    }

	post-destroot {
		# allow doxywizard to be called from the command line
		ln -s ${applications_dir}/DoxyWizard.app/Contents/MacOS/DoxyWizard ${destroot}${prefix}/bin/doxywizard
	}
}

# This is a patch written by René Zaumseil that adds Tcl support to Doxygen.
variant tcl description {Add EXPERIMENTAL support for Tcl (http://wiki.tcl.tk/27011)} {
    patch_sites         sourceforge:kbskit/doxygen\+tcl
    patchfiles-append   doxygen\+tcl.patch
    checksums-append    doxygen\+tcl.patch \
                        sha1    c9276520bb386f63756def5c064c4756975e06a7 \
                        rmd160  d3ff1de4a6b75d33655ae44dbe11a60c04224419 \
}

platform darwin {
	# Specify the platform explicitly to avoid a universal build.
	global tmake_conf arch_flags

		set tmake_conf	${worksrcpath}/tmake/lib/macosx-c++/tmake.conf
		configure.args-append	--platform macosx-c++
	if { ![variant_isset universal] } {
		set arch_flags ${configure.cc_archflags}
	} else {
		set arch_flags ${configure.universal_cflags}
	}
}
