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