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