Correct own error in adding colors
[blender.git] / build_files / build_environment / install_deps.sh
1 #!/usr/bin/env bash
2 # ##### BEGIN GPL LICENSE BLOCK #####
3 #
4 #  This program is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU General Public License
6 #  as published by the Free Software Foundation; either version 2
7 #  of the License, or (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software Foundation,
16 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # ##### END GPL LICENSE BLOCK #####
19
20 # A shell script installing/building all needed dependencies to build Blender, for some Linux distributions.
21
22 ##### Args and Help Handling #####
23
24 # Parse command line!
25 ARGS=$( \
26 getopt \
27 -o s:i:t:h \
28 --long source:,install:,tmp:,info:,threads:,help,show-deps,no-sudo,no-build,no-confirm,\
29 with-all,with-opencollada,\
30 ver-ocio:,ver-oiio:,ver-llvm:,ver-osl:,ver-osd:,ver-openvdb:,\
31 force-all,force-python,force-numpy,force-boost,\
32 force-ocio,force-openexr,force-oiio,force-llvm,force-osl,force-osd,force-openvdb,\
33 force-ffmpeg,force-opencollada,force-alembic,\
34 build-all,build-python,build-numpy,build-boost,\
35 build-ocio,build-openexr,build-oiio,build-llvm,build-osl,build-osd,build-openvdb,\
36 build-ffmpeg,build-opencollada,build-alembic,\
37 skip-python,skip-numpy,skip-boost,\
38 skip-ocio,skip-openexr,skip-oiio,skip-llvm,skip-osl,skip-osd,skip-openvdb,\
39 skip-ffmpeg,skip-opencollada,skip-alembic \
40 -- "$@" \
41 )
42
43 COMMANDLINE=$@
44
45 DISTRO=""
46 RPM=""
47 SRC="$HOME/src/blender-deps"
48 INST="/opt/lib"
49 TMP="/tmp"
50 CWD=$PWD
51 INFO_PATH=$CWD
52 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
53
54 # Do not install some optional, potentially conflicting libs by default...
55 WITH_ALL=false
56
57 # Do not yet enable opencollada, use --with-opencollada (or --with-all) option to try it.
58 WITH_OPENCOLLADA=false
59
60 THREADS=$(nproc)
61
62 COMMON_INFO="\"Source code of dependencies needed to be compiled will be downloaded and extracted into '\$SRC'.
63 Built libs of dependencies needed to be compiled will be installed into '\$INST'.
64 Please edit \\\$SRC and/or \\\$INST variables at the beginning of this script,
65 or use --source/--install options, if you want to use other paths!
66
67 Number of threads for building: \$THREADS (automatically detected, use --threads=<nbr> to override it).
68 Full install: \$WITH_ALL (use --with-all option to enable it).
69 Building OpenCOLLADA: \$WITH_OPENCOLLADA (use --with-opencollada option to enable it).
70
71 Example:
72 Full install without OpenCOLLADA: --with-all --skip-opencollada
73
74 Use --help to show all available options!\""
75
76 ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
77     -h, --help
78         Show this message and exit.
79
80     --show-deps
81         Show main dependencies of Blender (including officially supported versions) and exit.
82
83     -s <path>, --source=<path>
84         Use a specific path where to store downloaded libraries sources (defaults to '\$SRC').
85
86     -i <path>, --install=<path>
87         Use a specific path where to install built libraries (defaults to '\$INST').
88
89     --tmp=<path>
90         Use a specific temp path (defaults to '\$TMP').
91
92     --info=<path>
93         Use a specific info path (to store BUILD_NOTES.txt, defaults to '\$INFO_PATH').
94
95     -t n, --threads=n
96         Use a specific number of threads when building the libraries (auto-detected as '\$THREADS').
97
98     --no-sudo
99         Disable use of sudo (this script won't be able to do much though, will just print needed packages...).
100
101     --no-build
102         Do not build (compile) anything, dependencies not installable with the package manager will remain missing.
103
104     --no-confirm
105         Disable any interaction with user (suitable for automated run).
106
107     --with-all
108         By default, a number of optional and not-so-often needed libraries are not installed.
109         This option will try to install them, at the cost of potential conflicts (depending on
110         how your package system is set…).
111         Note this option also implies all other (more specific) --with-foo options below.
112
113     --with-opencollada
114         Build and install the OpenCOLLADA libraries.
115
116     --ver-ocio=<ver>
117         Force version of OCIO library.
118
119     --ver-oiio=<ver>
120         Force version of OIIO library.
121
122     --ver-llvm=<ver>
123         Force version of LLVM library.
124
125     --ver-osl=<ver>
126         Force version of OSL library.
127
128     --ver-osd=<ver>
129         Force version of OSD library.
130
131     --ver-openvdb=<ver>
132         Force version of OpenVDB library.
133
134     Note about the --ver-foo options:
135         It may not always work as expected (some libs are actually checked out from a git rev...), yet it might help
136         to fix some build issues (like LLVM mismatch with the version used by your graphic system).
137
138     --build-all
139         Force the build of all possible libraries.
140
141     --build-python
142         Force the build of Python.
143
144     --build-numpy
145         Force the build of NumPy.
146
147     --build-boost
148         Force the build of Boost.
149
150     --build-ocio
151         Force the build of OpenColorIO.
152
153     --build-openexr
154         Force the build of OpenEXR.
155
156     --build-oiio
157         Force the build of OpenImageIO.
158
159     --build-llvm
160         Force the build of LLVM.
161
162     --build-osl
163         Force the build of OpenShadingLanguage.
164
165     --build-osd
166         Force the build of OpenSubdiv.
167
168     --build-openvdb
169         Force the build of OpenVDB.
170
171     --build-alembic
172         Force the build of Alembic.
173
174     --build-opencollada
175         Force the build of OpenCOLLADA.
176
177     --build-ffmpeg
178         Force the build of FFMpeg.
179
180     Note about the --build-foo options:
181         * They force the script to prefer building dependencies rather than using available packages.
182           This may make things simpler and allow working around some distribution bugs, but on the other hand it will
183           use much more space on your hard drive.
184         * Please be careful with the Blender building options if you have both 'official' dev packages and
185           install_deps' built ones on your system, by default CMake will prefer official packages, which may lead to
186           linking issues. Please ensure your CMake configuration always uses all correct library paths.
187         * If the “force-built” library is a dependency of others, it will force the build
188           of those libraries as well (e.g. --build-boost also implies --build-oiio and --build-osl...).
189
190     --force-all
191         Force the rebuild of all built libraries.
192
193     --force-python
194         Force the rebuild of Python.
195
196     --force-numpy
197         Force the rebuild of NumPy.
198
199     --force-boost
200         Force the rebuild of Boost.
201
202     --force-ocio
203         Force the rebuild of OpenColorIO.
204
205     --force-openexr
206         Force the rebuild of OpenEXR.
207
208     --force-oiio
209         Force the rebuild of OpenImageIO.
210
211     --force-llvm
212         Force the rebuild of LLVM.
213
214     --force-osl
215         Force the rebuild of OpenShadingLanguage.
216
217     --force-osd
218         Force the rebuild of OpenSubdiv.
219
220     --force-openvdb
221         Force the rebuild of OpenVDB.
222
223     --force-alembic
224         Force the rebuild of Alembic.
225
226     --force-opencollada
227         Force the rebuild of OpenCOLLADA.
228
229     --force-ffmpeg
230         Force the rebuild of FFMpeg.
231
232     Note about the --force-foo options:
233         * They obviously only have an effect if those libraries are built by this script
234           (i.e. if there is no available and satisfactory package)!
235         * If the “force-rebuilt” library is a dependency of others, it will force the rebuild
236           of those libraries too (e.g. --force-boost will also rebuild oiio and osl...).
237
238     --skip-python
239         Unconditionally skip Python installation/building.
240
241     --skip-numpy
242         Unconditionally skip NumPy installation/building.
243
244     --skip-boost
245         Unconditionally skip Boost installation/building.
246
247     --skip-ocio
248         Unconditionally skip OpenColorIO installation/building.
249
250     --skip-openexr
251         Unconditionally skip OpenEXR installation/building.
252
253     --skip-oiio
254         Unconditionally skip OpenImageIO installation/building.
255
256     --skip-llvm
257         Unconditionally skip LLVM installation/building.
258
259     --skip-osl
260         Unconditionally skip OpenShadingLanguage installation/building.
261
262     --skip-osd
263         Unconditionally skip OpenSubdiv installation/building.
264
265     --skip-openvdb
266         Unconditionally skip OpenVDB installation/building.
267
268     --skip-alembic
269         Unconditionally skip Alembic installation/building.
270
271     --skip-opencollada
272         Unconditionally skip OpenCOLLADA installation/building.
273
274     --skip-ffmpeg
275         Unconditionally skip FFMpeg installation/building.\""
276
277 ##### Main Vars #####
278
279 DO_SHOW_DEPS=false
280
281 SUDO="sudo"
282
283 NO_BUILD=false
284 NO_CONFIRM=false
285 USE_CXX11=true  # Mandatory in blender2.8
286
287 PYTHON_VERSION="3.5.2"
288 PYTHON_VERSION_MIN="3.5"
289 PYTHON_FORCE_BUILD=false
290 PYTHON_FORCE_REBUILD=false
291 PYTHON_SKIP=false
292
293 NUMPY_VERSION="1.10.1"
294 NUMPY_VERSION_MIN="1.8"
295 NUMPY_FORCE_BUILD=false
296 NUMPY_FORCE_REBUILD=false
297 NUMPY_SKIP=false
298
299 BOOST_VERSION="1.60.0"
300 BOOST_VERSION_MIN="1.49"
301 BOOST_FORCE_BUILD=false
302 BOOST_FORCE_REBUILD=false
303 BOOST_SKIP=false
304
305 OCIO_VERSION="1.0.9"
306 OCIO_VERSION_MIN="1.0"
307 OCIO_FORCE_BUILD=false
308 OCIO_FORCE_REBUILD=false
309 OCIO_SKIP=false
310
311 OPENEXR_VERSION="2.2.0"
312 OPENEXR_VERSION_MIN="2.0.1"
313 ILMBASE_VERSION="2.2.0"
314 ILMBASE_VERSION_MIN="2.2"
315 OPENEXR_FORCE_BUILD=false
316 OPENEXR_FORCE_REBUILD=false
317 OPENEXR_SKIP=false
318 _with_built_openexr=false
319
320 OIIO_VERSION="1.7.13"
321 OIIO_VERSION_MIN="1.7.13"
322 OIIO_VERSION_MAX="1.9.0"  # UNKNOWN currently # Not supported by current OSL...
323 OIIO_FORCE_BUILD=false
324 OIIO_FORCE_REBUILD=false
325 OIIO_SKIP=false
326
327 LLVM_VERSION="3.4"
328 LLVM_VERSION_MIN="3.4"
329 LLVM_VERSION_FOUND=""
330 LLVM_FORCE_BUILD=false
331 LLVM_FORCE_REBUILD=false
332 LLVM_SKIP=false
333
334 # OSL needs to be compiled for now!
335 OSL_VERSION="1.7.5"
336 OSL_VERSION_MIN=$OSL_VERSION
337 OSL_FORCE_BUILD=false
338 OSL_FORCE_REBUILD=false
339 OSL_SKIP=false
340
341 # OpenSubdiv needs to be compiled for now
342 OSD_VERSION="3.1.1"
343 OSD_VERSION_MIN=$OSD_VERSION
344 OSD_FORCE_BUILD=false
345 OSD_FORCE_REBUILD=false
346 OSD_SKIP=false
347
348 # OpenVDB needs to be compiled for now
349 OPENVDB_BLOSC_VERSION="1.7.0"
350
351 OPENVDB_VERSION="3.1.0"
352 OPENVDB_VERSION_MIN=$OPENVDB_VERSION
353 OPENVDB_FORCE_BUILD=false
354 OPENVDB_FORCE_REBUILD=false
355 OPENVDB_SKIP=false
356
357 # Alembic needs to be compiled for now
358 ALEMBIC_VERSION="1.7.1"
359 ALEMBIC_VERSION_MIN=$ALEMBIC_VERSION
360 ALEMBIC_FORCE_BUILD=false
361 ALEMBIC_FORCE_REBUILD=false
362 ALEMBIC_SKIP=false
363
364 # Version??
365 OPENCOLLADA_VERSION="1.3"
366 OPENCOLLADA_FORCE_BUILD=false
367 OPENCOLLADA_FORCE_REBUILD=false
368 OPENCOLLADA_SKIP=false
369
370 FFMPEG_VERSION="3.2.1"
371 FFMPEG_VERSION_MIN="2.8.4"
372 FFMPEG_FORCE_BUILD=false
373 FFMPEG_FORCE_REBUILD=false
374 FFMPEG_SKIP=false
375 _ffmpeg_list_sep=";"
376
377 # FFMPEG optional libs.
378 VORBIS_USE=false
379 VORBIS_DEV=""
380 OGG_USE=false
381 OGG_DEV=""
382 THEORA_USE=false
383 THEORA_DEV=""
384 XVID_USE=false
385 XVID_DEV=""
386 X264_USE=false
387 X264_DEV=""
388 X264_VERSION_MIN=0.118
389 VPX_USE=false
390 VPX_VERSION_MIN=0.9.7
391 VPX_DEV=""
392 MP3LAME_USE=false
393 MP3LAME_DEV=""
394 OPENJPEG_USE=false
395 OPENJPEG_DEV=""
396
397 # Whether to use system GLEW or not (OpenSubDiv needs recent glew to work).
398 NO_SYSTEM_GLEW=false
399
400 # Switch to english language, else some things (like check_package_DEB()) won't work!
401 LANG_BACK=$LANG
402 LANG=""
403 export LANG
404
405 ##### Generic Helpers #####
406
407 BLACK=$(tput setaf 0)
408 RED=$(tput setaf 1)
409 GREEN=$(tput setaf 2)
410 YELLOW=$(tput setaf 3)
411 LIME_YELLOW=$(tput setaf 190)
412 POWDER_BLUE=$(tput setaf 153)
413 BLUE=$(tput setaf 4)
414 MAGENTA=$(tput setaf 5)
415 CYAN=$(tput setaf 6)
416 WHITE=$(tput setaf 7)
417 BRIGHT=$(tput bold)
418 NORMAL=$(tput sgr0)
419 BLINK=$(tput blink)
420 REVERSE=$(tput smso)
421 UNDERLINE=$(tput smul)
422
423 _echo() {
424   if [ "X$1" = "X-n" ]; then
425      shift; printf "%s" "$@"
426   else
427      printf "%s\n" "$@"
428   fi
429 }
430
431 ERROR() {
432   _echo "${BRIGHT}${RED}ERROR! ${NORMAL}${RED}$@${NORMAL}"
433 }
434
435 WARNING() {
436   _echo "${BRIGHT}${YELLOW}WARNING! ${NORMAL}${YELLOW}$@${NORMAL}"
437 }
438
439 INFO() {
440   _echo "${GREEN}$@${NORMAL}"
441 }
442
443 PRINT() {
444   _echo "$@"
445 }
446
447 ##### Args Handling #####
448
449 # Finish parsing the commandline args.
450 eval set -- "$ARGS"
451 while true; do
452   case $1 in
453     -s|--source)
454       SRC="$2"; shift; shift; continue
455     ;;
456     -i|--install)
457       INST="$2"; shift; shift; continue
458     ;;
459     --tmp)
460       TMP="$2"; shift; shift; continue
461     ;;
462     --info)
463       INFO_PATH="$2"; shift; shift; continue
464     ;;
465     -t|--threads)
466       THREADS="$2"; shift; shift; continue
467     ;;
468     -h|--help)
469       PRINT ""
470       PRINT "USAGE:"
471       PRINT ""
472       PRINT "`eval _echo "$COMMON_INFO"`"
473       PRINT ""
474       PRINT "`eval _echo "$ARGUMENTS_INFO"`"
475       PRINT ""
476       exit 0
477     ;;
478     --show-deps)
479       # We have to defer...
480       DO_SHOW_DEPS=true; shift; continue
481     ;;
482     --no-sudo)
483       PRINT ""
484       WARNING "--no-sudo enabled, this script might not be able to do much..."
485       PRINT ""
486       SUDO=""; shift; continue
487     ;;
488     --no-build)
489       PRINT ""
490       WARNING "--no-build enabled, this script will not be able to install all dependencies..."
491       PRINT ""
492       NO_BUILD=true; shift; continue
493     ;;
494     --no-confirm)
495       NO_CONFIRM=true; shift; continue
496     ;;
497     --with-all)
498       WITH_ALL=true; shift; continue
499     ;;
500     --with-opencollada)
501       WITH_OPENCOLLADA=true; shift; continue
502     ;;
503     --ver-ocio)
504       OCIO_VERSION="$2"
505       OCIO_VERSION_MIN=$OCIO_VERSION
506       shift; shift; continue
507     ;;
508     --ver-oiio)
509       OIIO_VERSION="$2"
510       OIIO_VERSION_MIN=$OIIO_VERSION
511       shift; shift; continue
512     ;;
513     --ver-llvm)
514       LLVM_VERSION="$2"
515       LLVM_VERSION_MIN=$LLVM_VERSION
516       shift; shift; continue
517     ;;
518     --ver-osl)
519       OSL_VERSION="$2"
520       OSL_VERSION_MIN=$OSL_VERSION
521       shift; shift; continue
522     ;;
523     --ver-osd)
524       OSD_VERSION="$2"
525       OSD_VERSION_MIN=$OSD_VERSION
526       shift; shift; continue
527     ;;
528     --ver-openvdb)
529       OPENVDB_VERSION="$2"
530       OPENVDB_VERSION_MIN=$OPENVDB_VERSION
531       shift; shift; continue
532     ;;
533     --build-all)
534       PYTHON_FORCE_BUILD=true
535       NUMPY_FORCE_BUILD=true
536       BOOST_FORCE_BUILD=true
537       OCIO_FORCE_BUILD=true
538       OPENEXR_FORCE_BUILD=true
539       OIIO_FORCE_BUILD=true
540       LLVM_FORCE_BUILD=true
541       OSL_FORCE_BUILD=true
542       OSD_FORCE_BUILD=true
543       OPENVDB_FORCE_BUILD=true
544       OPENCOLLADA_FORCE_BUILD=true
545       FFMPEG_FORCE_BUILD=true
546       ALEMBIC_FORCE_BUILD=true
547       shift; continue
548     ;;
549     --build-python)
550       PYTHON_FORCE_BUILD=true
551       NUMPY_FORCE_BUILD=true
552       shift; continue
553     ;;
554     --build-numpy)
555       PYTHON_FORCE_BUILD=true
556       NUMPY_FORCE_BUILD=true
557       shift; continue
558     ;;
559     --build-boost)
560       BOOST_FORCE_BUILD=true; shift; continue
561     ;;
562     --build-ocio)
563       OCIO_FORCE_BUILD=true; shift; continue
564     ;;
565     --build-openexr)
566       OPENEXR_FORCE_BUILD=true; shift; continue
567     ;;
568     --build-oiio)
569       OIIO_FORCE_BUILD=true; shift; continue
570     ;;
571     --build-llvm)
572       LLVM_FORCE_BUILD=true; shift; continue
573     ;;
574     --build-osl)
575       OSL_FORCE_BUILD=true; shift; continue
576     ;;
577     --build-osd)
578       OSD_FORCE_BUILD=true; shift; continue
579     ;;
580     --build-openvdb)
581       OPENVDB_FORCE_BUILD=true; shift; continue
582     ;;
583     --build-opencollada)
584       OPENCOLLADA_FORCE_BUILD=true; shift; continue
585     ;;
586     --build-ffmpeg)
587       FFMPEG_FORCE_BUILD=true; shift; continue
588     ;;
589     --build-alembic)
590       ALEMBIC_FORCE_BUILD=true; shift; continue
591     ;;
592     --force-all)
593       PYTHON_FORCE_REBUILD=true
594       NUMPY_FORCE_REBUILD=true
595       BOOST_FORCE_REBUILD=true
596       OCIO_FORCE_REBUILD=true
597       OPENEXR_FORCE_REBUILD=true
598       OIIO_FORCE_REBUILD=true
599       LLVM_FORCE_REBUILD=true
600       OSL_FORCE_REBUILD=true
601       OSD_FORCE_REBUILD=true
602       OPENVDB_FORCE_REBUILD=true
603       OPENCOLLADA_FORCE_REBUILD=true
604       FFMPEG_FORCE_REBUILD=true
605       ALEMBIC_FORCE_REBUILD=true
606       shift; continue
607     ;;
608     --force-python)
609       PYTHON_FORCE_REBUILD=true
610       NUMPY_FORCE_REBUILD=true
611       shift; continue
612     ;;
613     --force-numpy)
614       NUMPY_FORCE_REBUILD=true; shift; continue
615     ;;
616     --force-boost)
617       BOOST_FORCE_REBUILD=true; shift; continue
618     ;;
619     --force-ocio)
620       OCIO_FORCE_REBUILD=true; shift; continue
621     ;;
622     --force-openexr)
623       OPENEXR_FORCE_REBUILD=true; shift; continue
624     ;;
625     --force-oiio)
626       OIIO_FORCE_REBUILD=true; shift; continue
627     ;;
628     --force-llvm)
629       LLVM_FORCE_REBUILD=true; shift; continue
630     ;;
631     --force-osl)
632       OSL_FORCE_REBUILD=true; shift; continue
633     ;;
634     --force-osd)
635       OSD_FORCE_REBUILD=true; shift; continue
636     ;;
637     --force-openvdb)
638       OPENVDB_FORCE_REBUILD=true; shift; continue
639     ;;
640     --force-opencollada)
641       OPENCOLLADA_FORCE_REBUILD=true; shift; continue
642     ;;
643     --force-ffmpeg)
644       FFMPEG_FORCE_REBUILD=true; shift; continue
645     ;;
646     --force-alembic)
647       ALEMBIC_FORCE_REBUILD=true; shift; continue
648     ;;
649     --skip-python)
650       PYTHON_SKIP=true; shift; continue
651     ;;
652     --skip-numpy)
653       NUMPY_SKIP=true; shift; continue
654     ;;
655     --skip-boost)
656       BOOST_SKIP=true; shift; continue
657     ;;
658     --skip-ocio)
659       OCIO_SKIP=true; shift; continue
660     ;;
661     --skip-openexr)
662       OPENEXR_SKIP=true; shift; continue
663     ;;
664     --skip-oiio)
665       OIIO_SKIP=true; shift; continue
666     ;;
667     --skip-llvm)
668       LLVM_SKIP=true; shift; continue
669     ;;
670     --skip-osl)
671       OSL_SKIP=true; shift; continue
672     ;;
673     --skip-osd)
674       OSD_SKIP=true; shift; continue
675     ;;
676     --skip-openvdb)
677       OPENVDB_SKIP=true; shift; continue
678     ;;
679     --skip-opencollada)
680       OPENCOLLADA_SKIP=true; shift; continue
681     ;;
682     --skip-ffmpeg)
683       FFMPEG_SKIP=true; shift; continue
684     ;;
685     --skip-alembic)
686       ALEMBIC_SKIP=true; shift; continue
687     ;;
688     --)
689       # no more arguments to parse
690       break
691     ;;
692     *)
693       PRINT ""
694       ERROR "Wrong parameter! Usage:"
695       PRINT ""
696       PRINT "`eval _echo "$COMMON_INFO"`"
697       PRINT ""
698       exit 1
699     ;;
700   esac
701 done
702
703 if [ "$WITH_ALL" = true -a "$OPENCOLLADA_SKIP" = false ]; then
704   WITH_OPENCOLLADA=true
705 fi
706
707
708 WARNING "****WARNING****"
709 PRINT "If you are experiencing issues building Blender, _*TRY A FRESH, CLEAN BUILD FIRST*_!"
710 PRINT "The same goes for install_deps itself, if you encounter issues, please first erase everything in $SRC and $INST"
711 PRINT "(provided obviously you did not add anything yourself in those dirs!), and run install_deps.sh again!"
712 PRINT "Often, changes in the libs built by this script, or in your distro package, cannot be handled simply, so..."
713 PRINT ""
714 PRINT "You may also try to use the '--build-foo' options to bypass your distribution's packages"
715 PRINT "for some troublesome/buggy libraries..."
716 PRINT ""
717 PRINT ""
718 PRINT "Ran with:"
719 PRINT "    install_deps.sh $COMMANDLINE"
720 PRINT ""
721 PRINT ""
722
723
724 # This has to be done here, because user might force some versions...
725 PYTHON_SOURCE=( "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz" )
726 NUMPY_SOURCE=( "http://sourceforge.net/projects/numpy/files/NumPy/$NUMPY_VERSION/numpy-$NUMPY_VERSION.tar.gz" )
727
728 _boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
729 BOOST_SOURCE=( "http://sourceforge.net/projects/boost/files/boost/$BOOST_VERSION/boost_$_boost_version_nodots.tar.bz2/download" )
730 BOOST_BUILD_MODULES="--with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time --with-wave --with-iostreams --with-python --with-program_options"
731
732 OCIO_SOURCE=( "https://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION" )
733
734 OPENEXR_USE_REPO=false
735 OPENEXR_SOURCE=( "http://download.savannah.nongnu.org/releases/openexr/openexr-$OPENEXR_VERSION.tar.gz" )
736 OPENEXR_SOURCE_REPO=( "https://github.com/mont29/openexr.git" )
737 OPENEXR_SOURCE_REPO_UID="2787aa1cf652d244ed45ae124eb1553f6cff11ee"
738 ILMBASE_SOURCE=( "http://download.savannah.nongnu.org/releases/openexr/ilmbase-$ILMBASE_VERSION.tar.gz" )
739
740 OIIO_USE_REPO=false
741 OIIO_SOURCE=( "https://github.com/OpenImageIO/oiio/archive/Release-$OIIO_VERSION.tar.gz" )
742 OIIO_SOURCE_REPO=( "https://github.com/OpenImageIO/oiio.git" )
743 OIIO_SOURCE_REPO_UID="c9e67275a0b248ead96152f6d2221cc0c0f278a4"
744
745 LLVM_SOURCE=( "http://llvm.org/releases/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.gz" )
746 LLVM_CLANG_SOURCE=( "http://llvm.org/releases/$LLVM_VERSION/clang-$LLVM_VERSION.src.tar.gz" "http://llvm.org/releases/$LLVM_VERSION/cfe-$LLVM_VERSION.src.tar.gz" )
747
748 OSL_USE_REPO=false
749 OSL_SOURCE=( "https://github.com/imageworks/OpenShadingLanguage/archive/Release-$OSL_VERSION.tar.gz" )
750 #~ OSL_SOURCE=( "https://github.com/Nazg-Gul/OpenShadingLanguage/archive/Release-1.5.11.tar.gz" )
751 #~ OSL_SOURCE_REPO=( "https://github.com/imageworks/OpenShadingLanguage.git" )
752 #~ OSL_SOURCE_REPO=( "https://github.com/mont29/OpenShadingLanguage.git" )
753 #~ OSL_SOURCE_REPO_UID="85179714e1bc69cd25ecb6bb711c1a156685d395"
754 #~ OSL_SOURCE_REPO_BRANCH="master"
755 OSL_SOURCE_REPO=( "https://github.com/Nazg-Gul/OpenShadingLanguage.git" )
756 OSL_SOURCE_REPO_UID="7d40ff5fe8e47b030042afb92d0e955f5aa96f48"
757 OSL_SOURCE_REPO_BRANCH="blender-fixes"
758
759 OSD_USE_REPO=false
760 # Script foo to make the version string compliant with the archive name:
761 # ${Varname//SearchForThisChar/ReplaceWithThisChar}
762 OSD_SOURCE=( "https://github.com/PixarAnimationStudios/OpenSubdiv/archive/v${OSD_VERSION//./_}.tar.gz" )
763 OSD_SOURCE_REPO=( "https://github.com/PixarAnimationStudios/OpenSubdiv.git" )
764 OSD_SOURCE_REPO_UID="404659fffa659da075d1c9416e4fc939139a84ee"
765 OSD_SOURCE_REPO_BRANCH="dev"
766
767 OPENVDB_USE_REPO=false
768 OPENVDB_BLOSC_SOURCE=( "https://github.com/Blosc/c-blosc/archive/v${OPENVDB_BLOSC_VERSION}.tar.gz" )
769 OPENVDB_SOURCE=( "https://github.com/dreamworksanimation/openvdb/archive/v${OPENVDB_VERSION}.tar.gz" )
770 #~ OPENVDB_SOURCE_REPO=( "https:///dreamworksanimation/openvdb.git" )
771 #~ OPENVDB_SOURCE_REPO_UID="404659fffa659da075d1c9416e4fc939139a84ee"
772 #~ OPENVDB_SOURCE_REPO_BRANCH="dev"
773
774 ALEMBIC_USE_REPO=false
775 ALEMBIC_SOURCE=( "https://github.com/alembic/alembic/archive/${ALEMBIC_VERSION}.tar.gz" )
776 # ALEMBIC_SOURCE_REPO=( "https://github.com/alembic/alembic.git" )
777 # ALEMBIC_SOURCE_REPO_UID="e6c90d4faa32c4550adeaaf3f556dad4b73a92bb"
778 # ALEMBIC_SOURCE_REPO_BRANCH="master"
779
780 OPENCOLLADA_SOURCE=( "https://github.com/KhronosGroup/OpenCOLLADA.git" )
781 OPENCOLLADA_REPO_UID="3335ac164e68b2512a40914b14c74db260e6ff7d"
782 OPENCOLLADA_REPO_BRANCH="master"
783
784 FFMPEG_SOURCE=( "http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2" )
785
786 CXXFLAGS_BACK=$CXXFLAGS
787 if [ "$USE_CXX11" = true ]; then
788   WARNING "C++11 is now mandatory for blender2.8, this *should* go smoothly with any very recent distribution.
789 However, if you are experiencing linking errors (also when building Blender itself), please try the following:
790     * Re-run this script with '--build-all --force-all' options.
791     * Ensure your gcc version is at the very least 4.8, if possible you should really rather use gcc-5.1 or above.
792
793 Please note that until the transition to C++11-built libraries if completed in your distribution, situation will
794 remain fuzzy and incompatibilities may happen..."
795   PRINT ""
796   PRINT ""
797   CXXFLAGS="$CXXFLAGS -std=c++11"
798   export CXXFLAGS
799 fi
800
801 #### Show Dependencies ####
802
803 # Need those to be after we defined versions...
804 DEPS_COMMON_INFO="\"COMMON DEPENDENCIES:
805
806 Those libraries should be available as packages in all recent distributions (optional ones are [between brackets]):
807
808     * Basics of dev environment (cmake, gcc, svn , git, ...).
809     * libjpeg, libpng, libtiff, [libopenjpeg], [libopenal].
810     * libx11, libxcursor, libxi, libxrandr, libxinerama (and other libx... as needed).
811     * libsqlite3, libbz2, libssl, libfftw3, libxml2, libtinyxml, yasm, libyaml-cpp.
812     * libsdl1.2, libglew, [libglewmx].\""
813
814 DEPS_SPECIFIC_INFO="\"BUILDABLE DEPENDENCIES:
815
816 The following libraries will probably not all be available as packages in your distribution
817 (install_deps will by default try to install packages, and fall back to building missing ones).
818 You can force install_deps to build those with '--build-all' or relevant 'build-foo' options, see '--help' message.
819 You may also want to build them yourself (optional ones are [between brackets]):
820
821     * Python $PYTHON_VERSION_MIN (from $PYTHON_SOURCE).
822     * [NumPy $NUMPY_VERSION_MIN] (from $NUMPY_SOURCE).
823     * Boost $BOOST_VERSION_MIN (from $BOOST_SOURCE, modules: $BOOST_BUILD_MODULES).
824     * [FFMpeg $FFMPEG_VERSION_MIN (needs libvorbis, libogg, libtheora, libx264, libmp3lame, libxvidcore, libvpx, ...)] (from $FFMPEG_SOURCE).
825     * [OpenColorIO $OCIO_VERSION_MIN] (from $OCIO_SOURCE).
826     * ILMBase $ILMBASE_VERSION_MIN (from $ILMBASE_SOURCE).
827     * OpenEXR $OPENEXR_VERSION_MIN (from $OPENEXR_SOURCE).
828     * OpenImageIO $OIIO_VERSION_MIN (from $OIIO_SOURCE).
829     * [LLVM $LLVM_VERSION_MIN (with clang)] (from $LLVM_SOURCE, and $LLVM_CLANG_SOURCE).
830     * [OpenShadingLanguage $OSL_VERSION_MIN] (from $OSL_SOURCE_REPO, branch $OSL_SOURCE_REPO_BRANCH, commit $OSL_SOURCE_REPO_UID).
831     * [OpenSubDiv $OSD_VERSION_MIN] (from $OSD_SOURCE_REPO, branch $OSD_SOURCE_REPO_BRANCH, commit $OSD_SOURCE_REPO_UID).
832     * [OpenVDB $OPENVDB_VERSION_MIN] (from $OPENVDB_SOURCE), [Blosc $OPENVDB_BLOSC_VERSION] (from $OPENVDB_BLOSC_SOURCE).
833     * [OpenCollada] (from $OPENCOLLADA_SOURCE, branch $OPENCOLLADA_REPO_BRANCH, commit $OPENCOLLADA_REPO_UID).
834     * [Alembic $ALEMBIC_VERSION] (from $ALEMBIC_SOURCE).\""
835
836 if [ "$DO_SHOW_DEPS" = true ]; then
837   PRINT ""
838   PRINT "Blender dependencies (libraries needed to build it):"
839   PRINT ""
840   PRINT "`eval _echo "$DEPS_COMMON_INFO"`"
841   PRINT ""
842   PRINT "`eval _echo "$DEPS_SPECIFIC_INFO"`"
843   PRINT ""
844   exit 0
845 fi
846
847
848
849 ##### Generic Helpers #####
850
851 # Check return code of wget for success...
852 download() {
853   declare -a sources=("${!1}")
854   sources_count=${#sources[@]}
855   error=1
856
857   for (( i=0; $i < $sources_count; i++ ))
858   do
859     wget -c ${sources[$i]} -O $2
860     if [ $? -eq 0 ]; then
861       error=0
862       break
863     fi
864   done
865
866   if [ $error -eq 1 ]; then
867     ERROR "wget could not find ${sources[@]}, or could not write it to $2, exiting"
868     exit 1
869   fi
870 }
871
872 # Return 0 if $1 = $2 (i.e. 1.01.0 = 1.1, but 1.1.1 != 1.1), else 1.
873 # $1 and $2 should be version numbers made of numbers only.
874 version_eq() {
875   backIFS=$IFS
876   IFS='.'
877
878   # Split both version numbers into their numeric elements.
879   arr1=( $1 )
880   arr2=( $2 )
881
882   ret=1
883
884   count1=${#arr1[@]}
885   count2=${#arr2[@]}
886   if [ $count2 -ge $count1 ]; then
887     _t=$count1
888     count1=$count2
889     count2=$_t
890     arr1=( $2 )
891     arr2=( $1 )
892   fi
893
894   ret=0
895   for (( i=0; $i < $count2; i++ ))
896   do
897     if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
898       ret=1
899       break
900     fi
901   done
902
903   for (( i=$count2; $i < $count1; i++ ))
904   do
905     if [ $(( 10#${arr1[$i]} )) -ne 0 ]; then
906       ret=1
907       break
908     fi
909   done
910
911   IFS=$backIFS
912   return $ret
913 }
914
915 # Return 0 if $1 >= $2, else 1.
916 # $1 and $2 should be version numbers made of numbers only.
917 version_ge() {
918   version_eq $1 $2
919   if [ $? -eq 1 -a $(_echo "$1" "$2" | sort --version-sort | head --lines=1) = "$1" ]; then
920     return 1
921   else
922     return 0
923   fi
924 }
925
926 # Return 0 if $3 > $1 >= $2, else 1.
927 # $1 and $2 should be version numbers made of numbers only.
928 version_ge_lt() {
929   version_ge $1 $3
930   if [ $? -eq 0 ]; then
931     return 1
932   else
933     version_ge $1 $2
934     return $?
935   fi
936 }
937
938 # Return 0 if $1 is into $2 (e.g. 3.3.2 is into 3.3, but not 3.3.0 or 3.3.5), else 1.
939 # $1 and $2 should be version numbers made of numbers only.
940 # $1 should be at least as long as $2!
941 version_match() {
942   backIFS=$IFS
943   IFS='.'
944
945   # Split both version numbers into their numeric elements.
946   arr1=( $1 )
947   arr2=( $2 )
948
949   ret=1
950
951   count1=${#arr1[@]}
952   count2=${#arr2[@]}
953   if [ $count1 -ge $count2 ]; then
954     ret=0
955     for (( i=0; $i < $count2; i++ ))
956     do
957       if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
958         ret=1
959         break
960       fi
961     done
962   fi
963
964   IFS=$backIFS
965   return $ret
966 }
967
968 ##### Generic compile helpers #####
969 prepare_opt() {
970   INFO "Ensuring $INST exists and is writable by us"
971   if [ ! $SUDO ]; then
972     WARNING "--no-sudo enabled, might be impossible to create install dir..."
973   fi
974   if [ ! -d  $INST ]; then
975     $SUDO mkdir -p $INST
976   fi
977
978   if [ ! -w $INST ]; then
979     $SUDO chown $USER $INST
980     $SUDO chmod 775 $INST
981   fi
982 }
983
984 # Check whether the current package needs to be recompiled, based on a dummy file containing a magic number in its name...
985 magic_compile_check() {
986   if [ -f $INST/.$1-magiccheck-$2-$USE_CXX11 ]; then
987     return 0
988   else
989     return 1
990   fi
991 }
992
993 magic_compile_set() {
994   rm -f $INST/.$1-magiccheck-*
995   touch $INST/.$1-magiccheck-$2-$USE_CXX11
996 }
997
998 # Note: should clean nicely in $INST, but not in $SRC, when we switch to a new version of a lib...
999 _clean() {
1000   rm -rf `readlink -f $_inst_shortcut`
1001   # Only remove $_src dir when not using git repo (avoids to re-clone the whole repo every time!!!).
1002   if [ $_git == false ]; then
1003     rm -rf $_src
1004   fi
1005   rm -rf $_inst
1006   rm -rf $_inst_shortcut
1007 }
1008
1009 _create_inst_shortcut() {
1010   rm -f $_inst_shortcut
1011   ln -s $_inst $_inst_shortcut
1012 }
1013
1014 # ldconfig
1015 run_ldconfig() {
1016   _lib_path="$INST/$1/lib"
1017   _ldconf_path="/etc/ld.so.conf.d/$1.conf"
1018   PRINT ""
1019   if [ ! $SUDO ]; then
1020     WARNING "--no-sudo enabled, impossible to run ldconfig for $1, you'll have to do it yourself..."
1021   else
1022     INFO "Running ldconfig for $1..."
1023     $SUDO sh -c "echo \"$_lib_path\" > $_ldconf_path"
1024     $SUDO /sbin/ldconfig  # XXX OpenSuse does not include sbin in command path with sudo!!!
1025   fi
1026   PRINT ""
1027 }
1028
1029 #### Build Python ####
1030 _init_python() {
1031   _src=$SRC/Python-$PYTHON_VERSION
1032   _git=false
1033   _inst=$INST/python-$PYTHON_VERSION
1034   _inst_shortcut=$INST/python-$PYTHON_VERSION_MIN
1035 }
1036
1037 clean_Python() {
1038   clean_Numpy
1039   _init_python
1040   _clean
1041 }
1042
1043 compile_Python() {
1044   if [ "$NO_BUILD" = true ]; then
1045     WARNING "--no-build enabled, Python will not be compiled!"
1046     return
1047   fi
1048
1049   # To be changed each time we make edits that would modify the compiled result!
1050   py_magic=1
1051   _init_python
1052
1053   # Clean install if needed!
1054   magic_compile_check python-$PYTHON_VERSION $py_magic
1055   if [ $? -eq 1 -o "$PYTHON_FORCE_REBUILD" = true ]; then
1056     clean_Python
1057   fi
1058
1059   if [ ! -d $_inst ]; then
1060     INFO "Building Python-$PYTHON_VERSION"
1061
1062     prepare_opt
1063
1064     if [ ! -d $_src ]; then
1065       mkdir -p $SRC
1066       download PYTHON_SOURCE[@] $_src.tgz
1067
1068       INFO "Unpacking Python-$PYTHON_VERSION"
1069       tar -C $SRC -xf $_src.tgz
1070     fi
1071
1072     cd $_src
1073
1074     ./configure --prefix=$_inst --libdir=$_inst/lib --enable-ipv6 \
1075         --enable-loadable-sqlite-extensions --with-dbmliborder=bdb \
1076         --with-computed-gotos --with-pymalloc
1077
1078     make -j$THREADS && make install
1079     make clean
1080
1081     if [ -d $_inst ]; then
1082       _create_inst_shortcut
1083     else
1084       ERROR "Python--$PYTHON_VERSION failed to compile, exiting"
1085       exit 1
1086     fi
1087
1088     magic_compile_set python-$PYTHON_VERSION $py_magic
1089
1090     cd $CWD
1091     INFO "Done compiling Python-$PYTHON_VERSION!"
1092   else
1093     INFO "Own Python-$PYTHON_VERSION is up to date, nothing to do!"
1094     INFO "If you want to force rebuild of this lib, use the --force-python option."
1095   fi
1096 }
1097
1098 ##### Build Numpy #####
1099 _init_numpy() {
1100   _src=$SRC/numpy-$NUMPY_VERSION
1101   _git=false
1102   _inst=$INST/numpy-$NUMPY_VERSION
1103   _python=$INST/python-$PYTHON_VERSION
1104   _site=lib/python$PYTHON_VERSION_MIN/site-packages
1105   _inst_shortcut=$_python/$_site/numpy
1106 }
1107
1108 clean_Numpy() {
1109   _init_numpy
1110   _clean
1111 }
1112
1113 compile_Numpy() {
1114   if [ "$NO_BUILD" = true ]; then
1115     WARNING "--no-build enabled, Numpy will not be compiled!"
1116     return
1117   fi
1118
1119   # To be changed each time we make edits that would modify the compiled result!
1120   numpy_magic=0
1121   _init_numpy
1122
1123   # Clean install if needed!
1124   magic_compile_check numpy-$NUMPY_VERSION $numpy_magic
1125   if [ $? -eq 1 -o "$NUMPY_FORCE_REBUILD" = true ]; then
1126     clean_Numpy
1127   fi
1128
1129   if [ ! -d $_inst ]; then
1130     INFO "Building Numpy-$NUMPY_VERSION"
1131
1132     prepare_opt
1133
1134     if [ ! -d $_src ]; then
1135       mkdir -p $SRC
1136       download NUMPY_SOURCE[@] $_src.tar.gz
1137
1138       INFO "Unpacking Numpy-$NUMPY_VERSION"
1139       tar -C $SRC -xf $_src.tar.gz
1140     fi
1141
1142     cd $_src
1143
1144     $_python/bin/python3 setup.py install --prefix=$_inst
1145
1146     if [ -d $_inst ]; then
1147       # Can't use _create_inst_shortcut here...
1148       rm -f $_inst_shortcut
1149       ln -s $_inst/$_site/numpy $_inst_shortcut
1150     else
1151       ERROR "Numpy-$NUMPY_VERSION failed to compile, exiting"
1152       exit 1
1153     fi
1154
1155     magic_compile_set numpy-$NUMPY_VERSION $numpy_magic
1156
1157     cd $CWD
1158     INFO "Done compiling Numpy-$NUMPY_VERSION!"
1159   else
1160     INFO "Own Numpy-$NUMPY_VERSION is up to date, nothing to do!"
1161     INFO "If you want to force rebuild of this lib, use the --force-numpy option."
1162   fi
1163 }
1164
1165 #### Build Boost ####
1166 _init_boost() {
1167   _src=$SRC/boost-$BOOST_VERSION
1168   _git=false
1169   _inst=$INST/boost-$BOOST_VERSION
1170   _inst_shortcut=$INST/boost
1171 }
1172
1173 clean_Boost() {
1174   _init_boost
1175   _clean
1176 }
1177
1178 compile_Boost() {
1179   if [ "$NO_BUILD" = true ]; then
1180     WARNING "--no-build enabled, Boost will not be compiled!"
1181     return
1182   fi
1183
1184   # To be changed each time we make edits that would modify the compiled result!
1185   boost_magic=11
1186
1187   _init_boost
1188
1189   # Clean install if needed!
1190   magic_compile_check boost-$BOOST_VERSION $boost_magic
1191   if [ $? -eq 1 -o "$BOOST_FORCE_REBUILD" = true ]; then
1192     clean_Boost
1193   fi
1194
1195   if [ ! -d $_inst ]; then
1196     INFO "Building Boost-$BOOST_VERSION"
1197
1198     # Rebuild dependecies as well!
1199     OIIO_FORCE_BUILD=true
1200     OIIO_FORCE_REBUILD=true
1201     OSL_FORCE_BUILD=true
1202     OSL_FORCE_REBUILD=true
1203     OPENVDB_FORCE_BUILD=true
1204     OPENVDB_FORCE_REBUILD=true
1205
1206     prepare_opt
1207
1208     if [ ! -d $_src ]; then
1209       INFO "Downloading Boost-$BOOST_VERSION"
1210       mkdir -p $SRC
1211       download BOOST_SOURCE[@] $_src.tar.bz2
1212       tar -C $SRC --transform "s,\w*,boost-$BOOST_VERSION,x" -xf $_src.tar.bz2
1213     fi
1214
1215     cd $_src
1216     if [ ! -f $_src/b2 ]; then
1217       ./bootstrap.sh
1218     fi
1219     ./b2 -j$THREADS -a $BOOST_BUILD_MODULES \
1220          --prefix=$_inst --disable-icu boost.locale.icu=off install
1221     ./b2 --clean
1222
1223     if [ -d $_inst ]; then
1224       _create_inst_shortcut
1225     else
1226       ERROR "Boost-$BOOST_VERSION failed to compile, exiting"
1227       exit 1
1228     fi
1229
1230     magic_compile_set boost-$BOOST_VERSION $boost_magic
1231
1232     cd $CWD
1233     INFO "Done compiling Boost-$BOOST_VERSION!"
1234   else
1235     INFO "Own Boost-$BOOST_VERSION is up to date, nothing to do!"
1236     INFO "If you want to force rebuild of this lib, use the --force-boost option."
1237   fi
1238
1239   # Just always run it, much simpler this way!
1240   run_ldconfig "boost"
1241 }
1242
1243 #### Build OCIO ####
1244 _init_ocio() {
1245   _src=$SRC/OpenColorIO-$OCIO_VERSION
1246   _git=false
1247   _inst=$INST/ocio-$OCIO_VERSION
1248   _inst_shortcut=$INST/ocio
1249 }
1250
1251 clean_OCIO() {
1252   _init_ocio
1253   _clean
1254 }
1255
1256 compile_OCIO() {
1257   if [ "$NO_BUILD" = true ]; then
1258     WARNING "--no-build enabled, OpenColorIO will not be compiled!"
1259     return
1260   fi
1261
1262   # To be changed each time we make edits that would modify the compiled result!
1263   ocio_magic=1
1264   _init_ocio
1265
1266   # Clean install if needed!
1267   magic_compile_check ocio-$OCIO_VERSION $ocio_magic
1268   if [ $? -eq 1 -o "$OCIO_FORCE_REBUILD" = true ]; then
1269     clean_OCIO
1270   fi
1271
1272   if [ ! -d $_inst ]; then
1273     INFO "Building OpenColorIO-$OCIO_VERSION"
1274
1275     prepare_opt
1276
1277     if [ ! -d $_src ]; then
1278       INFO "Downloading OpenColorIO-$OCIO_VERSION"
1279       mkdir -p $SRC
1280       download OCIO_SOURCE[@] $_src.tar.gz
1281
1282       INFO "Unpacking OpenColorIO-$OCIO_VERSION"
1283       tar -C $SRC --transform "s,(.*/?)imageworks-OpenColorIO[^/]*(.*),\1OpenColorIO-$OCIO_VERSION\2,x" \
1284           -xf $_src.tar.gz
1285     fi
1286
1287     cd $_src
1288     # Always refresh the whole build!
1289     if [ -d build ]; then
1290       rm -rf build
1291     fi
1292     mkdir build
1293     cd build
1294
1295     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1296     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1297     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1298     cmake_d="$cmake_d -D OCIO_BUILD_APPS=OFF"
1299     cmake_d="$cmake_d -D OCIO_BUILD_PYGLUE=OFF"
1300
1301     if file /bin/cp | grep -q '32-bit'; then
1302       cflags="-fPIC -m32 -march=i686"
1303     else
1304       cflags="-fPIC"
1305     fi
1306
1307     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1308
1309     make -j$THREADS && make install
1310
1311     # Force linking against static libs
1312     rm -f $_inst/lib/*.so*
1313
1314     # Additional depencencies
1315     cp ext/dist/lib/libtinyxml.a $_inst/lib
1316     cp ext/dist/lib/libyaml-cpp.a $_inst/lib
1317
1318     make clean
1319
1320     if [ -d $_inst ]; then
1321       _create_inst_shortcut
1322     else
1323       ERROR "OpenColorIO-$OCIO_VERSION failed to compile, exiting"
1324       exit 1
1325     fi
1326
1327     magic_compile_set ocio-$OCIO_VERSION $ocio_magic
1328
1329     cd $CWD
1330     INFO "Done compiling OpenColorIO-$OCIO_VERSION!"
1331   else
1332     INFO "Own OpenColorIO-$OCIO_VERSION is up to date, nothing to do!"
1333     INFO "If you want to force rebuild of this lib, use the --force-ocio option."
1334   fi
1335
1336   run_ldconfig "ocio"
1337 }
1338
1339 #### Build ILMBase ####
1340 _init_ilmbase() {
1341   _src=$SRC/ILMBase-$ILMBASE_VERSION
1342   _git=false
1343   _inst=$TMP/ilmbase-$ILMBASE_VERSION
1344   _inst_shortcut=$TMP/ilmbase
1345 }
1346
1347 clean_ILMBASE() {
1348   _init_ilmbase
1349   _clean
1350 }
1351
1352 compile_ILMBASE() {
1353   if [ "$NO_BUILD" = true ]; then
1354     WARNING "--no-build enabled, ILMBase will not be compiled!"
1355     return
1356   fi
1357
1358   # To be changed each time we make edits that would modify the compiled result!
1359   ilmbase_magic=10
1360   _init_ilmbase
1361
1362   # Clean install if needed!
1363   magic_compile_check ilmbase-$ILMBASE_VERSION $ilmbase_magic
1364   if [ $? -eq 1 -o "$OPENEXR_FORCE_REBUILD" = true ]; then
1365     clean_ILMBASE
1366     rm -rf $_openexr_inst
1367   fi
1368
1369   if [ ! -d $_openexr_inst ]; then
1370     INFO "Building ILMBase-$ILMBASE_VERSION"
1371
1372     # Rebuild dependecies as well!
1373     OPENEXR_FORCE_BUILD=true
1374     OPENEXR_FORCE_REBUILD=true
1375
1376     prepare_opt
1377
1378     if [ ! -d $_src ]; then
1379       INFO "Downloading ILMBase-$ILMBASE_VERSION"
1380       mkdir -p $SRC
1381       download ILMBASE_SOURCE[@] $_src.tar.gz
1382
1383       INFO "Unpacking ILMBase-$ILMBASE_VERSION"
1384       tar -C $SRC --transform "s,(.*/?)ilmbase-[^/]*(.*),\1ILMBase-$ILMBASE_VERSION\2,x" -xf $_src.tar.gz
1385
1386     fi
1387
1388     cd $_src
1389     # Always refresh the whole build!
1390     if [ -d build ]; then
1391       rm -rf build
1392     fi
1393     mkdir build
1394     cd build
1395
1396     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1397     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1398     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1399     cmake_d="$cmake_d -D BUILD_SHARED_LIBS=ON"
1400     cmake_d="$cmake_d -D NAMESPACE_VERSIONING=OFF"  # VERY IMPORTANT!!!
1401
1402     if file /bin/cp | grep -q '32-bit'; then
1403       cflags="-fPIC -m32 -march=i686"
1404     else
1405       cflags="-fPIC"
1406     fi
1407
1408     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1409
1410     make -j$THREADS && make install
1411
1412     make clean
1413
1414     if [ -d $_inst ]; then
1415       _create_inst_shortcut
1416     else
1417       ERROR "ILMBase-$ILMBASE_VERSION failed to compile, exiting"
1418       exit 1
1419     fi
1420     cd $CWD
1421     INFO "Done compiling ILMBase-$ILMBASE_VERSION!"
1422   else
1423     INFO "Own ILMBase-$ILMBASE_VERSION is up to date, nothing to do!"
1424     INFO "If you want to force rebuild of this lib (and openexr), use the --force-openexr option."
1425   fi
1426
1427   magic_compile_set ilmbase-$ILMBASE_VERSION $ilmbase_magic
1428 }
1429
1430 #### Build OpenEXR ####
1431 _init_openexr() {
1432   _src=$SRC/OpenEXR-$OPENEXR_VERSION
1433   _git=true
1434   _inst=$_openexr_inst
1435   _inst_shortcut=$INST/openexr
1436 }
1437
1438 clean_OPENEXR() {
1439   clean_ILMBASE
1440   _init_openexr
1441   _clean
1442 }
1443
1444 compile_OPENEXR() {
1445   if [ "$NO_BUILD" = true ]; then
1446     WARNING "--no-build enabled, OpenEXR will not be compiled!"
1447     return
1448   fi
1449
1450   # To be changed each time we make edits that would modify the compiled result!
1451   openexr_magic=14
1452
1453   # Clean install if needed!
1454   magic_compile_check openexr-$OPENEXR_VERSION $openexr_magic
1455   if [ $? -eq 1 -o "$OPENEXR_FORCE_REBUILD" = true ]; then
1456     clean_OPENEXR
1457   fi
1458
1459   _openexr_inst=$INST/openexr-$OPENEXR_VERSION
1460   compile_ILMBASE
1461   PRINT ""
1462   _ilmbase_inst=$_inst_shortcut
1463   _init_openexr
1464
1465   if [ ! -d $_inst ]; then
1466     INFO "Building OpenEXR-$OPENEXR_VERSION"
1467
1468     # Rebuild dependecies as well!
1469     OIIO_FORCE_BUILD=true
1470     OIIO_FORCE_REBUILD=true
1471
1472     prepare_opt
1473
1474     if [ ! -d $_src ]; then
1475       INFO "Downloading OpenEXR-$OPENEXR_VERSION"
1476       mkdir -p $SRC
1477
1478       if [ "$OPENEXR_USE_REPO" = true ]; then
1479         git clone ${OPENEXR_SOURCE_REPO[0]} $_src
1480       else
1481         download OPENEXR_SOURCE[@] $_src.tar.gz
1482         INFO "Unpacking OpenEXR-$OPENEXR_VERSION"
1483         tar -C $SRC --transform "s,(.*/?)openexr[^/]*(.*),\1OpenEXR-$OPENEXR_VERSION\2,x" -xf $_src.tar.gz
1484       fi
1485
1486     fi
1487
1488     cd $_src
1489
1490     if [ "$OPENEXR_USE_REPO" = true ]; then
1491       # XXX For now, always update from latest repo...
1492       git pull origin master
1493       # Stick to same rev as windows' libs...
1494       git checkout $OPENEXR_SOURCE_REPO_UID
1495       git reset --hard
1496       oiio_src_path="../OpenEXR"
1497     else
1498       oiio_src_path=".."
1499     fi
1500
1501     # Always refresh the whole build!
1502     if [ -d build ]; then
1503       rm -rf build
1504     fi
1505     mkdir build
1506     cd build
1507
1508     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1509     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1510     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1511     cmake_d="$cmake_d -D ILMBASE_PACKAGE_PREFIX=$_ilmbase_inst"
1512     cmake_d="$cmake_d -D BUILD_SHARED_LIBS=ON"
1513     cmake_d="$cmake_d -D NAMESPACE_VERSIONING=OFF"  # VERY IMPORTANT!!!
1514
1515     if file /bin/cp | grep -q '32-bit'; then
1516       cflags="-fPIC -m32 -march=i686"
1517     else
1518       cflags="-fPIC"
1519     fi
1520
1521     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" $oiio_src_path
1522
1523     make -j$THREADS && make install
1524
1525     make clean
1526
1527     if [ -d $_inst ]; then
1528       _create_inst_shortcut
1529       # Copy ilmbase files here (blender expects same dir for ilmbase and openexr :/).
1530       cp -an $_ilmbase_inst/* $_inst_shortcut
1531     else
1532       ERROR "OpenEXR-$OPENEXR_VERSION failed to compile, exiting"
1533       exit 1
1534     fi
1535
1536     magic_compile_set openexr-$OPENEXR_VERSION $openexr_magic
1537
1538     cd $CWD
1539     INFO "Done compiling OpenEXR-$OPENEXR_VERSION!"
1540   else
1541     INFO "Own OpenEXR-$OPENEXR_VERSION is up to date, nothing to do!"
1542     INFO "If you want to force rebuild of this lib, use the --force-openexr option."
1543   fi
1544
1545   _with_built_openexr=true
1546
1547   # Just always run it, much simpler this way!
1548   run_ldconfig "openexr"
1549 }
1550
1551 #### Build OIIO ####
1552 _init_oiio() {
1553   _src=$SRC/OpenImageIO-$OIIO_VERSION
1554   _git=true
1555   _inst=$INST/oiio-$OIIO_VERSION
1556   _inst_shortcut=$INST/oiio
1557 }
1558
1559 clean_OIIO() {
1560   _init_oiio
1561   _clean
1562 }
1563
1564 compile_OIIO() {
1565   if [ "$NO_BUILD" = true ]; then
1566     WARNING "--no-build enabled, OpenImageIO will not be compiled!"
1567     return
1568   fi
1569
1570   # To be changed each time we make edits that would modify the compiled result!
1571   oiio_magic=16
1572   _init_oiio
1573
1574   # Clean install if needed!
1575   magic_compile_check oiio-$OIIO_VERSION $oiio_magic
1576   if [ $? -eq 1 -o "$OIIO_FORCE_REBUILD" = true ]; then
1577     clean_OIIO
1578   fi
1579
1580   if [ ! -d $_inst ]; then
1581     INFO "Building OpenImageIO-$OIIO_VERSION"
1582
1583     # Rebuild dependecies as well!
1584     OSL_FORCE_BUILD=true
1585     OSL_FORCE_REBUILD=true
1586
1587     prepare_opt
1588
1589     if [ ! -d $_src ]; then
1590       mkdir -p $SRC
1591
1592       if [ "$OIIO_USE_REPO" = true ]; then
1593         git clone ${OIIO_SOURCE_REPO[0]} $_src
1594       else
1595         download OIIO_SOURCE[@] "$_src.tar.gz"
1596         INFO "Unpacking OpenImageIO-$OIIO_VERSION"
1597         tar -C $SRC --transform "s,(.*/?)oiio-Release-[^/]*(.*),\1OpenImageIO-$OIIO_VERSION\2,x" -xf $_src.tar.gz
1598       fi
1599     fi
1600
1601     cd $_src
1602
1603     if [ "$OIIO_USE_REPO" = true ]; then
1604       # XXX For now, always update from latest repo...
1605       git pull origin master
1606       # Stick to same rev as windows' libs...
1607       git checkout $OIIO_SOURCE_REPO_UID
1608       git reset --hard
1609     fi
1610
1611     # Always refresh the whole build!
1612     if [ -d build ]; then
1613       rm -rf build
1614     fi
1615     mkdir build
1616     cd build
1617
1618     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1619     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1620     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1621     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1622     cmake_d="$cmake_d -D BUILDSTATIC=OFF"
1623     cmake_d="$cmake_d -D LINKSTATIC=OFF"
1624     cmake_d="$cmake_d -D USE_SIMD=sse2"
1625
1626     cmake_d="$cmake_d -D ILMBASE_VERSION=$ILMBASE_VERSION"
1627     cmake_d="$cmake_d -D OPENEXR_VERSION=$OPENEXR_VERSION"
1628
1629     if [ "$_with_built_openexr" = true ]; then
1630       cmake_d="$cmake_d -D ILMBASE_HOME=$INST/openexr"
1631       cmake_d="$cmake_d -D OPENEXR_HOME=$INST/openexr"
1632       INFO "ILMBASE_HOME=$INST/openexr"
1633     fi
1634
1635     # Optional tests and cmd tools
1636     cmake_d="$cmake_d -D USE_QT=OFF"
1637     cmake_d="$cmake_d -D USE_PYTHON=OFF"
1638     cmake_d="$cmake_d -D USE_FFMPEG=OFF"
1639     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1640     cmake_d="$cmake_d -D OIIO_BUILD_TESTS=OFF"
1641     cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=OFF"
1642     #cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1643     #cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1644
1645     if [ -d $INST/boost ]; then
1646       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1647     fi
1648
1649     # Looks like we do not need ocio in oiio for now...
1650 #    if [ -d $INST/ocio ]; then
1651 #      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
1652 #    fi
1653     cmake_d="$cmake_d -D USE_OCIO=OFF"
1654
1655     if [ "$USE_CXX11" = true ]; then
1656       cmake_d="$cmake_d -D OIIO_BUILD_CPP11=ON"
1657     fi
1658
1659     if file /bin/cp | grep -q '32-bit'; then
1660       cflags="-fPIC -m32 -march=i686"
1661     else
1662       cflags="-fPIC"
1663     fi
1664
1665     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1666
1667     make -j$THREADS && make install
1668     make clean
1669
1670     if [ -d $_inst ]; then
1671       _create_inst_shortcut
1672     else
1673       ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
1674       exit 1
1675     fi
1676
1677     magic_compile_set oiio-$OIIO_VERSION $oiio_magic
1678
1679     cd $CWD
1680     INFO "Done compiling OpenImageIO-$OIIO_VERSION!"
1681   else
1682     INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
1683     INFO "If you want to force rebuild of this lib, use the --force-oiio option."
1684   fi
1685
1686   # Just always run it, much simpler this way!
1687   run_ldconfig "oiio"
1688 }
1689
1690 #### Build LLVM ####
1691 _init_llvm() {
1692   _src=$SRC/LLVM-$LLVM_VERSION
1693   _src_clang=$SRC/CLANG-$LLVM_VERSION
1694   _git=false
1695   _inst=$INST/llvm-$LLVM_VERSION
1696   _inst_shortcut=$INST/llvm
1697 }
1698
1699 clean_LLVM() {
1700   _init_llvm
1701   _clean
1702 }
1703
1704 compile_LLVM() {
1705   if [ "$NO_BUILD" = true ]; then
1706     WARNING "--no-build enabled, LLVM will not be compiled!"
1707     return
1708   fi
1709
1710   # To be changed each time we make edits that would modify the compiled result!
1711   llvm_magic=3
1712   _init_llvm
1713
1714   # Clean install if needed!
1715   magic_compile_check llvm-$LLVM_VERSION $llvm_magic
1716   if [ $? -eq 1 -o "$LLVM_FORCE_REBUILD" = true ]; then
1717     clean_LLVM
1718   fi
1719
1720   if [ ! -d $_inst ]; then
1721     INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
1722
1723     # Rebuild dependecies as well!
1724     OSL_FORCE_BUILD=true
1725     OSL_FORCE_REBUILD=true
1726
1727     prepare_opt
1728
1729     if [ ! -d $_src -o true ]; then
1730       mkdir -p $SRC
1731       download LLVM_SOURCE[@] "$_src.tar.gz"
1732       download LLVM_CLANG_SOURCE[@] "$_src_clang.tar.gz"
1733
1734       INFO "Unpacking LLVM-$LLVM_VERSION"
1735       tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
1736           -xf $_src.tar.gz
1737       INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
1738       # Stupid clang guys renamed 'clang' to 'cfe' for now handle both cases... :(
1739       tar -C $_src/tools \
1740           --transform "s,([^/]*/?)(clang|cfe)-[^/]*(.*),\1clang\3,x" \
1741           -xf $_src_clang.tar.gz
1742
1743       cd $_src
1744
1745       # XXX Ugly patching hack!
1746       patch -p1 -i "$SCRIPT_DIR/install_deps_patches/llvm.patch"
1747
1748       cd $CWD
1749
1750     fi
1751
1752     cd $_src
1753
1754     # Always refresh the whole build!
1755     if [ -d build ]; then
1756       rm -rf build
1757     fi
1758     mkdir build
1759     cd build
1760
1761     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1762     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1763     cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
1764     cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
1765     cmake_d="$cmake_d -D LLVM_ENABLE_TERMINFO=OFF"
1766
1767     if [ -d $_FFI_INCLUDE_DIR ]; then
1768       cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
1769     fi
1770
1771     cmake $cmake_d ..
1772
1773     make -j$THREADS && make install
1774     make clean
1775
1776     if [ -d $_inst ]; then
1777       _create_inst_shortcut
1778     else
1779       ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
1780       exit 1
1781     fi
1782
1783     magic_compile_set llvm-$LLVM_VERSION $llvm_magic
1784
1785     cd $CWD
1786     INFO "Done compiling LLVM-$LLVM_VERSION (CLANG included)!"
1787   else
1788     INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
1789     INFO "If you want to force rebuild of this lib, use the --force-llvm option."
1790   fi
1791 }
1792
1793 #### Build OSL ####
1794 _init_osl() {
1795   _src=$SRC/OpenShadingLanguage-$OSL_VERSION
1796   _git=true
1797   _inst=$INST/osl-$OSL_VERSION
1798   _inst_shortcut=$INST/osl
1799 }
1800
1801 clean_OSL() {
1802   _init_osl
1803   _clean
1804 }
1805
1806 compile_OSL() {
1807   if [ "$NO_BUILD" = true ]; then
1808     WARNING "--no-build enabled, OpenShadingLanguage will not be compiled!"
1809     return
1810   fi
1811
1812   # To be changed each time we make edits that would modify the compiled result!
1813   osl_magic=21
1814   _init_osl
1815
1816   # Clean install if needed!
1817   magic_compile_check osl-$OSL_VERSION $osl_magic
1818   if [ $? -eq 1 -o "$OSL_FORCE_REBUILD" = true ]; then
1819     #~ rm -Rf $_src  # XXX Radical, but not easy to change remote repo fully automatically
1820     clean_OSL
1821   fi
1822
1823   if [ ! -d $_inst ]; then
1824     INFO "Building OpenShadingLanguage-$OSL_VERSION"
1825
1826     prepare_opt
1827
1828     if [ ! -d $_src ]; then
1829       mkdir -p $SRC
1830
1831       if [ "$OSL_USE_REPO" = true ]; then
1832         git clone ${OSL_SOURCE_REPO[0]} $_src
1833       else
1834         download OSL_SOURCE[@] "$_src.tar.gz"
1835         INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
1836         tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
1837             -xf $_src.tar.gz
1838       fi
1839     fi
1840
1841     cd $_src
1842
1843     if [ "$OSL_USE_REPO" = true ]; then
1844       git remote set-url origin ${OSL_SOURCE_REPO[0]}
1845       # XXX For now, always update from latest repo...
1846       git pull --no-edit -X theirs origin $OSL_SOURCE_REPO_BRANCH
1847       # Stick to same rev as windows' libs...
1848       git checkout $OSL_SOURCE_REPO_UID
1849       git reset --hard
1850
1851       # XXX Ugly patching hack!
1852       patch -p1 -i "$SCRIPT_DIR/install_deps_patches/osl.patch"
1853     fi
1854
1855     # Always refresh the whole build!
1856     if [ -d build ]; then
1857       rm -rf build
1858     fi
1859     mkdir build
1860     cd build
1861
1862     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1863     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1864     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1865     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1866     cmake_d="$cmake_d -D BUILDSTATIC=OFF"
1867     cmake_d="$cmake_d -D OSL_BUILD_PLUGINS=OFF"
1868     cmake_d="$cmake_d -D OSL_BUILD_TESTS=OFF"
1869     cmake_d="$cmake_d -D USE_SIMD=sse2"
1870     if [ "$USE_CXX11" = true ]; then
1871         cmake_d="$cmake_d -D OSL_BUILD_CPP11=1"
1872     fi
1873
1874     #~ cmake_d="$cmake_d -D ILMBASE_VERSION=$ILMBASE_VERSION"
1875
1876     if [ "$_with_built_openexr" = true ]; then
1877       INFO "ILMBASE_HOME=$INST/openexr"
1878       cmake_d="$cmake_d -D ILMBASE_HOME=$INST/openexr"
1879       # XXX Temp workaround... sigh, ILMBase really messed the things up by defining their custom names ON by default :(
1880       cmake_d="$cmake_d -D ILMBASE_CUSTOM=ON"
1881       cmake_d="$cmake_d -D ILMBASE_CUSTOM_LIBRARIES='Half;Iex;Imath;IlmThread'"
1882     fi
1883
1884     if [ -d $INST/boost ]; then
1885       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1886     fi
1887
1888     if [ -d $INST/oiio ]; then
1889       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
1890     fi
1891
1892     if [ ! -z $LLVM_VERSION_FOUND ]; then
1893       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1894       if [ -d $INST/llvm ]; then
1895         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
1896         cmake_d="$cmake_d -D LLVM_STATIC=ON"
1897       fi
1898     fi
1899
1900     #~ cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1901     #~ cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1902
1903     cmake $cmake_d ..
1904
1905     make -j$THREADS && make install
1906     make clean
1907
1908     if [ -d $_inst ]; then
1909       _create_inst_shortcut
1910     else
1911       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
1912       exit 1
1913     fi
1914
1915     magic_compile_set osl-$OSL_VERSION $osl_magic
1916
1917     cd $CWD
1918     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
1919   else
1920     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
1921     INFO "If you want to force rebuild of this lib, use the --force-osl option."
1922   fi
1923
1924   run_ldconfig "osl"
1925 }
1926
1927 #### Build OSD ####
1928 _init_osd() {
1929   _src=$SRC/OpenSubdiv-$OSD_VERSION
1930   _git=true
1931   _inst=$INST/osd-$OSD_VERSION
1932   _inst_shortcut=$INST/osd
1933 }
1934
1935 clean_OSD() {
1936   _init_osd
1937   _clean
1938 }
1939
1940 compile_OSD() {
1941   if [ "$NO_BUILD" = true ]; then
1942     WARNING "--no-build enabled, OpenSubdiv will not be compiled!"
1943     return
1944   fi
1945
1946   # To be changed each time we make edits that would modify the compiled result!
1947   osd_magic=2
1948   _init_osd
1949
1950   # Clean install if needed!
1951   magic_compile_check osd-$OSD_VERSION $osd_magic
1952   if [ $? -eq 1 -o "$OSD_FORCE_REBUILD" = true ]; then
1953     clean_OSD
1954   fi
1955
1956   if [ ! -d $_inst ]; then
1957     INFO "Building OpenSubdiv-$OSD_VERSION"
1958
1959     prepare_opt
1960
1961     if [ ! -d $_src ]; then
1962       mkdir -p $SRC
1963
1964       if [ "$OSD_USE_REPO" = true ]; then
1965         git clone ${OSD_SOURCE_REPO[0]} $_src
1966       else
1967         download OSD_SOURCE[@] "$_src.tar.gz"
1968         INFO "Unpacking OpenSubdiv-$OSD_VERSION"
1969         tar -C $SRC --transform "s,(.*/?)OpenSubdiv-[^/]*(.*),\1OpenSubdiv-$OSD_VERSION\2,x" \
1970             -xf $_src.tar.gz
1971       fi
1972     fi
1973
1974     cd $_src
1975
1976     if [ "$OSD_USE_REPO" = true ]; then
1977       git remote set-url origin ${OSD_SOURCE_REPO[0]}
1978       # XXX For now, always update from latest repo...
1979       git pull --no-edit -X theirs origin $OSD_SOURCE_REPO_BRANCH
1980       # Stick to same rev as windows' libs...
1981       git checkout $OSD_SOURCE_REPO_UID
1982       git reset --hard
1983     fi
1984
1985     # Always refresh the whole build!
1986     if [ -d build ]; then
1987       rm -rf build
1988     fi
1989     mkdir build
1990     cd build
1991
1992     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1993     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1994     # ptex is only needed when nicholas bishop is ready
1995     cmake_d="$cmake_d -D NO_PTEX=1"
1996     cmake_d="$cmake_d -D NO_CLEW=1 -D NO_CUDA=1 -D NO_OPENCL=1"
1997     # maya plugin, docs, tutorials, regression tests and examples are not needed
1998     cmake_d="$cmake_d -D NO_MAYA=1 -D NO_DOC=1 -D NO_TUTORIALS=1 -D NO_REGRESSION=1 -DNO_EXAMPLES=1"
1999
2000     cmake $cmake_d ..
2001
2002     make -j$THREADS && make install
2003     make clean
2004
2005     if [ -d $_inst ]; then
2006       _create_inst_shortcut
2007     else
2008       ERROR "OpenSubdiv-$OSD_VERSION failed to compile, exiting"
2009       exit 1
2010     fi
2011
2012     magic_compile_set osd-$OSD_VERSION $osd_magic
2013
2014     cd $CWD
2015     INFO "Done compiling OpenSubdiv-$OSD_VERSION!"
2016   else
2017     INFO "Own OpenSubdiv-$OSD_VERSION is up to date, nothing to do!"
2018     INFO "If you want to force rebuild of this lib, use the --force-osd option."
2019   fi
2020
2021   run_ldconfig "osd"
2022 }
2023
2024 #### Build Blosc ####
2025 _init_blosc() {
2026   _src=$SRC/c-blosc-$OPENVDB_BLOSC_VERSION
2027   _git=false
2028   _inst=$INST/blosc-$OPENVDB_BLOSC_VERSION
2029   _inst_shortcut=$INST/blosc
2030 }
2031
2032 clean_BLOSC() {
2033   _init_blosc
2034   _clean
2035 }
2036
2037 compile_BLOSC() {
2038   if [ "$NO_BUILD" = true ]; then
2039     WARNING "--no-build enabled, Blosc will not be compiled!"
2040     return
2041   fi
2042
2043   # To be changed each time we make edits that would modify the compiled result!
2044   blosc_magic=0
2045   _init_blosc
2046
2047   # Clean install if needed!
2048   magic_compile_check blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
2049   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
2050     clean_BLOSC
2051     rm -rf $_inst
2052   fi
2053
2054   if [ ! -d $_inst ]; then
2055     INFO "Building Blosc-$OPENVDB_BLOSC_VERSION"
2056
2057     # Rebuild dependecies as well!
2058     OPENVDB_FORCE_BUILD=true
2059     OPENVDB_FORCE_REBUILD=true
2060
2061     prepare_opt
2062
2063     if [ ! -d $_src ]; then
2064       INFO "Downloading Blosc-$OPENVDB_BLOSC_VERSION"
2065       mkdir -p $SRC
2066       download OPENVDB_BLOSC_SOURCE[@] $_src.tar.gz
2067
2068       INFO "Unpacking Blosc-$OPENVDB_BLOSC_VERSION"
2069       tar -C $SRC -xf $_src.tar.gz
2070     fi
2071
2072     cd $_src
2073     # Always refresh the whole build!
2074     if [ -d build ]; then
2075       rm -rf build
2076     fi
2077     mkdir build
2078     cd build
2079
2080     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2081     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2082     cmake_d="$cmake_d -D BUILD_STATIC=OFF"
2083     cmake_d="$cmake_d -D BUILD_TESTS=OFF"
2084     cmake_d="$cmake_d -D BUILD_BENCHMARKS=OFF"
2085     INFO "$cmake_d"
2086
2087     cmake $cmake_d ..
2088
2089     make -j$THREADS && make install
2090
2091     make clean
2092
2093     if [ -d $_inst ]; then
2094       _create_inst_shortcut
2095     else
2096       ERROR "Blosc-$OPENVDB_BLOSC_VERSION failed to compile, exiting"
2097       exit 1
2098     fi
2099     cd $CWD
2100     INFO "Done compiling Blosc-$OPENVDB_BLOSC_VERSION!"
2101   else
2102     INFO "Own Blosc-$OPENVDB_BLOSC_VERSION is up to date, nothing to do!"
2103     INFO "If you want to force rebuild of this lib (and openvdb), use the --force-openvdb option."
2104   fi
2105
2106   magic_compile_set blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
2107
2108   run_ldconfig "blosc"
2109 }
2110
2111 #### Build OpenVDB ####
2112 _init_openvdb() {
2113   _src=$SRC/openvdb-$OPENVDB_VERSION
2114   _git=false
2115   _inst=$INST/openvdb-$OPENVDB_VERSION
2116   _inst_shortcut=$INST/openvdb
2117 }
2118
2119 clean_OPENVDB() {
2120   _init_openvdb
2121   _clean
2122 }
2123
2124 compile_OPENVDB() {
2125   if [ "$NO_BUILD" = true ]; then
2126     WARNING "--no-build enabled, OpenVDB will not be compiled!"
2127     return
2128   fi
2129
2130   compile_BLOSC
2131   PRINT ""
2132
2133   # To be changed each time we make edits that would modify the compiled result!
2134   openvdb_magic=1
2135   _init_openvdb
2136
2137   # Clean install if needed!
2138   magic_compile_check openvdb-$OPENVDB_VERSION $openvdb_magic
2139   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
2140     clean_OPENVDB
2141   fi
2142
2143   if [ ! -d $_inst ]; then
2144     INFO "Building OpenVDB-$OPENVDB_VERSION"
2145
2146     prepare_opt
2147
2148     if [ ! -d $_src -o true ]; then
2149       mkdir -p $SRC
2150       download OPENVDB_SOURCE[@] "$_src.tar.gz"
2151
2152       INFO "Unpacking OpenVDB-$OPENVDB_VERSION"
2153       tar -C $SRC -xf $_src.tar.gz
2154     fi
2155
2156     cd $_src
2157
2158     #~ if [ "$OPENVDB_USE_REPO" = true ]; then
2159       #~ git remote set-url origin ${OPENVDB_SOURCE_REPO[0]}
2160       #~ # XXX For now, always update from latest repo...
2161       #~ git pull --no-edit -X theirs origin $OPENVDB_SOURCE_REPO_BRANCH
2162       #~ # Stick to same rev as windows' libs...
2163       #~ git checkout $OPENVDB_SOURCE_REPO_UID
2164       #~ git reset --hard
2165     #~ fi
2166
2167     # Source builds here
2168     cd openvdb
2169
2170     make_d="DESTDIR=$_inst"
2171     make_d="$make_d HDSO=/usr"
2172
2173     if [ -d $INST/boost ]; then
2174       make_d="$make_d BOOST_INCL_DIR=$INST/boost/include BOOST_LIB_DIR=$INST/boost/lib"
2175     fi
2176
2177     if [ "$_with_built_openexr" = true ]; then
2178       make_d="$make_d ILMBASE_INCL_DIR=$INST/openexr/include ILMBASE_LIB_DIR=$INST/openexr/lib"
2179       make_d="$make_d EXR_INCL_DIR=$INST/openexr/include EXR_LIB_DIR=$INST/openexr/lib"
2180       INFO "ILMBASE_HOME=$INST/openexr"
2181     fi
2182
2183     if [ -d $INST/blosc ]; then
2184       make_d="$make_d BLOSC_INCL_DIR=$INST/blosc/include BLOSC_LIB_DIR=$INST/blosc/lib"
2185     fi
2186
2187     # Build without log4cplus, glfw, python module & docs
2188     make_d="$make_d LOG4CPLUS_INCL_DIR= GLFW_INCL_DIR= PYTHON_VERSION= DOXYGEN="
2189
2190     make -j$THREADS lib $make_d install
2191     make clean
2192
2193     if [ -d $_inst ]; then
2194       _create_inst_shortcut
2195     else
2196       ERROR "OpenVDB-$OPENVDB_VERSION failed to compile, exiting"
2197       exit 1
2198     fi
2199
2200     magic_compile_set openvdb-$OPENVDB_VERSION $openvdb_magic
2201
2202     cd $CWD
2203     INFO "Done compiling OpenVDB-$OPENVDB_VERSION!"
2204   else
2205     INFO "Own OpenVDB-$OPENVDB_VERSION is up to date, nothing to do!"
2206     INFO "If you want to force rebuild of this lib, use the --force-openvdb option."
2207   fi
2208
2209   run_ldconfig "openvdb"
2210 }
2211
2212 #### Build Alembic ####
2213 _init_alembic() {
2214   _src=$SRC/alembic-$ALEMBIC_VERSION
2215   _git=false
2216   _inst=$INST/alembic-$ALEMBIC_VERSION
2217   _inst_shortcut=$INST/alembic
2218 }
2219
2220 clean_ALEMBIC() {
2221   _init_alembic
2222   _clean
2223 }
2224
2225 compile_ALEMBIC() {
2226   if [ "$NO_BUILD" = true ]; then
2227     WARNING "--no-build enabled, Alembic will not be compiled!"
2228     return
2229   fi
2230
2231   # To be changed each time we make edits that would modify the compiled result!
2232   alembic_magic=2
2233   _init_alembic
2234
2235   # Clean install if needed!
2236   magic_compile_check alembic-$ALEMBIC_VERSION $alembic_magic
2237   if [ $? -eq 1 -o "$ALEMBIC_FORCE_REBUILD" = true ]; then
2238     clean_ALEMBIC
2239   fi
2240
2241   if [ ! -d $_inst ]; then
2242     INFO "Building Alembic-$ALEMBIC_VERSION"
2243
2244     prepare_opt
2245
2246     if [ ! -d $_src -o true ]; then
2247       mkdir -p $SRC
2248       download ALEMBIC_SOURCE[@] "$_src.tar.gz"
2249
2250       INFO "Unpacking Alembic-$ALEMBIC_VERSION"
2251       tar -C $SRC -xf $_src.tar.gz
2252     fi
2253
2254     cd $_src
2255
2256     cmake_d="-D CMAKE_INSTALL_PREFIX=$_inst"
2257
2258     # Without Boost or TR1, Alembic requires C++11.
2259     if [ "$USE_CXX11" != true ]; then
2260       cmake_d="$cmake_d -D ALEMBIC_LIB_USES_BOOST=ON"
2261       cmake_d="$cmake_d -D ALEMBIC_LIB_USES_TR1=OFF"
2262     fi
2263
2264     if [ -d $INST/boost ]; then
2265       if [ -d $INST/boost ]; then
2266         cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost"
2267       fi
2268       cmake_d="$cmake_d -D USE_STATIC_BOOST=ON"
2269     else
2270       cmake_d="$cmake_d -D USE_STATIC_BOOST=OFF"
2271     fi
2272
2273     if [ "$_with_built_openexr" = true ]; then
2274       cmake_d="$cmake_d -D ILMBASE_ROOT=$INST/openexr"
2275       cmake_d="$cmake_d -D USE_ARNOLD=OFF"
2276       cmake_d="$cmake_d -D USE_BINARIES=OFF"
2277       cmake_d="$cmake_d -D USE_EXAMPLES=OFF"
2278       cmake_d="$cmake_d -D USE_HDF5=OFF"
2279       cmake_d="$cmake_d -D USE_MAYA=OFF"
2280       cmake_d="$cmake_d -D USE_PRMAN=OFF"
2281       cmake_d="$cmake_d -D USE_PYALEMBIC=OFF"
2282       cmake_d="$cmake_d -D USE_STATIC_HDF5=OFF"
2283       cmake_d="$cmake_d -D ALEMBIC_ILMBASE_LINK_STATIC=OFF"
2284       cmake_d="$cmake_d -D ALEMBIC_SHARED_LIBS=OFF"
2285       INFO "ILMBASE_ROOT=$INST/openexr"
2286     fi
2287
2288     cmake $cmake_d ./
2289     make -j$THREADS install
2290     make clean
2291
2292     if [ -d $_inst ]; then
2293       _create_inst_shortcut
2294     else
2295       ERROR "Alembic-$ALEMBIC_VERSION failed to compile, exiting"
2296       exit 1
2297     fi
2298
2299     magic_compile_set alembic-$ALEMBIC_VERSION $alembic_magic
2300
2301     cd $CWD
2302     INFO "Done compiling Alembic-$ALEMBIC_VERSION!"
2303   else
2304     INFO "Own Alembic-$ALEMBIC_VERSION is up to date, nothing to do!"
2305     INFO "If you want to force rebuild of this lib, use the --force-alembic option."
2306   fi
2307
2308   run_ldconfig "alembic"
2309 }
2310
2311 #### Build OpenCOLLADA ####
2312 _init_opencollada() {
2313   _src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
2314   _git=true
2315   _inst=$INST/opencollada-$OPENCOLLADA_VERSION
2316   _inst_shortcut=$INST/opencollada
2317 }
2318
2319 clean_OpenCOLLADA() {
2320   _init_opencollada
2321   _clean
2322 }
2323
2324 compile_OpenCOLLADA() {
2325   if [ "$NO_BUILD" = true ]; then
2326     WARNING "--no-build enabled, OpenCOLLADA will not be compiled!"
2327     return
2328   fi
2329
2330   # To be changed each time we make edits that would modify the compiled results!
2331   opencollada_magic=9
2332   _init_opencollada
2333
2334   # Clean install if needed!
2335   magic_compile_check opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2336   if [ $? -eq 1 -o "$OPENCOLLADA_FORCE_REBUILD" = true ]; then
2337     clean_OpenCOLLADA
2338   fi
2339
2340   if [ ! -d $_inst ]; then
2341     INFO "Building OpenCOLLADA-$OPENCOLLADA_VERSION"
2342
2343     prepare_opt
2344
2345     if [ ! -d $_src ]; then
2346       mkdir -p $SRC
2347       git clone $OPENCOLLADA_SOURCE $_src
2348     fi
2349
2350     cd $_src
2351
2352     # XXX For now, always update from latest repo...
2353     git pull origin $OPENCOLLADA_REPO_BRANCH
2354
2355     # Stick to same rev as windows' libs...
2356     git checkout $OPENCOLLADA_REPO_UID
2357     git reset --hard
2358
2359     # Always refresh the whole build!
2360     if [ -d build ]; then
2361       rm -rf build
2362     fi
2363     mkdir build
2364     cd build
2365
2366     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2367     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2368     cmake_d="$cmake_d -D USE_EXPAT=OFF"
2369     cmake_d="$cmake_d -D USE_LIBXML=ON"
2370     # XXX Does not work!
2371 #    cmake_d="$cmake_d -D USE_STATIC=OFF"
2372     cmake_d="$cmake_d -D USE_STATIC=ON"
2373
2374     cmake $cmake_d ../
2375
2376     make -j$THREADS && make install
2377     make clean
2378
2379     if [ -d $_inst ]; then
2380       _create_inst_shortcut
2381     else
2382       ERROR "OpenCOLLADA-$OPENCOLLADA_VERSION failed to compile, exiting"
2383       exit 1
2384     fi
2385
2386     magic_compile_set opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2387
2388     cd $CWD
2389     INFO "Done compiling OpenCOLLADA-$OPENCOLLADA_VERSION!"
2390   else
2391     INFO "Own OpenCOLLADA-$OPENCOLLADA_VERSION is up to date, nothing to do!"
2392     INFO "If you want to force rebuild of this lib, use the --force-opencollada option."
2393   fi
2394 }
2395
2396 #### Build FFMPEG ####
2397 _init_ffmpeg() {
2398   _src=$SRC/ffmpeg-$FFMPEG_VERSION
2399   _inst=$INST/ffmpeg-$FFMPEG_VERSION
2400   _inst_shortcut=$INST/ffmpeg
2401 }
2402
2403 clean_FFmpeg() {
2404   _init_ffmpeg
2405   _clean
2406 }
2407
2408 compile_FFmpeg() {
2409   if [ "$NO_BUILD" = true ]; then
2410     WARNING "--no-build enabled, ffmpeg will not be compiled!"
2411     return
2412   fi
2413
2414   # To be changed each time we make edits that would modify the compiled result!
2415   ffmpeg_magic=5
2416   _init_ffmpeg
2417
2418   # Clean install if needed!
2419   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2420   if [ $? -eq 1 -o "$FFMPEG_FORCE_REBUILD" = true ]; then
2421     clean_FFmpeg
2422   fi
2423
2424   if [ ! -d $_inst ]; then
2425     INFO "Building ffmpeg-$FFMPEG_VERSION"
2426
2427     prepare_opt
2428
2429     if [ ! -d $_src ]; then
2430       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
2431       mkdir -p $SRC
2432       download FFMPEG_SOURCE[@] "$_src.tar.bz2"
2433
2434       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
2435       tar -C $SRC -xf $_src.tar.bz2
2436     fi
2437
2438     cd $_src
2439
2440     extra=""
2441
2442     if [ "$VORBIS_USE" = true ]; then
2443       extra="$extra --enable-libvorbis"
2444     fi
2445
2446     if [ "$THEORA_USE" = true ]; then
2447       extra="$extra --enable-libtheora"
2448     fi
2449
2450     if [ "$XVID_USE" = true ]; then
2451       extra="$extra --enable-libxvid"
2452     fi
2453
2454     if [ "$X264_USE" = true ]; then
2455       extra="$extra --enable-libx264"
2456     fi
2457
2458     if [ "$VPX_USE" = true ]; then
2459       extra="$extra --enable-libvpx"
2460     fi
2461
2462     if [ "$MP3LAME_USE" = true ]; then
2463       extra="$extra --enable-libmp3lame"
2464     fi
2465
2466     if [ "$OPENJPEG_USE" = true ]; then
2467       extra="$extra --enable-libopenjpeg"
2468     fi
2469
2470     ./configure --cc="gcc -Wl,--as-needed" \
2471         --extra-ldflags="-pthread -static-libgcc" \
2472         --prefix=$_inst --enable-static \
2473         --disable-ffplay --disable-ffserver --disable-doc \
2474         --enable-gray \
2475         --enable-avfilter --disable-vdpau \
2476         --disable-bzlib --disable-libgsm --disable-libspeex \
2477         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
2478         --disable-vaapi --disable-nonfree --enable-gpl \
2479         --disable-postproc --disable-librtmp --disable-libopencore-amrnb \
2480         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3 --disable-outdev=sdl \
2481         --disable-libxcb \
2482         --disable-outdev=xv --disable-indev=sndio --disable-outdev=sndio \
2483         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
2484         --disable-indev=lavfi $extra
2485
2486     make -j$THREADS && make install
2487     make clean
2488
2489     if [ -d $_inst ]; then
2490       _create_inst_shortcut
2491     else
2492       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
2493       exit 1
2494     fi
2495
2496     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2497
2498     cd $CWD
2499     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
2500   else
2501     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
2502     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
2503   fi
2504 }
2505
2506
2507 #### Install on DEB-like ####
2508 get_package_version_DEB() {
2509     dpkg-query -W -f '${Version}' $1 | sed -r 's/([0-9]+:)?(([0-9]+\.?)+([0-9]+)).*/\2/'
2510 }
2511
2512 check_package_DEB() {
2513   r=`apt-cache show $1 | grep -c 'Package:'`
2514
2515   if [ $r -ge 1 ]; then
2516     return 0
2517   else
2518     return 1
2519   fi
2520 }
2521
2522 check_package_installed_DEB() {
2523   r=`dpkg-query -W -f='${Status}' $1 | grep -c "install ok"`
2524
2525   if [ $r -ge 1 ]; then
2526     return 0
2527   else
2528     return 1
2529   fi
2530 }
2531
2532 check_package_version_match_DEB() {
2533   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
2534
2535   if [ -z "$v" ]; then
2536     return 1
2537   fi
2538
2539   version_match $v $2
2540   return $?
2541 }
2542
2543 check_package_version_ge_DEB() {
2544   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2545
2546   if [ -z "$v" ]; then
2547     return 1
2548   fi
2549
2550   version_ge $v $2
2551   return $?
2552 }
2553
2554 check_package_version_ge_lt_DEB() {
2555   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2556
2557   if [ -z "$v" ]; then
2558     return 1
2559   fi
2560
2561   version_ge_lt $v $2 $3
2562   return $?
2563 }
2564
2565 install_packages_DEB() {
2566   if [ ! $SUDO ]; then
2567     WARNING "--no-sudo enabled, impossible to run apt-get install for $@, you'll have to do it yourself..."
2568   else
2569     $SUDO apt-get install -y $@
2570     if [ $? -ge 1 ]; then
2571       ERROR "apt-get failed to install requested packages, exiting."
2572       exit 1
2573     fi
2574   fi
2575 }
2576
2577 install_DEB() {
2578   PRINT ""
2579   INFO "Installing dependencies for DEB-based distribution"
2580   PRINT ""
2581   PRINT "`eval _echo "$COMMON_INFO"`"
2582   PRINT ""
2583
2584   if [ "$NO_CONFIRM" = false ]; then
2585     read -p "Do you want to continue (Y/n)?"
2586     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
2587   fi
2588
2589   if [ ! $SUDO ]; then
2590     WARNING "--no-sudo enabled, impossible to run apt-get update, you'll have to do it yourself..."
2591   else
2592     $SUDO apt-get update
2593   fi
2594
2595   # These libs should always be available in debian/ubuntu official repository...
2596   OPENJPEG_DEV="libopenjpeg-dev"
2597   VORBIS_DEV="libvorbis-dev"
2598   OGG_DEV="libogg-dev"
2599   THEORA_DEV="libtheora-dev"
2600
2601   _packages="gawk cmake cmake-curses-gui build-essential libjpeg-dev libpng-dev libtiff-dev \
2602              git libfreetype6-dev libx11-dev flex bison libtbb-dev libxxf86vm-dev \
2603              libxcursor-dev libxi-dev wget libsqlite3-dev libxrandr-dev libxinerama-dev \
2604              libbz2-dev libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
2605              libopenal-dev libglew-dev yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV \
2606              libsdl1.2-dev libfftw3-dev patch bzip2 libxml2-dev libtinyxml-dev libjemalloc-dev"
2607              # libglewmx-dev  (broken in deb testing currently...)
2608
2609   OPENJPEG_USE=true
2610   VORBIS_USE=true
2611   OGG_USE=true
2612   THEORA_USE=true
2613
2614   PRINT ""
2615   # Some not-so-old distro (ubuntu 12.4) do not have it, do not fail in this case, just warn.
2616   YAMLCPP_DEV="libyaml-cpp-dev"
2617   check_package_DEB $YAMLCPP_DEV
2618   if [ $? -eq 0 ]; then
2619     _packages="$_packages $YAMLCPP_DEV"
2620   else
2621     PRINT ""
2622     WARNING "libyaml-cpp-dev not found, you may have to install it by hand to get Blender compiling..."
2623     PRINT ""
2624   fi
2625
2626   if [ "$WITH_ALL" = true ]; then
2627     _packages="$_packages libspnav-dev"
2628     # Only install jack if jack2 is not already installed!
2629     JACK="libjack-dev"
2630     JACK2="libjack-jackd2-dev"
2631     check_package_installed_DEB $JACK2
2632     if [ $? -eq 0 ]; then
2633       _packages="$_packages $JACK2"
2634     else
2635       _packages="$_packages $JACK"
2636     fi
2637   fi
2638
2639   PRINT ""
2640   install_packages_DEB $_packages
2641
2642   PRINT""
2643   SNDFILE_DEV="libsndfile1-dev"
2644   check_package_DEB $SNDFILE_DEV
2645   if [ $? -eq 0 ]; then
2646     install_packages_DEB $SNDFILE_DEV
2647   fi
2648
2649   PRINT ""
2650   X264_DEV="libx264-dev"
2651   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
2652   if [ $? -eq 0 ]; then
2653     install_packages_DEB $X264_DEV
2654     X264_USE=true
2655   fi
2656
2657   if [ "$WITH_ALL" = true ]; then
2658     PRINT ""
2659     XVID_DEV="libxvidcore-dev"
2660     check_package_DEB $XVID_DEV
2661     if [ $? -eq 0 ]; then
2662       install_packages_DEB $XVID_DEV
2663       XVID_USE=true
2664     fi
2665
2666     PRINT ""
2667     MP3LAME_DEV="libmp3lame-dev"
2668     check_package_DEB $MP3LAME_DEV
2669     if [ $? -eq 0 ]; then
2670       install_packages_DEB $MP3LAME_DEV
2671       MP3LAME_USE=true
2672     fi
2673
2674     PRINT ""
2675     VPX_DEV="libvpx-dev"
2676     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
2677     if [ $? -eq 0 ]; then
2678       install_packages_DEB $VPX_DEV
2679       VPX_USE=true
2680     fi
2681   fi
2682
2683   # Check cmake/glew versions and disable features for older distros.
2684   # This is so Blender can at least compile.
2685   PRINT ""
2686   _cmake=`get_package_version_DEB cmake`
2687   version_ge $_cmake "2.8.10"
2688   if [ $? -eq 1 ]; then
2689     version_ge $_cmake "2.8.8"
2690     if [ $? -eq 1 ]; then
2691       WARNING "OpenVDB and OpenCOLLADA disabled because cmake-$_cmake is not enough"
2692       OPENVDB_SKIP=true
2693       OPENCOLLADA_SKIP=true
2694     else
2695       WARNING "OpenVDB disabled because cmake-$_cmake is not enough"
2696       OPENVDB_SKIP=true
2697     fi
2698   fi
2699
2700   PRINT ""
2701   _glew=`get_package_version_DEB libglew-dev`
2702   if [ -z $_glew ]; then
2703     # Stupid virtual package in Ubuntu 12.04 doesn't show version number...
2704     _glew=`apt-cache showpkg libglew-dev|tail -n1|awk '{print $2}'|sed 's/-.*//'`
2705   fi
2706   version_ge $_glew "1.9.0"
2707   if [ $? -eq 1 ]; then
2708     version_ge $_glew "1.7.0"
2709     if [ $? -eq 1 ]; then
2710       WARNING "OpenSubdiv disabled because GLEW-$_glew is not enough"
2711       WARNING "Blender will not use system GLEW library"
2712       OSD_SKIP=true
2713       NO_SYSTEM_GLEW=true
2714     else
2715       WARNING "OpenSubdiv will compile with GLEW-$_glew but with limited capability"
2716       WARNING "Blender will not use system GLEW library"
2717       NO_SYSTEM_GLEW=true
2718     fi
2719   fi
2720
2721
2722   PRINT ""
2723   _do_compile_python=false
2724   if [ "$PYTHON_SKIP" = true ]; then
2725     WARNING "Skipping Python/NumPy installation, as requested..."
2726   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
2727     INFO "Forced Python/NumPy building, as requested..."
2728     _do_compile_python=true
2729   else
2730     check_package_DEB python$PYTHON_VERSION_MIN-dev
2731     if [ $? -eq 0 ]; then
2732       install_packages_DEB python$PYTHON_VERSION_MIN-dev
2733       clean_Python
2734       PRINT ""
2735       if [ "$NUMPY_SKIP" = true ]; then
2736         WARNING "Skipping NumPy installation, as requested..."
2737       else
2738         check_package_DEB python3-numpy
2739         if [ $? -eq 0 ]; then
2740           install_packages_DEB python3-numpy
2741         else
2742           WARNING "Sorry, using python package but no valid numpy package available!" \
2743                   "    Use --build-numpy to force building of both Python and NumPy."
2744         fi
2745       fi
2746     else
2747       _do_compile_python=true
2748     fi
2749   fi
2750
2751   if $_do_compile_python; then
2752     compile_Python
2753     PRINT ""
2754     if [ "$NUMPY_SKIP" = true ]; then
2755       WARNING "Skipping NumPy installation, as requested..."
2756     else
2757       compile_Numpy
2758     fi
2759   fi
2760
2761
2762   PRINT ""
2763   if [ "$BOOST_SKIP" = true ]; then
2764     WARNING "Skipping Boost installation, as requested..."
2765   elif [ "$BOOST_FORCE_BUILD" = true ]; then
2766     INFO "Forced Boost building, as requested..."
2767     compile_Boost
2768   else
2769     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
2770     if [ $? -eq 0 ]; then
2771       install_packages_DEB libboost-dev
2772
2773       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
2774
2775       install_packages_DEB libboost-{filesystem,iostreams,locale,regex,system,thread,wave,program-options}$boost_version-dev
2776       clean_Boost
2777     else
2778       compile_Boost
2779     fi
2780   fi
2781
2782
2783   PRINT ""
2784   if [ "$OCIO_SKIP" = true ]; then
2785     WARNING "Skipping OpenColorIO installation, as requested..."
2786   elif [ "$OCIO_FORCE_BUILD" = true ]; then
2787     INFO "Forced OpenColorIO building, as requested..."
2788     compile_OCIO
2789   else
2790     # XXX Always force build of own OCIO, until linux distro guys update their package to default libyaml-cpp ver (0.5)!
2791     #check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
2792     #if [ $? -eq 0 ]; then
2793       #install_packages_DEB libopencolorio-dev
2794       #clean_OCIO
2795     #else
2796       compile_OCIO
2797     #fi
2798   fi
2799
2800
2801   PRINT ""
2802   if [ "$OPENEXR_SKIP" = true ]; then
2803     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
2804   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
2805     INFO "Forced ILMBase/OpenEXR building, as requested..."
2806     compile_OPENEXR
2807   else
2808     check_package_version_ge_DEB libopenexr-dev $OPENEXR_VERSION_MIN
2809     if [ $? -eq 0 ]; then
2810       install_packages_DEB libopenexr-dev
2811       OPENEXR_VERSION=`get_package_version_DEB libopenexr-dev`
2812       ILMBASE_VERSION=$OPENEXR_VERSION
2813       clean_OPENEXR
2814     else
2815       compile_OPENEXR
2816     fi
2817   fi
2818
2819
2820   PRINT ""
2821   if [ "$OIIO_SKIP" = true ]; then
2822     WARNING "Skipping OpenImageIO installation, as requested..."
2823   elif [ "$OIIO_FORCE_BUILD" = true ]; then
2824     INFO "Forced OpenImageIO building, as requested..."
2825     compile_OIIO
2826   else
2827     # XXX Debian Testing / Ubuntu 16.04 pulls in WAY too many deps (gtk2/opencv ?!) incl. OCIO build against libyaml-cpp0.3 so build for now...
2828     #check_package_version_ge_lt_DEB libopenimageio-dev $OIIO_VERSION_MIN $OIIO_VERSION_MAX
2829     #if [ $? -eq 0 -a "$_with_built_openexr" = false ]; then
2830     #  install_packages_DEB libopenimageio-dev
2831     #  clean_OIIO
2832     #else
2833       compile_OIIO
2834     #fi
2835   fi
2836
2837
2838   PRINT ""
2839   have_llvm=false
2840   _do_compile_llvm=false
2841   if [ "$LLVM_SKIP" = true ]; then
2842     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
2843     OSL_SKIP=true
2844   elif [ "$LLVM_FORCE_BUILD" = true ]; then
2845     INFO "Forced LLVM building, as requested..."
2846     _do_compile_llvm=true
2847   else
2848     check_package_DEB clang-$LLVM_VERSION
2849     if [ $? -eq 0 ]; then
2850       install_packages_DEB llvm-$LLVM_VERSION-dev clang-$LLVM_VERSION
2851       have_llvm=true
2852       LLVM_VERSION_FOUND=$LLVM_VERSION
2853       clean_LLVM
2854     else
2855       _do_compile_llvm=true
2856     fi
2857   fi
2858
2859   if [ "$_do_compile_llvm" = true ]; then
2860     install_packages_DEB libffi-dev
2861     # LLVM can't find the debian ffi header dir
2862     _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
2863     PRINT ""
2864     compile_LLVM
2865     have_llvm=true
2866     LLVM_VERSION_FOUND=$LLVM_VERSION
2867   fi
2868
2869
2870   PRINT ""
2871   _do_compile_osl=false
2872   if [ "$OSL_SKIP" = true ]; then
2873     WARNING "Skipping OpenShadingLanguage installation, as requested..."
2874   elif [ "$OSL_FORCE_BUILD" = true ]; then
2875     INFO "Forced OpenShadingLanguage building, as requested..."
2876     _do_compile_osl=true
2877   else
2878     # No package currently!
2879     _do_compile_osl=true
2880   fi
2881
2882   if [ "$_do_compile_osl" = true ]; then
2883     if [ "$have_llvm" = true ]; then
2884       PRINT ""
2885       compile_OSL
2886     else
2887       WARNING "No LLVM available, cannot build OSL!"
2888     fi
2889   fi
2890
2891
2892   PRINT ""
2893   if [ "$OSD_SKIP" = true ]; then
2894     WARNING "Skipping OpenSubdiv installation, as requested..."
2895   elif [ "$OSD_FORCE_BUILD" = true ]; then
2896     INFO "Forced OpenSubdiv building, as requested..."
2897     compile_OSD
2898   else
2899     # No package currently!
2900     PRINT ""
2901     compile_OSD
2902   fi
2903
2904   PRINT ""
2905   if [ "$OPENVDB_SKIP" = true ]; then
2906     WARNING "Skipping OpenVDB installation, as requested..."
2907   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
2908     INFO "Forced OpenVDB building, as requested..."
2909     compile_OPENVDB
2910   else
2911     check_package_version_ge_DEB libopenvdb-dev $OPENVDB_VERSION_MIN
2912     if [ $? -eq 0 ]; then
2913       install_packages_DEB libopenvdb-dev libblosc-dev
2914       clean_OPENVDB
2915     else
2916       compile_OPENVDB
2917     fi
2918   fi
2919
2920   PRINT ""
2921   if [ "$ALEMBIC_SKIP" = true ]; then
2922     WARNING "Skipping Alembic installation, as requested..."
2923   elif [ "$ALEMBIC_FORCE_BUILD" = true ]; then
2924     INFO "Forced Alembic building, as requested..."
2925     compile_ALEMBIC
2926   else
2927     # No package currently, only HDF5!
2928     compile_ALEMBIC
2929   fi
2930
2931
2932   if [ "$WITH_OPENCOLLADA" = true ]; then
2933     _do_compile_collada=false
2934     PRINT ""
2935     if [ "$OPENCOLLADA_SKIP" = true ]; then
2936       WARNING "Skipping OpenCOLLADA installation, as requested..."
2937     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
2938       INFO "Forced OpenCollada building, as requested..."
2939       _do_compile_collada=true
2940     else
2941       # No package currently!
2942       _do_compile_collada=true
2943     fi
2944
2945     if [ "$_do_compile_collada" = true ]; then
2946       install_packages_DEB libpcre3-dev
2947       # Find path to libxml shared lib...
2948       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
2949       # No package
2950       PRINT ""
2951       compile_OpenCOLLADA
2952     fi
2953   fi
2954
2955
2956   PRINT ""
2957   if [ "$FFMPEG_SKIP" = true ]; then
2958     WARNING "Skipping FFMpeg installation, as requested..."
2959   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
2960     INFO "Forced FFMpeg building, as requested..."
2961     compile_FFmpeg
2962   else
2963     # XXX Debian Testing / Ubuntu 16.04 finally includes FFmpeg, so check as usual
2964     check_package_DEB ffmpeg
2965     if [ $? -eq 0 ]; then
2966       check_package_version_ge_DEB ffmpeg $FFMPEG_VERSION_MIN
2967       if [ $? -eq 0 ]; then
2968         install_packages_DEB libavdevice-dev
2969         clean_FFmpeg
2970       else
2971         compile_FFmpeg
2972       fi
2973     else
2974       compile_FFmpeg
2975     fi
2976   fi
2977 }
2978
2979
2980 #### Install on RPM-like ####
2981 rpm_flavour() {
2982   if [ -f /etc/redhat-release ]; then
2983     if [ "`grep '[6-7]\.' /etc/redhat-release`" ]; then
2984       RPM="RHEL"
2985     else
2986       RPM="FEDORA"
2987     fi
2988   elif [ -f /etc/SuSE-release ]; then
2989     RPM="SUSE"
2990   fi
2991 }
2992
2993 get_package_version_RPM() {
2994   rpm_flavour
2995   if [ "$RPM" = "RHEL" ]; then
2996     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
2997   elif [ "$RPM" = "FEDORA" ]; then
2998     dnf info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
2999   elif [ "$RPM" = "SUSE" ]; then
3000     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
3001   fi
3002 }
3003
3004 check_package_RPM() {
3005   rpm_flavour
3006   if [ "$RPM" = "RHEL" ]; then
3007     r=`yum info $1 | grep -c 'Summary'`
3008   elif [ "$RPM" = "FEDORA" ]; then
3009     r=`dnf info $1 | grep -c 'Summary'`
3010   elif [ "$RPM" = "SUSE" ]; then
3011     r=`zypper info $1 | grep -c 'Summary'`
3012   fi
3013
3014   if [ $r -ge 1 ]; then
3015     return 0
3016   else
3017     return 1
3018   fi
3019 }
3020
3021 check_package_version_match_RPM() {
3022   v=`get_package_version_RPM $1`
3023
3024   if [ -z "$v" ]; then
3025     return 1
3026   fi
3027
3028   version_match $v $2
3029   return $?
3030 }
3031
3032 check_package_version_ge_RPM() {
3033   v=`get_package_version_RPM $1`
3034
3035   if [ -z "$v" ]; then
3036     return 1
3037   fi
3038
3039   version_ge $v $2
3040   return $?
3041 }
3042
3043 check_package_version_ge_lt_RPM() {
3044   v=`get_package_version_RPM $1`
3045
3046   if [ -z "$v" ]; then
3047     return 1
3048   fi
3049
3050   version_ge_lt $v $2 $3
3051   return $?
3052 }
3053
3054 install_packages_RPM() {
3055   rpm_flavour
3056   if [ ! $SUDO ]; then
3057     WARNING "--no-sudo enabled, impossible to install $@, you'll have to do it yourself..."
3058   fi
3059   if [ "$RPM" = "RHEL" ]; then
3060     $SUDO yum install -y $@
3061     if [ $? -ge 1 ]; then
3062       ERROR "yum failed to install requested packages, exiting."
3063       exit 1
3064     fi
3065
3066   elif [ "$RPM" = "FEDORA" ]; then
3067     $SUDO dnf install -y $@
3068     if [ $? -ge 1 ]; then
3069       ERROR "dnf failed to install requested packages, exiting."
3070       exit 1
3071     fi
3072
3073   elif [ "$RPM" = "SUSE" ]; then
3074     $SUDO zypper --non-interactive install --auto-agree-with-licenses $@
3075     if [ $? -ge 1 ]; then
3076       ERROR "zypper failed to install requested packages, exiting."
3077       exit 1
3078     fi
3079   fi
3080 }
3081
3082 install_RPM() {
3083   PRINT ""
3084   INFO "Installing dependencies for RPM-based distribution"
3085   PRINT ""
3086   PRINT "`eval _echo "$COMMON_INFO"`"
3087   PRINT ""
3088
3089   if [ "$NO_CONFIRM" = false ]; then
3090     read -p "Do you want to continue (Y/n)?"
3091     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
3092   fi
3093
3094   # Enable non-free repositories for all flavours
3095   if [ ! $SUDO ]; then
3096     WARNING "--no-sudo enabled, impossible to install third party repositories, you'll have to do it yourself..."
3097   else
3098     rpm_flavour
3099     if [ "$RPM" = "FEDORA" ]; then
3100       _fedora_rel="`egrep "[0-9]{1,}" /etc/fedora-release -o`"
3101       $SUDO dnf -y install --nogpgcheck \
3102       http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$_fedora_rel.noarch.rpm \
3103       http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$_fedora_rel.noarch.rpm
3104
3105       $SUDO dnf -y update
3106
3107     elif [ "$RPM" = "RHEL" ]; then
3108       if [ "`grep '6\.' /etc/redhat-release`" ]; then
3109         ERROR "Building with GCC 4.4 is not supported!"
3110         exit 1
3111       else
3112         $SUDO yum -y install --nogpgcheck \
3113         http://download.fedoraproject.org/pub/epel/7/$(uname -i)/e/epel-release-7-6.noarch.rpm \
3114         http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
3115
3116         $SUDO yum -y update
3117       fi
3118
3119     elif [ "$RPM" = "SUSE" ]; then
3120       # Packman repo now includes name in link...
3121       _suse_rel="`grep -w VERSION /etc/os-release | sed 's/[^0-9.]*//g'`"
3122       _suse_name="`grep -w NAME /etc/os-release | gawk '{print $2}' | sed 's/\"//'`"
3123       if [ $_suse_name ]; then
3124         _suse_rel="${_suse_name}_${_suse_rel}"
3125       fi
3126
3127       PRINT ""
3128       INFO "About to add 'packman' repository from http://packman.inode.at/suse/openSUSE_$_suse_rel/"
3129       INFO "This is only needed if you do not already have a packman repository enabled..."
3130       read -p "Do you want to add this repo (Y/n)?"
3131       if [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" == "y" ]; then
3132         INFO "    Installing packman..."
3133         $SUDO zypper ar -f -n packman http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_$_suse_rel/ packman
3134         INFO "    Done."
3135       else
3136         INFO "    Skipping packman installation."
3137       fi
3138       $SUDO zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
3139     fi
3140   fi
3141
3142   # These libs should always be available in fedora/suse official repository...
3143   OPENJPEG_DEV="openjpeg-devel"
3144   VORBIS_DEV="libvorbis-devel"
3145   OGG_DEV="libogg-devel"
3146   THEORA_DEV="libtheora-devel"
3147
3148   _packages="gcc gcc-c++ git make cmake tar bzip2 xz findutils flex bison \
3149              libtiff-devel libjpeg-devel libpng-devel sqlite-devel fftw-devel SDL-devel \
3150              libX11-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel \
3151              wget ncurses-devel readline-devel $OPENJPEG_DEV openal-soft-devel \
3152              glew-devel yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV patch \
3153              libxml2-devel yaml-cpp-devel tinyxml-devel jemalloc-devel"
3154
3155   OPENJPEG_USE=true
3156   VORBIS_USE=true
3157   OGG_USE=true
3158   THEORA_USE=true
3159
3160   if [ "$RPM" = "FEDORA" -o "$RPM" = "RHEL" ]; then
3161     _packages="$_packages freetype-devel tbb-devel"
3162
3163     if [ "$WITH_ALL" = true ]; then
3164       _packages="$_packages jack-audio-connection-kit-devel"
3165     fi
3166
3167     PRINT ""
3168     install_packages_RPM $_packages
3169
3170     PRINT ""
3171     X264_DEV="x264-devel"
3172     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
3173     if [ $? -eq 0 ]; then
3174       install_packages_RPM $X264_DEV
3175       X264_USE=true
3176     fi
3177
3178     if [ "$WITH_ALL" = true ]; then
3179       PRINT ""
3180       XVID_DEV="xvidcore-devel"
3181       check_package_RPM $XVID_DEV
3182       if [ $? -eq 0 ]; then
3183         install_packages_RPM $XVID_DEV
3184         XVID_USE=true
3185       fi
3186
3187       PRINT ""
3188       MP3LAME_DEV="lame-devel"
3189       check_package_RPM $MP3LAME_DEV
3190       if [ $? -eq 0 ]; then
3191         install_packages_RPM $MP3LAME_DEV
3192         MP3LAME_USE=true
3193       fi
3194     fi
3195
3196   elif [ "$RPM" = "SUSE" ]; then
3197     _packages="$_packages freetype2-devel"
3198
3199     PRINT ""
3200     install_packages_RPM $_packages
3201
3202     PRINT ""
3203     # Install TBB on openSUSE, from temporary repo
3204     check_package_RPM tbb-devel
3205     if [ $? -eq 0 ]; then
3206       install_packages_RPM tbb-devel
3207     else
3208       $SUDO zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$_suse_rel/devel:libraries:c_c++.repo
3209       $SUDO zypper -n --gpg-auto-import-keys install tbb-devel
3210       $SUDO zypper rr devel_libraries_c_c++
3211     fi
3212
3213     PRINT ""
3214     X264_DEV="libx264-devel"
3215     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
3216     if [ $? -eq 0 ]; then
3217       install_packages_RPM $X264_DEV
3218       X264_USE=true
3219     fi
3220
3221     if [ "$WITH_ALL" = true ]; then
3222       PRINT ""
3223       XVID_DEV="libxvidcore-devel"
3224       check_package_RPM $XVID_DEV
3225       if [ $? -eq 0 ]; then
3226         install_packages_RPM $XVID_DEV
3227         XVID_USE=true
3228       fi
3229
3230       PRINT ""
3231       MP3LAME_DEV="libmp3lame-devel"
3232       check_package_RPM $MP3LAME_DEV
3233       if [ $? -eq 0 ]; then
3234         install_packages_RPM $MP3LAME_DEV
3235         MP3LAME_USE=true
3236       fi
3237     fi
3238   fi
3239
3240   PRINT""
3241   SNDFILE_DEV="libsndfile-devel"
3242   check_package_RPM $SNDFILE_DEV
3243   if [ $? -eq 0 ]; then
3244     install_packages_RPM $SNDFILE_DEV
3245   fi
3246
3247   if [ "$WITH_ALL" = true ]; then
3248     PRINT ""
3249     VPX_DEV="libvpx-devel"
3250     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
3251     if [ $? -eq 0 ]; then
3252       install_packages_RPM $VPX_DEV
3253       VPX_USE=true
3254     fi
3255     PRINT ""
3256     install_packages_RPM libspnav-devel
3257   fi
3258
3259
3260   PRINT ""
3261   _do_compile_python=false
3262   if [ "$PYTHON_SKIP" = true ]; then
3263     WARNING "Skipping Python installation, as requested..."
3264   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3265     INFO "Forced Python/NumPy building, as requested..."
3266     _do_compile_python=true
3267   else
3268     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
3269     if [ $? -eq 0 ]; then
3270       install_packages_RPM python3-devel
3271       clean_Python
3272       PRINT ""
3273       if [ "$NUMPY_SKIP" = true ]; then
3274         WARNING "Skipping NumPy installation, as requested..."
3275       else
3276         check_package_version_ge_RPM python3-numpy $NUMPY_VERSION_MIN
3277         if [ $? -eq 0 ]; then
3278           install_packages_RPM python3-numpy
3279         else
3280           WARNING "Sorry, using python package but no valid numpy package available!" \
3281                   "    Use --build-numpy to force building of both Python and NumPy."
3282         fi
3283       fi
3284     else
3285       _do_compile_python=true
3286     fi
3287   fi
3288
3289   if [ "$_do_compile_python" = true ]; then
3290     compile_Python
3291     PRINT ""
3292     if [ "$NUMPY_SKIP" = true ]; then
3293       WARNING "Skipping NumPy installation, as requested..."
3294     else
3295       compile_Numpy
3296     fi
3297   fi
3298
3299
3300   PRINT ""
3301   _do_compile_boost=false
3302   if [ "$BOOST_SKIP" = true ]; then
3303     WARNING "Skipping Boost installation, as requested..."
3304   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3305     INFO "Forced Boost building, as requested..."
3306     _do_compile_boost=true
3307   else
3308     check_package_version_ge_RPM boost-devel $BOOST_VERSION_MIN
3309     if [ $? -eq 0 ]; then
3310       install_packages_RPM boost-devel
3311       clean_Boost
3312     else
3313       _do_compile_boost=true
3314     fi
3315   fi
3316
3317   if [ "$_do_compile_boost" = true ]; then
3318     if [ "$RPM" = "SUSE" ]; then
3319       install_packages_RPM gcc-fortran
3320     else
3321       install_packages_RPM libquadmath-devel bzip2-devel
3322     fi
3323     PRINT ""
3324     compile_Boost
3325   fi
3326
3327
3328   PRINT ""
3329   if [ "$OCIO_SKIP" = true ]; then
3330     WARNING "Skipping OpenColorIO installation, as requested..."
3331   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3332     INFO "Forced OpenColorIO building, as requested..."
3333     compile_OCIO
3334   else
3335     if [ "$RPM" = "SUSE" ]; then
3336       check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
3337       if [ $? -eq 0 ]; then
3338         install_packages_RPM OpenColorIO-devel
3339         clean_OCIO
3340       else
3341         compile_OCIO
3342       fi
3343     # XXX Fedora/RHEL OCIO still depends on libyaml-cpp v0.3 even when system default is v0.5!
3344     else
3345       compile_OCIO
3346     fi
3347   fi
3348
3349   PRINT ""
3350   if [ "$OPENEXR_SKIP" = true ]; then
3351     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
3352   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
3353     INFO "Forced ILMBase/OpenEXR building, as requested..."
3354     compile_OPENEXR
3355   else
3356     check_package_version_ge_RPM openexr-devel $OPENEXR_VERSION_MIN
3357     if [ $? -eq 0 ]; then
3358       install_packages_RPM openexr-devel
3359       OPENEXR_VERSION=`get_package_version_RPM openexr-devel`
3360       ILMBASE_VERSION=$OPENEXR_VERSION
3361       clean_OPENEXR
3362     else
3363       compile_OPENEXR
3364     fi
3365   fi
3366
3367   PRINT ""
3368   if [ "$OIIO_SKIP" = true ]; then
3369     WARNING "Skipping OpenImageIO installation, as requested..."
3370   elif [ "$OIIO_FORCE_BUILD" = true ]; then
3371     INFO "Forced OpenImageIO building, as requested..."
3372     compile_OIIO
3373   else
3374     # XXX RPM distros pulls in too much and depends on old libs, so better to build for now...
3375     #check_package_version_ge_lt_RPM OpenImageIO-devel $OIIO_VERSION_MIN $OIIO_VERSION_MAX
3376     #if [ $? -eq 0 -a $_with_built_openexr == false ]; then
3377     #  install_packages_RPM OpenImageIO-devel
3378     #  clean_OIIO
3379     #else
3380       compile_OIIO
3381     #fi
3382   fi
3383
3384
3385   PRINT ""
3386   have_llvm=false
3387   _do_compile_llvm=false
3388   if [ "$LLVM_SKIP" = true ]; then
3389     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
3390     OSL_SKIP=true
3391   elif [ "$LLVM_FORCE_BUILD" = true ]; then
3392     INFO "Forced LLVM building, as requested..."
3393     _do_compile_llvm=true
3394   else
3395     if [ "$RPM" = "SUSE" ]; then
3396       CLANG_DEV="llvm-clang-devel"
3397     else
3398       CLANG_DEV="clang-devel"
3399     fi
3400     # XXX RHEL has 3.4 in repo but OSL complains about not finding MCJIT_LIBRARY, so compile for now...
3401     #check_package_version_match_RPM $CLANG_DEV $LLVM_VERSION
3402     #if [ $? -eq 0 ]; then
3403     #  install_packages_RPM llvm-devel $CLANG_DEV
3404     #  have_llvm=true
3405     #  LLVM_VERSION_FOUND=$LLVM_VERSION
3406     #  clean_LLVM
3407     #else
3408       _do_compile_llvm=true
3409     #fi
3410   fi
3411
3412   if [ "$_do_compile_llvm" = true ]; then
3413     install_packages_RPM libffi-devel
3414     # LLVM can't find the fedora ffi header dir...
3415     _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
3416     PRINT ""
3417     compile_LLVM
3418     have_llvm=true
3419     LLVM_VERSION_FOUND=$LLVM_VERSION
3420   fi
3421
3422
3423   PRINT ""
3424   _do_compile_osl=false
3425   if [ "$OSL_SKIP" = true ]; then
3426     WARNING "Skipping OpenShadingLanguage installation, as requested..."
3427   elif [ "$OSL_FORCE_BUILD" = true ]; then
3428     INFO "Forced OpenShadingLanguage building, as requested..."
3429     _do_compile_osl=true
3430   else
3431     # No package currently!
3432     _do_compile_osl=true
3433   fi
3434
3435   if [ "$_do_compile_osl" = true ]; then
3436     if [ "$have_llvm" = true ]; then
3437       PRINT ""
3438       compile_OSL
3439     else
3440       WARNING "No LLVM available, cannot build OSL!"
3441     fi
3442   fi
3443
3444
3445   PRINT ""
3446   if [ "$OSD_SKIP" = true ]; then
3447     WARNING "Skipping OpenSubdiv installation, as requested..."
3448   elif [ "$OSD_FORCE_BUILD" = true ]; then
3449     INFO "Forced OpenSubdiv building, as requested..."
3450     compile_OSD
3451   else
3452     # No package currently!
3453     compile_OSD
3454   fi
3455
3456
3457   PRINT ""
3458   if [ "$OPENVDB_SKIP" = true ]; then
3459     WARNING "Skipping OpenVDB installation, as requested..."
3460   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
3461     INFO "Forced OpenVDB building, as requested..."
3462     compile_OPENVDB
3463   else
3464     # No package currently!
3465     compile_OPENVDB
3466   fi
3467
3468   PRINT ""
3469   if [ "$ALEMBIC_SKIP" = true ]; then
3470     WARNING "Skipping Alembic installation, as requested..."
3471   elif [ "$ALEMBIC_FORCE_BUILD" = true ]; then
3472     INFO "Forced Alembic building, as requested..."
3473     compile_ALEMBIC
3474   else
3475     # No package currently!
3476     compile_ALEMBIC
3477   fi
3478
3479
3480   if [ "$WITH_OPENCOLLADA" = true ]; then
3481     PRINT ""
3482     _do_compile_collada=false
3483     if [ "$OPENCOLLADA_SKIP" = true ]; then
3484       WARNING "Skipping OpenCOLLADA installation, as requested..."
3485     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
3486       INFO "Forced OpenCollada building, as requested..."
3487       _do_compile_collada=true
3488     else
3489       # No package...
3490       _do_compile_collada=true
3491     fi
3492
3493     if [ "$_do_compile_collada" = true ]; then
3494       install_packages_RPM pcre-devel
3495       # Find path to libxml shared lib...
3496       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
3497       PRINT ""
3498       compile_OpenCOLLADA
3499     fi
3500   fi
3501
3502
3503   PRINT ""
3504   if [ "$FFMPEG_SKIP" = true ]; then
3505     WARNING "Skipping FFMpeg installation, as requested..."
3506   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
3507     INFO "Forced FFMpeg building, as requested..."
3508     compile_FFmpeg
3509   else
3510     check_package_version_ge_RPM ffmpeg-devel $FFMPEG_VERSION_MIN
3511     if [ $? -eq 0 ]; then
3512       install_packages_RPM ffmpeg ffmpeg-devel
3513       clean_FFmpeg
3514     else
3515       compile_FFmpeg
3516     fi
3517   fi
3518 }
3519
3520
3521 #### Install on ARCH-like ####
3522 get_package_version_ARCH() {
3523   pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+?(([0-9]+\.?)+).*/\1/'
3524 }
3525
3526 check_package_ARCH() {
3527   r=`pacman -Si $1 | grep -c 'Description'`
3528
3529   if [ $r -ge 1 ]; then
3530     return 0
3531   else
3532     return 1
3533   fi
3534 }
3535
3536 check_package_version_match_ARCH() {
3537   v=`get_package_version_ARCH $1`
3538
3539   if [ -z "$v" ]; then
3540     return 1
3541   fi
3542
3543   version_match $v $2
3544   return $?
3545 }
3546
3547 check_package_version_ge_ARCH() {
3548   v=`get_package_version_ARCH $1`
3549
3550   if [ -z "$v" ]; then
3551     return 1
3552   fi
3553
3554   version_ge $v $2
3555   return $?
3556 }
3557
3558 check_package_version_ge_lt_ARCH() {
3559   v=`get_package_version_ARCH $1`
3560
3561   if [ -z "$v" ]; then
3562     return 1
3563   fi
3564
3565   version_ge_lt $v $2 $3
3566   return $?
3567 }
3568
3569 install_packages_ARCH() {
3570   if [ ! $SUDO ]; then
3571     WARNING "--no-sudo enabled, impossible to run pacman for $@, you'll have to do it yourself..."
3572   else
3573     $SUDO pacman -S --needed --noconfirm $@
3574     if [ $? -ge 1 ]; then
3575       ERROR "pacman failed to install requested packages, exiting."
3576       exit 1
3577     fi
3578   fi
3579 }
3580
3581 install_ARCH() {
3582   PRINT ""
3583   INFO "Installing dependencies for ARCH-based distribution"
3584   PRINT ""
3585   PRINT "`eval _echo "$COMMON_INFO"`"
3586   PRINT ""
3587
3588   if [ "$NO_CONFIRM" = false ]; then
3589     read -p "Do you want to continue (Y/n)?"
3590     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
3591   fi
3592
3593   # Check for sudo...
3594   if [ $SUDO ]; then
3595     if [ ! -x "/usr/bin/sudo" ]; then
3596       PRINT ""
3597       ERROR "This script requires sudo but it is not installed."
3598       PRINT "Please setup sudo according to:"
3599       PRINT "https://wiki.archlinux.org/index.php/Sudo"
3600       PRINT "and try again."
3601       PRINT ""
3602       exit
3603     fi
3604   fi
3605
3606   if [ ! $SUDO ]; then
3607     WARNING "--no-sudo enabled, impossible to run pacman -Sy, you'll have to do it yourself..."
3608   else
3609     $SUDO pacman -Sy
3610   fi
3611
3612   # These libs should always be available in arch official repository...
3613   OPENJPEG_DEV="openjpeg"
3614   VORBIS_DEV="libvorbis"
3615   OGG_DEV="libogg"
3616   THEORA_DEV="libtheora"
3617
3618   BASE_DEVEL="base-devel"
3619
3620   # Avoid conflicts when gcc-multilib is installed
3621   pacman -Qi gcc-multilib &>/dev/null
3622   if [ $? -eq 0 ]; then
3623     BASE_DEVEL=`pacman -Sgq base-devel | sed -e 's/^gcc$/gcc-multilib/g' | paste -s -d' '`
3624   fi
3625
3626   _packages="$BASE_DEVEL git cmake \
3627              libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \
3628              $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw intel-tbb \
3629              libxml2 yaml-cpp tinyxml python-requests jemalloc"
3630
3631   OPENJPEG_USE=true
3632   VORBIS_USE=true
3633   OGG_USE=true
3634   THEORA_USE=true
3635
3636   if [ "$WITH_ALL" = true ]; then
3637     _packages="$_packages jack libspnav"
3638   fi
3639
3640   PRINT ""
3641   install_packages_ARCH $_packages
3642
3643   PRINT""
3644   SNDFILE_DEV="libsndfile"
3645   check_package_ARCH $SNDFILE_DEV
3646   if [ $? -eq 0 ]; then
3647     install_packages_ARCH $SNDFILE_DEV
3648   fi
3649
3650   PRINT ""
3651   X264_DEV="x264"
3652   check_package_version_ge_ARCH $X264_DEV $X264_VERSION_MIN
3653   if [ $? -eq 0 ]; then
3654     install_packages_ARCH $X264_DEV
3655     X264_USE=true
3656   fi
3657
3658   if [ "$WITH_ALL" = true ]; then
3659     PRINT ""
3660     XVID_DEV="xvidcore"
3661     check_package_ARCH $XVID_DEV
3662     if [ $? -eq 0 ]; then
3663       install_packages_ARCH $XVID_DEV
3664       XVID_USE=true
3665     fi
3666
3667     PRINT ""
3668     MP3LAME_DEV="lame"
3669     check_package_ARCH $MP3LAME_DEV
3670     if [ $? -eq 0 ]; then
3671       install_packages_ARCH $MP3LAME_DEV
3672       MP3LAME_USE=true
3673     fi
3674
3675     PRINT ""
3676     VPX_DEV="libvpx"
3677     check_package_version_ge_ARCH $VPX_DEV $VPX_VERSION_MIN
3678     if [ $? -eq 0 ]; then
3679       install_packages_ARCH $VPX_DEV
3680       VPX_USE=true
3681     fi
3682   fi
3683
3684
3685   PRINT ""
3686   _do_compile_python=false
3687   if [ "$PYTHON_SKIP" = true ]; then
3688     WARNING "Skipping Python installation, as requested..."
3689   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3690     INFO "Forced Python/NumPy building, as requested..."
3691     _do_compile_python=true
3692   else
3693     check_package_version_ge_ARCH python $PYTHON_VERSION_MIN
3694     if [ $? -eq 0 ]; then
3695       install_packages_ARCH python
3696       clean_Python
3697       PRINT ""
3698       if [ "$NUMPY_SKIP" = true ]; then
3699         WARNING "Skipping NumPy installation, as requested..."
3700       else
3701         check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
3702         if [ $? -eq 0 ]; then
3703           install_packages_ARCH python-numpy
3704         else
3705           WARNING "Sorry, using python package but no valid numpy package available!" \
3706                   "Use --build-numpy to force building of both Python and NumPy."
3707         fi
3708       fi
3709     else
3710       _do_compile_python=true
3711     fi
3712   fi
3713
3714   if [ "$_do_compile_python" = true ]; then
3715     compile_Python
3716     PRINT ""
3717     if [ "$NUMPY_SKIP" = true ]; then
3718       WARNING "Skipping NumPy installation, as requested..."
3719     else
3720       compile_Numpy
3721     fi
3722   fi
3723
3724
3725   PRINT ""
3726   if [ "$BOOST_SKIP" = true ]; then
3727     WARNING "Skipping Boost installation, as requested..."
3728   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3729     INFO "Forced Boost building, as requested..."
3730     compile_Boost
3731   else
3732     check_package_version_ge_ARCH boost $BOOST_VERSION_MIN
3733     if [ $? -eq 0 ]; then
3734       install_packages_ARCH boost
3735       clean_Boost
3736     else
3737       compile_Boost
3738     fi
3739   fi
3740
3741
3742   PRINT ""
3743   if [ "$OCIO_SKIP" = true ]; then
3744     WARNING "Skipping OpenColorIO installation, as requested..."
3745   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3746     INFO "Forced OpenColorIO building, as requested..."
3747     compile_OCIO
3748   else
3749     check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
3750     if [ $? -eq 0 ]; then
3751       install_packages_ARCH opencolorio
3752       clean_OCIO
3753     else
3754       compile_OCIO
3755     fi
3756   fi
3757
3758
3759   PRINT ""
3760   if [ "$OPENEXR_SKIP" = true ]; then
3761     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
3762   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
3763     INFO "Forced ILMBase/OpenEXR building, as requested..."
3764     compile_OPENEXR
3765   else
3766     check_package_version_ge_ARCH openexr $OPENEXR_VERSION_MIN
3767     if [ $? -eq 0 ]; then
3768       install_packages_ARCH openexr
3769       OPENEXR_VERSION=`get_package_version_ARCH openexr`
3770       ILMBASE_VERSION=$OPENEXR_VERSION
3771       clean_OPENEXR
3772     else
3773       compile_OPENEXR
3774     fi
3775   fi
3776
3777
3778   PRINT ""
3779   if [ "$OIIO_SKIP" = true ]; then
3780     WARNING "Skipping OpenImageIO installation, as requested..."
3781   elif [ "$OIIO_FORCE_BUILD" = true ]; then
3782     INFO "Forced OpenImageIO building, as requested..."
3783     compile_OIIO
3784   else
3785     check_package_version_ge_lt_ARCH openimageio $OIIO_VERSION_MIN $OIIO_VERSION_MAX
3786     if [ $? -eq 0 ]; then
3787       install_packages_ARCH openimageio
3788       clean_OIIO
3789     else
3790       compile_OIIO
3791     fi
3792   fi
3793
3794
3795   PRINT ""
3796   have_llvm=false
3797   _do_compile_llvm=false