media-gfx/imagemagick: use magick.sh wrapper in src_test
[gentoo.git] / media-gfx / imagemagick / imagemagick-6.9.10.14.ebuild
1 # Copyright 1999-2018 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 inherit eapi7-ver eutils flag-o-matic libtool perl-functions toolchain-funcs multilib
7
8 MY_P=ImageMagick-$(ver_rs 3 '-')
9
10 DESCRIPTION="A collection of tools and libraries for many image formats"
11 HOMEPAGE="https://www.imagemagick.org/"
12 SRC_URI="mirror://${PN}/${MY_P}.tar.xz"
13
14 LICENSE="imagemagick"
15 SLOT="0/${PV}"
16 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~x64-solaris ~x86-solaris"
17 IUSE="bzip2 corefonts cxx djvu fftw fontconfig fpx graphviz hdri heif jbig jpeg jpeg2k lcms lqr lzma opencl openexr openmp pango perl png postscript q32 q8 raw static-libs svg test tiff truetype webp wmf X xml zlib"
18
19 RESTRICT="perl? ( userpriv )"
20
21 RDEPEND="
22         dev-libs/libltdl:0
23         bzip2? ( app-arch/bzip2 )
24         corefonts? ( media-fonts/corefonts )
25         djvu? ( app-text/djvu )
26         fftw? ( sci-libs/fftw:3.0 )
27         fontconfig? ( media-libs/fontconfig )
28         fpx? ( >=media-libs/libfpx-1.3.0-r1 )
29         graphviz? ( media-gfx/graphviz )
30         heif? ( media-libs/libheif:= )
31         jbig? ( >=media-libs/jbigkit-2:= )
32         jpeg? ( virtual/jpeg:0 )
33         jpeg2k? ( >=media-libs/openjpeg-2.1.0:2 )
34         lcms? ( media-libs/lcms:2= )
35         lqr? ( media-libs/liblqr )
36         opencl? ( virtual/opencl )
37         openexr? ( media-libs/openexr:0= )
38         pango? ( x11-libs/pango )
39         perl? ( >=dev-lang/perl-5.8.8:0= )
40         png? ( media-libs/libpng:0= )
41         postscript? ( app-text/ghostscript-gpl )
42         raw? ( media-libs/libraw:= )
43         svg? ( gnome-base/librsvg )
44         tiff? ( media-libs/tiff:0= )
45         truetype? (
46                 media-fonts/urw-fonts
47                 >=media-libs/freetype-2
48                 )
49         webp? ( media-libs/libwebp:0= )
50         wmf? ( media-libs/libwmf )
51         X? (
52                 x11-libs/libICE
53                 x11-libs/libSM
54                 x11-libs/libXext
55                 x11-libs/libXt
56                 )
57         xml? ( dev-libs/libxml2:= )
58         lzma? ( app-arch/xz-utils )
59         zlib? ( sys-libs/zlib:= )"
60 DEPEND="${RDEPEND}
61         !media-gfx/graphicsmagick[imagemagick]
62         virtual/pkgconfig
63         X? ( x11-base/xorg-proto )"
64
65 REQUIRED_USE="corefonts? ( truetype )
66         test? ( corefonts )"
67
68 S="${WORKDIR}/${MY_P}"
69
70 src_prepare() {
71         default
72
73         # Apply hardening #664236
74         cp "${FILESDIR}"/policy-hardening.snippet "${S}" || die
75         sed -i -e '/^<policymap>$/ {
76                         r policy-hardening.snippet
77                         d
78                 }' \
79                 config/policy.xml || \
80                 die "Failed to apply hardening of policy.xml"
81         einfo "policy.xml hardened"
82
83         elibtoolize # for Darwin modules
84
85         # For testsuite, see https://bugs.gentoo.org/show_bug.cgi?id=500580#c3
86         local mesa_cards ati_cards nvidia_cards render_cards
87         shopt -s nullglob
88         ati_cards=$(echo -n /dev/ati/card* | sed 's/ /:/g')
89         if test -n "${ati_cards}"; then
90                 addpredict "${ati_cards}"
91         fi
92         mesa_cards=$(echo -n /dev/dri/card* | sed 's/ /:/g')
93         if test -n "${mesa_cards}"; then
94                 addpredict "${mesa_cards}"
95         fi
96         nvidia_cards=$(echo -n /dev/nvidia** | sed 's/ /:/g')
97         if test -n "${nvidia_cards}"; then
98                 addpredict "${nvidia_cards}"
99         fi
100         render_cards=$(echo -n /dev/dri/renderD128* | sed 's/ /:/g')
101         if test -n "${render_cards}"; then
102                 addpredict "${render_cards}"
103         fi
104         shopt -u nullglob
105         addpredict /dev/nvidiactl
106 }
107
108 src_configure() {
109         local depth=16
110         use q8 && depth=8
111         use q32 && depth=32
112
113         local openmp=disable
114         use openmp && { tc-has-openmp && openmp=enable; }
115
116         use perl && perl_check_env
117
118         [[ ${CHOST} == *-solaris* ]] && append-ldflags -lnsl -lsocket
119
120         local myeconfargs=(
121                 $(use_enable static-libs static)
122                 $(use_enable hdri)
123                 $(use_enable opencl)
124                 --with-threads
125                 --with-modules
126                 --with-quantum-depth=${depth}
127                 $(use_with cxx magick-plus-plus)
128                 $(use_with perl)
129                 --with-perl-options='INSTALLDIRS=vendor'
130                 --with-gs-font-dir="${EPREFIX}"/usr/share/fonts/urw-fonts
131                 $(use_with bzip2 bzlib)
132                 $(use_with X x)
133                 $(use_with zlib)
134                 --without-autotrace
135                 $(use_with postscript dps)
136                 $(use_with djvu)
137                 --with-dejavu-font-dir="${EPREFIX}"/usr/share/fonts/dejavu
138                 $(use_with fftw)
139                 $(use_with fpx)
140                 $(use_with fontconfig)
141                 $(use_with truetype freetype)
142                 $(use_with postscript gslib)
143                 $(use_with graphviz gvc)
144                 $(use_with heif heic)
145                 $(use_with jbig)
146                 $(use_with jpeg)
147                 $(use_with jpeg2k openjp2)
148                 $(use_with lcms)
149                 $(use_with lqr)
150                 $(use_with lzma)
151                 $(use_with openexr)
152                 $(use_with pango)
153                 $(use_with png)
154                 $(use_with raw)
155                 $(use_with svg rsvg)
156                 $(use_with tiff)
157                 $(use_with webp)
158                 $(use_with corefonts windows-font-dir "${EPREFIX}"/usr/share/fonts/corefonts)
159                 $(use_with wmf)
160                 $(use_with xml)
161                 --${openmp}-openmp
162                 --with-gcc-arch=no-automagic
163         )
164         CONFIG_SHELL=$(type -P bash) econf "${myeconfargs[@]}"
165 }
166
167 src_test() {
168         # Install default (unrestricted) policy in $HOME for test suite #664238
169         local _im_local_config_home="${HOME}/.config/ImageMagick"
170         mkdir -p "${_im_local_config_home}" || \
171                 die "Failed to create IM config dir in '${_im_local_config_home}'"
172         cp "${FILESDIR}"/policy.test.xml "${_im_local_config_home}/policy.xml" || \
173                 die "Failed to install default blank policy.xml in '${_im_local_config_home}'"
174
175         local im_command= IM_COMMANDS=()
176         IM_COMMANDS+=( "magick -version" ) # Verify that we are using version we just built
177         IM_COMMANDS+=( "magick -list policy" ) # Verify that policy.xml is used
178         IM_COMMANDS+=( "emake check" ) # Run tests
179
180         for im_command in "${IM_COMMANDS[@]}"; do
181                 "${S}"/magick.sh \
182                 ${im_command} || die
183         done
184 }
185
186 src_install() {
187         # Ensure documentation installation files and paths with each release!
188         emake \
189                 DESTDIR="${D}" \
190                 DOCUMENTATION_PATH="${EPREFIX}"/usr/share/doc/${PF}/html \
191                 install
192
193         rm -f "${ED%/}"/usr/share/doc/${PF}/html/{ChangeLog,LICENSE,NEWS.txt}
194         dodoc {AUTHORS,README}.txt ChangeLog
195
196         if use perl; then
197                 find "${ED}" -type f -name perllocal.pod -exec rm -f {} +
198                 find "${ED}" -depth -mindepth 1 -type d -empty -exec rm -rf {} +
199         fi
200
201         find "${ED}" -name '*.la' -exec sed -i -e "/^dependency_libs/s:=.*:='':" {} +
202
203         if use opencl; then
204                 cat <<-EOF > "${T}"/99${PN}
205                 SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-uvm:/dev/ati/card:/dev/dri/card:/dev/dri/renderD128"
206                 EOF
207
208                 insinto /etc/sandbox.d
209                 doins "${T}"/99${PN} #472766
210         fi
211
212         insinto /usr/share/${PN}
213         doins config/*icm
214 }
215
216 pkg_postinst() {
217         local _show_policy_xml_notice=
218
219         if [[ -z "${REPLACING_VERSIONS}" ]]; then
220                 # This is a new installation
221                 _show_policy_xml_notice=yes
222         else
223                 local v
224                 for v in ${REPLACING_VERSIONS}; do
225                         if ! ver_test "${v}" -gt "6.9.10.10-r2"; then
226                                 # This is an upgrade
227                                 _show_policy_xml_notice=yes
228
229                                 # Show this elog only once
230                                 break
231                         fi
232                 done
233         fi
234
235         if [[ -n "${_show_policy_xml_notice}" ]]; then
236                 elog "For security reasons, a policy.xml file was installed in /etc/ImageMagick-6"
237                 elog "which will prevent the usage of the following coders by default:"
238                 elog ""
239                 elog "  - PS"
240                 elog "  - PS2"
241                 elog "  - PS3"
242                 elog "  - EPS"
243                 elog "  - PDF"
244                 elog "  - XPS"
245         fi
246 }