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