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