22c4be8b581ba0036b28d0f0dcae3e5b064ac66e
[gentoo.git] / media-gfx / blender / blender-2.79b-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python3_6 )
7
8 inherit check-reqs cmake-utils xdg-utils flag-o-matic xdg-utils \
9         pax-utils python-single-r1 toolchain-funcs eapi7-ver
10
11 DESCRIPTION="3D Creation/Animation/Publishing System"
12 HOMEPAGE="https://www.blender.org"
13
14 SRC_URI="https://download.blender.org/source/${P}.tar.gz"
15
16 # Blender can have letters in the version string,
17 # so strip off the letter if it exists.
18 MY_PV="$(ver_cut 1-2)"
19
20 SLOT="0"
21 LICENSE="|| ( GPL-2 BL )"
22 KEYWORDS="amd64 ~x86"
23 IUSE="+bullet +dds +elbeem +game-engine +openexr collada color-management \
24         cuda cycles debug doc ffmpeg fftw headless jack jemalloc jpeg2k libav \
25         llvm man ndof nls openal opencl openimageio openmp opensubdiv openvdb \
26         osl player sdl sndfile test tiff valgrind"
27 RESTRICT="!test? ( test )"
28
29 REQUIRED_USE="${PYTHON_REQUIRED_USE}
30         cuda? ( cycles )
31         cycles? ( openexr tiff openimageio )
32         opencl? ( cycles )
33         osl? ( cycles llvm )
34         player? ( game-engine !headless )"
35
36 RDEPEND="${PYTHON_DEPS}
37         >=dev-libs/boost-1.62:=[nls?,threads(+)]
38         dev-libs/lzo:2
39         >=dev-python/numpy-1.10.1[${PYTHON_USEDEP}]
40         dev-python/requests[${PYTHON_USEDEP}]
41         media-libs/freetype
42         media-libs/glew:*
43         media-libs/libpng:0=
44         media-libs/libsamplerate
45         sys-libs/zlib
46         virtual/glu
47         virtual/jpeg:0=
48         virtual/libintl
49         virtual/opengl
50         collada? ( >=media-libs/opencollada-1.6.18:= )
51         color-management? ( media-libs/opencolorio )
52         cuda? ( dev-util/nvidia-cuda-toolkit:= )
53         ffmpeg? ( media-video/ffmpeg:=[x264,mp3,encode,theora,jpeg2k?] )
54         libav? ( >=media-video/libav-11.3:=[x264,mp3,encode,theora,jpeg2k?] )
55         fftw? ( sci-libs/fftw:3.0= )
56         !headless? (
57                 x11-libs/libX11
58                 x11-libs/libXi
59                 x11-libs/libXxf86vm
60         )
61         jack? ( virtual/jack )
62         jemalloc? ( dev-libs/jemalloc:= )
63         jpeg2k? ( media-libs/openjpeg:0 )
64         llvm? ( sys-devel/llvm:= )
65         ndof? (
66                 app-misc/spacenavd
67                 dev-libs/libspnav
68         )
69         nls? ( virtual/libiconv )
70         openal? ( media-libs/openal )
71         opencl? ( virtual/opencl )
72         openimageio? ( >=media-libs/openimageio-1.7.0 )
73         openexr? (
74                 >=media-libs/ilmbase-2.2.0:=
75                 >=media-libs/openexr-2.2.0:=
76         )
77         opensubdiv? ( >=media-libs/opensubdiv-3.3.0:=[cuda=,opencl=] )
78         openvdb? (
79                 media-gfx/openvdb[${PYTHON_USEDEP},-abi3-compat(-),abi4-compat(+)]
80                 dev-cpp/tbb
81                 >=dev-libs/c-blosc-1.5.2
82         )
83         osl? ( media-libs/osl:= )
84         sdl? ( media-libs/libsdl2[sound,joystick] )
85         sndfile? ( media-libs/libsndfile )
86         tiff? ( media-libs/tiff:0 )
87         valgrind? ( dev-util/valgrind )"
88
89 DEPEND="${RDEPEND}
90         >=dev-cpp/eigen-3.2.8:3
91         virtual/pkgconfig
92         doc? (
93                 app-doc/doxygen[-nodot(-),dot(+),latex]
94                 dev-python/sphinx[latex]
95         )
96         nls? ( sys-devel/gettext )"
97
98 PATCHES=(
99         "${FILESDIR}/${PN}-fix-install-rules.patch"
100         "${FILESDIR}/${P}-gcc-8.patch"
101         "${FILESDIR}/${P}-ffmpeg-4-compat.patch"
102         "${FILESDIR}/${P}-fix-for-gcc9-new-openmp-data-sharing.patch"
103 )
104
105 blender_check_requirements() {
106         [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp
107
108         if use doc; then
109                 CHECKREQS_DISK_BUILD="4G" check-reqs_pkg_pretend
110         fi
111 }
112
113 pkg_pretend() {
114         blender_check_requirements
115 }
116
117 pkg_setup() {
118         blender_check_requirements
119         python-single-r1_pkg_setup
120 }
121
122 src_prepare() {
123         cmake-utils_src_prepare
124
125         # we don't want static glew, but it's scattered across
126         # multiple files that differ from version to version
127         # !!!CHECK THIS SED ON EVERY VERSION BUMP!!!
128         local file
129         while IFS="" read -d $'\0' -r file ; do
130                 sed -i -e '/-DGLEW_STATIC/d' "${file}" || die
131         done < <(find . -type f -name "CMakeLists.txt")
132
133         # Disable MS Windows help generation. The variable doesn't do what it
134         # it sounds like.
135         sed -e "s|GENERATE_HTMLHELP      = YES|GENERATE_HTMLHELP      = NO|" \
136             -i doc/doxygen/Doxyfile || die
137 }
138
139 src_configure() {
140         # FIX: forcing '-funsigned-char' fixes an anti-aliasing issue with menu
141         # shadows, see bug #276338 for reference
142         append-flags -funsigned-char
143         append-lfs-flags
144         # Blender is compatible ABI 4 or less, so use ABI 4.
145         append-cppflags -DOPENVDB_ABI_VERSION_NUMBER=4
146
147         local mycmakeargs=(
148                 -DPYTHON_VERSION="${EPYTHON/python/}"
149                 -DPYTHON_LIBRARY="$(python_get_library_path)"
150                 -DPYTHON_INCLUDE_DIR="$(python_get_includedir)"
151                 -DWITH_INSTALL_PORTABLE=OFF
152                 -DWITH_PYTHON_INSTALL=OFF
153                 -DWITH_PYTHON_INSTALL_NUMPY=OFF
154                 -DWITH_STATIC_LIBS=OFF
155                 -DWITH_SYSTEM_GLEW=ON
156                 -DWITH_SYSTEM_OPENJPEG=ON
157                 -DWITH_SYSTEM_EIGEN3=ON
158                 -DWITH_SYSTEM_LZO=ON
159                 -DWITH_C11=ON
160                 -DWITH_CXX11=ON
161                 -DWITH_BOOST=ON
162                 -DWITH_BULLET=$(usex bullet)
163                 -DWITH_CODEC_FFMPEG=$(usex ffmpeg)
164                 -DWITH_CODEC_SNDFILE=$(usex sndfile)
165                 -DWITH_CUDA=$(usex cuda)
166                 -DWITH_CYCLES_DEVICE_CUDA=$(usex cuda TRUE FALSE)
167                 -DWITH_CYCLES=$(usex cycles)
168                 -DWITH_CYCLES_OSL=$(usex osl)
169                 -DWITH_LLVM=$(usex llvm)
170                 -DWITH_FFTW3=$(usex fftw)
171                 -DWITH_GAMEENGINE=$(usex game-engine)
172                 -DWITH_HEADLESS=$(usex headless)
173                 -DWITH_X11=$(usex !headless)
174                 -DWITH_IMAGE_DDS=$(usex dds)
175                 -DWITH_IMAGE_OPENEXR=$(usex openexr)
176                 -DWITH_IMAGE_OPENJPEG=$(usex jpeg2k)
177                 -DWITH_IMAGE_TIFF=$(usex tiff)
178                 -DWITH_INPUT_NDOF=$(usex ndof)
179                 -DWITH_INTERNATIONAL=$(usex nls)
180                 -DWITH_JACK=$(usex jack)
181                 -DWITH_MOD_FLUID=$(usex elbeem)
182                 -DWITH_MOD_OCEANSIM=$(usex fftw)
183                 -DWITH_OPENAL=$(usex openal)
184                 -DWITH_OPENCL=$(usex opencl)
185                 -DWITH_OPENCOLORIO=$(usex color-management)
186                 -DWITH_OPENCOLLADA=$(usex collada)
187                 -DWITH_OPENIMAGEIO=$(usex openimageio)
188                 -DWITH_OPENMP=$(usex openmp)
189                 -DWITH_OPENSUBDIV=$(usex opensubdiv)
190                 -DWITH_OPENVDB=$(usex openvdb)
191                 -DWITH_OPENVDB_BLOSC=$(usex openvdb)
192                 -DWITH_PLAYER=$(usex player)
193                 -DWITH_SDL=$(usex sdl)
194                 -DWITH_CXX_GUARDEDALLOC=$(usex debug)
195                 -DWITH_ASSERT_ABORT=$(usex debug)
196                 -DWITH_GTESTS=$(usex test)
197                 -DWITH_DOC_MANPAGE=$(usex man)
198                 -DWITH_MEM_JEMALLOC=$(usex jemalloc)
199                 -DWITH_MEM_VALGRIND=$(usex valgrind)
200         )
201         cmake-utils_src_configure
202 }
203
204 src_compile() {
205         cmake-utils_src_compile
206
207         if use doc; then
208                 # Workaround for binary drivers.
209                 addpredict /dev/ati
210                 addpredict /dev/dri
211                 addpredict /dev/nvidiactl
212
213                 einfo "Generating Blender C/C++ API docs ..."
214                 cd "${CMAKE_USE_DIR}"/doc/doxygen || die
215                 doxygen -u Doxyfile || die
216                 doxygen || die "doxygen failed to build API docs."
217
218                 cd "${CMAKE_USE_DIR}" || die
219                 einfo "Generating (BPY) Blender Python API docs ..."
220                 "${BUILD_DIR}"/bin/blender --background --python doc/python_api/sphinx_doc_gen.py -noaudio || die "sphinx failed."
221
222                 cd "${CMAKE_USE_DIR}"/doc/python_api || die
223                 sphinx-build sphinx-in BPY_API || die "sphinx failed."
224         fi
225 }
226
227 src_test() {
228         if use test; then
229                 einfo "Running Blender Unit Tests ..."
230                 cd "${BUILD_DIR}"/bin/tests || die
231                 local f
232                 for f in *_test; do
233                         ./"${f}" || die
234                 done
235         fi
236 }
237
238 src_install() {
239         # Pax mark blender for hardened support.
240         pax-mark m "${CMAKE_BUILD_DIR}"/bin/blender
241
242         if use doc; then
243                 docinto "html/API/python"
244                 dodoc -r "${CMAKE_USE_DIR}"/doc/python_api/BPY_API/.
245
246                 docinto "html/API/blender"
247                 dodoc -r "${CMAKE_USE_DIR}"/doc/doxygen/html/.
248         fi
249
250         cmake-utils_src_install
251
252         # fix doc installdir
253         docinto "html"
254         dodoc "${CMAKE_USE_DIR}"/release/text/readme.html
255         rm -r "${ED%/}"/usr/share/doc/blender || die
256
257         python_fix_shebang "${ED%/}/usr/bin/blender-thumbnailer.py"
258         python_optimize "${ED%/}/usr/share/blender/${MY_PV}/scripts"
259 }
260
261 pkg_postinst() {
262         elog
263         elog "Blender uses python integration. As such, may have some"
264         elog "inherit risks with running unknown python scripts."
265         elog
266         elog "It is recommended to change your blender temp directory"
267         elog "from /tmp to /home/user/tmp or another tmp file under your"
268         elog "home directory. This can be done by starting blender, then"
269         elog "dragging the main menu down do display all paths."
270         elog
271         ewarn
272         ewarn "This ebuild does not unbundle the massive amount of 3rd party"
273         ewarn "libraries which are shipped with blender. Note that"
274         ewarn "these have caused security issues in the past."
275         ewarn "If you are concerned about security, file a bug upstream:"
276         ewarn "  https://developer.blender.org/"
277         ewarn
278         xdg_icon_cache_update
279         xdg_mimeinfo_database_update
280 }
281
282 pkg_postrm() {
283         xdg_icon_cache_update
284         xdg_mimeinfo_database_update
285
286         ewarn ""
287         ewarn "You may want to remove the following directory."
288         ewarn "~/.config/${PN}/${MY_PV}/cache/"
289         ewarn "It may contain extra render kernels not tracked by portage"
290         ewarn ""
291 }