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