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