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