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