aboutsummaryrefslogtreecommitdiff
path: root/graphics/rawtherapee/Makefile
blob: bb85be8aaa568f18ac5081f50d90f400fe62d4a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
PORTNAME=	rawtherapee
PORTVERSION=	5.10
PORTREVISION=	0
CATEGORIES=	graphics
MASTER_SITES=	https://rawtherapee.com/shared/source/ \
		LOCAL/mandree/

MAINTAINER=	mandree@FreeBSD.org
COMMENT=	Powerful RAW image processing application
WWW=		https://www.rawtherapee.com/

LICENSE=	GPLv3

LIB_DEPENDS=	\
		libcanberra-gtk3.so:audio/libcanberra-gtk3 \
		libexiv2.so:graphics/exiv2 \
		libexpat.so:textproc/expat2 \
		libfftw3.so:math/fftw3 \
		libfftw3f.so:math/fftw3-float \
		libfontconfig.so:x11-fonts/fontconfig \
		libfreetype.so:print/freetype2 \
		libiptcdata.so:graphics/libiptcdata \
		liblcms2.so:graphics/lcms2 \
		liblensfun.so:graphics/lensfun \
		libpng.so:graphics/png \
		libsigc-2.0.so:devel/libsigc++20 \
		libtiff.so:graphics/tiff

# We cannot use gcc-c++11-lib as of 2024-02-23 because
# Uses/compiler.mk would use the default compiler instead
# as though USE_GCC=yes had been set.
USES=		cmake desktop-file-utils compiler:c++11-lib gnome \
		jpeg localbase:ldflags pkgconfig tar:xz

# Older clang versions (for instance clang 9.0, as of 2019-09-29),
# were known to miscompile RawTherapee, causing SIGSEGV or SIBGUS.
# As of 2024-02, GCC-12.3 compiled RawTherapee appears to be
# up to twice as fast as clang-16.0 compiled code.
# So we shall stick to a modern GCC for now.
#
# Unfortunately, we can't even upgrade to GCC 13 because that fails
# with our header files, see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273682
USE_GCC=	12

USE_GNOME=	gtkmm30 librsvg2

_LTO_FLAGS=	-flto=${MAKE_JOBS_NUMBER}
# gcc needs -flto=${MAKE_JOBS_NUMBER} for parallel link (fixed in GCC 10?)
#     and does not understand -flto=thin
#
# llvm/clang needs -flto=thin and will automatically parallelize the link

# Fix <https://bugs.freebsd.org/251041>:
# 11.x has binutils that don't accept a --plugin option,
# and gcc-ar9 appears to grab those, so make sure that USE_BINUTILS
# override those in /usr/bin which usually is first in the PATH,
# before ${LOCALBASE}/bin.
# (For some reason, poudriere does not trigger this.)
BINARY_ALIAS+=	ar=${AR} ranlib=${RANLIB}
#
_AR=		${CC:S/gcc/gcc-ar/}
_RANLIB=	${CC:S/gcc/gcc-ranlib/}
CMAKE_ARGS+=	-DDOCDIR="${DOCSDIR}" \
		-DCREDITSDIR="${DOCSDIR}" \
		-DLICENCEDIR="${DOCSDIR}" \
		-DDESKTOPDIR="${DESKTOPDIR}" \
		-DDATADIR="${DATADIR}" \
		-DCACHE_NAME_SUFFIX="" \
		-Wno-dev \
		-DCMAKE_AR:FILEPATH=${_AR} \
		-DCMAKE_RANLIB:FILEPATH=${_RANLIB} \
		-DCMAKE_POLICY_DEFAULT_CMP0056:STRING=NEW
# 3.4.x: CMAKE_EXE_LINKER_FLAGS is not passed to TRY_COMPILE by default
# any more. The CMP0056 policy must be explicitly set to NEW to ensure
# linker flags are passed. Else -lomp is not found with clang.
# See: https://cmake.org/cmake/help/v3.4/policy/CMP0056.html
CFLAGS+=	-I${LOCALBASE}/include -fPIC ${_OPT_FLAGS}
LDFLAGS+=	-Wl,--as-needed -lpthread ${_OPT_FLAGS}

.if defined(PACKAGE_BUILDING) && empty(CFLAGS:M-march*) && (${ARCH} == i386 || ${ARCH} == amd64 || ${ARCH} == aarch64)
# this gets translated to -mtune=generic, see ${WRKSRC}/ProcessorTargets.cmake
# and as of GCC 8.3, it appears that among FreeBSD's supported architectures,
# only the three listed above support this GCC option.
CMAKE_ARGS+=	-DPROC_TARGET_NUMBER="1"
.endif

# For gcc-based builds, rawtherapee's cmake ends up with GCC's absolute path
# in the CC/CXX variables, effectively disabling ccache. Wrap compiler in ccache explicitly.
# CCACHE_ENABLED does not get enabled soon enough as of dceadb6b0011 in February 2024,
# so we need to re-do what bsd.ccache.mk does.
# See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277204
# NB: When changing this, make sure that the compiler is still wrapped by ccache!
.if "${WITH_CCACHE_BUILD}" == "yes" && !defined(NO_CCACHE)
CMAKE_ARGS+=	-DCMAKE_C_COMPILER_LAUNCHER=${CCACHE_BIN} \
		-DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE_BIN}
.endif

OPTIONS_DEFINE=		DOCS NATIVE LTO
OPTIONS_DEFINE_amd64=	OPENMP
OPTIONS_DEFINE_i386=	OPENMP
OPTIONS_DEFAULT=	OPENMP LTO
NATIVE_DESC=		Use -march=native (avoid for generic packages!)
OPENMP_DESC=		Enable OpenMP parallel processing (i386/amd64 only)

LTO_CFLAGS=		${_LTO_FLAGS}
LTO_LDFLAGS=		${_LTO_FLAGS}
NATIVE_CMAKE_ON=	-DPROC_TARGET_NUMBER="2"
OPENMP_CMAKE_BOOL=	OPTION_OMP
OPENMP_LDFLAGS=		-lm -lomp

.include <bsd.port.options.mk>

# -------------------------------------------------------------------

.if (${OPSYS} == FreeBSD) && (${OSVERSION} >= 1500000)
# don't waste everybody's time with Tier-2 and moving targets.
ONLY_FOR_ARCHS=	amd64
ONLY_FOR_ARCHS_REASON=only amd64 is supported on non-released FreeBSD versions
.endif

.if defined(WITH_DEBUG)
STRIP=
CMAKE_BUILD_TYPE=	None	# Arch Linux packaging trick to avoid cmake overriding our flags
_OPT_FLAGS=	-ggdb3 -Og	# -Og is GCC-specific, use -O1 for clang
.else
_OPT_FLAGS=	-O3 -funroll-loops
.endif

# x86_64/amd64 includes -msse2 by default
.if ${ARCH} == i386
# -mstackrealign: workaround for values passed on the stack that cause SIGBUS on SSE2
# -msse2: SSE2 has been around since the year 2003 latest
_OPT_FLAGS+=	-msse2
_OPT_FLAGS+=	-mstackrealign
.endif

# -------------------------------------------------------------------

.include <bsd.port.pre.mk>

.if ${COMPILER_FEATURES:Mlibc++}
CXXFLAGS+=	-stdlib=libc++
.endif

post-patch:
	@${REINPLACE_CMD} -e 's#DESTINATION "$${CMAKE_INSTALL_PREFIX}/share/man/man1"#DESTINATION "${PREFIX}/share/man/man1/"#' \
		${WRKSRC}/CMakeLists.txt

TESTIMAGES=	${MASTERDIR}/testimages

# paranoia: run rawtherapee to be sure it finds all its
# shared libraries (this hinges on proper RPATH setting and propagation)
#
# _check_version strips stuffixes from distnames etc. that do not appear
# in the program's version numbering
_check_version=	${PKGVERSION:C/.g0//}
_env=		LANG= LC_ALL=C LANGUAGE= DISPLAY= HOME="$$TMP" RT_SETTINGS=${WRKDIR}/rt-config RT_CACHE="$$TMP/rtcache"
post-install:
	@${RM} -f ${WRKDIR}/selftest.exitcodes ${WRKDIR}/selftest.expect
	@(set -e; _mp=$$(/bin/df -P ${STAGEDIR}${PREFIX}/bin/rawtherapee | ${AWK} 'NR==2{print $$NF}') ; \
	_fsflags=$$(${MOUNT} -p | ${AWK} "{ if (\$$2 == \"$$_mp\") { print \$$4 } }") ; \
	case $$_fsflags in *noexec*) \
		${TOUCH} ${WRKDIR}/selftest.expect ${WRKDIR}/selftest.exitcodes ; \
		${ECHO_CMD} "===> Skipping smoke tests, STAGEDIR=${STAGEDIR} is on a noexec file system" ; \
		exit 0 ;; \
	esac ; \
	${ECHO_MSG} "===> Running smoke tests" ; \
	${RM} -rf ${WRKDIR}/rt-config ; \
	${MKDIR} ${WRKDIR}/rt-config ${WRKDIR}/rt-config/dcpprofiles ${WRKDIR}/rt-config/profiles ; \
	${CP} ${WRKSRC}/rtengine/camconst.json ${WRKDIR}/rt-config ; \
	${CP} ${WRKSRC}/rtdata/options/options.lin ${WRKDIR}/rt-config/options ; \
	(cd ${WRKSRC}/rtdata/ && ${COPYTREE_SHARE} "profiles dcpprofiles" ${WRKDIR}/rt-config ) ; \
	(set -x ; TMP=$$(${MKTEMP} -d -t ${PORTNAME}) && trap "rc=$$? ; ${RM} -rf \"$$TMP\" ; exit \$$rc" 0 && \
		( set +e ; ${SETENV} ${_env} ${STAGEDIR}${PREFIX}/bin/rawtherapee -v ; \
		    ${ECHO_CMD} $$? >&3 ) 3>&3 | ${EGREP} -q "RawTherapee, version ${_check_version:C/_.*//:C/,.*//}|cannot open display:" && \
		( set +e ; ${SETENV} ${_env} ${STAGEDIR}${PREFIX}/bin/rawtherapee-cli | dd ibs=8k ; \
		    ${ECHO_CMD} $$? >&3 ) 3>&3 | ${EGREP} -q "RawTherapee, version ${_check_version:C/_.*//:C/,.*//}" && \
		expect=$$'0\n0\n' && \
		onefile=$$(ls "${TESTIMAGES}"/* | head -1) && \
		if test -d "${TESTIMAGES}" && test -n "$$onefile" -a -r "$$onefile" ; then \
		  expect=$$'0\n0\n0\n0\n0\n' && \
		  ( set +e ; \
		  /usr/bin/time ${SETENV} ${_env} ${STAGEDIR}${PREFIX}/bin/rawtherapee-cli \
			-o "$$TMP" -q -f -c ${TESTIMAGES} ; ${ECHO_CMD} $$? >&3 ; \
		  /usr/bin/time ${SETENV} ${_env} ${STAGEDIR}${PREFIX}/bin/rawtherapee-cli \
			-o "$$TMP" -q -s -Y -c ${TESTIMAGES} ; ${ECHO_CMD} $$? >&3 ; \
		  /usr/bin/time ${SETENV} ${_env} ${STAGEDIR}${PREFIX}/bin/rawtherapee-cli \
			-o "$$TMP" -q -s -Y -tz -c ${TESTIMAGES} ; ${ECHO_CMD} $$? >&3 ) 3>&3 ; \
		fi ; \
		ls -Rlbai "${TESTIMAGES}" "$${TMP}" || :; \
	${PRINTF} "%s" "$$expect" >&4 ) ) 3>${WRKDIR}/selftest.exitcodes 4>${WRKDIR}/selftest.expect  ; \
	${HEAD} ${WRKDIR}/selftest.exitcodes ${WRKDIR}/selftest.expect ; \
	cmp ${WRKDIR}/selftest.expect ${WRKDIR}/selftest.exitcodes \
	|| { ${ECHO_CMD} '===> !!! SELF-TEST FAILED !!! <===' ; exit 1 ; }

.include <bsd.port.post.mk>