install_deps.sh:
[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     # Optional tests and cmd tools
801     cmake_d="$cmake_d -D USE_QT=OFF"
802     cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=OFF"
803     cmake_d="$cmake_d -D OIIO_BUILD_TESTS=OFF"
804
805     # linking statically could give issues on Debian/Ubuntu (and probably other distros
806     # which doesn't like static linking) when linking shared oiio library due to missing
807     # text symbols (static libs should be compiled with -fPIC)
808     # cmake_d="$cmake_d -D LINKSTATIC=ON"
809
810     if [ -d $INST/boost ]; then
811       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
812       if $ALL_STATIC; then
813         cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"
814       fi
815     fi
816
817     # Looks like we do not need ocio in oiio for now...
818 #    if [ -d $INST/ocio ]; then
819 #      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
820 #    fi
821
822     if file /bin/cp | grep -q '32-bit'; then
823       cflags="-fPIC -m32 -march=i686"
824     else
825       cflags="-fPIC"
826     fi
827
828     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ../src
829
830     make -j$THREADS && make install
831     make clean
832
833     if [ -d $_inst ]; then
834       rm -f $INST/oiio
835       ln -s oiio-$OIIO_VERSION $INST/oiio
836     else
837       ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
838       exit 1
839     fi
840
841     magic_compile_set oiio-$OIIO_VERSION $oiio_magic
842
843     # Rebuild dependecies as well!
844     OSL_FORCE_REBUILD=true
845
846     cd $CWD
847     INFO "Done compiling OpenImageIO-$OIIO_VERSION!"
848   else
849     INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
850     INFO "If you want to force rebuild of this lib, use the --force-oiio option."
851   fi
852 }
853
854 compile_LLVM() {
855   # To be changed each time we make edits that would modify the compiled result!
856   llvm_magic=1
857
858   _src=$SRC/LLVM-$LLVM_VERSION
859   _inst=$INST/llvm-$LLVM_VERSION
860   _src_clang=$SRC/CLANG-$LLVM_VERSION
861
862   # Clean install if needed!
863   magic_compile_check llvm-$LLVM_VERSION $llvm_magic
864   if [ $? -eq 1 -o $LLVM_FORCE_REBUILD == true ]; then
865     rm -rf $_inst
866     rm -rf $_inst_clang
867   fi
868
869   if [ ! -d $_inst ]; then
870     INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
871
872     prepare_opt
873
874     if [ ! -d $_src -o true ]; then
875       mkdir -p $SRC
876       wget -c $LLVM_SOURCE -O "$_src.tar.gz"
877       wget -c $LLVM_CLANG_SOURCE -O "$_src_clang.tar.gz"
878
879       INFO "Unpacking LLVM-$LLVM_VERSION"
880       tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
881           -xf $_src.tar.gz
882       INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
883       tar -C $_src/tools \
884           --transform "s,([^/]*/?)clang-[^/]*(.*),\1clang\2,x" \
885           -xf $_src_clang.tar.gz
886
887       cd $_src
888
889       # XXX Ugly patching hack!
890       cat << EOF | patch -p1
891 --- a/CMakeLists.txt
892 +++ b/CMakeLists.txt
893 @@ -13,7 +13,7 @@
894  set(LLVM_VERSION_MAJOR 3)
895  set(LLVM_VERSION_MINOR 1)
896  
897 -set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
898 +set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
899  
900  set_property(GLOBAL PROPERTY USE_FOLDERS ON)
901  
902 EOF
903
904       cd $CWD
905
906     fi
907
908     cd $_src
909
910     # Always refresh the whole build!
911     if [ -d build ]; then
912       rm -rf build
913     fi    
914     mkdir build
915     cd build
916
917     cmake_d="-D CMAKE_BUILD_TYPE=Release"
918     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
919     cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
920     cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
921
922     if [ -d $_FFI_INCLUDE_DIR ]; then
923       cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
924     fi
925
926     cmake $cmake_d ..
927
928     make -j$THREADS && make install
929     make clean
930
931     if [ -d $_inst ]; then
932       rm -f $INST/llvm
933       ln -s llvm-$LLVM_VERSION $INST/llvm
934     else
935       ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
936       exit 1
937     fi
938
939     magic_compile_set llvm-$LLVM_VERSION $llvm_magic
940
941     # Rebuild dependecies as well!
942     OSL_FORCE_REBUILD=true
943
944     cd $CWD
945     INFO "Done compiling LLVM-$LLVM_VERSION (CLANG included)!"
946   else
947     INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
948     INFO "If you want to force rebuild of this lib, use the --force-llvm option."
949   fi
950 }
951
952 compile_OSL() {
953   # To be changed each time we make edits that would modify the compiled result!
954   osl_magic=7
955
956   _src=$SRC/OpenShadingLanguage-$OSL_VERSION
957   _inst=$INST/osl-$OSL_VERSION
958
959   # Clean install if needed!
960   magic_compile_check osl-$OSL_VERSION $osl_magic
961   if [ $? -eq 1 -o $OSL_FORCE_REBUILD == true ]; then
962     rm -rf $_inst
963   fi
964
965   if [ ! -d $_inst ]; then
966     INFO "Building OpenShadingLanguage-$OSL_VERSION"
967
968     prepare_opt
969
970     if [ ! -d $_src ]; then
971       mkdir -p $SRC
972
973       # XXX Using git on my own repo for now, looks like archives are not updated immediately... :/
974 #      wget -c $OSL_SOURCE -O "$_src.tar.gz"
975
976 #      INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
977 #      tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
978 #          -xf $_src.tar.gz
979       git clone https://github.com/mont29/OpenShadingLanguage.git $_src
980       cd $_src
981       git checkout blender-fixes
982       cd $CWD
983     fi
984
985     cd $_src
986     # XXX For now, always update from latest repo...
987     git pull origin
988
989     # Always refresh the whole build!
990     if [ -d build ]; then
991       rm -rf build
992     fi    
993     mkdir build
994     cd build
995
996     cmake_d="-D CMAKE_BUILD_TYPE=Release"
997     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
998     cmake_d="$cmake_d -D BUILDSTATIC=ON"
999     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1000     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1001
1002     if [ -d $INST/boost ]; then
1003       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1004       if $ALL_STATIC; then
1005         cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
1006       fi
1007     fi
1008
1009     if [ -d $INST/oiio ]; then
1010       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
1011     fi
1012
1013     if [ ! -z $LLVM_VERSION_FOUND ]; then
1014       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1015       if [ -d $INST/llvm ]; then
1016         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
1017         cmake_d="$cmake_d -D LLVM_STATIC=ON"
1018       fi
1019     fi
1020
1021     cmake $cmake_d ../src
1022
1023     make -j$THREADS && make install
1024     make clean
1025
1026     if [ -d $_inst ]; then
1027       rm -f $INST/osl
1028       ln -s osl-$OSL_VERSION $INST/osl
1029     else
1030       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
1031       exit 1
1032     fi
1033
1034     magic_compile_set osl-$OSL_VERSION $osl_magic
1035
1036     cd $CWD
1037     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
1038   else
1039     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
1040     INFO "If you want to force rebuild of this lib, use the --force-osl option."
1041   fi
1042 }
1043
1044 compile_OpenCOLLADA() {
1045   # To be changed each time we make edits that would modify the compiled results!
1046   opencollada_magic=5
1047
1048   _src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
1049   _inst=$INST/opencollada-$OPENCOLLADA_VERSION
1050
1051   # Clean install if needed!
1052   magic_compile_check opencollada-$OPENCOLLADA_VERSION $opencollada_magic
1053   if [ $? -eq 1 -o $OPENCOLLADA_FORCE_REBUILD == true ]; then
1054     rm -rf $_inst
1055   fi
1056
1057   if [ ! -d $_inst ]; then
1058     INFO "Building OpenCOLLADA-$OPENCOLLADA_VERSION"
1059
1060     prepare_opt
1061
1062     if [ ! -d $_src ]; then
1063       mkdir -p $SRC
1064       git clone $OPENCOLLADA_SOURCE $_src
1065     fi
1066
1067     cd $_src
1068
1069     # XXX For now, always update from latest repo...
1070     git pull origin
1071
1072     # Always refresh the whole build!
1073     if [ -d build ]; then
1074       rm -rf build
1075     fi
1076     mkdir build
1077     cd build
1078
1079     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1080     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1081     cmake_d="$cmake_d -D USE_EXPAT=OFF"
1082     cmake_d="$cmake_d -D USE_LIBXML=ON"
1083     cmake_d="$cmake_d -D USE_STATIC=ON"
1084
1085     cmake $cmake_d ../
1086
1087     make -j$THREADS && make install
1088     make clean
1089
1090     if [ -d $_inst ]; then
1091       rm -f $INST/opencollada
1092       ln -s opencollada-$OPENCOLLADA_VERSION $INST/opencollada
1093     else
1094       ERROR "OpenCOLLADA-$OPENCOLLADA_VERSION failed to compile, exiting"
1095       exit 1
1096     fi
1097
1098     magic_compile_set opencollada-$OPENCOLLADA_VERSION $opencollada_magic
1099
1100     cd $CWD
1101     INFO "Done compiling OpenCOLLADA-$OPENCOLLADA_VERSION!"
1102   else
1103     INFO "Own OpenCOLLADA-$OPENCOLLADA_VERSION is up to date, nothing to do!"
1104     INFO "If you want to force rebuild of this lib, use the --force-opencollada option."
1105   fi
1106 }
1107
1108 compile_FFmpeg() {
1109   # To be changed each time we make edits that would modify the compiled result!
1110   ffmpeg_magic=3
1111
1112   _src=$SRC/ffmpeg-$FFMPEG_VERSION
1113   _inst=$INST/ffmpeg-$FFMPEG_VERSION
1114
1115   # Clean install if needed!
1116   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
1117   if [ $? -eq 1 -o $FFMPEG_FORCE_REBUILD == true ]; then
1118     rm -rf $_inst
1119   fi
1120
1121   if [ ! -d $_inst ]; then
1122     INFO "Building ffmpeg-$FFMPEG_VERSION"
1123
1124     prepare_opt
1125
1126     if [ ! -d $_src ]; then
1127       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
1128       mkdir -p $SRC
1129       wget -c $FFMPEG_SOURCE -O "$_src.tar.bz2"
1130
1131       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
1132       tar -C $SRC -xf $_src.tar.bz2
1133     fi
1134
1135     cd $_src
1136
1137     extra=""
1138
1139     if $VORBIS_USE; then
1140       extra="$extra --enable-libvorbis"
1141     fi
1142
1143     if $THEORA_USE; then
1144       extra="$extra --enable-libtheora"
1145     fi
1146
1147     # XXX At least under Debian, static schro gives problem at blender linking time... :/
1148     if $SCHRO_USE && ! $ALL_STATIC; then
1149       extra="$extra --enable-libschroedinger"
1150     fi
1151
1152     if $XVID_USE; then
1153       extra="$extra --enable-libxvid"
1154     fi
1155
1156     if $X264_USE; then
1157       extra="$extra --enable-libx264"
1158     fi
1159
1160     if $VPX_USE; then
1161       extra="$extra --enable-libvpx"
1162     fi
1163
1164     if $MP3LAME_USE; then
1165       extra="$extra --enable-libmp3lame"
1166     fi
1167
1168     if $OPENJPEG_USE; then
1169       extra="$extra --enable-libopenjpeg"
1170     fi
1171
1172     ./configure --cc="gcc -Wl,--as-needed" \
1173         --extra-ldflags="-pthread -static-libgcc" \
1174         --prefix=$_inst --enable-static \
1175         --disable-ffplay --disable-ffserver --disable-doc \
1176         --enable-gray \
1177         --enable-avfilter --disable-vdpau \
1178         --disable-bzlib --disable-libgsm --disable-libspeex \
1179         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
1180         --disable-vaapi --disable-libfaac --disable-nonfree --enable-gpl \
1181         --disable-postproc --disable-x11grab --disable-librtmp --disable-libopencore-amrnb \
1182         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3 --disable-outdev=sdl \
1183         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
1184         --disable-indev=lavfi $extra
1185
1186     make -j$THREADS && make install
1187     make clean
1188
1189     if [ -d $_inst ]; then
1190       rm -f $INST/ffmpeg
1191       ln -s ffmpeg-$FFMPEG_VERSION $INST/ffmpeg
1192     else
1193       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
1194       exit 1
1195     fi
1196
1197     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
1198
1199     cd $CWD
1200     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
1201   else
1202     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
1203     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
1204   fi
1205 }
1206
1207
1208
1209 get_package_version_DEB() {
1210     dpkg-query -W -f '${Version}' $1 | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'
1211 }
1212
1213 check_package_DEB() {
1214   r=`apt-cache policy $1 | grep -c 'Candidate:'`
1215
1216   if [ $r -ge 1 ]; then
1217     return 0
1218   else
1219     return 1
1220   fi
1221 }
1222
1223 check_package_version_match_DEB() {
1224   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
1225
1226   if [ -z "$v" ]; then
1227     return 1
1228   fi
1229
1230   version_match $v $2
1231   return $?
1232 }
1233
1234 check_package_version_ge_DEB() {
1235   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
1236
1237   if [ -z "$v" ]; then
1238     return 1
1239   fi
1240
1241   version_ge $v $2
1242   return $?
1243 }
1244
1245 install_packages_DEB() {
1246   sudo apt-get install -y --force-yes $@
1247   if [ $? -ge 1 ]; then
1248     ERROR "apt-get failed to install requested packages, exiting."
1249     exit 1
1250   fi
1251 }
1252
1253 install_DEB() {
1254   INFO ""
1255   INFO "Installing dependencies for DEB-based distribution"
1256   INFO ""
1257   INFO "`eval _echo "$COMMON_INFO"`"
1258   INFO ""
1259
1260   read -p "Do you want to continue (Y/n)?"
1261   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1262
1263   if [ ! -z "`cat /etc/debian_version | grep ^6`"  ]; then
1264     if [ -z "`cat /etc/apt/sources.list | grep backports.debian.org`"  ]; then
1265       INFO "Looks like you're using Debian Squeeze which does have broken CMake"
1266       INFO "It is highly recommended to install cmake from backports, otherwise"
1267       INFO "compilation of some libraries could fail"
1268       INFO ""
1269       INFO "You could install newer CMake from debian-backports repository"
1270       INFO "Add this this line to your /etc/apt/sources.lixt:"
1271       INFO ""
1272       INFO "deb http://backports.debian.org/debian-backports squeeze-backports main"
1273       INFO ""
1274       INFO "and then run:"
1275       INFO ""
1276       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"
1277       INFO ""
1278       INFO "(you could also add this reporisotry using GUI like synaptic)"
1279       INFO ""
1280       INFO "Hit Enter to continue running the script, or hit Ctrl-C to abort the script"
1281
1282       read
1283       INFO ""
1284     fi
1285   fi
1286
1287   sudo apt-get update
1288
1289   # These libs should always be available in debian/ubuntu official repository...
1290   OPENJPEG_DEV="libopenjpeg-dev"
1291   VORBIS_DEV="libvorbis-dev"
1292   THEORA_DEV="libtheora-dev"
1293
1294   _packages="gawk cmake cmake-curses-gui scons build-essential libjpeg-dev libpng-dev \
1295              libfreetype6-dev libx11-dev libxi-dev wget libsqlite3-dev libbz2-dev \
1296              libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
1297              libopenexr-dev libopenal-dev libglew-dev yasm $THEORA_DEV $VORBIS_DEV \
1298              libsdl1.2-dev libfftw3-dev patch bzip2"
1299
1300   OPENJPEG_USE=true
1301   VORBIS_USE=true
1302   THEORA_USE=true
1303
1304   # Install newest libtiff-dev in debian/ubuntu.
1305   TIFF="libtiff5"
1306   check_package_DEB $TIFF
1307   if [ $? -eq 0 ]; then
1308     _packages="$_packages $TIFF-dev"
1309   else
1310     TIFF="libtiff"
1311     check_package_DEB $TIFF
1312     if [ $? -eq 0 ]; then
1313       _packages="$_packages $TIFF-dev"
1314     fi
1315   fi
1316
1317   if $WITH_ALL; then
1318     _packages="$_packages libspnav-dev libjack-dev"
1319   fi
1320
1321   INFO ""
1322   install_packages_DEB $_packages
1323
1324   INFO ""
1325   X264_DEV="libx264-dev"
1326   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
1327   if [ $? -eq 0 ]; then
1328     install_packages_DEB $X264_DEV
1329     X264_USE=true
1330   fi
1331
1332   if $WITH_ALL; then
1333     INFO ""
1334     # Grmpf, debian is libxvidcore-dev and ubuntu libxvidcore4-dev!
1335     # Note: not since ubuntu 10.04
1336     XVID_DEV="libxvidcore-dev"
1337     check_package_DEB $XVID_DEV
1338     if [ $? -eq 0 ]; then
1339       install_packages_DEB $XVID_DEV
1340       XVID_USE=true
1341     else
1342       XVID_DEV="libxvidcore4-dev"
1343       check_package_DEB $XVID_DEV
1344       if [ $? -eq 0 ]; then
1345         install_packages_DEB $XVID_DEV
1346         XVID_USE=true
1347       fi
1348     fi
1349
1350     INFO ""
1351     MP3LAME_DEV="libmp3lame-dev"
1352     check_package_DEB $MP3LAME_DEV
1353     if [ $? -eq 0 ]; then
1354       install_packages_DEB $MP3LAME_DEV
1355       MP3LAME_USE=true
1356     fi
1357
1358     INFO ""
1359     VPX_DEV="libvpx-dev"
1360     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
1361     if [ $? -eq 0 ]; then
1362       install_packages_DEB $VPX_DEV
1363       VPX_USE=true
1364     fi
1365
1366     INFO ""
1367     SCHRO_DEV="libschroedinger-dev"
1368     check_package_DEB $SCHRO_DEV
1369     if [ $? -eq 0 ]; then
1370       install_packages_DEB $SCHRO_DEV
1371       SCHRO_USE=true
1372     fi
1373   fi
1374
1375   INFO ""
1376   if $PYTHON_SKIP; then
1377     INFO "WARNING! Skipping Python installation, as requested..."
1378   else
1379     check_package_DEB python$PYTHON_VERSION_MIN-dev
1380     if [ $? -eq 0 ]; then
1381       install_packages_DEB python$PYTHON_VERSION_MIN-dev
1382       INFO ""
1383       if $NUMPY_SKIP; then
1384         INFO "WARNING! Skipping NumPy installation, as requested..."
1385       else
1386         check_package_DEB python$PYTHON_VERSION_MIN-numpy
1387         if [ $? -eq 0 ]; then
1388           install_packages_DEB python$PYTHON_VERSION_MIN-numpy
1389         else
1390           INFO "WARNING! Sorry, using python package but no numpy package available!"
1391         fi
1392       fi
1393     else
1394       compile_Python
1395       INFO ""
1396       if $NUMPY_SKIP; then
1397         INFO "WARNING! Skipping NumPy installation, as requested..."
1398       else
1399         compile_Numpy
1400       fi
1401     fi
1402   fi
1403
1404   INFO ""
1405   if $BOOST_SKIP; then
1406     INFO "WARNING! Skipping Boost installation, as requested..."
1407   else
1408     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
1409     if [ $? -eq 0 ]; then
1410       install_packages_DEB libboost-dev
1411
1412       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
1413
1414       check_package_DEB libboost-locale$boost_version-dev
1415       if [ $? -eq 0 ]; then
1416         install_packages_DEB libboost-locale$boost_version-dev libboost-filesystem$boost_version-dev \
1417                              libboost-regex$boost_version-dev libboost-system$boost_version-dev \
1418                              libboost-thread$boost_version-dev
1419       else
1420         compile_Boost
1421       fi
1422     else
1423       compile_Boost
1424     fi
1425   fi
1426
1427   INFO ""
1428   if $OCIO_SKIP; then
1429     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1430   else
1431     check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
1432     if [ $? -eq 0 ]; then
1433       install_packages_DEB libopencolorio-dev
1434     else
1435       compile_OCIO
1436     fi
1437   fi
1438
1439   INFO ""
1440   if $OIIO_SKIP; then
1441     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1442   else
1443     check_package_version_ge_DEB libopenimageio-dev $OIIO_VERSION_MIN
1444     if [ $? -eq 0 ]; then
1445       install_packages_DEB libopenimageio-dev
1446     else
1447       compile_OIIO
1448     fi
1449   fi
1450
1451   if $WITH_OSL; then
1452     have_llvm=false
1453
1454     if $LLVM_SKIP; then
1455       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1456     else
1457       INFO ""
1458       check_package_DEB llvm-$LLVM_VERSION-dev
1459       if [ $? -eq 0 ]; then
1460         install_packages_DEB llvm-$LLVM_VERSION-dev clang
1461         have_llvm=true
1462         LLVM_VERSION_FOUND=$LLVM_VERSION
1463       else
1464         check_package_DEB llvm-$LLVM_VERSION_MIN-dev
1465         if [ $? -eq 0 ]; then
1466           install_packages_DEB llvm-$LLVM_VERSION_MIN-dev clang
1467           have_llvm=true
1468           LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
1469         else
1470           install_packages_DEB libffi-dev
1471           # LLVM can't find the debian ffi header dir
1472           _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1473           INFO ""
1474           compile_LLVM
1475           have_llvm=true
1476           LLVM_VERSION_FOUND=$LLVM_VERSION
1477         fi
1478       fi
1479     fi
1480
1481     if $OSL_SKIP; then
1482       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1483     else
1484       if $have_llvm; then
1485         INFO ""
1486         install_packages_DEB flex bison libtbb-dev git
1487         # No package currently!
1488         INFO ""
1489         compile_OSL
1490       fi
1491     fi
1492   fi
1493
1494   if $WITH_OPENCOLLADA; then
1495     if $OPENCOLLADA_SKIP; then
1496       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1497     else
1498       INFO ""
1499       install_packages_DEB git libpcre3-dev libxml2-dev
1500       # Find path to libxml shared lib...
1501       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
1502       # No package
1503       INFO ""
1504       compile_OpenCOLLADA
1505     fi
1506   fi
1507
1508   INFO ""
1509   if $FFMPEG_SKIP; then
1510     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1511   else
1512 #    XXX Debian features libav packages as ffmpeg, those are not really compatible with blender code currently :/
1513 #        So for now, always build our own ffmpeg.
1514 #    check_package_DEB ffmpeg
1515 #    if [ $? -eq 0 ]; then
1516 #      install_packages_DEB ffmpeg
1517 #      ffmpeg_version=`get_package_version_DEB ffmpeg`
1518 #      INFO "ffmpeg version: $ffmpeg_version"
1519 #      if [ ! -z "$ffmpeg_version" ]; then
1520 #        if  dpkg --compare-versions $ffmpeg_version gt 0.7.2; then
1521 #          install_packages_DEB libavfilter-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev
1522 #        else
1523 #          compile_FFmpeg
1524 #        fi
1525 #      fi
1526 #    fi
1527     compile_FFmpeg
1528   fi
1529 }
1530
1531
1532
1533 get_package_version_RPM() {
1534   rpm_flavour
1535   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1536     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1537   elif [ $RPM = "SUSE" ]; then
1538     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1539   fi  
1540 }
1541
1542 check_package_RPM() {
1543   rpm_flavour
1544   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1545     r=`yum info $1 | grep -c 'Summary'`
1546   elif [ $RPM = "SUSE" ]; then
1547     r=`zypper info $1 | grep -c 'Summary'`
1548   fi
1549
1550   if [ $r -ge 1 ]; then
1551     return 0
1552   else
1553     return 1
1554   fi
1555 }
1556
1557 check_package_version_match_RPM() {
1558   v=`get_package_version_RPM $1`
1559
1560   if [ -z "$v" ]; then
1561     return 1
1562   fi
1563
1564   version_match $v $2
1565   return $?
1566 }
1567
1568 check_package_version_ge_RPM() {
1569   v=`get_package_version_RPM $1`
1570
1571   if [ -z "$v" ]; then
1572     return 1
1573   fi
1574
1575   version_ge $v $2
1576   return $?
1577 }
1578
1579 install_packages_RPM() {
1580   rpm_flavour
1581   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1582     sudo yum install -y $@
1583     if [ $? -ge 1 ]; then
1584       ERROR "yum failed to install requested packages, exiting."
1585       exit 1
1586     fi
1587
1588   elif [ $RPM = "SUSE" ]; then
1589     sudo zypper --non-interactive install --auto-agree-with-licenses $@
1590     if [ $? -ge 1 ]; then
1591       ERROR "zypper failed to install requested packages, exiting."
1592       exit 1
1593     fi
1594   fi
1595 }
1596
1597 install_RPM() {
1598   INFO ""
1599   INFO "Installing dependencies for RPM-based distribution"
1600   INFO ""
1601   INFO "`eval _echo "$COMMON_INFO"`"
1602   INFO ""
1603
1604   read -p "Do you want to continue (Y/n)?"
1605   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1606
1607   # Enable non-free repositories for all flavours
1608   rpm_flavour
1609   if [ $RPM = "FEDORA" ]; then
1610     sudo yum -y localinstall --nogpgcheck \
1611     http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \
1612     http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
1613
1614     sudo yum -y update
1615
1616     # Install cmake now because of difference with RHEL
1617     sudo yum -y install cmake
1618
1619   elif [ $RPM = "RHEL" ]; then
1620     sudo yum -y localinstall --nogpgcheck \
1621     http://download.fedoraproject.org/pub/epel/6/$(uname -i)/epel-release-6-8.noarch.rpm \
1622     http://download1.rpmfusion.org/free/el/updates/6/$(uname -i)/rpmfusion-free-release-6-1.noarch.rpm \
1623     http://download1.rpmfusion.org/nonfree/el/updates/6/$(uname -i)/rpmfusion-nonfree-release-6-1.noarch.rpm
1624
1625     sudo yum -y update
1626
1627     # Install cmake 2.8 from other repo
1628     mkdir -p $SRC
1629     if [ -f $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm ]; then
1630       INFO ""
1631       INFO "Special cmake already installed"
1632     else
1633       curl -O ftp://ftp.pbone.net/mirror/atrpms.net/el6-$(uname -i)/atrpms/testing/cmake-2.8.8-4.el6.$(uname -m).rpm
1634       mv cmake-2.8.8-4.el6.$(uname -m).rpm $SRC/
1635       sudo rpm -ihv $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm
1636     fi
1637
1638   elif [ $RPM = "SUSE" ]; then
1639     _suse_rel="`grep VERSION /etc/SuSE-release | gawk '{print $3}'`"
1640     sudo zypper ar -f http://packman.inode.at/suse/openSUSE_$_suse_rel/ packman
1641
1642     sudo zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
1643   fi
1644
1645   # These libs should always be available in fedora/suse official repository...
1646   OPENJPEG_DEV="openjpeg-devel"
1647   VORBIS_DEV="libvorbis-devel"
1648   THEORA_DEV="libtheora-devel"
1649
1650   _packages="gcc gcc-c++ make scons libpng-devel libtiff-devel \
1651              freetype-devel libX11-devel libXi-devel wget ncurses-devel \
1652              readline-devel $OPENJPEG_DEV openal-soft-devel \
1653              glew-devel yasm $THEORA_DEV $VORBIS_DEV SDL-devel fftw-devel \
1654              libjpeg-devel patch"
1655
1656   OPENJPEG_USE=true
1657   VORBIS_USE=true
1658   THEORA_USE=true
1659
1660   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1661
1662     _packages="$_packages libsqlite3-devel openexr-devel"
1663
1664     if $WITH_ALL; then
1665       _packages="$_packages jack-audio-connection-kit-devel libspnav-devel"
1666     fi
1667
1668     INFO ""
1669     install_packages_RPM $_packages
1670
1671     INFO ""
1672     X264_DEV="x264-devel"
1673     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1674     if [ $? -eq 0 ]; then
1675       install_packages_RPM $X264_DEV
1676       X264_USE=true
1677     fi
1678
1679     if $WITH_ALL; then
1680       INFO ""
1681       XVID_DEV="xvidcore-devel"
1682       check_package_RPM $XVID_DEV
1683       if [ $? -eq 0 ]; then
1684         install_packages_RPM $XVID_DEV
1685         XVID_USE=true
1686       fi
1687
1688       INFO ""
1689       MP3LAME_DEV="lame-devel"
1690       check_package_RPM $MP3LAME_DEV
1691       if [ $? -eq 0 ]; then
1692         install_packages_RPM $MP3LAME_DEV
1693         MP3LAME_USE=true
1694       fi
1695     fi
1696
1697   elif [ $RPM = "SUSE" ]; then
1698
1699     _packages="$_packages cmake sqlite3-devel libopenexr-devel"
1700
1701     if $WITH_ALL; then
1702       _packages="$_packages libjack-devel libspnav-devel"
1703     fi
1704
1705     INFO ""
1706     install_packages_RPM $_packages
1707
1708     INFO ""
1709     X264_DEV="libx264-devel"
1710     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1711     if [ $? -eq 0 ]; then
1712       install_packages_RPM $X264_DEV
1713       X264_USE=true
1714     fi
1715
1716     if $WITH_ALL; then
1717       INFO ""
1718       XVID_DEV="libxvidcore-devel"
1719       check_package_RPM $XVID_DEV
1720       if [ $? -eq 0 ]; then
1721         install_packages_RPM $XVID_DEV
1722         XVID_USE=true
1723       fi
1724
1725       INFO ""
1726       MP3LAME_DEV="libmp3lame-devel"
1727       check_package_RPM $MP3LAME_DEV
1728       if [ $? -eq 0 ]; then
1729         install_packages_RPM $MP3LAME_DEV
1730         MP3LAME_USE=true
1731       fi
1732     fi
1733   fi
1734
1735   if $WITH_ALL; then
1736     INFO ""
1737     VPX_DEV="libvpx-devel"
1738     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
1739     if [ $? -eq 0 ]; then
1740       install_packages_RPM $VPX_DEV
1741       VPX_USE=true
1742     fi
1743
1744     INFO ""
1745     SCHRO_DEV="schroedinger-devel"
1746     check_package_RPM $SCHRO_DEV
1747     if [ $? -eq 0 ]; then
1748       install_packages_RPM $SCHRO_DEV
1749       SCHRO_USE=true
1750     fi
1751   fi
1752  
1753   INFO ""
1754   if $PYTHON_SKIP; then
1755     INFO "WARNING! Skipping Python installation, as requested..."
1756   else
1757     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
1758     if [ $? -eq 0 ]; then
1759       install_packages_RPM python3-devel
1760       INFO ""
1761       if $NUMPY_SKIP; then
1762         INFO "WARNING! Skipping NumPy installation, as requested..."
1763       else
1764         check_package_version_match_RPM python3-numpy $NUMPY_VERSION_MIN
1765         if [ $? -eq 0 ]; then
1766           install_packages_RPM python3-numpy
1767         else
1768           INFO "WARNING! Sorry, using python package but no numpy package available!"
1769         fi
1770       fi
1771     else
1772       compile_Python
1773       INFO ""
1774       if $NUMPY_SKIP; then
1775         INFO "WARNING! Skipping NumPy installation, as requested..."
1776       else
1777         compile_Numpy
1778       fi
1779     fi
1780   fi
1781
1782   INFO ""
1783   if $BOOST_SKIP; then
1784     INFO "WARNING! Skipping Boost installation, as requested..."
1785   else
1786     check_package_version_ge_RPM boost-devel $BOOST_VERSION
1787     if [ $? -eq 0 ]; then
1788       install_packages_RPM boost-devel
1789     else
1790       compile_Boost
1791     fi
1792   fi
1793
1794   INFO ""
1795   if $OCIO_SKIP; then
1796     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1797   else
1798     check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
1799     if [ $? -eq 0 ]; then
1800       install_packages_RPM OpenColorIO-devel
1801     else
1802       compile_OCIO
1803     fi
1804   fi
1805
1806   INFO ""
1807   if $OIIO_SKIP; then
1808     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1809   else
1810     check_package_version_ge_RPM OpenImageIO-devel $OIIO_VERSION_MIN
1811     if [ $? -eq 0 ]; then
1812       install_packages_RPM OpenImageIO-devel
1813     else
1814       compile_OIIO
1815     fi
1816   fi
1817
1818   if $WITH_OSL; then
1819     have_llvm=false
1820
1821     INFO ""
1822     if $LLVM_SKIP; then
1823       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1824     else
1825       check_package_RPM llvm-$LLVM_VERSION-devel
1826       if [ $? -eq 0 ]; then
1827         install_packages_RPM llvm-$LLVM_VERSION-devel clang
1828         have_llvm=true
1829         LLVM_VERSION_FOUND=$LLVM_VERSION
1830       else
1831         #
1832         # Better to compile it than use minimum version from repo...
1833         #
1834       install_packages_RPM libffi-devel
1835       # LLVM can't find the fedora ffi header dir...
1836       _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1837       INFO ""
1838       compile_LLVM
1839       have_llvm=true
1840       LLVM_VERSION_FOUND=$LLVM_VERSION
1841       fi
1842     fi
1843
1844     if $OSL_SKIP; then
1845       INFO ""
1846       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1847     else
1848       if $have_llvm; then
1849         # No package currently!
1850         INFO ""
1851         install_packages_RPM flex bison git
1852         if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1853           install_packages_RPM tbb-devel
1854         fi
1855         INFO ""
1856         compile_OSL
1857       fi
1858     fi
1859   fi
1860
1861   if $WITH_OPENCOLLADA; then
1862     if $OPENCOLLADA_SKIP; then
1863       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1864     else
1865       INFO ""
1866       install_packages_RPM pcre-devel libxml2-devel git
1867       # Find path to libxml shared lib...
1868       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
1869       # No package...
1870       INFO ""
1871       compile_OpenCOLLADA
1872     fi
1873   fi
1874
1875   INFO ""
1876   if $FFMPEG_SKIP; then
1877     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1878   else
1879     # Always for now, not sure which packages should be installed
1880     compile_FFmpeg
1881   fi
1882 }
1883
1884
1885
1886 print_info_ffmpeglink_DEB() {
1887   if $ALL_STATIC; then
1888     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1889   else
1890     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1891   fi
1892 }
1893
1894 print_info_ffmpeglink_RPM() {
1895 #  # XXX No static libs...
1896 #  if $ALL_STATIC; then
1897 #    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1898 #  else
1899   rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1900 #  fi
1901 }
1902
1903 print_info_ffmpeglink() {
1904   # This func must only print a ';'-separated list of libs...
1905   if [ -z "$DISTRO" ]; then
1906     ERROR "Failed to detect distribution type"
1907     exit 1
1908   fi
1909
1910   # Create list of packages from which to get libs names...
1911   _packages=""
1912
1913   if $THEORA_USE; then
1914     _packages="$_packages $THEORA_DEV"
1915   fi
1916
1917   if $VORBIS_USE; then
1918     _packages="$_packages $VORBIS_DEV"
1919   fi
1920
1921   if $XVID_USE; then
1922     _packages="$_packages $XVID_DEV"
1923   fi
1924
1925   if $VPX_USE; then
1926     _packages="$_packages $VPX_DEV"
1927   fi
1928
1929   if $MP3LAME_USE; then
1930     _packages="$_packages $MP3LAME_DEV"
1931   fi
1932
1933   if $X264_USE; then
1934     _packages="$_packages $X264_DEV"
1935   fi
1936
1937   if $OPENJPEG_USE; then
1938     _packages="$_packages $OPENJPEG_DEV"
1939   fi
1940
1941   if $SCHRO_USE; then
1942     _packages="$_packages $SCHRO_DEV"
1943   fi
1944
1945   if [ "$DISTRO" = "DEB" ]; then
1946     print_info_ffmpeglink_DEB
1947   elif [ "$DISTRO" = "RPM" ]; then
1948     print_info_ffmpeglink_RPM
1949 #  elif [ "$DISTRO" = "ARCH" ]; then
1950 #    print_info_ffmpeglink_ARCH
1951   # XXX TODO!
1952   else INFO "<Could not determine additional link libraries needed for ffmpeg, replace this by valid list of libs...>"
1953   fi
1954 }
1955
1956 print_info() {
1957   INFO ""
1958   INFO "If you're using CMake add this to your configuration flags:"
1959
1960   _buildargs=""
1961
1962   if $ALL_STATIC; then
1963     _1="-D WITH_STATIC_LIBS=ON"
1964     # XXX Force linking with shared SDL lib!
1965     _2="-D SDL_LIBRARY='libSDL.so;-lpthread'"
1966     INFO "  $_1"
1967     INFO "  $_2"
1968     _buildargs="$_buildargs $_1 $_2"
1969   fi
1970
1971   if [ -d $INST/boost ]; then
1972     _1="-D BOOST_ROOT=$INST/boost"
1973     _2="-D Boost_NO_SYSTEM_PATHS=ON"
1974     INFO "  $_1"
1975     INFO "  $_2"
1976     _buildargs="$_buildargs $_1 $_2"
1977   elif $ALL_STATIC; then
1978     _1="-D WITH_BOOST_ICU=ON"
1979     INFO "  $_1"
1980     _buildargs="$_buildargs $_1"
1981   fi
1982
1983   if [ -d $INST/osl -a $WITH_OSL == true ]; then
1984     _1="-D CYCLES_OSL=$INST/osl"
1985     _2="-D WITH_CYCLES_OSL=ON"
1986     _3="-D LLVM_VERSION=$LLVM_VERSION_FOUND"
1987     INFO "  $_1"
1988     INFO "  $_2"
1989     INFO "  $_3"
1990     _buildargs="$_buildargs $_1 $_2 $_3"
1991     if [ -d $INST/llvm ]; then
1992       _1="-D LLVM_DIRECTORY=$INST/llvm"
1993       _2="-D LLVM_STATIC=ON"
1994       INFO "  $_1"
1995       INFO "  $_2"
1996       _buildargs="$_buildargs $_1 $_2"
1997     fi
1998   fi
1999
2000   if [ -d $INST/opencollada -a $WITH_OPENCOLLADA == true ]; then
2001     _1="-D WITH_OPENCOLLADA=ON"
2002     INFO "  $_1"
2003     _buildargs="$_buildargs $_1"
2004     if $ALL_STATIC; then
2005       _1="-D XML2_LIBRARY=$_XML2_LIB"
2006       INFO "  $_1"
2007       _buildargs="$_buildargs $_1"
2008     fi
2009   fi
2010
2011   if [ -d $INST/ffmpeg ]; then
2012     _1="-D WITH_CODEC_FFMPEG=ON"
2013     _2="-D FFMPEG=$INST/ffmpeg"
2014     _3="-D FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;rt;`print_info_ffmpeglink`'"
2015     INFO "  $_1"
2016     INFO "  $_2"
2017     INFO "  $_3"
2018     _buildargs="$_buildargs $_1 $_2 $_3"
2019   fi
2020
2021   INFO ""
2022   INFO "Or even simpler, just run (in your blender-source dir):"
2023   INFO "  make -j$THREADS BUILD_CMAKE_ARGS=\"$_buildargs\""
2024
2025   INFO ""
2026   INFO "If you're using SCons add this to your user-config:"
2027
2028   if [ -d $INST/python-$PYTHON_VERSION_MIN ]; then
2029     INFO "BF_PYTHON = '$INST/python-$PYTHON_VERSION_MIN'"
2030     INFO "BF_PYTHON_ABI_FLAGS = 'm'"
2031   fi
2032
2033   if [ -d $INST/ocio ]; then
2034     INFO "BF_OCIO = '$INST/ocio'"
2035   fi
2036
2037   if [ -d $INST/oiio ]; then
2038     INFO "BF_OIIO = '$INST/oiio'"
2039   fi
2040
2041   if [ -d $INST/osl ]; then
2042     INFO "BF_OSL = '$INST/osl'"
2043   fi
2044
2045   if [ -d $INST/boost ]; then
2046     INFO "BF_BOOST = '$INST/boost'"
2047     INFO "WITH_BF_BOOST = True"
2048   fi
2049
2050   if [ -d $INST/ffmpeg ]; then
2051     INFO "BF_FFMPEG = '$INST/ffmpeg'"
2052     _ffmpeg_list_sep=" "
2053     INFO "BF_FFMPEG_LIB = 'avformat avcodec swscale avutil avdevice `print_info_ffmpeglink`'"
2054   fi
2055
2056   INFO ""
2057   INFO ""
2058   INFO "WARNING: If this script had to build boost into $INST, and you are dynamically linking "
2059   INFO "         blender against it, you will have to run those commands as root user:"
2060   INFO ""
2061   INFO "    echo \"$INST/boost/lib\" > /etc/ld.so.conf.d/boost.conf"
2062   INFO "    ldconfig"
2063   INFO ""
2064 }
2065
2066 # Detect distributive type used on this machine
2067 detect_distro
2068
2069 if [ -z "$DISTRO" ]; then
2070   ERROR "Failed to detect distribution type"
2071   exit 1
2072 elif [ "$DISTRO" = "DEB" ]; then
2073   install_DEB
2074 elif [ "$DISTRO" = "RPM" ]; then
2075   install_RPM
2076 #elif [ "$DISTRO" = "ARCH" ]; then
2077 #  install_ARCH
2078 fi
2079
2080 print_info | tee BUILD_NOTES.txt
2081 INFO ""
2082 INFO "This information has been written to BUILD_NOTES.txt"
2083 INFO ""
2084
2085 # Switch back to user language.
2086 LANG=LANG_BACK
2087 export LANG