OSL install deps script: set STOP_ON_WARNING to OFF to disable -Werror.
[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     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
880
881     if [ -d $INST/boost ]; then
882       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
883       if $ALL_STATIC; then
884         cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
885       fi
886     fi
887
888     if [ -d $INST/oiio ]; then
889       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
890     fi
891
892     if [ ! -z $LLVM_VERSION_FOUND ]; then
893       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
894       if [ -d $INST/llvm ]; then
895         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
896         cmake_d="$cmake_d -D LLVM_STATIC=ON"
897       fi
898     fi
899
900     cmake $cmake_d ../src
901
902     make -j$THREADS && make install
903     make clean
904
905     if [ -d $_inst ]; then
906       rm -f $INST/osl
907       ln -s osl-$OSL_VERSION $INST/osl
908     else
909       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
910       exit 1
911     fi
912
913     magic_compile_set osl-$OSL_VERSION $osl_magic
914
915     cd $CWD
916     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
917   else
918     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
919     INFO "If you want to force rebuild of this lib, use the --force-osl option."
920   fi
921 }
922
923 compile_FFmpeg() {
924   # To be changed each time we make edits that would modify the compiled result!
925   ffmpeg_magic=3
926
927   _src=$SRC/ffmpeg-$FFMPEG_VERSION
928   _inst=$INST/ffmpeg-$FFMPEG_VERSION
929
930   # Clean install if needed!
931   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
932   if [ $? -eq 1 -o $FFMPEG_FORCE_REBUILD == true ]; then
933     rm -rf $_inst
934   fi
935
936   if [ ! -d $_inst ]; then
937     INFO "Building ffmpeg-$FFMPEG_VERSION"
938
939     prepare_opt
940
941     if [ ! -d $_src ]; then
942       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
943       mkdir -p $SRC
944       wget -c $FFMPEG_SOURCE -O "$_src.tar.bz2"
945
946       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
947       tar -C $SRC -xf $_src.tar.bz2
948     fi
949
950     cd $_src
951
952     extra=""
953
954     if $VORBIS_USE; then
955       extra="$extra --enable-libvorbis"
956     fi
957
958     if $THEORA_USE; then
959       extra="$extra --enable-libtheora"
960     fi
961
962     # XXX At least under Debian, static schro gives problem at blender linking time... :/
963     if $SCHRO_USE && ! $ALL_STATIC; then
964       extra="$extra --enable-libschroedinger"
965     fi
966
967     if $XVID_USE; then
968       extra="$extra --enable-libxvid"
969     fi
970
971     if $X264_USE; then
972       extra="$extra --enable-libx264"
973     fi
974
975     if $VPX_USE; then
976       extra="$extra --enable-libvpx"
977     fi
978
979     if $MP3LAME_USE; then
980       extra="$extra --enable-libmp3lame"
981     fi
982
983     if $OPENJPEG_USE; then
984       extra="$extra --enable-libopenjpeg"
985     fi
986
987     ./configure --cc="gcc -Wl,--as-needed" \
988         --extra-ldflags="-pthread -static-libgcc" \
989         --prefix=$_inst --enable-static \
990         --disable-ffplay --disable-ffserver --disable-doc \
991         --enable-gray \
992         --enable-avfilter --disable-vdpau \
993         --disable-bzlib --disable-libgsm --disable-libspeex \
994         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
995         --disable-vaapi  --disable-libfaac --disable-nonfree --enable-gpl \
996         --disable-postproc --disable-x11grab  --disable-librtmp  --disable-libopencore-amrnb \
997         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3  --disable-outdev=sdl \
998         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
999         --disable-indev=lavfi $extra
1000
1001     make -j$THREADS && make install
1002     make clean
1003
1004     if [ -d $_inst ]; then
1005       rm -f $INST/ffmpeg
1006       ln -s ffmpeg-$FFMPEG_VERSION $INST/ffmpeg
1007     else
1008       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
1009       exit 1
1010     fi
1011
1012     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
1013
1014     cd $CWD
1015     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
1016   else
1017     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
1018     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
1019   fi
1020 }
1021
1022 get_package_version_DEB() {
1023     dpkg-query -W -f '${Version}' $1 | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'
1024 }
1025
1026 check_package_DEB() {
1027   r=`apt-cache policy $1 | grep -c 'Candidate:'`
1028
1029   if [ $r -ge 1 ]; then
1030     return 0
1031   else
1032     return 1
1033   fi
1034 }
1035
1036 check_package_version_match_DEB() {
1037   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
1038
1039   if [ -z "$v" ]; then
1040     return 1
1041   fi
1042
1043   version_match $v $2
1044   return $?
1045 }
1046
1047 check_package_version_ge_DEB() {
1048   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
1049
1050   if [ -z "$v" ]; then
1051     return 1
1052   fi
1053
1054   version_ge $v $2
1055   return $?
1056 }
1057
1058 install_packages_DEB() {
1059   sudo apt-get install -y $@
1060   if [ $? -ge 1 ]; then
1061     ERROR "apt-get failed to install requested packages, exiting."
1062     exit 1
1063   fi
1064 }
1065
1066 install_DEB() {
1067   INFO ""
1068   INFO "Installing dependencies for DEB-based distribution"
1069   INFO ""
1070   INFO "`eval _echo "$COMMON_INFO"`"
1071   INFO ""
1072
1073   if [ ! -z "`cat /etc/debian_version | grep ^6`"  ]; then
1074     if [ -z "`cat /etc/apt/sources.list | grep backports.debian.org`"  ]; then
1075       INFO "Looks like you're using Debian Squeeze which does have broken CMake"
1076       INFO "It is highly recommended to install cmake from backports, otherwise"
1077       INFO "compilation of some libraries could fail"
1078       INFO ""
1079       INFO "You could install newer CMake from debian-backports repository"
1080       INFO "Add this this line to your /etc/apt/sources.lixt:"
1081       INFO ""
1082       INFO "deb http://backports.debian.org/debian-backports squeeze-backports main"
1083       INFO ""
1084       INFO "and then run:"
1085       INFO ""
1086       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"
1087       INFO ""
1088       INFO "(you could also add this reporisotry using GUI like synaptic)"
1089       INFO ""
1090       INFO "Hit Enter to continue running the script, or hit Ctrl-C to abort the script"
1091
1092       read
1093       INFO ""
1094     fi
1095   fi
1096
1097   sudo apt-get update
1098 # XXX Why in hell? Let's let this stuff to the user's responsability!!!
1099 #  sudo apt-get -y upgrade
1100
1101   # These libs should always be available in debian/ubuntu official repository...
1102   OPENJPEG_DEV="libopenjpeg-dev"
1103   SCHRO_DEV="libschroedinger-dev"
1104   VORBIS_DEV="libvorbis-dev"
1105   THEORA_DEV="libtheora-dev"
1106
1107   _packages="gawk cmake scons build-essential libjpeg-dev libpng-dev libtiff-dev \
1108              libfreetype6-dev libx11-dev libxi-dev wget libsqlite3-dev libbz2-dev \
1109              libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
1110              libopenexr-dev libopenal-dev libglew-dev yasm $THEORA_DEV \
1111              $VORBIS_DEV libsdl1.2-dev libfftw3-dev python-dev patch bzip2"
1112   OPENJPEG_USE=true
1113   VORBIS_USE=true
1114   THEORA_USE=true
1115
1116   if $WITH_ALL; then
1117     _packages="$_packages $SCHRO_DEV libjack0 libjack-dev"
1118     SCHRO_USE=true
1119   fi
1120
1121   INFO ""
1122   install_packages_DEB $_packages
1123
1124   INFO ""
1125   X264_DEV="libx264-dev"
1126   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
1127   if [ $? -eq 0 ]; then
1128     install_packages_DEB $X264_DEV
1129     X264_USE=true
1130   fi
1131
1132   if $WITH_ALL; then
1133     INFO ""
1134     # Grmpf, debian is libxvidcore-dev and ubuntu libxvidcore4-dev!
1135     XVID_DEV="libxvidcore-dev"
1136     check_package_DEB $XVID_DEV
1137     if [ $? -eq 0 ]; then
1138       install_packages_DEB $XVID_DEV
1139       XVID_USE=true
1140     else
1141       XVID_DEV="libxvidcore4-dev"
1142       check_package_DEB $XVID_DEV
1143       if [ $? -eq 0 ]; then
1144         install_packages_DEB $XVID_DEV
1145         XVID_USE=true
1146       fi
1147     fi
1148
1149     INFO ""
1150     MP3LAME_DEV="libmp3lame-dev"
1151     check_package_DEB $MP3LAME_DEV
1152     if [ $? -eq 0 ]; then
1153       install_packages_DEB $MP3LAME_DEV
1154       MP3LAME_USE=true
1155     fi
1156
1157     INFO ""
1158     VPX_DEV="libvpx-dev"
1159     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
1160     if [ $? -eq 0 ]; then
1161       install_packages_DEB $VPX_DEV
1162       VPX_USE=true
1163     fi
1164
1165     INFO ""
1166     check_package_DEB libspnav-dev
1167     if [ $? -eq 0 ]; then
1168       install_packages_DEB libspnav-dev
1169     fi
1170   fi
1171
1172   INFO ""
1173   if $PYTHON_SKIP; then
1174     INFO "WARNING! Skipping Python installation, as requested..."
1175   else
1176     check_package_DEB python3.3-dev
1177     if [ $? -eq 0 ]; then
1178       install_packages_DEB python3.3-dev
1179     else
1180       compile_Python
1181     fi
1182   fi
1183
1184   INFO ""
1185   if $BOOST_SKIP; then
1186     INFO "WARNING! Skipping Boost installation, as requested..."
1187   else
1188     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
1189     if [ $? -eq 0 ]; then
1190       install_packages_DEB libboost-dev
1191
1192       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
1193
1194       check_package_DEB libboost-locale$boost_version-dev
1195       if [ $? -eq 0 ]; then
1196         install_packages_DEB libboost-locale$boost_version-dev libboost-filesystem$boost_version-dev \
1197                              libboost-regex$boost_version-dev libboost-system$boost_version-dev \
1198                              libboost-thread$boost_version-dev
1199       else
1200         compile_Boost
1201       fi
1202     else
1203       compile_Boost
1204     fi
1205   fi
1206
1207   INFO ""
1208   if $OCIO_SKIP; then
1209     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1210   else
1211     check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
1212     if [ $? -eq 0 ]; then
1213       install_packages_DEB libopencolorio-dev
1214     else
1215       compile_OCIO
1216     fi
1217   fi
1218
1219   INFO ""
1220   if $OIIO_SKIP; then
1221     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1222   else
1223     check_package_version_ge_DEB libopenimageio-dev $OIIO_VERSION_MIN
1224     if [ $? -eq 0 ]; then
1225       install_packages_DEB libopenimageio-dev
1226     else
1227       compile_OIIO
1228     fi
1229   fi
1230
1231   if $WITH_OSL; then
1232     have_llvm=false
1233
1234     if $LLVM_SKIP; then
1235       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1236     else
1237       INFO ""
1238       check_package_DEB llvm-$LLVM_VERSION-dev
1239       if [ $? -eq 0 ]; then
1240         install_packages_DEB llvm-$LLVM_VERSION-dev
1241         have_llvm=true
1242         LLVM_VERSION_FOUND=$LLVM_VERSION
1243       else
1244         check_package_DEB llvm-$LLVM_VERSION_MIN-dev
1245         if [ $? -eq 0 ]; then
1246           install_packages_DEB llvm-$LLVM_VERSION_MIN-dev
1247           have_llvm=true
1248           LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
1249         else
1250           install_packages_DEB libffi-dev
1251           INFO ""
1252           compile_LLVM
1253           have_llvm=true
1254           LLVM_VERSION_FOUND=$LLVM_VERSION
1255         fi
1256       fi
1257     fi
1258
1259     if $OSL_SKIP; then
1260       INFO ""
1261       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1262     else
1263       if $have_llvm; then
1264         INFO ""
1265         install_packages_DEB clang flex bison libtbb-dev git
1266         # No package currently!
1267         INFO ""
1268         compile_OSL
1269       fi
1270     fi
1271   fi
1272
1273
1274   INFO ""
1275   if $FFMPEG_SKIP; then
1276     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1277   else
1278 #    XXX Debian features libav packages as ffmpeg, those are not really compatible with blender code currently :/
1279 #        So for now, always build our own ffmpeg.
1280 #    check_package_DEB ffmpeg
1281 #    if [ $? -eq 0 ]; then
1282 #      install_packages_DEB ffmpeg
1283 #      ffmpeg_version=`get_package_version_DEB ffmpeg`
1284 #      INFO "ffmpeg version: $ffmpeg_version"
1285 #      if [ ! -z "$ffmpeg_version" ]; then
1286 #        if  dpkg --compare-versions $ffmpeg_version gt 0.7.2; then
1287 #          install_packages_DEB libavfilter-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev
1288 #        else
1289 #          compile_FFmpeg
1290 #        fi
1291 #      fi
1292 #    fi
1293     compile_FFmpeg
1294   fi
1295 }
1296
1297 get_package_version_RPM() {
1298   yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1299 }
1300
1301 check_package_RPM() {
1302   r=`yum info $1 | grep -c 'Summary'`
1303
1304   if [ $r -ge 1 ]; then
1305     return 0
1306   else
1307     return 1
1308   fi
1309 }
1310
1311 check_package_version_match_RPM() {
1312   v=`get_package_version_RPM $1`
1313
1314   if [ -z "$v" ]; then
1315     return 1
1316   fi
1317
1318   version_match $v $2
1319   return $?
1320 }
1321
1322 check_package_version_ge_RPM() {
1323   v=`get_package_version_RPM $1`
1324
1325   if [ -z "$v" ]; then
1326     return 1
1327   fi
1328
1329   version_ge $v $2
1330   return $?
1331 }
1332
1333 install_packages_RPM() {
1334   sudo yum install -y $@
1335   if [ $? -ge 1 ]; then
1336     ERROR "yum failed to install requested packages, exiting."
1337     exit 1
1338   fi
1339 }
1340
1341 install_RPM() {
1342   INFO ""
1343   INFO "Installing dependencies for RPM-based distribution"
1344   INFO ""
1345   INFO "`eval _echo "$COMMON_INFO"`"
1346   INFO ""
1347
1348   sudo yum -y update
1349
1350   # These libs should always be available in debian/ubuntu official repository...
1351   OPENJPEG_DEV="openjpeg-devel"
1352   SCHRO_DEV="schroedinger-devel"
1353   VORBIS_DEV="libvorbis-devel"
1354   THEORA_DEV="libtheora-devel"
1355
1356   _packages="gawk gcc gcc-c++ cmake scons libpng-devel libtiff-devel freetype-devel \
1357              libX11-devel libXi-devel wget libsqlite3x-devel ncurses-devel \
1358              readline-devel $OPENJPEG_DEV openexr-devel openal-soft-devel \
1359              glew-devel yasm $THEORA_DEV $VORBIS_DEV SDL-devel fftw-devel \
1360              lame-libs libjpeg-devel patch python-devel"
1361   OPENJPEG_USE=true
1362   VORBIS_USE=true
1363   THEORA_USE=true
1364
1365   if $WITH_ALL; then
1366     _packages="$_packages $SCHRO_DEV jack-audio-connection-kit-devel libspnav-devel"
1367     SCHRO_USE=true
1368   fi
1369
1370   INFO ""
1371   install_packages_RPM $_packages
1372
1373   INFO ""
1374   X264_DEV="x264-devel"
1375   check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1376   if [ $? -eq 0 ]; then
1377     install_packages_RPM $X264_DEV
1378     X264_USE=true
1379   fi
1380
1381   if $WITH_ALL; then
1382     INFO ""
1383     XVID_DEV="xvidcore-devel"
1384     check_package_RPM $XVID_DEV
1385     if [ $? -eq 0 ]; then
1386       install_packages_RPM $XVID_DEV
1387       XVID_USE=true
1388     fi
1389
1390     INFO ""
1391     VPX_DEV="libvpx-devel"
1392     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
1393     if [ $? -eq 0 ]; then
1394       install_packages_RPM $VPX_DEV
1395       VPX_USE=true
1396     fi
1397
1398     INFO ""
1399     MP3LAME_DEV="lame-devel"
1400     check_package_RPM $MP3LAME_DEV
1401     if [ $? -eq 0 ]; then
1402       install_packages_RPM $MP3LAME_DEV
1403       MP3LAME_USE=true
1404     fi
1405   fi
1406
1407   INFO ""
1408   if $PYTHON_SKIP; then
1409     INFO "WARNING! Skipping Python installation, as requested..."
1410   else
1411     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
1412     if [ $? -eq 0 ]; then
1413       install_packages_RPM python3-devel
1414     else
1415       compile_Python
1416     fi
1417   fi
1418
1419   INFO ""
1420   if $BOOST_SKIP; then
1421     INFO "WARNING! Skipping Boost installation, as requested..."
1422   else
1423     check_package_version_ge_RPM boost-devel $BOOST_VERSION_MIN
1424     if [ $? -eq 0 ]; then
1425       install_packages_RPM boost-devel
1426     else
1427       compile_Boost
1428     fi
1429   fi
1430
1431   INFO ""
1432   if $OCIO_SKIP; then
1433     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1434   else
1435     check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
1436     if [ $? -eq 0 ]; then
1437       install_packages_RPM OpenColorIO-devel
1438     else
1439       compile_OCIO
1440     fi
1441   fi
1442
1443   INFO ""
1444   if $OIIO_SKIP; then
1445     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1446   else
1447     check_package_version_ge_RPM OpenImageIO-devel $OIIO_VERSION_MIN
1448     if [ $? -eq 0 ]; then
1449       install_packages_RPM OpenImageIO-devel
1450     else
1451       compile_OIIO
1452     fi
1453   fi
1454
1455   if $WITH_OSL; then
1456     have_llvm=false
1457
1458     INFO ""
1459     if $LLVM_SKIP; then
1460       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1461     else
1462       check_package_RPM llvm-$LLVM_VERSION-devel
1463       if [ $? -eq 0 ]; then
1464         install_packages_RPM llvm-$LLVM_VERSION-devel
1465         have_llvm=true
1466         LLVM_VERSION_FOUND=$LLVM_VERSION
1467       else
1468 #        check_package_RPM llvm-$LLVM_VERSION_MIN-devel
1469 #        if [ $? -eq 0 ]; then
1470 #          install_packages_RPM llvm-$LLVM_VERSION_MIN-devel
1471 #          have_llvm=true
1472 #          LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
1473 #        else
1474 #          check_package_version_ge_RPM llvm-devel $LLVM_VERSION_MIN
1475 #          if [ $? -eq 0 ]; then
1476 #            install_packages_RPM llvm-devel
1477 #            have_llvm=true
1478 #            LLVM_VERSION_FOUND=`get_package_version_RPM llvm-devel`
1479 #          fi
1480 #        fi
1481       install_packages_RPM libffi-devel
1482       # XXX Stupid fedora puts ffi header into a darn stupid dir!
1483       _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1484       INFO ""
1485       compile_LLVM
1486       have_llvm=true
1487       LLVM_VERSION_FOUND=$LLVM_VERSION
1488       fi
1489     fi
1490
1491     if $OSL_SKIP; then
1492       INFO ""
1493       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1494     else
1495       if $have_llvm; then
1496         INFO ""
1497         install_packages_RPM flex bison clang tbb-devel git
1498         # No package currently!
1499         INFO ""
1500         compile_OSL
1501       fi
1502     fi
1503   fi
1504
1505   INFO ""
1506   if $FFMPEG_SKIP; then
1507     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1508   else
1509     # Always for now, not sure which packages should be installed
1510     compile_FFmpeg
1511   fi
1512 }
1513
1514 get_package_version_SUSE() {
1515   zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1516 }
1517
1518 check_package_SUSE() {
1519   r=`zypper info $1 | grep -c 'Summary'`
1520
1521   if [ $r -ge 1 ]; then
1522     return 0
1523   else
1524     return 1
1525   fi
1526 }
1527
1528 check_package_version_match_SUSE() {
1529   v=`get_package_version_SUSE $1`
1530
1531   if [ -z "$v" ]; then
1532     return 1
1533   fi
1534
1535   version_match $v $2
1536   return $?
1537 }
1538
1539 check_package_version_ge_SUSE() {
1540   v=`get_package_version_SUSE $1`
1541
1542   if [ -z "$v" ]; then
1543     return 1
1544   fi
1545
1546   version_ge $v $2
1547   return $?
1548 }
1549
1550 install_packages_SUSE() {
1551   sudo zypper --non-interactive install --auto-agree-with-licenses $@
1552   if [ $? -ge 1 ]; then
1553     ERROR "zypper failed to install requested packages, exiting."
1554     exit 1
1555   fi
1556 }
1557
1558
1559 install_SUSE() {
1560   INFO ""
1561   INFO "Installing dependencies for SuSE-based distribution"
1562   INFO ""
1563   INFO "`eval _echo "$COMMON_INFO"`"
1564   INFO ""
1565
1566   sudo zypper --non-interactive update --auto-agree-with-licenses
1567
1568   # These libs should always be available in debian/ubuntu official repository...
1569   OPENJPEG_DEV="openjpeg-devel"
1570   SCHRO_DEV="schroedinger-devel"
1571   VORBIS_DEV="libvorbis-devel"
1572   THEORA_DEV="libtheora-devel"
1573
1574   _packages="gawk gcc gcc-c++ cmake scons libpng12-devel libtiff-devel freetype-devel \
1575              libX11-devel libXi-devel wget sqlite3-devel ncurses-devel \
1576              readline-devel $OPENJPEG_DEV libopenexr-devel openal-soft-devel \
1577              glew-devel yasm $THEORA_DEV $VORBIS_DEV libSDL-devel fftw3-devel \
1578              libjpeg62-devel patch python-devel"
1579   OPENJPEG_USE=true
1580   VORBIS_USE=true
1581   THEORA_USE=true
1582
1583   if $WITH_ALL; then
1584     _packages="$_packages $SCHRO_DEV libjack-devel libspnav-devel"
1585     SCHRO_USE=true
1586   fi
1587
1588   INFO ""
1589   install_packages_SUSE $_packages
1590
1591   OPENJPEG_USE=true
1592   SCHRO_USE=true
1593   VORBIS_USE=true
1594   THEORA_USE=true
1595
1596   INFO ""
1597   X264_DEV="x264-devel"
1598   check_package_version_ge_SUSE $X264_DEV $X264_VERSION_MIN
1599   if [ $? -eq 0 ]; then
1600     install_packages_SUSE $X264_DEV
1601     X264_USE=true
1602   fi
1603
1604   if $WITH_ALL; then
1605     INFO ""
1606     XVID_DEV="xvidcore-devel"
1607     check_package_SUSE $XVID_DEV
1608     if [ $? -eq 0 ]; then
1609       install_packages_SUSE $XVID_DEV
1610       XVID_USE=true
1611     fi
1612
1613     INFO ""
1614     VPX_DEV="libvpx-devel"
1615     check_package_version_ge_SUSE $VPX_DEV $VPX_VERSION_MIN
1616     if [ $? -eq 0 ]; then
1617       install_packages_SUSE $VPX_DEV
1618       VPX_USE=true
1619     fi
1620
1621     INFO ""
1622     # No mp3 in suse, it seems.
1623     MP3LAME_DEV="lame-devel"
1624     check_package_SUSE $MP3LAME_DEV
1625     if [ $? -eq 0 ]; then
1626       install_packages_SUSE $MP3LAME_DEV
1627       MP3LAME_USE=true
1628     fi
1629   fi
1630
1631   INFO ""
1632   if $PYTHON_SKIP; then
1633     INFO "WARNING! Skipping Python installation, as requested..."
1634   else
1635     check_package_version_match_SUSE python3-devel 3.3.
1636     if [ $? -eq 0 ]; then
1637       install_packages_SUSE python3-devel
1638     else
1639       compile_Python
1640     fi
1641   fi
1642
1643   INFO ""
1644   if $BOOST_SKIP; then
1645     INFO "WARNING! Skipping Boost installation, as requested..."
1646   else
1647     # No boost_locale currently available, so let's build own boost.
1648     compile_Boost
1649   fi
1650
1651   INFO ""
1652   if $OCIO_SKIP; then
1653     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1654   else
1655     # No ocio currently available, so let's build own boost.
1656     compile_OCIO
1657   fi
1658
1659   INFO ""
1660   if $OIIO_SKIP; then
1661     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1662   else
1663     # No oiio currently available, so let's build own boost.
1664     compile_OIIO
1665   fi
1666
1667   if $WITH_OSL; then
1668     have_llvm=false
1669
1670     INFO ""
1671     if $LLVM_SKIP; then
1672       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1673     else
1674       # Suse llvm package *_$SUCKS$_* (tm) !!!
1675 #      check_package_version_ge_SUSE llvm-devel $LLVM_VERSION_MIN
1676 #      if [ $? -eq 0 ]; then
1677 #        install_packages_SUSE llvm-devel
1678 #        have_llvm=true
1679 #        LLVM_VERSION_FOUND=`get_package_version_SUSE llvm-devel`
1680 #      fi
1681
1682       install_packages_SUSE libffi47-devel
1683       INFO ""
1684       compile_LLVM
1685       have_llvm=true
1686       LLVM_VERSION_FOUND=$LLVM_VERSION
1687     fi
1688
1689     if $OSL_SKIP; then
1690       INFO ""
1691       INFO "WARNING! Skipping OpenShaderLanguage installation, as requested..."
1692     else
1693       if $have_llvm; then
1694         INFO ""
1695         # XXX No tbb lib!
1696         install_packages_SUSE flex bison git
1697         # No package currently!
1698         INFO ""
1699         compile_OSL
1700       fi
1701     fi
1702   fi
1703
1704   INFO ""
1705   if $FFMPEG_SKIP; then
1706     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1707   else
1708     # No ffmpeg currently available, so let's build own boost.
1709     compile_FFmpeg
1710   fi
1711 }
1712
1713 print_info_ffmpeglink_DEB() {
1714   if $ALL_STATIC; then
1715     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1716   else
1717     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1718   fi
1719 }
1720
1721 print_info_ffmpeglink_RPM() {
1722   if $ALL_STATIC; then
1723     rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1724   else
1725     rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1726   fi
1727 }
1728
1729 print_info_ffmpeglink_SUSE() {
1730   if $ALL_STATIC; then
1731     rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
1732   else
1733     rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
1734   fi
1735 }
1736
1737 print_info_ffmpeglink() {
1738   # This func must only print a ';'-separated list of libs...
1739   if [ -z "$DISTRO" ]; then
1740     ERROR "Failed to detect distribution type"
1741     exit 1
1742   fi
1743
1744   # Create list of packages from which to get libs names...
1745   _packages=""
1746
1747   if $THEORA_USE; then
1748     _packages="$_packages $THEORA_DEV"
1749   fi
1750
1751   if $VORBIS_USE; then
1752     _packages="$_packages $VORBIS_DEV"
1753   fi
1754
1755   if $XVID_USE; then
1756     _packages="$_packages $XVID_DEV"
1757   fi
1758
1759   if $VPX_USE; then
1760     _packages="$_packages $VPX_DEV"
1761   fi
1762
1763   if $MP3LAME_USE; then
1764     _packages="$_packages $MP3LAME_DEV"
1765   fi
1766
1767   if $X264_USE; then
1768     _packages="$_packages $X264_DEV"
1769   fi
1770
1771   if $OPENJPEG_USE; then
1772     _packages="$_packages $OPENJPEG_DEV"
1773   fi
1774
1775   # XXX At least under Debian, static schro gives problem at blender linking time... :/
1776   if $SCHRO_USE && ! $ALL_STATIC; then
1777     _packages="$_packages $SCHRO_DEV"
1778   fi
1779
1780   if [ "$DISTRO" = "DEB" ]; then
1781     print_info_ffmpeglink_DEB
1782   elif [ "$DISTRO" = "RPM" ]; then
1783     print_info_ffmpeglink_RPM
1784   elif [ "$DISTRO" = "SUSE" ]; then
1785     print_info_ffmpeglink_SUSE
1786   # XXX TODO!
1787   else INFO "<Could not determine additional link libraries needed for ffmpeg, replace this by valid list of libs...>"
1788   fi
1789 }
1790
1791 print_info() {
1792   INFO ""
1793   INFO "If you're using CMake add this to your configuration flags:"
1794
1795   if $ALL_STATIC; then
1796     INFO "  -D WITH_STATIC_LIBS=ON"
1797   fi
1798
1799   if [ -d $INST/boost ]; then
1800     INFO "  -D BOOST_ROOT=$INST/boost"
1801     INFO "  -D Boost_NO_SYSTEM_PATHS=ON"
1802   elif $ALL_STATIC; then
1803     INFO "  -D Boost_USE_ICU=ON"
1804   fi
1805
1806   if [ -d $INST/osl -a $WITH_OSL == true ]; then
1807     INFO "  -D CYCLES_OSL=$INST/osl"
1808     INFO "  -D WITH_CYCLES_OSL=ON"
1809     INFO "  -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1810     if [ -d $INST/llvm ]; then
1811       INFO "  -D LLVM_DIRECTORY=$INST/llvm"
1812       INFO "  -D LLVM_STATIC=ON"
1813     fi
1814   fi
1815
1816   if [ -d $INST/ffmpeg ]; then
1817     INFO "  -D WITH_CODEC_FFMPEG=ON"
1818     INFO "  -D FFMPEG=$INST/ffmpeg"
1819     INFO "  -D FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;rt;`print_info_ffmpeglink`'"
1820   fi
1821
1822   INFO ""
1823   INFO "If you're using SCons add this to your user-config:"
1824
1825   if [ -d $INST/python-3.3 ]; then
1826     INFO "BF_PYTHON = '$INST/python-3.3'"
1827     INFO "BF_PYTHON_ABI_FLAGS = 'm'"
1828   fi
1829
1830   if [ -d $INST/ocio ]; then
1831     INFO "BF_OCIO = '$INST/ocio'"
1832   fi
1833
1834   if [ -d $INST/oiio ]; then
1835     INFO "BF_OIIO = '$INST/oiio'"
1836   fi
1837
1838   if [ -d $INST/boost ]; then
1839     INFO "BF_BOOST = '$INST/boost'"
1840   fi
1841
1842   if [ -d $INST/ffmpeg ]; then
1843     INFO "BF_FFMPEG = '$INST/ffmpeg'"
1844     _ffmpeg_list_sep=" "
1845     INFO "BF_FFMPEG_LIB = 'avformat avcodec swscale avutil avdevice `print_info_ffmpeglink`'"
1846   fi
1847
1848   INFO ""
1849   INFO ""
1850   INFO "WARNING: If this script had to build boost into $INST, and you are dynamically linking "
1851   INFO "         blender against it, you will have to run those commands as root user:"
1852   INFO ""
1853   INFO "    echo \"$INST/boost/lib\" > /etc/ld.so.conf.d/boost.conf"
1854   INFO "    ldconfig"
1855   INFO ""
1856 }
1857
1858 # Detect distributive type used on this machine
1859 detect_distro
1860
1861 if [ -z "$DISTRO" ]; then
1862   ERROR "Failed to detect distribution type"
1863   exit 1
1864 elif [ "$DISTRO" = "DEB" ]; then
1865   install_DEB
1866 elif [ "$DISTRO" = "RPM" ]; then
1867   install_RPM
1868 elif [ "$DISTRO" = "SUSE" ]; then
1869   install_SUSE
1870 fi
1871
1872 print_info
1873
1874 # Switch back to user language.
1875 LANG=LANG_BACK
1876 export LANG