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