Install_deps script:
[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 # Parse command line!
23 ARGS=$( \
24 getopt \
25 -o s:i:t:h \
26 --long source:,install:,threads:,help,with-all,with-osl,with-opencollada,all-static,force-all,\
27 force-python,force-numpy,force-boost,force-ocio,force-oiio,force-llvm,force-osl,force-opencollada,\
28 force-ffmpeg,skip-python,skip-numpy,skip-boost,skip-ocio,skip-oiio,skip-llvm,skip-osl,skip-ffmpeg,\
29 skip-opencollada \
30 -- "$@" \
31 )
32
33 DISTRO=""
34 RPM=""
35 SRC="$HOME/src/blender-deps"
36 INST="/opt/lib"
37 CWD=$PWD
38
39 # Do not install some optional, potentially conflicting libs by default...
40 WITH_ALL=false
41
42 # Do not yet enable osl, use --with-osl (or --with-all) option to try it.
43 WITH_OSL=false
44
45 # Do not yet enable opencollada, use --with-opencollada (or --with-all) option to try it.
46 WITH_OPENCOLLADA=false
47
48 # Try to link everything statically. Use this to produce portable versions of blender.
49 ALL_STATIC=false
50
51 THREADS=`cat /proc/cpuinfo | grep cores | uniq | sed -e "s/.*: *\(.*\)/\\1/"`
52 if [ -z "$THREADS" ]; then
53   THREADS=1
54 fi
55
56 COMMON_INFO="\"Source code of dependencies needed to be compiled will be downloaded and extracted into '\$SRC'.
57 Built libs of dependencies needed to be compiled will be installed into '\$INST'.
58 Please edit \\\$SRC and/or \\\$INST variables at the beginning of this script,
59 or use --source/--install options, if you want to use other paths!
60
61 Number of threads for building: \$THREADS (automatically detected, use --threads=<nbr> to override it).
62 Full install: \$WITH_ALL (use --with-all option to enable it).
63 Building OSL: \$WITH_OSL (use --with-osl option to enable it).
64 Building OpenCOLLADA: \$WITH_OPENCOLLADA (use --with-opencollada option to enable it).
65 All static linking: \$ALL_STATIC (use --all-static option to enable it).
66
67 Example:
68 Full install without OpenCOLLADA: --with-all --skip-opencollada
69
70 Use --help to show all available options!\""
71
72 ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
73     -h, --help
74         Show this message and exit.
75
76     -s <path>, --source=<path>
77         Use a specific path where to store downloaded libraries sources (defaults to '\$SRC').
78
79     -i <path>, --install=<path>
80         Use a specific path where to install built libraries (defaults to '\$INST').
81
82     -t n, --threads=n
83         Use a specific number of threads when building the libraries (auto-detected as '\$THREADS').
84
85     --with-all
86         By default, a number of optional and not-so-often needed libraries are not installed.
87         This option will try to install them, at the cost of potential conflicts (depending on
88         how your package system is set…).
89         Note this option also implies all other (more specific) --with-foo options below.
90
91     --with-osl
92         Try to install or build the OpenShadingLanguage libraries (and their dependencies).
93         Still experimental!
94
95     --with-opencollada
96         Build and install the OpenCOLLADA libraries.
97
98     --all-static
99         Build libraries as statically as possible, to create static builds of Blender.
100
101     --force-all
102         Force the rebuild of all built libraries.
103
104     --force-python
105         Force the rebuild of Python.
106
107     --force-numpy
108         Force the rebuild of NumPy.
109
110     --force-boost
111         Force the rebuild of Boost.
112
113     --force-ocio
114         Force the rebuild of OpenColorIO.
115
116     --force-oiio
117         Force the rebuild of OpenImageIO.
118
119     --force-llvm
120         Force the rebuild of LLVM.
121
122     --force-osl
123         Force the rebuild of OpenShadingLanguage.
124
125     --force-opencollada
126         Force the rebuild of OpenCOLLADA.
127
128     --force-ffmpeg
129         Force the rebuild of FFMpeg.
130
131     Note about the --force-foo options:
132         * They obviously only have an effect if those libraries are built by this script
133           (i.e. if there is no available and satisfactory package)!
134         * If the “force-rebuilt” library is a dependency of others, it will force the rebuild
135           of those libraries too (e.g. --force-boost will also rebuild oiio and osl...).
136         * Do not forget --with-osl if you built it and still want it!
137
138     --skip-python
139         Unconditionally skip Python installation/building.
140
141     --skip-numpy
142         Unconditionally skip NumPy installation/building.
143
144     --skip-boost
145         Unconditionally skip Boost installation/building.
146
147     --skip-ocio
148         Unconditionally skip OpenColorIO installation/building.
149
150     --skip-oiio
151         Unconditionally skip OpenImageIO installation/building.
152
153     --skip-llvm
154         Unconditionally skip LLVM installation/building.
155
156     --skip-osl
157         Unconditionally skip OpenShadingLanguage installation/building.
158
159     --skip-opencollada
160         Unconditionally skip OpenCOLLADA installation/building.
161
162     --skip-ffmpeg
163         Unconditionally skip FFMpeg installation/building.\""
164
165 PYTHON_VERSION="3.3.0"
166 PYTHON_VERSION_MIN="3.3"
167 PYTHON_SOURCE="http://python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.bz2"
168 PYTHON_FORCE_REBUILD=false
169 PYTHON_SKIP=false
170
171 #Could not get numpy-1.6.2 to compile with python-3.3
172 NUMPY_VERSION="1.7.0rc1"
173 NUMPY_VERSION_MIN="1.7"
174 NUMPY_SOURCE="http://sourceforge.net/projects/numpy/files/NumPy/$NUMPY_VERSION/numpy-$NUMPY_VERSION.tar.gz"
175 NUMPY_FORCE_REBUILD=false
176 NUMPY_SKIP=false
177
178 BOOST_VERSION="1.51.0"
179 _boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
180 BOOST_SOURCE="http://sourceforge.net/projects/boost/files/boost/$BOOST_VERSION/boost_$_boost_version_nodots.tar.bz2/download"
181 BOOST_VERSION_MIN="1.49"
182 BOOST_FORCE_REBUILD=false
183 BOOST_SKIP=false
184
185 OCIO_VERSION="1.0.7"
186 OCIO_SOURCE="https://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION"
187 OCIO_VERSION_MIN="1.0"
188 OCIO_FORCE_REBUILD=false
189 OCIO_SKIP=false
190
191 OIIO_VERSION="1.1.7"
192 OIIO_SOURCE="https://github.com/OpenImageIO/oiio/tarball/Release-$OIIO_VERSION"
193 OIIO_VERSION_MIN="1.1"
194 OIIO_FORCE_REBUILD=false
195 OIIO_SKIP=false
196
197 LLVM_VERSION="3.1"
198 LLVM_VERSION_MIN="3.0"
199 LLVM_VERSION_FOUND=""
200 LLVM_SOURCE="http://llvm.org/releases/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.gz"
201 LLVM_CLANG_SOURCE="http://llvm.org/releases/$LLVM_VERSION/clang-$LLVM_VERSION.src.tar.gz"
202 LLVM_FORCE_REBUILD=false
203 LLVM_SKIP=false
204
205 # OSL needs to be compiled for now!
206 OSL_VERSION="1.3.0"
207 OSL_SOURCE="https://github.com/imageworks/OpenShadingLanguage/archive/Release-1.3.0.tar.gz"
208 OSL_FORCE_REBUILD=false
209 OSL_SKIP=false
210
211 # Version??
212 OPENCOLLADA_VERSION="1.3"
213 OPENCOLLADA_SOURCE="https://github.com/KhronosGroup/OpenCOLLADA.git"
214 OPENCOLLADA_FORCE_REBUILD=false
215 OPENCOLLADA_SKIP=false
216
217 FFMPEG_VERSION="1.0"
218 FFMPEG_SOURCE="http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2"
219 FFMPEG_VERSION_MIN="0.7.6"
220 FFMPEG_FORCE_REBUILD=false
221 FFMPEG_SKIP=false
222 _ffmpeg_list_sep=";"
223
224 # FFMPEG optional libs.
225 VORBIS_USE=false
226 VORBIS_DEV=""
227 SCHRO_USE=false
228 SCRHO_DEV=""
229 THEORA_USE=false
230 THEORA_DEV=""
231 XVID_USE=false
232 XVID_DEV=""
233 X264_USE=false
234 X264_DEV=""
235 X264_VERSION_MIN=0.118
236 VPX_USE=false
237 VPX_VERSION_MIN=0.9.7
238 VPX_DEV=""
239 MP3LAME_USE=false
240 MP3LAME_DEV=""
241 OPENJPEG_USE=false
242 OPENJPEG_DEV=""
243
244 # Switch to english language, else some things (like check_package_DEB()) won't work!
245 LANG_BACK=$LANG
246 LANG=""
247 export LANG
248
249
250 _echo() {
251   if [ "X$1" = "X-n" ]; then
252      shift; printf "%s" "$@"
253   else
254      printf "%s\n" "$@"
255   fi
256 }
257
258 ERROR() {
259   _echo "$@"
260 }
261
262 INFO() {
263   _echo "$@"
264 }
265
266 # Finish parsing the commandline args.
267 eval set -- "$ARGS"
268 while true; do
269   case $1 in
270     -s|--source)
271       SRC="$2"; shift; shift; continue
272     ;;
273     -i|--install)
274       INST="$2"; shift; shift; continue
275     ;;
276     -t|--threads)
277       THREADS="$2"; shift; shift; continue
278     ;;
279     -h|--help)
280       INFO ""
281       INFO "USAGE:"
282       INFO ""
283       INFO "`eval _echo "$COMMON_INFO"`"
284       INFO ""
285       INFO "`eval _echo "$ARGUMENTS_INFO"`"
286       INFO ""
287       exit 0
288     ;;
289     --with-all)
290       WITH_ALL=true; shift; continue
291     ;;
292     --with-osl)
293       WITH_OSL=true; shift; continue
294     ;;
295     --with-opencollada)
296       WITH_OPENCOLLADA=true; shift; continue
297     ;;
298     --all-static)
299       ALL_STATIC=true; shift; continue
300     ;;
301     --force-all)
302       PYTHON_FORCE_REBUILD=true
303       NUMPY_FORCE_REBUILD=true
304       BOOST_FORCE_REBUILD=true
305       OCIO_FORCE_REBUILD=true
306       OIIO_FORCE_REBUILD=true
307       LLVM_FORCE_REBUILD=true
308       OSL_FORCE_REBUILD=true
309       OPENCOLLADA_FORCE_REBUILD=true
310       FFMPEG_FORCE_REBUILD=true
311       shift; continue
312     ;;
313     --force-python)
314       PYTHON_FORCE_REBUILD=true; shift; continue
315     ;;
316     --force-numpy)
317       NUMPY_FORCE_REBUILD=true; shift; continue
318     ;;
319     --force-boost)
320       BOOST_FORCE_REBUILD=true; shift; continue
321     ;;
322     --force-ocio)
323       OCIO_FORCE_REBUILD=true; shift; continue
324     ;;
325     --force-oiio)
326       OIIO_FORCE_REBUILD=true; shift; continue
327     ;;
328     --force-llvm)
329       LLVM_FORCE_REBUILD=true; shift; continue
330     ;;
331     --force-osl)
332       OSL_FORCE_REBUILD=true; shift; continue
333     ;;
334     --force-opencollada)
335       OPENCOLLADA_FORCE_REBUILD=true; shift; continue
336     ;;
337     --force-ffmpeg)
338       FFMPEG_FORCE_REBUILD=true; shift; continue
339     ;;
340     --skip-python)
341       PYTHON_SKIP=true; shift; continue
342     ;;
343     --skip-numpy)
344       NUMPY_SKIP=true; shift; continue
345     ;;
346     --skip-boost)
347       BOOST_SKIP=true; shift; continue
348     ;;
349     --skip-ocio)
350       OCIO_SKIP=true; shift; continue
351     ;;
352     --skip-oiio)
353       OIIO_SKIP=true; shift; continue
354     ;;
355     --skip-llvm)
356       LLVM_SKIP=true; shift; continue
357     ;;
358     --skip-osl)
359       OSL_SKIP=true; shift; continue
360     ;;
361     --skip-opencollada)
362       OPENCOLLADA_SKIP=true; shift; continue
363     ;;
364     --skip-ffmpeg)
365       FFMPEG_SKIP=true; shift; continue
366     ;;
367     --)
368       # no more arguments to parse
369       break
370     ;;
371     *)
372       INFO ""
373       INFO "Wrong parameter! Usage:"
374       INFO ""
375       INFO "`eval _echo "$COMMON_INFO"`"
376       INFO ""
377       exit 1
378     ;;
379   esac
380 done
381
382 if $WITH_ALL; then
383   WITH_OSL=true
384   WITH_OPENCOLLADA=true
385 fi
386
387 # Return 0 if $1 = $2 (i.e. 1.01.0 = 1.1, but 1.1.1 != 1.1), else 1.
388 # $1 and $2 should be version numbers made of numbers only.
389 version_eq() {
390   backIFS=$IFS
391   IFS='.'
392
393   # Split both version numbers into their numeric elements.
394   arr1=( $1 )
395   arr2=( $2 )
396
397   ret=1
398
399   count1=${#arr1[@]}
400   count2=${#arr2[@]}
401   if [ $count2 -ge $count1 ]; then
402     _t=$count1
403     count1=$count2
404     count2=$_t
405     arr1=( $2 )
406     arr2=( $1 )
407   fi
408
409   ret=0
410   for (( i=0; $i < $count2; i++ ))
411   do
412     if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
413       ret=1
414       break
415     fi
416   done
417
418   for (( i=$count2; $i < $count1; i++ ))
419   do
420     if [ $(( 10#${arr1[$i]} )) -ne 0 ]; then
421       ret=1
422       break
423     fi
424   done
425
426   IFS=$backIFS
427   return $ret
428 }
429
430 # Return 0 if $1 >= $2, else 1.
431 # $1 and $2 should be version numbers made of numbers only.
432 version_ge() {
433   version_eq $1 $2
434   if [ $? -eq 1 -a $(_echo "$1" "$2" | sort --version-sort | head --lines=1) = "$1" ]; then
435     return 1
436   else
437     return 0
438   fi
439 }
440
441 # 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.
442 # $1 and $2 should be version numbers made of numbers only.
443 # $1 should be at least as long as $2!
444 version_match() {
445   backIFS=$IFS
446   IFS='.'
447
448   # Split both version numbers into their numeric elements.
449   arr1=( $1 )
450   arr2=( $2 )
451
452   ret=1
453
454   count1=${#arr1[@]}
455   count2=${#arr2[@]}
456   if [ $count1 -ge $count2 ]; then
457     ret=0
458     for (( i=0; $i < $count2; i++ ))
459     do
460       if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
461         ret=1
462         break
463       fi
464     done
465   fi
466
467   IFS=$backIFS
468   return $ret
469 }
470
471 detect_distro() {
472   if [ -f /etc/debian_version ]; then
473     DISTRO="DEB"
474   elif [ -f /etc/redhat-release -o /etc/SuSE-release ]; then
475     DISTRO="RPM"
476   elif [ -f /etc/arch-release ]; then
477     DISTRO="ARCH"
478   fi
479 }
480
481 rpm_flavour() {
482   if [ -f /etc/redhat-release ]; then
483     if [ "`grep '6\.' /etc/redhat-release`" ]; then
484       RPM="RHEL"
485     else
486       RPM="FEDORA"
487     fi
488   elif [ -f /etc/SuSE-release ]; then
489     RPM="SUSE"
490   fi
491 }
492
493 prepare_opt() {
494   INFO "Ensuring $INST exists and is writable by us"
495   if [ ! -d  $INST ]; then
496     sudo mkdir -p $INST
497   fi
498
499   if [ ! -w $INST ]; then
500     sudo chown $USER $INST
501     sudo chmod 775 $INST
502   fi
503 }
504
505 # Check whether the current package needs to be recompiled, based on a dummy file containing a magic number in its name...
506 magic_compile_check() {
507   if [ -f $INST/.$1-magiccheck-$2 ]; then
508     return 0
509   else
510     return 1
511   fi
512 }
513
514 magic_compile_set() {
515   rm -f $INST/.$1-magiccheck-*
516   touch $INST/.$1-magiccheck-$2
517 }
518
519 compile_Python() {
520   # To be changed each time we make edits that would modify the compiled result!
521   py_magic=0
522
523   _src=$SRC/Python-$PYTHON_VERSION
524   _inst=$INST/python-$PYTHON_VERSION
525
526   # Clean install if needed!
527   magic_compile_check python-$PYTHON_VERSION $py_magic
528   if [ $? -eq 1 -o $PYTHON_FORCE_REBUILD == true ]; then
529     rm -rf $_inst
530   fi
531
532   if [ ! -d $_inst ]; then
533     INFO "Building Python-$PYTHON_VERSION"
534
535     prepare_opt
536
537     if [ ! -d $_src ]; then
538       mkdir -p $SRC
539       wget -c $PYTHON_SOURCE -O $_src.tar.bz2
540
541       INFO "Unpacking Python-$PYTHON_VERSION"
542       tar -C $SRC -xf $_src.tar.bz2
543     fi
544
545     cd $_src
546
547     ./configure --prefix=$_inst --enable-ipv6 \
548         --enable-loadable-sqlite-extensions --with-dbmliborder=bdb \
549         --with-computed-gotos --with-pymalloc
550
551     make -j$THREADS && make install
552     make clean
553
554     if [ -d $_inst ]; then
555       rm -f $INST/python-3.3
556       ln -s python-$PYTHON_VERSION $INST/python-3.3
557     else
558       ERROR "Python--$PYTHON_VERSION failed to compile, exiting"
559       exit 1
560     fi
561
562     magic_compile_set python-$PYTHON_VERSION $py_magic
563
564     cd $CWD
565     INFO "Done compiling Python-$PYTHON_VERSION!"
566   else
567     INFO "Own Python-$PYTHON_VERSION is up to date, nothing to do!"
568     INFO "If you want to force rebuild of this lib, use the --force-python option."
569   fi
570 }
571
572 compile_Numpy() {
573   # To be changed each time we make edits that would modify the compiled result!
574   py_magic=0
575
576   _src=$SRC/numpy-$NUMPY_VERSION
577   _inst=$INST/numpy-$NUMPY_VERSION
578   _python=$INST/python-$PYTHON_VERSION
579   _site=lib/python3.3/site-packages
580
581   # Clean install if needed!
582   magic_compile_check numpy-$NUMPY_VERSION $py_magic
583   if [ $? -eq 1 -o $NUMPY_FORCE_REBUILD == true ]; then
584     rm -rf $_inst
585   fi
586
587   if [ ! -d $_inst ]; then
588     INFO "Building Numpy-$NUMPY_VERSION"
589
590     prepare_opt
591
592     if [ ! -d $_src ]; then
593       mkdir -p $SRC
594       wget -c $NUMPY_SOURCE -O $_src.tar.gz
595
596       INFO "Unpacking Numpy-$NUMPY_VERSION"
597       tar -C $SRC -xf $_src.tar.gz
598     fi
599
600     cd $_src
601
602     $_python/bin/python3 setup.py install --prefix=$_inst
603
604     if [ -d $_inst ]; then
605       rm -f $_python/$_site/numpy
606       ln -s $_inst/$_site/numpy $_python/$_site/numpy
607     else
608       ERROR "Numpy-$NUMPY_VERSION failed to compile, exiting"
609       exit 1
610     fi
611
612     magic_compile_set numpy-$NUMPY_VERSION $py_magic
613
614     cd $CWD
615     INFO "Done compiling Numpy-$NUMPY_VERSION!"
616   else
617     INFO "Own Numpy-$NUMPY_VERSION is up to date, nothing to do!"
618     INFO "If you want to force rebuild of this lib, use the --force-numpy option."
619   fi
620 }
621
622 compile_Boost() {
623   # To be changed each time we make edits that would modify the compiled result!
624   boost_magic=7
625
626   _src=$SRC/boost-$BOOST_VERSION
627   _inst=$INST/boost-$BOOST_VERSION
628
629   # Clean install if needed!
630   magic_compile_check boost-$BOOST_VERSION $boost_magic
631   if [ $? -eq 1 -o $BOOST_FORCE_REBUILD == true ]; then
632     rm -rf $_inst
633   fi
634
635   if [ ! -d $_inst ]; then
636     INFO "Building Boost-$BOOST_VERSION"
637
638     prepare_opt
639
640     if [ ! -d $_src ]; then
641       INFO "Downloading Boost-$BOOST_VERSION"
642       mkdir -p $SRC
643       wget -c $BOOST_SOURCE -O $_src.tar.bz2
644       tar -C $SRC --transform "s,(.*/?)boost_1_[^/]+(.*),\1boost-$BOOST_VERSION\2,x" -xf $_src.tar.bz2
645     fi
646
647     cd $_src
648     if [ ! -f $_src/b2 ]; then
649       ./bootstrap.sh
650     fi
651     ./b2 -j$THREADS -a --with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time \
652          --prefix=$_inst --disable-icu boost.locale.icu=off install
653     ./b2 --clean
654
655     if [ -d $_inst ]; then
656       rm -f $INST/boost
657       ln -s boost-$BOOST_VERSION $INST/boost
658     else
659       ERROR "Boost-$BOOST_VERSION failed to compile, exiting"
660       exit 1
661     fi
662
663     magic_compile_set boost-$BOOST_VERSION $boost_magic
664
665     # Rebuild dependecies as well!
666     OIIO_FORCE_REBUILD=true
667     OSL_FORCE_REBUILD=true
668
669     cd $CWD
670     INFO "Done compiling Boost-$BOOST_VERSION!"
671   else
672     INFO "Own Boost-$BOOST_VERSION is up to date, nothing to do!"
673     INFO "If you want to force rebuild of this lib, use the --force-boost option."
674   fi
675 }
676
677 compile_OCIO() {
678   # To be changed each time we make edits that would modify the compiled result!
679   ocio_magic=1
680
681   _src=$SRC/OpenColorIO-$OCIO_VERSION
682   _inst=$INST/ocio-$OCIO_VERSION
683
684   # Clean install if needed!
685   magic_compile_check ocio-$OCIO_VERSION $ocio_magic
686   if [ $? -eq 1 -o $OCIO_FORCE_REBUILD == true ]; then
687     rm -rf $_inst
688   fi
689
690   if [ ! -d $_inst ]; then
691     INFO "Building OpenColorIO-$OCIO_VERSION"
692
693     prepare_opt
694
695     if [ ! -d $_src ]; then
696       INFO "Downloading OpenColorIO-$OCIO_VERSION"
697       mkdir -p $SRC
698       wget -c $OCIO_SOURCE -O $_src.tar.gz
699
700       INFO "Unpacking OpenColorIO-$OCIO_VERSION"
701       tar -C $SRC --transform "s,(.*/?)imageworks-OpenColorIO[^/]*(.*),\1OpenColorIO-$OCIO_VERSION\2,x" \
702           -xf $_src.tar.gz
703     fi
704
705     cd $_src
706     # Always refresh the whole build!
707     if [ -d build ]; then
708       rm -rf build
709     fi    
710     mkdir build
711     cd build
712
713     if file /bin/cp | grep -q '32-bit'; then
714       cflags="-fPIC -m32 -march=i686"
715     else
716       cflags="-fPIC"
717     fi
718
719     cmake -D CMAKE_BUILD_TYPE=Release \
720           -D CMAKE_PREFIX_PATH=$_inst \
721           -D CMAKE_INSTALL_PREFIX=$_inst \
722           -D CMAKE_CXX_FLAGS="$cflags" \
723           -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" \
724           -D OCIO_BUILD_APPS=OFF \
725           -D OCIO_BUILD_PYGLUE=OFF \
726           ..
727
728     make -j$THREADS && make install
729
730     # Force linking against static libs
731     rm -f $_inst/lib/*.so*
732
733     # Additional depencencies
734     cp ext/dist/lib/libtinyxml.a $_inst/lib
735     cp ext/dist/lib/libyaml-cpp.a $_inst/lib
736
737     make clean
738
739     if [ -d $_inst ]; then
740       rm -f $INST/ocio
741       ln -s ocio-$OCIO_VERSION $INST/ocio
742     else
743       ERROR "OpenColorIO-$OCIO_VERSION failed to compile, exiting"
744       exit 1
745     fi
746
747     magic_compile_set ocio-$OCIO_VERSION $ocio_magic
748
749     cd $CWD
750     INFO "Done compiling OpenColorIO-$OCIO_VERSION!"
751   else
752     INFO "Own OpenColorIO-$OCIO_VERSION is up to date, nothing to do!"
753     INFO "If you want to force rebuild of this lib, use the --force-ocio option."
754   fi
755 }
756
757 compile_OIIO() {
758   # To be changed each time we make edits that would modify the compiled result!
759   oiio_magic=7
760
761   _src=$SRC/OpenImageIO-$OIIO_VERSION
762   _inst=$INST/oiio-$OIIO_VERSION
763
764   # Clean install if needed!
765   magic_compile_check oiio-$OIIO_VERSION $oiio_magic
766   if [ $? -eq 1 -o $OIIO_FORCE_REBUILD == true ]; then
767     rm -rf $_inst
768   fi
769
770   if [ ! -d $_inst ]; then
771     INFO "Building OpenImageIO-$OIIO_VERSION"
772
773     prepare_opt
774
775     if [ ! -d $_src ]; then
776       mkdir -p $SRC
777       wget -c $OIIO_SOURCE -O "$_src.tar.gz"
778
779       INFO "Unpacking OpenImageIO-$OIIO_VERSION"
780       tar -C $SRC --transform "s,(.*/?)OpenImageIO-oiio[^/]*(.*),\1OpenImageIO-$OIIO_VERSION\2,x" \
781           -xf $_src.tar.gz
782
783       cd $CWD
784
785     fi
786
787     cd $_src
788     # Always refresh the whole build!
789     if [ -d build ]; then
790       rm -rf build
791     fi    
792     mkdir build
793     cd build
794
795     cmake_d="-D CMAKE_BUILD_TYPE=Release"
796     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
797     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
798     cmake_d="$cmake_d -D BUILDSTATIC=ON"
799
800     # linking statically could give issues on Debian/Ubuntu (and probably other distros
801     # which doesn't like static linking) when linking shared oiio library due to missing
802     # text symbols (static libs should be compiled with -fPIC)
803     # cmake_d="$cmake_d -D LINKSTATIC=ON"
804
805     if [ -d $INST/boost ]; then
806       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
807       if $ALL_STATIC; then
808         cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"
809       fi
810     fi
811
812     # Looks like we do not need ocio in oiio for now...
813 #    if [ -d $INST/ocio ]; then
814 #      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
815 #    fi
816
817     if file /bin/cp | grep -q '32-bit'; then
818       cflags="-fPIC -m32 -march=i686"
819     else
820       cflags="-fPIC"
821     fi
822
823     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ../src
824
825     make -j$THREADS && make install
826     make clean
827
828     if [ -d $_inst ]; then
829       rm -f $INST/oiio
830       ln -s oiio-$OIIO_VERSION $INST/oiio
831     else
832       ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
833       exit 1
834     fi
835
836     magic_compile_set oiio-$OIIO_VERSION $oiio_magic
837
838     # Rebuild dependecies as well!
839     OSL_FORCE_REBUILD=true
840
841     cd $CWD
842     INFO "Done compiling OpenImageIO-$OIIO_VERSION!"
843   else
844     INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
845     INFO "If you want to force rebuild of this lib, use the --force-oiio option."
846   fi
847 }
848
849 compile_LLVM() {
850   # To be changed each time we make edits that would modify the compiled result!
851   llvm_magic=1
852
853   _src=$SRC/LLVM-$LLVM_VERSION
854   _inst=$INST/llvm-$LLVM_VERSION
855   _src_clang=$SRC/CLANG-$LLVM_VERSION
856
857   # Clean install if needed!
858   magic_compile_check llvm-$LLVM_VERSION $llvm_magic
859   if [ $? -eq 1 -o $LLVM_FORCE_REBUILD == true ]; then
860     rm -rf $_inst
861     rm -rf $_inst_clang
862   fi
863
864   if [ ! -d $_inst ]; then
865     INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
866
867     prepare_opt
868
869     if [ ! -d $_src -o true ]; then
870       mkdir -p $SRC
871       wget -c $LLVM_SOURCE -O "$_src.tar.gz"
872       wget -c $LLVM_CLANG_SOURCE -O "$_src_clang.tar.gz"
873
874       INFO "Unpacking LLVM-$LLVM_VERSION"
875       tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
876           -xf $_src.tar.gz
877       INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
878       tar -C $_src/tools \
879           --transform "s,([^/]*/?)clang-[^/]*(.*),\1clang\2,x" \
880           -xf $_src_clang.tar.gz
881
882       cd $_src
883
884       # XXX Ugly patching hack!
885       cat << EOF | patch -p1
886 --- a/CMakeLists.txt
887 +++ b/CMakeLists.txt
888 @@ -13,7 +13,7 @@
889  set(LLVM_VERSION_MAJOR 3)
890  set(LLVM_VERSION_MINOR 1)
891  
892 -set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
893 +set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
894  
895  set_property(GLOBAL PROPERTY USE_FOLDERS ON)
896  
897 EOF
898
899       cd $CWD
900
901     fi
902
903     cd $_src
904
905     # Always refresh the whole build!
906     if [ -d build ]; then
907       rm -rf build
908     fi    
909     mkdir build
910     cd build
911
912     cmake_d="-D CMAKE_BUILD_TYPE=Release"
913     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
914     cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
915     cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
916
917     if [ -d $_FFI_INCLUDE_DIR ]; then
918       cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
919     fi
920
921     cmake $cmake_d ..
922
923     make -j$THREADS && make install
924     make clean
925
926     if [ -d $_inst ]; then
927       rm -f $INST/llvm
928       ln -s llvm-$LLVM_VERSION $INST/llvm
929     else
930       ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
931       exit 1
932     fi
933
934     magic_compile_set llvm-$LLVM_VERSION $llvm_magic
935
936     # Rebuild dependecies as well!
937     OSL_FORCE_REBUILD=true
938
939     cd $CWD
940     INFO "Done compiling LLVM-$LLVM_VERSION (CLANG included)!"
941   else
942     INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
943     INFO "If you want to force rebuild of this lib, use the --force-llvm option."
944   fi
945 }
946
947 compile_OSL() {
948   # To be changed each time we make edits that would modify the compiled result!
949   osl_magic=7
950
951   _src=$SRC/OpenShadingLanguage-$OSL_VERSION
952   _inst=$INST/osl-$OSL_VERSION
953
954   # Clean install if needed!
955   magic_compile_check osl-$OSL_VERSION $osl_magic
956   if [ $? -eq 1 -o $OSL_FORCE_REBUILD == true ]; then
957     rm -rf $_inst
958   fi
959
960   if [ ! -d $_inst ]; then
961     INFO "Building OpenShadingLanguage-$OSL_VERSION"
962
963     prepare_opt
964
965     if [ ! -d $_src ]; then
966       mkdir -p $SRC
967
968       # XXX Using git on my own repo for now, looks like archives are not updated immediately... :/
969 #      wget -c $OSL_SOURCE -O "$_src.tar.gz"
970
971 #      INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
972 #      tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
973 #          -xf $_src.tar.gz
974       git clone https://github.com/mont29/OpenShadingLanguage.git $_src
975       cd $_src
976       git checkout blender-fixes
977       cd $CWD
978     fi
979
980     cd $_src
981     # XXX For now, always update from latest repo...
982     git pull origin
983
984     # Always refresh the whole build!
985     if [ -d build ]; then
986       rm -rf build
987     fi    
988     mkdir build
989     cd build
990
991     cmake_d="-D CMAKE_BUILD_TYPE=Release"
992     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
993     cmake_d="$cmake_d -D BUILDSTATIC=ON"
994     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
995     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
996
997     if [ -d $INST/boost ]; then
998       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
999       if $ALL_STATIC; then
1000         cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
1001       fi
1002     fi
1003
1004     if [ -d $INST/oiio ]; then
1005       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
1006     fi
1007
1008     if [ ! -z $LLVM_VERSION_FOUND ]; then
1009       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1010       if [ -d $INST/llvm ]; then
1011         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
1012         cmake_d="$cmake_d -D LLVM_STATIC=ON"
1013       fi
1014     fi
1015
1016     cmake $cmake_d ../src
1017
1018     make -j$THREADS && make install
1019     make clean
1020
1021     if [ -d $_inst ]; then
1022       rm -f $INST/osl
1023       ln -s osl-$OSL_VERSION $INST/osl
1024     else
1025       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
1026       exit 1
1027     fi
1028
1029     magic_compile_set osl-$OSL_VERSION $osl_magic
1030
1031     cd $CWD
1032     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
1033   else
1034     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
1035     INFO "If you want to force rebuild of this lib, use the --force-osl option."
1036   fi
1037 }
1038
1039 compile_OpenCOLLADA() {
1040   # To be changed each time we make edits that would modify the compiled results!
1041   opencollada_magic=5
1042
1043   _src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
1044   _inst=$INST/opencollada-$OPENCOLLADA_VERSION
1045
1046   # Clean install if needed!
1047   magic_compile_check opencollada-$OPENCOLLADA_VERSION $opencollada_magic
1048   if [ $? -eq 1 -o $OPENCOLLADA_FORCE_REBUILD == true ]; then
1049     rm -rf $_inst
1050   fi
1051
1052   if [ ! -d $_inst ]; then
1053     INFO "Building OpenCOLLADA-$OPENCOLLADA_VERSION"
1054
1055     prepare_opt
1056
1057     if [ ! -d $_src ]; then
1058       mkdir -p $SRC
1059       git clone $OPENCOLLADA_SOURCE $_src
1060     fi
1061
1062     cd $_src
1063
1064     # XXX For now, always update from latest repo...
1065     git pull origin
1066
1067     # Always refresh the whole build!
1068     if [ -d build ]; then
1069       rm -rf build
1070     fi
1071     mkdir build
1072     cd build
1073
1074     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1075     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1076     cmake_d="$cmake_d -D USE_EXPAT=OFF"
1077     cmake_d="$cmake_d -D USE_LIBXML=ON"
1078     cmake_d="$cmake_d -D USE_STATIC=ON"
1079
1080     cmake $cmake_d ../
1081
1082     make -j$THREADS && make install
1083     make clean
1084
1085     if [ -d $_inst ]; then
1086       rm -f $INST/opencollada
1087       ln -s opencollada-$OPENCOLLADA_VERSION $INST/opencollada
1088     else
1089       ERROR "OpenCOLLADA-$OPENCOLLADA_VERSION failed to compile, exiting"
1090       exit 1
1091     fi
1092
1093     magic_compile_set opencollada-$OPENCOLLADA_VERSION $opencollada_magic
1094
1095     cd $CWD
1096     INFO "Done compiling OpenCOLLADA-$OPENCOLLADA_VERSION!"
1097   else
1098     INFO "Own OpenCOLLADA-$OPENCOLLADA_VERSION is up to date, nothing to do!"
1099     INFO "If you want to force rebuild of this lib, use the --force-opencollada option."
1100   fi
1101 }
1102
1103 compile_FFmpeg() {
1104   # To be changed each time we make edits that would modify the compiled result!
1105   ffmpeg_magic=3
1106
1107   _src=$SRC/ffmpeg-$FFMPEG_VERSION
1108   _inst=$INST/ffmpeg-$FFMPEG_VERSION
1109
1110   # Clean install if needed!
1111   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
1112   if [ $? -eq 1 -o $FFMPEG_FORCE_REBUILD == true ]; then
1113     rm -rf $_inst
1114   fi
1115
1116   if [ ! -d $_inst ]; then
1117     INFO "Building ffmpeg-$FFMPEG_VERSION"
1118
1119     prepare_opt
1120
1121     if [ ! -d $_src ]; then
1122       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
1123       mkdir -p $SRC
1124       wget -c $FFMPEG_SOURCE -O "$_src.tar.bz2"
1125
1126       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
1127       tar -C $SRC -xf $_src.tar.bz2
1128     fi
1129
1130     cd $_src
1131
1132     extra=""
1133
1134     if $VORBIS_USE; then
1135       extra="$extra --enable-libvorbis"
1136     fi
1137
1138     if $THEORA_USE; then
1139       extra="$extra --enable-libtheora"
1140     fi
1141
1142     # XXX At least under Debian, static schro gives problem at blender linking time... :/
1143     if $SCHRO_USE && ! $ALL_STATIC; then
1144       extra="$extra --enable-libschroedinger"
1145     fi
1146
1147     if $XVID_USE; then
1148       extra="$extra --enable-libxvid"
1149     fi
1150
1151     if $X264_USE; then
1152       extra="$extra --enable-libx264"
1153     fi
1154
1155     if $VPX_USE; then
1156       extra="$extra --enable-libvpx"
1157     fi
1158
1159     if $MP3LAME_USE; then
1160       extra="$extra --enable-libmp3lame"
1161     fi
1162
1163     if $OPENJPEG_USE; then
1164       extra="$extra --enable-libopenjpeg"
1165     fi
1166
1167     ./configure --cc="gcc -Wl,--as-needed" \
1168         --extra-ldflags="-pthread -static-libgcc" \
1169         --prefix=$_inst --enable-static \
1170         --disable-ffplay --disable-ffserver --disable-doc \
1171         --enable-gray \
1172         --enable-avfilter --disable-vdpau \
1173         --disable-bzlib --disable-libgsm --disable-libspeex \
1174         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
1175         --disable-vaapi --disable-libfaac --disable-nonfree --enable-gpl \
1176         --disable-postproc --disable-x11grab --disable-librtmp --disable-libopencore-amrnb \
1177         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3 --disable-outdev=sdl \
1178         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
1179         --disable-indev=lavfi $extra
1180
1181     make -j$THREADS && make install
1182     make clean
1183
1184     if [ -d $_inst ]; then
1185       rm -f $INST/ffmpeg
1186       ln -s ffmpeg-$FFMPEG_VERSION $INST/ffmpeg
1187     else
1188       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
1189       exit 1
1190     fi
1191
1192     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
1193
1194     cd $CWD
1195     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
1196   else
1197     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
1198     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
1199   fi
1200 }
1201
1202
1203
1204 get_package_version_DEB() {
1205     dpkg-query -W -f '${Version}' $1 | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'
1206 }
1207
1208 check_package_DEB() {
1209   r=`apt-cache policy $1 | grep -c 'Candidate:'`
1210
1211   if [ $r -ge 1 ]; then
1212     return 0
1213   else
1214     return 1
1215   fi
1216 }
1217
1218 check_package_version_match_DEB() {
1219   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
1220
1221   if [ -z "$v" ]; then
1222     return 1
1223   fi
1224
1225   version_match $v $2
1226   return $?
1227 }
1228
1229 check_package_version_ge_DEB() {
1230   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
1231
1232   if [ -z "$v" ]; then
1233     return 1
1234   fi
1235
1236   version_ge $v $2
1237   return $?
1238 }
1239
1240 install_packages_DEB() {
1241   sudo apt-get install -y --force-yes $@
1242   if [ $? -ge 1 ]; then
1243     ERROR "apt-get failed to install requested packages, exiting."
1244     exit 1
1245   fi
1246 }
1247
1248 install_DEB() {
1249   INFO ""
1250   INFO "Installing dependencies for DEB-based distribution"
1251   INFO ""
1252   INFO "`eval _echo "$COMMON_INFO"`"
1253   INFO ""
1254
1255   read -p "Do you want to continue (Y/n)?"
1256   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1257
1258   if [ ! -z "`cat /etc/debian_version | grep ^6`"  ]; then
1259     if [ -z "`cat /etc/apt/sources.list | grep backports.debian.org`"  ]; then
1260       INFO "Looks like you're using Debian Squeeze which does have broken CMake"
1261       INFO "It is highly recommended to install cmake from backports, otherwise"
1262       INFO "compilation of some libraries could fail"
1263       INFO ""
1264       INFO "You could install newer CMake from debian-backports repository"
1265       INFO "Add this this line to your /etc/apt/sources.lixt:"
1266       INFO ""
1267       INFO "deb http://backports.debian.org/debian-backports squeeze-backports main"
1268       INFO ""
1269       INFO "and then run:"
1270       INFO ""
1271       INFO "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"
1272       INFO ""
1273       INFO "(you could also add this reporisotry using GUI like synaptic)"
1274       INFO ""
1275       INFO "Hit Enter to continue running the script, or hit Ctrl-C to abort the script"
1276
1277       read
1278       INFO ""
1279     fi
1280   fi
1281
1282   sudo apt-get update
1283
1284   # These libs should always be available in debian/ubuntu official repository...
1285   OPENJPEG_DEV="libopenjpeg-dev"
1286   VORBIS_DEV="libvorbis-dev"
1287   THEORA_DEV="libtheora-dev"
1288
1289   _packages="gawk cmake cmake-curses-gui scons build-essential libjpeg-dev libpng-dev \
1290              libfreetype6-dev libx11-dev libxi-dev wget libsqlite3-dev libbz2-dev \
1291              libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
1292              libopenexr-dev libopenal-dev libglew-dev yasm $THEORA_DEV $VORBIS_DEV \
1293              libsdl1.2-dev libfftw3-dev patch bzip2"
1294
1295   OPENJPEG_USE=true
1296   VORBIS_USE=true
1297   THEORA_USE=true
1298
1299   # Install newest libtiff-dev in debian/ubuntu.
1300   TIFF="libtiff5"
1301   check_package_DEB $TIFF
1302   if [ $? -eq 0 ]; then
1303     _packages="$_packages $TIFF-dev"
1304   else
1305     TIFF="libtiff"
1306     check_package_DEB $TIFF
1307     if [ $? -eq 0 ]; then
1308       _packages="$_packages $TIFF-dev"
1309     fi
1310   fi
1311
1312   if $WITH_ALL; then
1313     _packages="$_packages libspnav-dev libjack-dev"
1314   fi
1315
1316   INFO ""
1317   install_packages_DEB $_packages
1318
1319   INFO ""
1320   X264_DEV="libx264-dev"
1321   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
1322   if [ $? -eq 0 ]; then
1323     install_packages_DEB $X264_DEV
1324     X264_USE=true
1325   fi
1326
1327   if $WITH_ALL; then
1328     INFO ""
1329     # Grmpf, debian is libxvidcore-dev and ubuntu libxvidcore4-dev!
1330     # Note: not since ubuntu 10.04
1331     XVID_DEV="libxvidcore-dev"
1332     check_package_DEB $XVID_DEV
1333     if [ $? -eq 0 ]; then
1334       install_packages_DEB $XVID_DEV
1335       XVID_USE=true
1336     else
1337       XVID_DEV="libxvidcore4-dev"
1338       check_package_DEB $XVID_DEV
1339       if [ $? -eq 0 ]; then
1340         install_packages_DEB $XVID_DEV
1341         XVID_USE=true
1342       fi
1343     fi
1344
1345     INFO ""
1346     MP3LAME_DEV="libmp3lame-dev"
1347     check_package_DEB $MP3LAME_DEV
1348     if [ $? -eq 0 ]; then
1349       install_packages_DEB $MP3LAME_DEV
1350       MP3LAME_USE=true
1351     fi
1352
1353     INFO ""
1354     VPX_DEV="libvpx-dev"
1355     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
1356     if [ $? -eq 0 ]; then
1357       install_packages_DEB $VPX_DEV
1358       VPX_USE=true
1359     fi
1360
1361     INFO ""
1362     SCHRO_DEV="libschroedinger-dev"
1363     check_package_DEB $SCHRO_DEV
1364     if [ $? -eq 0 ]; then
1365       install_packages_DEB $SCHRO_DEV
1366       SCHRO_USE=true
1367     fi
1368   fi
1369
1370   INFO ""
1371   if $PYTHON_SKIP; then
1372     INFO "WARNING! Skipping Python installation, as requested..."
1373   else
1374     check_package_DEB python$PYTHON_VERSION_MIN-dev
1375     if [ $? -eq 0 ]; then
1376       install_packages_DEB python$PYTHON_VERSION_MIN-dev
1377       INFO ""
1378       if $NUMPY_SKIP; then
1379         INFO "WARNING! Skipping NumPy installation, as requested..."
1380       else
1381         check_package_DEB python$PYTHON_VERSION_MIN-numpy
1382         if [ $? -eq 0 ]; then
1383           install_packages_DEB python$PYTHON_VERSION_MIN-numpy
1384         else
1385           INFO "WARNING! Sorry, using python package but no numpy package available!"
1386         fi
1387       fi
1388     else
1389       compile_Python
1390       INFO ""
1391       if $NUMPY_SKIP; then
1392         INFO "WARNING! Skipping NumPy installation, as requested..."
1393       else
1394         compile_Numpy
1395       fi
1396     fi
1397   fi
1398
1399   INFO ""
1400   if $BOOST_SKIP; then
1401     INFO "WARNING! Skipping Boost installation, as requested..."
1402   else
1403     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
1404     if [ $? -eq 0 ]; then
1405       install_packages_DEB libboost-dev
1406
1407       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
1408
1409       check_package_DEB libboost-locale$boost_version-dev
1410       if [ $? -eq 0 ]; then
1411         install_packages_DEB libboost-locale$boost_version-dev libboost-filesystem$boost_version-dev \
1412                              libboost-regex$boost_version-dev libboost-system$boost_version-dev \
1413                              libboost-thread$boost_version-dev
1414       else
1415         compile_Boost
1416       fi
1417     else
1418       compile_Boost
1419     fi
1420   fi
1421
1422   INFO ""
1423   if $OCIO_SKIP; then
1424     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1425   else
1426     check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
1427     if [ $? -eq 0 ]; then
1428       install_packages_DEB libopencolorio-dev
1429     else
1430       compile_OCIO
1431     fi
1432   fi
1433
1434   INFO ""
1435   if $OIIO_SKIP; then
1436     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1437   else
1438     check_package_version_ge_DEB libopenimageio-dev $OIIO_VERSION_MIN
1439     if [ $? -eq 0 ]; then
1440       install_packages_DEB libopenimageio-dev
1441     else
1442       compile_OIIO
1443     fi
1444   fi
1445
1446   if $WITH_OSL; then
1447     have_llvm=false
1448
1449     if $LLVM_SKIP; then
1450       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1451     else
1452       INFO ""
1453       check_package_DEB llvm-$LLVM_VERSION-dev
1454       if [ $? -eq 0 ]; then
1455         install_packages_DEB llvm-$LLVM_VERSION-dev clang
1456         have_llvm=true
1457         LLVM_VERSION_FOUND=$LLVM_VERSION
1458       else
1459         check_package_DEB llvm-$LLVM_VERSION_MIN-dev
1460         if [ $? -eq 0 ]; then
1461           install_packages_DEB llvm-$LLVM_VERSION_MIN-dev clang
1462           have_llvm=true
1463           LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
1464         else
1465           install_packages_DEB libffi-dev
1466           # LLVM can't find the debian ffi header dir
1467           _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1468           INFO ""
1469           compile_LLVM
1470           have_llvm=true
1471           LLVM_VERSION_FOUND=$LLVM_VERSION
1472         fi
1473       fi
1474     fi
1475
1476     if $OSL_SKIP; then
1477       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1478     else
1479       if $have_llvm; then
1480         INFO ""
1481         install_packages_DEB flex bison libtbb-dev git
1482         # No package currently!
1483         INFO ""
1484         compile_OSL
1485       fi
1486     fi
1487   fi
1488
1489   if $WITH_OPENCOLLADA; then
1490     if $OPENCOLLADA_SKIP; then
1491       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1492     else
1493       INFO ""
1494       install_packages_DEB git libpcre3-dev libxml2-dev
1495       # Find path to libxml shared lib...
1496       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
1497       # No package
1498       INFO ""
1499       compile_OpenCOLLADA
1500     fi
1501   fi
1502
1503   INFO ""
1504   if $FFMPEG_SKIP; then
1505     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1506   else
1507 #    XXX Debian features libav packages as ffmpeg, those are not really compatible with blender code currently :/
1508 #        So for now, always build our own ffmpeg.
1509 #    check_package_DEB ffmpeg
1510 #    if [ $? -eq 0 ]; then
1511 #      install_packages_DEB ffmpeg
1512 #      ffmpeg_version=`get_package_version_DEB ffmpeg`
1513 #      INFO "ffmpeg version: $ffmpeg_version"
1514 #      if [ ! -z "$ffmpeg_version" ]; then
1515 #        if  dpkg --compare-versions $ffmpeg_version gt 0.7.2; then
1516 #          install_packages_DEB libavfilter-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev
1517 #        else
1518 #          compile_FFmpeg
1519 #        fi
1520 #      fi
1521 #    fi
1522     compile_FFmpeg
1523   fi
1524 }
1525
1526
1527
1528 get_package_version_RPM() {
1529   rpm_flavour
1530   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1531     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1532   elif [ $RPM = "SUSE" ]; then
1533     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1534   fi  
1535 }
1536
1537 check_package_RPM() {
1538   rpm_flavour
1539   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1540     r=`yum info $1 | grep -c 'Summary'`
1541   elif [ $RPM = "SUSE" ]; then
1542     r=`zypper info $1 | grep -c 'Summary'`
1543   fi
1544
1545   if [ $r -ge 1 ]; then
1546     return 0
1547   else
1548     return 1
1549   fi
1550 }
1551
1552 check_package_version_match_RPM() {
1553   v=`get_package_version_RPM $1`
1554
1555   if [ -z "$v" ]; then
1556     return 1
1557   fi
1558
1559   version_match $v $2
1560   return $?
1561 }
1562
1563 check_package_version_ge_RPM() {
1564   v=`get_package_version_RPM $1`
1565
1566   if [ -z "$v" ]; then
1567     return 1
1568   fi
1569
1570   version_ge $v $2
1571   return $?
1572 }
1573
1574 install_packages_RPM() {
1575   rpm_flavour
1576   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1577     sudo yum install -y $@
1578     if [ $? -ge 1 ]; then
1579       ERROR "yum failed to install requested packages, exiting."
1580       exit 1
1581     fi
1582
1583   elif [ $RPM = "SUSE" ]; then
1584     sudo zypper --non-interactive install --auto-agree-with-licenses $@
1585     if [ $? -ge 1 ]; then
1586       ERROR "zypper failed to install requested packages, exiting."
1587       exit 1
1588     fi
1589   fi
1590 }
1591
1592 install_RPM() {
1593   INFO ""
1594   INFO "Installing dependencies for RPM-based distribution"
1595   INFO ""
1596   INFO "`eval _echo "$COMMON_INFO"`"
1597   INFO ""
1598
1599   read -p "Do you want to continue (Y/n)?"
1600   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1601
1602   # Enable non-free repositories for all flavours
1603   rpm_flavour
1604   if [ $RPM = "FEDORA" ]; then
1605     sudo yum -y localinstall --nogpgcheck \
1606     http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \
1607     http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
1608
1609     sudo yum -y update
1610
1611     # Install cmake now because of difference with RHEL
1612     sudo yum -y install cmake
1613
1614   elif [ $RPM = "RHEL" ]; then
1615     sudo yum -y localinstall --nogpgcheck \
1616     http://download.fedoraproject.org/pub/epel/6/$(uname -i)/epel-release-6-8.noarch.rpm \
1617     http://download1.rpmfusion.org/free/el/updates/6/$(uname -i)/rpmfusion-free-release-6-1.noarch.rpm \
1618     http://download1.rpmfusion.org/nonfree/el/updates/6/$(uname -i)/rpmfusion-nonfree-release-6-1.noarch.rpm
1619
1620     sudo yum -y update
1621
1622     # Install cmake 2.8 from other repo
1623     mkdir -p $SRC
1624     if [ -f $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm ]; then
1625       INFO ""
1626       INFO "Special cmake already installed"
1627     else
1628       curl -O ftp://ftp.pbone.net/mirror/atrpms.net/el6-$(uname -i)/atrpms/testing/cmake-2.8.8-4.el6.$(uname -m).rpm
1629       mv cmake-2.8.8-4.el6.$(uname -m).rpm $SRC/
1630       sudo rpm -ihv $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm
1631     fi
1632
1633   elif [ $RPM = "SUSE" ]; then
1634     _suse_rel="`grep VERSION /etc/SuSE-release | gawk '{print $3}'`"
1635     sudo zypper ar -f http://packman.inode.at/suse/openSUSE_$_suse_rel/ packman
1636
1637     sudo zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
1638   fi
1639
1640   # These libs should always be available in fedora/suse official repository...
1641   OPENJPEG_DEV="openjpeg-devel"
1642   VORBIS_DEV="libvorbis-devel"
1643   THEORA_DEV="libtheora-devel"
1644
1645   _packages="gcc gcc-c++ make scons libpng-devel libtiff-devel \
1646              freetype-devel libX11-devel libXi-devel wget ncurses-devel \
1647              readline-devel $OPENJPEG_DEV openal-soft-devel \
1648              glew-devel yasm $THEORA_DEV $VORBIS_DEV SDL-devel fftw-devel \
1649              libjpeg-devel patch"
1650
1651   OPENJPEG_USE=true
1652   VORBIS_USE=true
1653   THEORA_USE=true
1654
1655   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1656
1657     _packages="$_packages libsqlite3-devel openexr-devel"
1658
1659     if $WITH_ALL; then
1660       _packages="$_packages jack-audio-connection-kit-devel libspnav-devel"
1661     fi
1662
1663     INFO ""
1664     install_packages_RPM $_packages
1665
1666     INFO ""
1667     X264_DEV="x264-devel"
1668     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1669     if [ $? -eq 0 ]; then
1670       install_packages_RPM $X264_DEV
1671       X264_USE=true
1672     fi
1673
1674     if $WITH_ALL; then
1675       INFO ""
1676       XVID_DEV="xvidcore-devel"
1677       check_package_RPM $XVID_DEV
1678       if [ $? -eq 0 ]; then
1679         install_packages_RPM $XVID_DEV
1680         XVID_USE=true
1681       fi
1682
1683       INFO ""
1684       MP3LAME_DEV="lame-devel"
1685       check_package_RPM $MP3LAME_DEV
1686       if [ $? -eq 0 ]; then
1687         install_packages_RPM $MP3LAME_DEV
1688         MP3LAME_USE=true
1689       fi
1690     fi
1691
1692   elif [ $RPM = "SUSE" ]; then
1693
1694     _packages="$_packages cmake sqlite3-devel libopenexr-devel"
1695
1696     if $WITH_ALL; then
1697       _packages="$_packages libjack-devel libspnav-devel"
1698     fi
1699
1700     INFO ""
1701     install_packages_RPM $_packages
1702
1703     INFO ""
1704     X264_DEV="libx264-devel"
1705     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1706     if [ $? -eq 0 ]; then
1707       install_packages_RPM $X264_DEV
1708       X264_USE=true
1709     fi
1710
1711     if $WITH_ALL; then
1712       INFO ""
1713       XVID_DEV="libxvidcore-devel"
1714       check_package_RPM $XVID_DEV
1715       if [ $? -eq 0 ]; then
1716         install_packages_RPM $XVID_DEV
1717         XVID_USE=true
1718       fi
1719
1720       INFO ""
1721       MP3LAME_DEV="libmp3lame-devel"
1722       check_package_RPM $MP3LAME_DEV
1723       if [ $? -eq 0 ]; then
1724         install_packages_RPM $MP3LAME_DEV
1725         MP3LAME_USE=true
1726       fi
1727     fi
1728   fi
1729
1730   if $WITH_ALL; then
1731     INFO ""
1732     VPX_DEV="libvpx-devel"
1733     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
1734     if [ $? -eq 0 ]; then
1735       install_packages_RPM $VPX_DEV
1736       VPX_USE=true
1737     fi
1738
1739     INFO ""
1740     SCHRO_DEV="schroedinger-devel"
1741     check_package_RPM $SCHRO_DEV
1742     if [ $? -eq 0 ]; then
1743       install_packages_RPM $SCHRO_DEV
1744       SCHRO_USE=true
1745     fi
1746   fi
1747  
1748   INFO ""
1749   if $PYTHON_SKIP; then
1750     INFO "WARNING! Skipping Python installation, as requested..."
1751   else
1752     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
1753     if [ $? -eq 0 ]; then
1754       install_packages_RPM python3-devel
1755       INFO ""
1756       if $NUMPY_SKIP; then
1757         INFO "WARNING! Skipping NumPy installation, as requested..."
1758       else
1759         check_package_version_match_RPM python3-numpy $NUMPY_VERSION_MIN
1760         if [ $? -eq 0 ]; then
1761           install_packages_RPM python3-numpy
1762         else
1763           INFO "WARNING! Sorry, using python package but no numpy package available!"
1764         fi
1765       fi
1766     else
1767       compile_Python
1768       INFO ""
1769       if $NUMPY_SKIP; then
1770         INFO "WARNING! Skipping NumPy installation, as requested..."
1771       else
1772         compile_Numpy
1773       fi
1774     fi
1775   fi
1776
1777   INFO ""
1778   if $BOOST_SKIP; then
1779     INFO "WARNING! Skipping Boost installation, as requested..."
1780   else
1781     check_package_version_ge_RPM boost-devel $BOOST_VERSION
1782     if [ $? -eq 0 ]; then
1783       install_packages_RPM boost-devel
1784     else
1785       compile_Boost
1786     fi
1787   fi
1788
1789   INFO ""
1790   if $OCIO_SKIP; then
1791     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1792   else
1793     check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
1794     if [ $? -eq 0 ]; then
1795       install_packages_RPM OpenColorIO-devel
1796     else
1797       compile_OCIO
1798     fi
1799   fi
1800
1801   INFO ""
1802   if $OIIO_SKIP; then
1803     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1804   else
1805     check_package_version_ge_RPM OpenImageIO-devel $OIIO_VERSION_MIN
1806     if [ $? -eq 0 ]; then
1807       install_packages_RPM OpenImageIO-devel
1808     else
1809       compile_OIIO
1810     fi
1811   fi
1812
1813   if $WITH_OSL; then
1814     have_llvm=false
1815
1816     INFO ""
1817     if $LLVM_SKIP; then
1818       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1819     else
1820       check_package_RPM llvm-$LLVM_VERSION-devel
1821       if [ $? -eq 0 ]; then
1822         install_packages_RPM llvm-$LLVM_VERSION-devel clang
1823         have_llvm=true
1824         LLVM_VERSION_FOUND=$LLVM_VERSION
1825       else
1826         #
1827         # Better to compile it than use minimum version from repo...
1828         #
1829       install_packages_RPM libffi-devel
1830       # LLVM can't find the fedora ffi header dir...
1831       _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1832       INFO ""
1833       compile_LLVM
1834       have_llvm=true
1835       LLVM_VERSION_FOUND=$LLVM_VERSION
1836       fi
1837     fi
1838
1839     if $OSL_SKIP; then
1840       INFO ""
1841       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1842     else
1843       if $have_llvm; then
1844         # No package currently!
1845         INFO ""
1846         install_packages_RPM flex bison git
1847         if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1848           install_packages_RPM tbb-devel
1849         fi
1850         INFO ""
1851         compile_OSL
1852       fi
1853     fi
1854   fi
1855
1856   if $WITH_OPENCOLLADA; then
1857     if $OPENCOLLADA_SKIP; then
1858       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1859     else
1860       INFO ""
1861       install_packages_RPM pcre-devel libxml2-devel git
1862       # Find path to libxml shared lib...
1863       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
1864       # No package...
1865       INFO ""
1866       compile_OpenCOLLADA
1867     fi
1868   fi
1869
1870   INFO ""
1871   if $FFMPEG_SKIP; then
1872     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1873   else
1874     # Always for now, not sure which packages should be installed
1875     compile_FFmpeg
1876   fi
1877 }
1878
1879
1880
1881 print_info_ffmpeglink_DEB() {
1882   if $ALL_STATIC; then
1883     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1884   else
1885     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1886   fi
1887 }
1888
1889 print_info_ffmpeglink_RPM() {
1890 #  # XXX No static libs...
1891 #  if $ALL_STATIC; then
1892 #    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1893 #  else
1894   rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1895 #  fi
1896 }
1897
1898 print_info_ffmpeglink() {
1899   # This func must only print a ';'-separated list of libs...
1900   if [ -z "$DISTRO" ]; then
1901     ERROR "Failed to detect distribution type"
1902     exit 1
1903   fi
1904
1905   # Create list of packages from which to get libs names...
1906   _packages=""
1907
1908   if $THEORA_USE; then
1909     _packages="$_packages $THEORA_DEV"
1910   fi
1911
1912   if $VORBIS_USE; then
1913     _packages="$_packages $VORBIS_DEV"
1914   fi
1915
1916   if $XVID_USE; then
1917     _packages="$_packages $XVID_DEV"
1918   fi
1919
1920   if $VPX_USE; then
1921     _packages="$_packages $VPX_DEV"
1922   fi
1923
1924   if $MP3LAME_USE; then
1925     _packages="$_packages $MP3LAME_DEV"
1926   fi
1927
1928   if $X264_USE; then
1929     _packages="$_packages $X264_DEV"
1930   fi
1931
1932   if $OPENJPEG_USE; then
1933     _packages="$_packages $OPENJPEG_DEV"
1934   fi
1935
1936   if $SCHRO_USE; then
1937     _packages="$_packages $SCHRO_DEV"
1938   fi
1939
1940   if [ "$DISTRO" = "DEB" ]; then
1941     print_info_ffmpeglink_DEB
1942   elif [ "$DISTRO" = "RPM" ]; then
1943     print_info_ffmpeglink_RPM
1944 #  elif [ "$DISTRO" = "ARCH" ]; then
1945 #    print_info_ffmpeglink_ARCH
1946   # XXX TODO!
1947   else INFO "<Could not determine additional link libraries needed for ffmpeg, replace this by valid list of libs...>"
1948   fi
1949 }
1950
1951 print_info() {
1952   INFO ""
1953   INFO "If you're using CMake add this to your configuration flags:"
1954
1955   _buildargs=""
1956
1957   if $ALL_STATIC; then
1958     _1="-D WITH_STATIC_LIBS=ON"
1959     # XXX Force linking with shared SDL lib!
1960     _2="-D SDL_LIBRARY='libSDL.so;-lpthread'"
1961     INFO "  $_1"
1962     INFO "  $_2"
1963     _buildargs="$_buildargs $_1 $_2"
1964   fi
1965
1966   if [ -d $INST/boost ]; then
1967     _1="-D BOOST_ROOT=$INST/boost"
1968     _2="-D Boost_NO_SYSTEM_PATHS=ON"
1969     INFO "  $_1"
1970     INFO "  $_2"
1971     _buildargs="$_buildargs $_1 $_2"
1972   elif $ALL_STATIC; then
1973     _1="-D Boost_USE_ICU=ON"
1974     INFO "  $_1"
1975     _buildargs="$_buildargs $_1"
1976   fi
1977
1978   if [ -d $INST/osl -a $WITH_OSL == true ]; then
1979     _1="-D CYCLES_OSL=$INST/osl"
1980     _2="-D WITH_CYCLES_OSL=ON"
1981     _3="-D LLVM_VERSION=$LLVM_VERSION_FOUND"
1982     INFO "  $_1"
1983     INFO "  $_2"
1984     INFO "  $_3"
1985     _buildargs="$_buildargs $_1 $_2 $_3"
1986     if [ -d $INST/llvm ]; then
1987       _1="-D LLVM_DIRECTORY=$INST/llvm"
1988       _2="-D LLVM_STATIC=ON"
1989       INFO "  $_1"
1990       INFO "  $_2"
1991       _buildargs="$_buildargs $_1 $_2"
1992     fi
1993   fi
1994
1995   if [ -d $INST/opencollada -a $WITH_OPENCOLLADA == true ]; then
1996     _1="-D WITH_OPENCOLLADA=ON"
1997     INFO "  $_1"
1998     _buildargs="$_buildargs $_1"
1999     if $ALL_STATIC; then
2000       _1="-D XML2_LIBRARY=$_XML2_LIB"
2001       INFO "  $_1"
2002       _buildargs="$_buildargs $_1"
2003     fi
2004   fi
2005
2006   if [ -d $INST/ffmpeg ]; then
2007     _1="-D WITH_CODEC_FFMPEG=ON"
2008     _2="-D FFMPEG=$INST/ffmpeg"
2009     _3="-D FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;rt;`print_info_ffmpeglink`'"
2010     INFO "  $_1"
2011     INFO "  $_2"
2012     INFO "  $_3"
2013     _buildargs="$_buildargs $_1 $_2 $_3"
2014   fi
2015
2016   INFO ""
2017   INFO "Or even simpler, just run (in your blender-source dir):"
2018   INFO "  make -j$THREADS BUILD_CMAKE_ARGS=\"$_buildargs\""
2019
2020   INFO ""
2021   INFO "If you're using SCons add this to your user-config:"
2022
2023   if [ -d $INST/python-$PYTHON_VERSION_MIN ]; then
2024     INFO "BF_PYTHON = '$INST/python-$PYTHON_VERSION_MIN'"
2025     INFO "BF_PYTHON_ABI_FLAGS = 'm'"
2026   fi
2027
2028   if [ -d $INST/ocio ]; then
2029     INFO "BF_OCIO = '$INST/ocio'"
2030   fi
2031
2032   if [ -d $INST/oiio ]; then
2033     INFO "BF_OIIO = '$INST/oiio'"
2034   fi
2035
2036   if [ -d $INST/osl ]; then
2037     INFO "BF_OSL = '$INST/osl'"
2038   fi
2039
2040   if [ -d $INST/boost ]; then
2041     INFO "BF_BOOST = '$INST/boost'"
2042     INFO "WITH_BF_BOOST = True"
2043   fi
2044
2045   if [ -d $INST/ffmpeg ]; then
2046     INFO "BF_FFMPEG = '$INST/ffmpeg'"
2047     _ffmpeg_list_sep=" "
2048     INFO "BF_FFMPEG_LIB = 'avformat avcodec swscale avutil avdevice `print_info_ffmpeglink`'"
2049   fi
2050
2051   INFO ""
2052   INFO ""
2053   INFO "WARNING: If this script had to build boost into $INST, and you are dynamically linking "
2054   INFO "         blender against it, you will have to run those commands as root user:"
2055   INFO ""
2056   INFO "    echo \"$INST/boost/lib\" > /etc/ld.so.conf.d/boost.conf"
2057   INFO "    ldconfig"
2058   INFO ""
2059 }
2060
2061 # Detect distributive type used on this machine
2062 detect_distro
2063
2064 if [ -z "$DISTRO" ]; then
2065   ERROR "Failed to detect distribution type"
2066   exit 1
2067 elif [ "$DISTRO" = "DEB" ]; then
2068   install_DEB
2069 elif [ "$DISTRO" = "RPM" ]; then
2070   install_RPM
2071 #elif [ "$DISTRO" = "ARCH" ]; then
2072 #  install_ARCH
2073 fi
2074
2075 print_info | tee BUILD_NOTES.txt
2076 INFO ""
2077 INFO "This information has been written to BUILD_NOTES.txt"
2078 INFO ""
2079
2080 # Switch back to user language.
2081 LANG=LANG_BACK
2082 export LANG