# Created by: stas
# $FreeBSD: graphics/rawtherapee/Makefile 334119 2013-11-17 20:07:07Z mandree $

PORTNAME=	rawtherapee
PORTVERSION=	4.0.11
PORTREVISION=	2
CATEGORIES=	graphics
MASTER_SITES=	GOOGLE_CODE

MAINTAINER=	mandree@FreeBSD.org
COMMENT=	A powerful RAW image processing application

LICENSE=	GPLv3

LIB_DEPENDS=	libgtkmm-2.4.so:${PORTSDIR}/x11-toolkits/gtkmm24 \
		libiptcdata.so:${PORTSDIR}/graphics/libiptcdata \
		libjpeg.so:${PORTSDIR}/graphics/jpeg \
		liblcms2.so:${PORTSDIR}/graphics/lcms2 \
		libpng15.so:${PORTSDIR}/graphics/png \
		libtiff.so:${PORTSDIR}/graphics/tiff \
		libsigc-2.0.so:${PORTSDIR}/devel/libsigc++20 \
		libfftw3.so:${PORTSDIR}/math/fftw3 \
		libfftw3f.so:${PORTSDIR}/math/fftw3-float \
		libcanberra-gtk3.so:${PORTSDIR}/audio/libcanberra-gtk3

USES=		cmake:outsource pkgconfig compiler:features desktop-file-utils
USE_XZ=		yes
USE_GNOME=	gtk20 glib20
USE_LDCONFIG=	yes
CFLAGS+=	-I${LOCALBASE}/include -fPIC ${PTHREAD_CFLAGS}
CXXFLAGS+=	-I${LOCALBASE}/include -fPIC ${PTHREAD_CFLAGS}
LDFLAGS+=	-L${LOCALBASE}/lib ${PTHREAD_LIBS}
CMAKE_ENV=	CFLAGS="${CFLAGS}" \
		LDFLAGS="${LDFLAGS}"
CMAKE_ARGS+=	-DDOCDIR="${DOCSDIR}" \
		-DCREDITSDIR="${DOCSDIR}" \
		-DLICENCEDIR="${DOCSDIR}" \
		-DDESKTOPDIR="${DESKTOPDIR}" \
		-DDATADIR="${DATADIR}" \
		-DCMAKE_C_FLAGS="${CFLAGS}" \
		-DCMAKE_CXX_FLAGS="${CXXFLAGS}"
SUB_FILES=	rawtherapee
SUB_LIST=	RTDIR="${RTDIR}"
INSTALLS_ICONS=	yes

RTDIR=		${PREFIX}/libdata/${PORTNAME}

OPTIONS_DEFINE=		OPTIMIZED_CFLAGS OPENMP
OPTIONS_DEFAULT=	OPTIMIZED_CFLAGS OPENMP
OPENMP_DESC=		Enable multicore processing using OpenMP

.include <bsd.port.options.mk>

.if ${OSVERSION} < 1000024
USE_GCC=	yes
.endif

.include <bsd.port.pre.mk>

post-patch:
	@${REINPLACE_CMD} -e 's#<auto_ptr.h>#<memory>#g' \
		${WRKSRC}/rtgui/darkframe.h ${WRKSRC}/rtgui/flatfield.h \
		${WRKSRC}/rtgui/icmpanel.h
	@${REINPLACE_CMD} -e 's#DESTINATION "$${CMAKE_INSTALL_PREFIX}/share/man/man1"#DESTINATION "${MANPREFIX}/man/man1/"#' \
		${WRKSRC}/CMakeLists.txt

.if ${COMPILER_TYPE} != gcc
pre-build:
	# must compile ipsharpen.cc with lower optimization else the compilation time is excessive
	# this is clang-specific and does not affect GCC.
	${REINPLACE_CMD} -e 's,-o CMakeFiles/rtengine.dir/ipsharpen.cc.o,-O1 &,' \
		${CONFIGURE_WRKSRC}/rtengine/CMakeFiles/rtengine.dir/build.make
.if ${PORT_OPTIONS:MOPENMP}
	@${ECHO_CMD} "WARNING: ignoring OpenMP option, not supported on clang." ; sleep 5
.endif
.endif

.if ${COMPILER_TYPE} == clang
CFLAGS+=	-Qunused-arguments
CXXFLAGS+=	-Qunused-arguments
.endif

# paranoia: run rawtherapee --help to be sure it finds all its
# shared libraries (this hinges on proper RPATH setting and propagation)
post-install:
	${SETENV} HOME=/dev/null ${STAGEDIR}${PREFIX}/bin/rawtherapee --help 2>&1 \
	| ${EGREP} -q "RawTherapee, version ${PKGVERSION:C/_.*//:C/,.*//}"


.if ${ARCH} == "amd64" || ${ARCH} == "i386"
.if ${PORT_OPTIONS:MOPTIMIZED_CFLAGS}
CFLAGS+=	-O3 -ffast-math -fexpensive-optimizations \
		-funroll-loops -msse
CXXFLAGS+=	-O3 -ffast-math -fexpensive-optimizations \
		-funroll-loops -msse
.endif
.endif

_OpenMP_args=	-DOPTION_OMP:BOOL=OFF
.if ${PORT_OPTIONS:MOPENMP} && ${COMPILER_TYPE} == gcc
_OpenMP_args=	-DOPTION_OMP:BOOL=ON
.endif

CMAKE_ARGS+=	${_OpenMP_args}

.include <bsd.port.post.mk>
