# $FreeBSD: branches/RELEASE_8_4_0/editors/libreoffice/Makefile 314805 2013-03-21 05:27:16Z mezz $

.include "${.CURDIR}/Makefile.common"

PORTREVISION=	1
MASTER_SITES+=	http://dev-www.libreoffice.org/src/:src \
		http://dev-www.libreoffice.org/extern/:ext
MASTER_SITE_SUBDIR=	src/${PORTVERSION}/

COMMENT=	Full integrated office productivity suite

BUILD_DEPENDS=	p5-Archive-Zip>=0:${PORTSDIR}/archivers/p5-Archive-Zip \
		unzip:${PORTSDIR}/archivers/unzip \
		zip:${PORTSDIR}/archivers/zip \
		${LOCALBASE}/lib/libboost_regex.a:${PORTSDIR}/devel/boost-libs \
		${LOCALBASE}/lib/libcppunit.so:${PORTSDIR}/devel/cppunit \
		dmake:${PORTSDIR}/devel/dmake \
		${LOCALBASE}/bin/gperf:${PORTSDIR}/devel/gperf \
		${LOCALBASE}/include/mdds/global.hpp:${PORTSDIR}/devel/mdds \
		gpatch:${PORTSDIR}/devel/patch \
		ucpp:${PORTSDIR}/devel/ucpp \
		vigra-config:${PORTSDIR}/graphics/vigra \
		bash:${PORTSDIR}/shells/bash \
		gsed:${PORTSDIR}/textproc/gsed

LIB_DEPENDS=	icutu:${PORTSDIR}/devel/icu \
		langtag:${PORTSDIR}/devel/liblangtag \
		orcus-0.4:${PORTSDIR}/devel/liborcus \
		curl.6:${PORTSDIR}/ftp/curl \
		cairo.2:${PORTSDIR}/graphics/cairo \
		graphite2:${PORTSDIR}/graphics/graphite2 \
		jpeg.11:${PORTSDIR}/graphics/jpeg \
		cdr:${PORTSDIR}/graphics/libcdr \
		lcms2:${PORTSDIR}/graphics/lcms2 \
		wpg-0.2.2:${PORTSDIR}/graphics/libwpg \
		png15:${PORTSDIR}/graphics/png \
		poppler:${PORTSDIR}/graphics/poppler \
		lpsolve55:${PORTSDIR}/math/lp_solve \
		cmis-0.3:${PORTSDIR}/net/libcmis \
		mspub-0.0:${PORTSDIR}/print/libmspub \
		nss3.1:${PORTSDIR}/security/nss \
		clucene-core:${PORTSDIR}/textproc/clucene \
		expat.6:${PORTSDIR}/textproc/expat2 \
		hunspell-1.3.0:${PORTSDIR}/textproc/hunspell \
		hyphen.2:${PORTSDIR}/textproc/hyphen \
		exttextcat-2.0.0:${PORTSDIR}/textproc/libexttextcat \
		visio-0.0.0:${PORTSDIR}/textproc/libvisio \
		xml2.5:${PORTSDIR}/textproc/libxml2 \
		xslt.2:${PORTSDIR}/textproc/libxslt \
		wpd-0.9.9:${PORTSDIR}/textproc/libwpd \
		wps-0.2.2:${PORTSDIR}/textproc/libwps \
		mythes-1.2.0:${PORTSDIR}/textproc/mythes \
		rdf.0:${PORTSDIR}/textproc/redland

RUN_DEPENDS=	${LOCALBASE}/lib/X11/fonts/dejavu/DejaVuSans.ttf:${PORTSDIR}/x11-fonts/dejavu \
		${LOCALBASE}/lib/X11/fonts/GentiumBasic/GenBasI.ttf:${PORTSDIR}/x11-fonts/gentium-basic \
		${LOCALBASE}/lib/X11/fonts/Liberation/LiberationMono-Bold.ttf:${PORTSDIR}/x11-fonts/liberation-fonts-ttf \
		${LOCALBASE}/lib/X11/fonts/LinLibertineG/LinLibertine_DR_G.ttf:${PORTSDIR}/x11-fonts/linuxlibertine-g

CONFLICTS_INSTALL=	libreoffice-legacy-[0-9]*

GNU_CONFIGURE=	yes
MAKE_JOBS_UNSAFE=	yes
USE_AUTOTOOLS=	autoconf aclocal
USE_GL=		gl glu
USE_GMAKE=	yes
USE_OPENLDAP=	yes
USE_PERL5_BUILD=	yes
USE_PKGCONFIG=	build
USE_PYTHON=	yes
USE_QT4=	# empty but required
USE_XORG=	xaw xrandr
USE_XZ=		yes
USES=		bison
WANT_GNOME=	yes

DISTFILES+=	${PORTNAME}-${LOVERSION}${EXTRACT_SUFX}
DISTFILES+=	${PORTNAME}-help-${LOVERSION}${EXTRACT_SUFX}

EXTRACT_ONLY:=	${DISTFILES}

DISTFILES+=	1f24ab1d39f4a51faf22244c94a6203f-xmlsec1-1.2.14.tar.gz:src

DIST_SUBDIR=	libreoffice
LODESTDIR=	${WRKDIR}/loinstall
WRKSRC=		${WRKDIR}/${PORTNAME}-${LOVERSION}

.if defined(DISABLE_MAKE_JOBS)
MAKE_JOBS_NUMBER=	1
.else
MAKE_JOBS_NUMBER?=	`${SYSCTL} -n kern.smp.cpus`
.endif

CONFIGURE_ENV=		DMAKE=${LOCALBASE}/bin/dmake \
			GPERF=${LOCALBASE}/bin/gperf \
			PYTHON_CFLAGS="`${PYTHON_VERSION}-config --cflags`" \
			PYTHON_LIBS="`${PYTHON_VERSION}-config --libs`"

CONFIGURE_ARGS+=	--disable-dependency-tracking \
			--disable-fetch-external \
			--disable-online-update \
			--exec-prefix=${PREFIX} \
			--with-build-version="FreeBSD ports ${PKGVERSION}" \
			--with-external-tar=${DISTDIR}/${DIST_SUBDIR} \
			--with-gnu-patch=${LOCALBASE}/bin/gpatch \
			--with-os-version=${OSVERSION} \
			--with-parallelism=${MAKE_JOBS_NUMBER} \
			--with-solver-and-workdir-root=${TMPDIR}/lobuild \
			--with-unix-wrapper="libreoffice" \
			--with-vendor="FreeBSD ports ${PKGVERSION}"

CONFIGURE_ARGS+=	--disable-epm \
			--disable-gnome-vfs \
			--disable-gstreamer \
			--disable-kde \
			--disable-kdeab \
			--disable-linkoo \
			--disable-zenity \
			--enable-cairo-canvas \
			--enable-graphite \
			--enable-python=system \
			--with-alloc=system \
			--with-external-dict-dir=${LOCALBASE}/share/hunspell \
			--with-external-hyph-dir=${LOCALBASE}/share/hyphen \
			--with-external-thes-dir=${LOCALBASE}/share/mythes \
			--with-system-altlinuxhyph \
			--with-system-boost \
			--with-system-cairo \
			--with-system-clucene \
			--with-system-cppunit \
			--with-system-curl \
			--with-system-dicts \
			--with-system-expat \
			--with-system-graphite \
			--with-system-hunspell \
			--with-system-icu \
			--with-system-jpeg \
			--with-system-lcms2 \
			--with-system-libcdr \
			--with-system-libcmis \
			--with-system-libexttextcat \
			--with-system-liblangtag \
			--with-system-libmspub \
			--with-system-libpng \
			--with-system-libvisio \
			--with-system-libwpd \
			--with-system-libwpg \
			--with-system-libwps \
			--with-system-libxml \
			--with-system-lpsolve \
			--with-system-mdds \
			--with-system-mesa-headers \
			--with-system-mythes \
			--with-system-nss \
			--with-system-openldap \
			--with-system-openssl \
			--with-system-orcus \
			--with-system-poppler \
			--with-system-redland \
			--with-system-stdlibs \
			--with-system-ucpp \
			--with-system-vigra \
			--with-system-zlib \
			--without-afms \
			--without-fonts \
			--without-myspell-dicts \
			--without-system-mozilla

MAN1=	libreoffice.1 \
	lobase.1 \
	localc.1 \
	lodraw.1 \
	loffice.1 \
	lofromtemplate.1 \
	loimpress.1 \
	lomath.1 \
	loweb.1 \
	lowriter.1 \
	unopkg.1

MANCOMPRESSED=	yes

OPTIONS_DEFINE=	CUPS DEBUG GNOME GTK2 GTK3 JAVA KDE4 MERGELIBS MMEDIA PGSQL \
		SDK SYSTRAY TEST WEBDAV
OPTIONS_DEFAULT=CUPS GTK2

JAVA_DESC=	Add java support (XML Filters, macros)
MERGELIBS_DESC=	Enable linking of big merged library
MMEDIA_DESC=	Enable multimedia backend for impress
PGSQL_DESC=	Build with PostgreSQL-SDBC driver
SDK_DESC=	Build with SDK
SYSTRAY_DESC=	Enable systemtray quickstarter
TEST_DESC=	Run all regression tests
WEBDAV_DESC=	Enable webdav protocol

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MCUPS}
LIB_DEPENDS+=		cups:${PORTSDIR}/print/cups-client
CONFIGURE_ARGS+=	--enable-cups --without-ppds
.else
CONFIGURE_ARGS+=	--disable-cups
.endif

.if ${PORT_OPTIONS:MDEBUG}
IGNORE=			known as broken
CONFIGURE_ARGS+=	--enable-debug \
			--enable-dbgutil \
			--enable-verbose \
			--enable-crashdump
.else
CONFIGURE_ARGS+=	--enable-release-build
.endif

.if ${PORT_OPTIONS:MGNOME}
LIB_DEPENDS+=		dbus-glib-1:${PORTSDIR}/devel/dbus-glib
USE_GNOME+=		gconf2
CONFIGURE_ARGS+=	--enable-dbus --enable-gconf --enable-gio \
			--enable-lockdown
.else
CONFIGURE_ARGS+=	--disable-dbus --disable-gconf --disable-gio \
			--disable-lockdown
.endif

.if ${PORT_OPTIONS:MGTK2} || ${PORT_OPTIONS:MGNOME}
USE_GNOME+=	gtk20 desktopfileutils
INSTALLS_ICONS=	yes
CONFIGURE_ARGS+=	--enable-gtk
.else
CONFIGURE_ARGS+=	--disable-gtk
.endif

.if ${PORT_OPTIONS:MGTK3}
BROKEN=		requires GTK+ 3.2 and later
USE_GNOME+=	gtk30 desktopfileutils
INSTALLS_ICONS=	yes
CONFIGURE_ARGS+=	--enable-gtk3
.else
CONFIGURE_ARGS+=	--disable-gtk3
.endif

.if ${PORT_OPTIONS:MJAVA}
# XXX jni.h from GNU classpath causes ABI conflicts.
CONFLICTS_BUILD=	classpath-[0-9]*
#additionnal distfiles needed for java
DISTFILES+=	17410483b5b5f267aa18b7e00b65e6e0-hsqldb_1_8_0.zip:src \
		2a177023f9ea8ec8bd00837605c5df1b-jakarta-tomcat-5.0.30-src.tar.gz:src \
		2ae988b339daec234019a7066f96733e-commons-lang-2.3-src.tar.gz:src \
		2c9b0f83ed5890af02c0df1c1776f39b-commons-httpclient-3.1-src.tar.gz:src \
		3404ab6b1792ae5f16bbd603bd1e1d03-libformula-1.1.7.zip:src \
		35c94d2df8893241173de1d16b6034c0-swingExSrc.zip:src \
		3c219630e4302863a9a83d0efde889db-commons-logging-1.1.1-src.tar.gz:src \
		3bdf40c0d199af31923e900d082ca2dd-libfonts-1.1.6.zip:src \
		39bb3fcea1514f1369fcfc87542390fd-sacjava-1.3.zip:src \
		798b2ffdc8bcfe7bca2cf92b62caf685-rhino1_5R5.zip:src \
		8ce2fcd72becf06c41f7201d15373ed9-librepository-1.1.6.zip:src \
		97b2d4dba862397f446b217e2b623e71-libloader-1.1.6.zip:src \
		a7983f859eafb2677d7ff386a023bc40-xsltml_2.1.2.zip:src \
		ace6ab49184e329db254e454a010f56d-libxml-1.1.7.zip:src \
		af3c3acf618de6108d65fcdc92b492e1-commons-codec-1.3-src.tar.gz:src \
		ba2930200c9f019c2d93a8c88c651a0f-flow-engine-0.9.4.zip:src \
		d8bd5eed178db6e2b18eeed243f85aa8-flute-1.1.6.zip:src \
		db60e4fde8dd6d6807523deb71ee34dc-liblayout-0.2.10.zip:src \
		ea570af93c284aa9e5621cd563f54f4d-bsh-2.0b1-src.tar.gz:src \
		eeb2c7ddf0d302fba4bfc6e97eac9624-libbase-1.1.6.zip:src \
		f94d9870737518e3b597f9265f4e9803-libserializer-1.1.6.zip:src

# LibreOffice works only with Java 6 -- which may not be the default
# if you specify the JAVA_VENDOR variable
CATEGORIES+=	java
USE_JAVA=	yes
JAVA_BUILD=	yes
JAVA_VERSION=	1.6
BUILD_DEPENDS+=	ant:${PORTSDIR}/devel/apache-ant \
		${JAVAJARDIR}/junit.jar:${PORTSDIR}/java/junit

CONFIGURE_ARGS+=	--enable-ext-report-builder \
			--enable-ext-wiki-publisher \
			--enable-scripting-beanshell \
			--enable-scripting-javascript \
			--with-ant-home=${LOCALBASE}/share/java/apache-ant/ \
			--with-jdk-home=${JAVA_HOME} \
			--with-junit=${JAVAJARDIR}/junit.jar

.else
CONFIGURE_ARGS+=	--without-java
.endif

.if ${PORT_OPTIONS:MKDE4}
USE_KDE4=	kdelibs
USE_QT4+=	moc_build qmake_build
CONFIGURE_ENV+=		QT4DIR="${QT_PREFIX}" QT4LIB="${QT_LIBDIR}" QT4INC="${QT_INCDIR}" KDE4DIR="${KDE4_PREFIX}"
CONFIGURE_ARGS+=	--enable-kde4
.else
CONFIGURE_ARGS+=	--disable-kde4
.endif

.if ${PORT_OPTIONS:MMERGELIBS}
BROKEN=		mergelibs causes runtime problems
CONFIGURE_ARGS+=	--enable-mergelibs
.else
CONFIGURE_ARGS+=	--disable-mergelibs
.endif

.if ${PORT_OPTIONS:MMMEDIA}
USE_GSTREAMER=	yes
CONFIGURE_ARGS+=	--enable-gstreamer-0-10
.else
CONFIGURE_ARGS+=	--disable-gstreamer-0-10
.endif

.if ${PORT_OPTIONS:MPGSQL}
USE_PGSQL=	yes
WANT_PGSQL_VER=	90+
CONFIGURE_ARGS+=	--enable-postgresql-sdbc --with-system-postgresql
.else
CONFIGURE_ARGS+=	--disable-postgresql-sdbc \
			--without-gssapi --without-krb5
.endif

.if ${PORT_OPTIONS:MSDK}
DISTFILES+=	185d60944ea767075d27247c3162b3bc-unowinreg.dll:ext
BUILD_DEPENDS+=	doxygen:${PORTSDIR}/devel/doxygen
CONFIGURE_ARGS+=	--enable-odk --with-doxygen=${LOCALBASE}/bin/doxygen
.else
CONFIGURE_ARGS+=	--disable-odk
.endif

.if ${PORT_OPTIONS:MSYSTRAY}
CONFIGURE_ARGS+=	--enable-systray
.else
CONFIGURE_ARGS+=	--disable-systray
.endif

.if ${PORT_OPTIONS:MTEST}
CONFIGURE_ARGS+=	--enable-cve-tests
.else
EXTRA_PATCHES+=		${FILESDIR}/disable-cppunittester
CONFIGURE_ARGS+=	--disable-cve-tests
.endif

.if ${PORT_OPTIONS:MWEBDAV}
CONFIGURE_ARGS+=	--enable-neon --with-system-neon
LIB_DEPENDS+=	neon.27:${PORTSDIR}/www/neon29
.else
CONFIGURE_ARGS+=	--disable-neon
.endif

.include <bsd.port.pre.mk>

.if defined(WITH_GCC)
USE_GCC=	4.6+
CONFIGURE_ENV+=	CXXCPP="${CPP}"
.else
.if exists(/usr/bin/clang) && ${OSVERSION} > 901502
CC=		/usr/bin/clang
CPP=		/usr/bin/clang-cpp
CXX=		/usr/bin/clang++
CONFIGURE_ENV+=	CXXCPP="${CPP}"
.else
# XXX Clang PR13308 (http://llvm.org/bugs/show_bug.cgi?id=13308)
BUILD_DEPENDS+=	clang>=3.2:${PORTSDIR}/lang/clang
CC=		${LOCALBASE}/bin/clang
CPP=		${CC} -E
CXX=		${LOCALBASE}/bin/clang++
CONFIGURE_ENV+=	CXXCPP="${CXX} -E"
.endif
.endif

.if ${OSVERSION} < 900506
CONFIGURE_ARGS+=	--with-linker-hash-style=sysv
.endif

ACLOCAL_ARGS=	-I "${WRKSRC}/m4"
CPPFLAGS=	-I${LOCALBASE}/include
LDFLAGS=	-L${LOCALBASE}/lib

MAKE_ENV+=	ENVCFLAGS="${CFLAGS}" ENVCXXFLAGS="${CXXFLAGS}"
MAKE_ENV+=	ENVLINKFLAGS="${LDFLAGS}"
MAKE_ENV+=	LANG=C LC_ALL=C
MAKE_ENV+=	SED="${LOCALBASE}/bin/gsed" USE_GMAKE=1

TMPDIR?=	/tmp

pre-configure:
	@${TOUCH} ${WRKSRC}/autogen.lastrun
	@${MKDIR} ${WRKDIR}/lobuild
	@${LN} -fs ${WRKDIR}/lobuild ${TMPDIR}

post-configure:
	@${TOUCH} ${WRKSRC}/src.downloaded

do-install:
	@cd ${WRKSRC} && ${SETENV} DESTDIR="${LODESTDIR}" \
	    ${GMAKE} distro-pack-install

post-install:
	@${RM} -f ${PLISTF} ${PLISTD}
	# It seems that the empty directories are necessary for libreoffice keep them for now
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -d lib/libreoffice -type d \
	    -empty -exec ${ECHO_CMD} "@exec ${MKDIR} %D/{}" \; >> ${PLISTD}

	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -H -s bin lib \
	    \( -type f -o -type l \) -print >> ${PLISTF}
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -d lib/libreoffice -type d \
	    -exec ${ECHO_CMD} "@dirrm {}" \; >> ${PLISTD}

	@${ECHO_CMD} etc/bash_completion.d/libreoffice.sh >> ${PLISTF}
	@${ECHO_CMD} "@dirrmtry etc/bash_completion.d" >> ${PLISTD}

.for subdir in applications icons mime mimelnk
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -H -s share/${subdir} \
	    \( -type f -o -type l \) -print >> ${PLISTF}
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -d share/${subdir} -type d \
	    -exec ${ECHO_CMD} "@dirrmtry {}" \; >> ${PLISTD}
.endfor
# do not add the subdir itself as dirrmtry
.for subdir in application-registry mime-info
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -H -s share/${subdir} \
	    \( -type f -o -type l \) -print >> ${PLISTF}
.endfor

.if ${PORT_OPTIONS:MGTK2} || ${PORT_OPTIONS:MGNOME} || ${PORT_OPTIONS:MGTK3}
	@${ECHO_CMD} "@exec ${LOCALBASE}/bin/update-desktop-database >/dev/null || ${TRUE}" >> ${TMPPLIST}
	@${ECHO_CMD} "@unexec ${LOCALBASE}/bin/update-desktop-database >/dev/null || ${TRUE}" >> ${TMPPLIST}
.endif

.if ${PORT_OPTIONS:MSDK}
.for subdir in include share share/doc share/idl
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -H -s ${subdir}/libreoffice \
	    \( -type f -o -type l \) -print >> ${PLISTF}
	@cd ${LODESTDIR}/${PREFIX} && ${FIND} -d ${subdir}/libreoffice \
	    -type d -exec echo "@dirrm {}" \; >> ${PLISTD}
.endfor
	@${ECHO_CMD} "@dirrmtry share/idl" >> ${PLISTD}
.endif

	@${SORT} -u ${PLISTF} >> ${TMPPLIST}
	@${GREP} '^@exec ' ${PLISTD} | ${SORT} -u >> ${TMPPLIST}
	@${GREP} '^@dirrm ' ${PLISTD} | ${SORT} -ru >> ${TMPPLIST}
	@${GREP} '^@dirrmtry ' ${PLISTD} | ${SORT} -ru | \
	    ${SED} -e '${PLIST_REINPLACE_DIRRMTRY}' >> ${TMPPLIST}

	@cd ${LODESTDIR}/${PREFIX} ; ${PAX} -rw . ${PREFIX}
	@${MKDIR} ${PREFIX}/etc/bash_completion.d
	@${INSTALL_SCRIPT} ${LODESTDIR}/etc/bash_completion.d/libreoffice.sh \
	    ${PREFIX}/etc/bash_completion.d

.if ${PORT_OPTIONS:MGTK2} || ${PORT_OPTIONS:MGNOME}
	@${LOCALBASE}/bin/update-desktop-database 2>/dev/null || ${TRUE}
.endif

post-clean:
	@${RM} -f ${TMPDIR}/lobuild
	@${RM} -fr ${TMPDIR}/LibreOffice ${TMPDIR}/LibreOffice_SDK

.include <bsd.port.post.mk>
