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