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