More fixes for install_deps.sh under ubuntu 10.04: git package is called "git-core...
[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 show $1 | grep -c 'Package:'`
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="libtiff"
1302   check_package_DEB $TIFF
1303   if [ $? -eq 0 ]; then
1304     _packages="$_packages $TIFF-dev"
1305   else
1306     TIFF="libtiff5"
1307     check_package_DEB $TIFF
1308     if [ $? -eq 0 ]; then
1309       _packages="$_packages $TIFF-dev"
1310     else
1311       TIFF="libtiff4"  # Some old distro, like e.g. ubuntu 10.04 :/
1312       check_package_DEB $TIFF
1313       if [ $? -eq 0 ]; then
1314         _packages="$_packages $TIFF-dev"
1315       fi
1316     fi
1317   fi
1318
1319   GIT="git"
1320   check_package_DEB $GIT
1321   if [ $? -eq 0 ]; then
1322     INFO $GIT
1323     _packages="$_packages $GIT"
1324   else
1325     GIT="git-core"  # Some old distro, like e.g. ubuntu 10.04 :/
1326     check_package_DEB $GIT
1327     if [ $? -eq 0 ]; then
1328       INFO $GIT
1329       _packages="$_packages $GIT"
1330     fi
1331   fi
1332
1333   if $WITH_ALL; then
1334     _packages="$_packages libspnav-dev libjack-dev"
1335   fi
1336
1337   INFO ""
1338   install_packages_DEB $_packages
1339
1340   INFO ""
1341   X264_DEV="libx264-dev"
1342   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
1343   if [ $? -eq 0 ]; then
1344     install_packages_DEB $X264_DEV
1345     X264_USE=true
1346   fi
1347
1348   if $WITH_ALL; then
1349     INFO ""
1350     # Grmpf, debian is libxvidcore-dev and ubuntu libxvidcore4-dev!
1351     # Note: not since ubuntu 10.04
1352     XVID_DEV="libxvidcore-dev"
1353     check_package_DEB $XVID_DEV
1354     if [ $? -eq 0 ]; then
1355       install_packages_DEB $XVID_DEV
1356       XVID_USE=true
1357     else
1358       XVID_DEV="libxvidcore4-dev"
1359       check_package_DEB $XVID_DEV
1360       if [ $? -eq 0 ]; then
1361         install_packages_DEB $XVID_DEV
1362         XVID_USE=true
1363       fi
1364     fi
1365
1366     INFO ""
1367     MP3LAME_DEV="libmp3lame-dev"
1368     check_package_DEB $MP3LAME_DEV
1369     if [ $? -eq 0 ]; then
1370       install_packages_DEB $MP3LAME_DEV
1371       MP3LAME_USE=true
1372     fi
1373
1374     INFO ""
1375     VPX_DEV="libvpx-dev"
1376     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
1377     if [ $? -eq 0 ]; then
1378       install_packages_DEB $VPX_DEV
1379       VPX_USE=true
1380     fi
1381   fi
1382
1383   INFO ""
1384   if $PYTHON_SKIP; then
1385     INFO "WARNING! Skipping Python installation, as requested..."
1386   else
1387     check_package_DEB python$PYTHON_VERSION_MIN-dev
1388     if [ $? -eq 0 ]; then
1389       install_packages_DEB python$PYTHON_VERSION_MIN-dev
1390       INFO ""
1391       if $NUMPY_SKIP; then
1392         INFO "WARNING! Skipping NumPy installation, as requested..."
1393       else
1394         check_package_DEB python$PYTHON_VERSION_MIN-numpy
1395         if [ $? -eq 0 ]; then
1396           install_packages_DEB python$PYTHON_VERSION_MIN-numpy
1397         else
1398           INFO "WARNING! Sorry, using python package but no numpy package available!"
1399         fi
1400       fi
1401     else
1402       compile_Python
1403       INFO ""
1404       if $NUMPY_SKIP; then
1405         INFO "WARNING! Skipping NumPy installation, as requested..."
1406       else
1407         compile_Numpy
1408       fi
1409     fi
1410   fi
1411
1412   INFO ""
1413   if $BOOST_SKIP; then
1414     INFO "WARNING! Skipping Boost installation, as requested..."
1415   else
1416     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
1417     if [ $? -eq 0 ]; then
1418       install_packages_DEB libboost-dev
1419
1420       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
1421
1422       check_package_DEB libboost-locale$boost_version-dev
1423       if [ $? -eq 0 ]; then
1424         install_packages_DEB libboost-locale$boost_version-dev libboost-filesystem$boost_version-dev \
1425                              libboost-regex$boost_version-dev libboost-system$boost_version-dev \
1426                              libboost-thread$boost_version-dev
1427       else
1428         compile_Boost
1429       fi
1430     else
1431       compile_Boost
1432     fi
1433   fi
1434
1435   INFO ""
1436   if $OCIO_SKIP; then
1437     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1438   else
1439     check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
1440     if [ $? -eq 0 ]; then
1441       install_packages_DEB libopencolorio-dev
1442     else
1443       compile_OCIO
1444     fi
1445   fi
1446
1447   INFO ""
1448   if $OIIO_SKIP; then
1449     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1450   else
1451     check_package_version_ge_DEB libopenimageio-dev $OIIO_VERSION_MIN
1452     if [ $? -eq 0 ]; then
1453       install_packages_DEB libopenimageio-dev
1454     else
1455       compile_OIIO
1456     fi
1457   fi
1458
1459   if $WITH_OSL; then
1460     have_llvm=false
1461
1462     if $LLVM_SKIP; then
1463       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1464     else
1465       INFO ""
1466       check_package_DEB llvm-$LLVM_VERSION-dev
1467       if [ $? -eq 0 ]; then
1468         install_packages_DEB llvm-$LLVM_VERSION-dev clang
1469         have_llvm=true
1470         LLVM_VERSION_FOUND=$LLVM_VERSION
1471       else
1472         check_package_DEB llvm-$LLVM_VERSION_MIN-dev
1473         if [ $? -eq 0 ]; then
1474           install_packages_DEB llvm-$LLVM_VERSION_MIN-dev clang
1475           have_llvm=true
1476           LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
1477         else
1478           install_packages_DEB libffi-dev
1479           # LLVM can't find the debian ffi header dir
1480           _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1481           INFO ""
1482           compile_LLVM
1483           have_llvm=true
1484           LLVM_VERSION_FOUND=$LLVM_VERSION
1485         fi
1486       fi
1487     fi
1488
1489     if $OSL_SKIP; then
1490       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1491     else
1492       if $have_llvm; then
1493         INFO ""
1494         install_packages_DEB flex bison libtbb-dev
1495         # No package currently!
1496         INFO ""
1497         compile_OSL
1498       fi
1499     fi
1500   fi
1501
1502   if $WITH_OPENCOLLADA; then
1503     if $OPENCOLLADA_SKIP; then
1504       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1505     else
1506       INFO ""
1507       install_packages_DEB libpcre3-dev libxml2-dev
1508       # Find path to libxml shared lib...
1509       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
1510       # No package
1511       INFO ""
1512       compile_OpenCOLLADA
1513     fi
1514   fi
1515
1516   INFO ""
1517   if $FFMPEG_SKIP; then
1518     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1519   else
1520 #    XXX Debian features libav packages as ffmpeg, those are not really compatible with blender code currently :/
1521 #        So for now, always build our own ffmpeg.
1522 #    check_package_DEB ffmpeg
1523 #    if [ $? -eq 0 ]; then
1524 #      install_packages_DEB ffmpeg
1525 #      ffmpeg_version=`get_package_version_DEB ffmpeg`
1526 #      INFO "ffmpeg version: $ffmpeg_version"
1527 #      if [ ! -z "$ffmpeg_version" ]; then
1528 #        if  dpkg --compare-versions $ffmpeg_version gt 0.7.2; then
1529 #          install_packages_DEB libavfilter-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev
1530 #        else
1531 #          compile_FFmpeg
1532 #        fi
1533 #      fi
1534 #    fi
1535     compile_FFmpeg
1536   fi
1537 }
1538
1539
1540
1541 get_package_version_RPM() {
1542   rpm_flavour
1543   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1544     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1545   elif [ $RPM = "SUSE" ]; then
1546     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1547   fi  
1548 }
1549
1550 check_package_RPM() {
1551   rpm_flavour
1552   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1553     r=`yum info $1 | grep -c 'Summary'`
1554   elif [ $RPM = "SUSE" ]; then
1555     r=`zypper info $1 | grep -c 'Summary'`
1556   fi
1557
1558   if [ $r -ge 1 ]; then
1559     return 0
1560   else
1561     return 1
1562   fi
1563 }
1564
1565 check_package_version_match_RPM() {
1566   v=`get_package_version_RPM $1`
1567
1568   if [ -z "$v" ]; then
1569     return 1
1570   fi
1571
1572   version_match $v $2
1573   return $?
1574 }
1575
1576 check_package_version_ge_RPM() {
1577   v=`get_package_version_RPM $1`
1578
1579   if [ -z "$v" ]; then
1580     return 1
1581   fi
1582
1583   version_ge $v $2
1584   return $?
1585 }
1586
1587 install_packages_RPM() {
1588   rpm_flavour
1589   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1590     sudo yum install -y $@
1591     if [ $? -ge 1 ]; then
1592       ERROR "yum failed to install requested packages, exiting."
1593       exit 1
1594     fi
1595
1596   elif [ $RPM = "SUSE" ]; then
1597     sudo zypper --non-interactive install --auto-agree-with-licenses $@
1598     if [ $? -ge 1 ]; then
1599       ERROR "zypper failed to install requested packages, exiting."
1600       exit 1
1601     fi
1602   fi
1603 }
1604
1605 install_RPM() {
1606   INFO ""
1607   INFO "Installing dependencies for RPM-based distribution"
1608   INFO ""
1609   INFO "`eval _echo "$COMMON_INFO"`"
1610   INFO ""
1611
1612   read -p "Do you want to continue (Y/n)?"
1613   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1614
1615   # Enable non-free repositories for all flavours
1616   rpm_flavour
1617   if [ $RPM = "FEDORA" ]; then
1618     _fedora_rel="`egrep "[0-9]{1,}" /etc/fedora-release -o`"
1619     sudo yum -y localinstall --nogpgcheck \
1620     http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$_fedora_rel.noarch.rpm \
1621     http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$_fedora_rel.noarch.rpm
1622
1623     sudo yum -y update
1624
1625     # Install cmake now because of difference with RHEL
1626     sudo yum -y install cmake
1627
1628   elif [ $RPM = "RHEL" ]; then
1629     sudo yum -y localinstall --nogpgcheck \
1630     http://download.fedoraproject.org/pub/epel/6/$(uname -i)/epel-release-6-8.noarch.rpm \
1631     http://download1.rpmfusion.org/free/el/updates/6/$(uname -i)/rpmfusion-free-release-6-1.noarch.rpm \
1632     http://download1.rpmfusion.org/nonfree/el/updates/6/$(uname -i)/rpmfusion-nonfree-release-6-1.noarch.rpm
1633
1634     sudo yum -y update
1635
1636     # Install cmake 2.8 from other repo
1637     mkdir -p $SRC
1638     if [ -f $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm ]; then
1639       INFO ""
1640       INFO "Special cmake already installed"
1641     else
1642       curl -O ftp://ftp.pbone.net/mirror/atrpms.net/el6-$(uname -i)/atrpms/testing/cmake-2.8.8-4.el6.$(uname -m).rpm
1643       mv cmake-2.8.8-4.el6.$(uname -m).rpm $SRC/
1644       sudo rpm -ihv $SRC/cmake-2.8.8-4.el6.$(uname -m).rpm
1645     fi
1646
1647   elif [ $RPM = "SUSE" ]; then
1648     # Install this now to avoid using the version from packman repository...
1649     if $WITH_ALL; then
1650       install_packages_RPM libjack-devel
1651     fi
1652
1653     _suse_rel="`grep VERSION /etc/SuSE-release | gawk '{print $3}'`"
1654     sudo zypper ar -f http://packman.inode.at/suse/openSUSE_$_suse_rel/ packman
1655
1656     sudo zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
1657   fi
1658
1659   # These libs should always be available in fedora/suse official repository...
1660   OPENJPEG_DEV="openjpeg-devel"
1661   VORBIS_DEV="libvorbis-devel"
1662   THEORA_DEV="libtheora-devel"
1663
1664   _packages="gcc gcc-c++ make scons libtiff-devel freetype-devel libjpeg-devel\
1665              libpng-devel libX11-devel libXi-devel wget ncurses-devel \
1666              readline-devel $OPENJPEG_DEV openal-soft-devel \
1667              glew-devel yasm $THEORA_DEV $VORBIS_DEV patch"
1668
1669   OPENJPEG_USE=true
1670   VORBIS_USE=true
1671   THEORA_USE=true
1672
1673   if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1674
1675     _packages="$_packages libsqlite3x-devel openexr-devel fftw-devel SDL-devel"
1676
1677     if $WITH_ALL; then
1678       _packages="$_packages jack-audio-connection-kit-devel"
1679     fi
1680
1681     INFO ""
1682     install_packages_RPM $_packages
1683
1684     INFO ""
1685     X264_DEV="x264-devel"
1686     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1687     if [ $? -eq 0 ]; then
1688       install_packages_RPM $X264_DEV
1689       X264_USE=true
1690     fi
1691
1692     if $WITH_ALL; then
1693       INFO ""
1694       XVID_DEV="xvidcore-devel"
1695       check_package_RPM $XVID_DEV
1696       if [ $? -eq 0 ]; then
1697         install_packages_RPM $XVID_DEV
1698         XVID_USE=true
1699       fi
1700
1701       INFO ""
1702       MP3LAME_DEV="lame-devel"
1703       check_package_RPM $MP3LAME_DEV
1704       if [ $? -eq 0 ]; then
1705         install_packages_RPM $MP3LAME_DEV
1706         MP3LAME_USE=true
1707       fi
1708     fi
1709
1710   elif [ $RPM = "SUSE" ]; then
1711
1712     _packages="$_packages cmake sqlite3-devel libopenexr-devel fftw3-devel libSDL-devel"
1713
1714     INFO ""
1715     install_packages_RPM $_packages
1716
1717     INFO ""
1718     X264_DEV="libx264-devel"
1719     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
1720     if [ $? -eq 0 ]; then
1721       install_packages_RPM $X264_DEV
1722       X264_USE=true
1723     fi
1724
1725     if $WITH_ALL; then
1726       INFO ""
1727       XVID_DEV="libxvidcore-devel"
1728       check_package_RPM $XVID_DEV
1729       if [ $? -eq 0 ]; then
1730         install_packages_RPM $XVID_DEV
1731         XVID_USE=true
1732       fi
1733
1734       INFO ""
1735       MP3LAME_DEV="libmp3lame-devel"
1736       check_package_RPM $MP3LAME_DEV
1737       if [ $? -eq 0 ]; then
1738         install_packages_RPM $MP3LAME_DEV
1739         MP3LAME_USE=true
1740       fi
1741     fi
1742   fi
1743
1744   if $WITH_ALL; then
1745     INFO ""
1746     VPX_DEV="libvpx-devel"
1747     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
1748     if [ $? -eq 0 ]; then
1749       install_packages_RPM $VPX_DEV
1750       VPX_USE=true
1751     fi
1752     INFO ""
1753     install_packages_RPM libspnav-devel
1754   fi
1755
1756   INFO ""
1757   if $PYTHON_SKIP; then
1758     INFO "WARNING! Skipping Python installation, as requested..."
1759   else
1760     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
1761     if [ $? -eq 0 ]; then
1762       install_packages_RPM python3-devel
1763       INFO ""
1764       if $NUMPY_SKIP; then
1765         INFO "WARNING! Skipping NumPy installation, as requested..."
1766       else
1767         check_package_version_match_RPM python3-numpy $NUMPY_VERSION_MIN
1768         if [ $? -eq 0 ]; then
1769           install_packages_RPM python3-numpy
1770         else
1771           INFO "WARNING! Sorry, using python package but no numpy package available!"
1772         fi
1773       fi
1774     else
1775       compile_Python
1776       INFO ""
1777       if $NUMPY_SKIP; then
1778         INFO "WARNING! Skipping NumPy installation, as requested..."
1779       else
1780         compile_Numpy
1781       fi
1782     fi
1783   fi
1784
1785   INFO ""
1786   if $BOOST_SKIP; then
1787     INFO "WARNING! Skipping Boost installation, as requested..."
1788   else
1789     check_package_version_ge_RPM boost-devel $BOOST_VERSION
1790     if [ $? -eq 0 ]; then
1791       install_packages_RPM boost-devel
1792     else
1793       compile_Boost
1794     fi
1795   fi
1796
1797   INFO ""
1798   if $OCIO_SKIP; then
1799     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
1800   else
1801     check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
1802     if [ $? -eq 0 ]; then
1803       install_packages_RPM OpenColorIO-devel
1804     else
1805       compile_OCIO
1806     fi
1807   fi
1808
1809   INFO ""
1810   if $OIIO_SKIP; then
1811     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
1812   else
1813     check_package_version_ge_RPM OpenImageIO-devel $OIIO_VERSION_MIN
1814     if [ $? -eq 0 ]; then
1815       install_packages_RPM OpenImageIO-devel
1816     else
1817       compile_OIIO
1818     fi
1819   fi
1820
1821   if $WITH_OSL; then
1822     have_llvm=false
1823
1824     INFO ""
1825     if $LLVM_SKIP; then
1826       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
1827     else
1828       # Problem compiling with LLVM 3.2 so match version 3.1 ...
1829       check_package_version_match_RPM llvm $LLVM_VERSION
1830       if [ $? -eq 0 ]; then
1831         if [ $RPM = "SUSE" ]; then
1832           install_packages_RPM llvm-devel llvm-clang-devel
1833         else
1834           install_packages_RPM llvm-devel clang-devel
1835         fi
1836         have_llvm=true
1837         LLVM_VERSION_FOUND=$LLVM_VERSION
1838       else
1839         #
1840         # Better to compile it than use minimum version from repo...
1841         #
1842         install_packages_RPM libffi-devel
1843         # LLVM can't find the fedora ffi header dir...
1844         _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
1845         INFO ""
1846         compile_LLVM
1847         have_llvm=true
1848         LLVM_VERSION_FOUND=$LLVM_VERSION
1849       fi
1850     fi
1851
1852     if $OSL_SKIP; then
1853       INFO ""
1854       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
1855     else
1856       if $have_llvm; then
1857         # No package currently!
1858         INFO ""
1859         install_packages_RPM flex bison git
1860         if [ $RPM = "FEDORA" -o $RPM = "RHEL" ]; then
1861           install_packages_RPM tbb-devel
1862         fi
1863         INFO ""
1864         compile_OSL
1865       fi
1866     fi
1867   fi
1868
1869   if $WITH_OPENCOLLADA; then
1870     if $OPENCOLLADA_SKIP; then
1871       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
1872     else
1873       INFO ""
1874       install_packages_RPM pcre-devel libxml2-devel git
1875       # Find path to libxml shared lib...
1876       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
1877       # No package...
1878       INFO ""
1879       compile_OpenCOLLADA
1880     fi
1881   fi
1882
1883   if $FFMPEG_SKIP; then
1884     INFO "WARNING! Skipping FFMpeg installation, as requested..."
1885   else
1886     check_package_version_ge_RPM ffmpeg $FFMPEG_VERSION_MIN
1887     if [ $? -eq 0 ]; then
1888       install_packages_RPM ffmpeg ffmpeg-devel
1889     else
1890       INFO ""
1891       compile_FFmpeg
1892     fi
1893   fi
1894 }
1895
1896
1897 get_package_version_ARCH() {
1898   pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
1899 }
1900
1901 check_package_ARCH() {
1902   r=`pacman -Si $1 | grep -c 'Description'`
1903
1904   if [ $r -ge 1 ]; then
1905     return 0
1906   else
1907     return 1
1908   fi
1909 }
1910
1911 check_package_version_match_ARCH() {
1912   v=`get_package_version_ARCH $1`
1913
1914   if [ -z "$v" ]; then
1915     return 1
1916   fi
1917
1918   version_match $v $2
1919   return $?
1920 }
1921
1922 check_package_version_ge_ARCH() {
1923   v=`get_package_version_ARCH $1`
1924
1925   if [ -z "$v" ]; then
1926     return 1
1927   fi
1928
1929   version_ge $v $2
1930   return $?
1931 }
1932
1933 install_packages_ARCH() {
1934   sudo pacman -S --needed --noconfirm $@
1935   if [ $? -ge 1 ]; then
1936     ERROR "pacman failed to install requested packages, exiting."
1937     exit 1
1938   fi
1939 }
1940
1941 install_ARCH() {
1942   INFO ""
1943   INFO "Installing dependencies for ARCH-based distribution"
1944   INFO ""
1945   INFO "`eval _echo "$COMMON_INFO"`"
1946   INFO ""
1947
1948   read -p "Do you want to continue (Y/n)?"
1949   [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
1950
1951   # Check for sudo...
1952   if [ ! -x "/usr/bin/sudo" ]; then
1953     INFO ""
1954     INFO "This script requires sudo but it is not installed."
1955     INFO "Please setup sudo according to:" 
1956     INFO "https://wiki.archlinux.org/index.php/Sudo"
1957     INFO "and try again."
1958     INFO ""
1959     exit
1960   fi
1961
1962   sudo pacman -Sy
1963
1964   # These libs should always be available in arch official repository...
1965   OPENJPEG_DEV="openjpeg"
1966   VORBIS_DEV="libvorbis"
1967   THEORA_DEV="libtheora"
1968
1969   _packages="base-devel scons cmake libxi glew libpng libtiff wget openal \
1970              $OPENJPEG_DEV $VORBIS_DEV $THEORA_DEV  openexr yasm sdl fftw"
1971
1972   OPENJPEG_USE=true
1973   VORBIS_USE=true
1974   THEORA_USE=true
1975
1976   if $WITH_ALL; then
1977     # No libspacenav in official arch repos...
1978     _packages="$_packages jack"
1979   fi
1980
1981   INFO ""
1982   install_packages_ARCH $_packages
1983
1984   INFO ""
1985   X264_DEV="x264"
1986   check_package_version_ge_ARCH $X264_DEV $X264_VERSION_MIN
1987   if [ $? -eq 0 ]; then
1988     install_packages_ARCH $X264_DEV
1989     X264_USE=true
1990   fi
1991
1992   if $WITH_ALL; then
1993     INFO ""
1994     XVID_DEV="xvidcore"
1995     check_package_ARCH $XVID_DEV
1996     if [ $? -eq 0 ]; then
1997       install_packages_ARCH $XVID_DEV
1998       XVID_USE=true
1999     fi
2000
2001     INFO ""
2002     MP3LAME_DEV="lame"
2003     check_package_ARCH $MP3LAME_DEV
2004     if [ $? -eq 0 ]; then
2005       install_packages_ARCH $MP3LAME_DEV
2006       MP3LAME_USE=true
2007     fi
2008
2009     INFO ""
2010     VPX_DEV="libvpx"
2011     check_package_version_ge_ARCH $VPX_DEV $VPX_VERSION_MIN
2012     if [ $? -eq 0 ]; then
2013       install_packages_ARCH $VPX_DEV
2014       VPX_USE=true
2015     fi
2016   fi
2017
2018   INFO ""
2019   if $PYTHON_SKIP; then
2020     INFO "WARNING! Skipping Python installation, as requested..."
2021   else
2022     check_package_version_ge_ARCH python $PYTHON_VERSION_MIN
2023     if [ $? -eq 0 ]; then
2024       install_packages_ARCH python
2025       INFO ""
2026       if $WITH_NUMPY; then
2027         if $NUMPY_SKIP; then
2028           INFO "WARNING! Skipping NumPy installation, as requested..."
2029         else
2030           check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
2031           if [ $? -eq 0 ]; then
2032             install_packages_ARCH python-numpy
2033           else
2034             INFO "WARNING! Sorry, using python package but no numpy package available!"
2035           fi
2036         fi
2037       fi
2038     else
2039       compile_Python
2040       INFO ""
2041       if $WITH_NUMPY; then
2042         if $NUMPY_SKIP; then
2043           INFO "WARNING! Skipping NumPy installation, as requested..."
2044         else
2045           compile_Numpy
2046         fi
2047       fi
2048     fi
2049   fi
2050
2051   INFO ""
2052   if $BOOST_SKIP; then
2053     INFO "WARNING! Skipping Boost installation, as requested..."
2054   else
2055     check_package_version_ge_ARCH boost $BOOST_VERSION_MIN
2056     if [ $? -eq 0 ]; then
2057       install_packages_ARCH boost
2058     else
2059       compile_Boost
2060     fi
2061   fi
2062
2063   INFO ""
2064   if $OCIO_SKIP; then
2065     INFO "WARNING! Skipping OpenColorIO installation, as requested..."
2066   else
2067     check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
2068     if [ $? -eq 0 ]; then
2069       install_packages_ARCH opencolorio yaml-cpp tinyxml
2070     else
2071       install_packages_ARCH yaml-cpp tinyxml
2072       compile_OCIO
2073     fi
2074   fi
2075
2076   INFO ""
2077   if $OIIO_SKIP; then
2078     INFO "WARNING! Skipping OpenImageIO installation, as requested..."
2079   else
2080     check_package_version_ge_ARCH openimageio $OIIO_VERSION_MIN
2081     if [ $? -eq 0 ]; then
2082       install_packages_ARCH openimageio
2083     else
2084       compile_OIIO
2085     fi
2086   fi
2087
2088   if $WITH_OSL; then
2089     have_llvm=false
2090
2091     INFO ""
2092     if $LLVM_SKIP; then
2093       INFO "WARNING! Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
2094     else
2095       check_package_version_ge_ARCH llvm $LLVM_VERSION_MIN
2096       if [ $? -eq 0 ]; then
2097         install_packages_ARCH llvm clang
2098         have_llvm=true
2099         LLVM_VERSION=`check_package_version_ge_ARCH llvm`
2100         LLVM_VERSION_FOUND=$LLVM_VERSION
2101       else
2102         install_packages_ARCH libffi
2103         # LLVM can't find the arch ffi header dir...
2104         _FFI_INCLUDE_DIR=`pacman -Ql libffi | grep -e ".*/ffi.h" | awk '{print $2}' | sed -r 's/(.*)\/ffi.h/\1/'`
2105         # LLVM 3.1 needs python2 to build and arch defaults to python3
2106         _PYTHON2_BIN="/usr/bin/python2"
2107         INFO ""
2108         compile_LLVM
2109         have_llvm=true
2110         LLVM_VERSION_FOUND=$LLVM_VERSION
2111       fi
2112     fi
2113
2114     if $OSL_SKIP; then
2115       INFO ""
2116       INFO "WARNING! Skipping OpenShadingLanguage installation, as requested..."
2117     else
2118       if $have_llvm; then
2119         check_package_version_ge_ARCH openshadinglanguage $OSL_VERSION_MIN
2120         if [ $? -eq 0 ]; then
2121           install_packages_ARCH openshadinglanguage
2122         else
2123           #XXX Note: will fail to build with LLVM 3.2! 
2124           INFO ""
2125           install_packages_ARCH git intel-tbb
2126           INFO ""
2127           compile_OSL
2128         fi
2129       fi
2130     fi
2131   fi
2132
2133   INFO ""
2134   if $WITH_OPENCOLLADA; then
2135     if $OPENCOLLADA_SKIP; then
2136       INFO "WARNING! Skipping OpenCOLLADA installation, as requested..."
2137     else
2138       INFO ""
2139       check_package_ARCH opencollada
2140       if [ $? -eq 0 ]; then
2141         install_packages_ARCH opencollada
2142       else
2143         install_packages_ARCH pcre git
2144         INFO ""
2145         compile_OpenCOLLADA
2146       fi
2147     # Find path to libxml shared lib...
2148     _XML2_LIB=`pacman -Ql libxml2 | grep -e ".*/libxml2.so$" | gawk '{print $2}'`
2149     fi
2150   fi
2151
2152   INFO ""
2153   if $FFMPEG_SKIP; then
2154     INFO "WARNING! Skipping FFMpeg installation, as requested..."
2155   else
2156     check_package_version_ge_ARCH ffmpeg $FFMPEG_VERSION_MIN
2157     if [ $? -eq 0 ]; then
2158       install_packages_ARCH ffmpeg
2159     else
2160       compile_FFmpeg
2161     fi
2162   fi
2163 }
2164
2165
2166 print_info_ffmpeglink_DEB() {
2167   if $ALL_STATIC; then
2168     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
2169   else
2170     dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
2171   fi
2172 }
2173
2174 print_info_ffmpeglink_RPM() {
2175 #  # XXX No static libs...
2176 #  if $ALL_STATIC; then
2177 #    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
2178 #  else
2179   rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
2180 #  fi
2181 }
2182
2183 print_info_ffmpeglink_ARCH() {
2184 # No static libs...
2185   pacman -Ql $_packages | grep -e ".*\/lib[^\/]\+\.so$" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", $0)); nlines++ }'
2186 }
2187
2188 print_info_ffmpeglink() {
2189   # This func must only print a ';'-separated list of libs...
2190   if [ -z "$DISTRO" ]; then
2191     ERROR "Failed to detect distribution type"
2192     exit 1
2193   fi
2194
2195   # Create list of packages from which to get libs names...
2196   _packages=""
2197
2198   if $THEORA_USE; then
2199     _packages="$_packages $THEORA_DEV"
2200   fi
2201
2202   if $VORBIS_USE; then
2203     _packages="$_packages $VORBIS_DEV"
2204   fi
2205
2206   if $XVID_USE; then
2207     _packages="$_packages $XVID_DEV"
2208   fi
2209
2210   if $VPX_USE; then
2211     _packages="$_packages $VPX_DEV"
2212   fi
2213
2214   if $MP3LAME_USE; then
2215     _packages="$_packages $MP3LAME_DEV"
2216   fi
2217
2218   if $X264_USE; then
2219     _packages="$_packages $X264_DEV"
2220   fi
2221
2222   if $OPENJPEG_USE; then
2223     _packages="$_packages $OPENJPEG_DEV"
2224   fi
2225
2226   if [ "$DISTRO" = "DEB" ]; then
2227     print_info_ffmpeglink_DEB
2228   elif [ "$DISTRO" = "RPM" ]; then
2229     print_info_ffmpeglink_RPM
2230   elif [ "$DISTRO" = "ARCH" ]; then
2231     print_info_ffmpeglink_ARCH
2232   # XXX TODO!
2233   else INFO "<Could not determine additional link libraries needed for ffmpeg, replace this by valid list of libs...>"
2234   fi
2235 }
2236
2237 print_info() {
2238   INFO ""
2239   INFO "If you're using CMake add this to your configuration flags:"
2240
2241   _buildargs=""
2242
2243   if $ALL_STATIC; then
2244     _1="-D WITH_STATIC_LIBS=ON"
2245     # XXX Force linking with shared SDL lib!
2246     _2="-D SDL_LIBRARY='libSDL.so;-lpthread'"
2247     INFO "  $_1"
2248     INFO "  $_2"
2249     _buildargs="$_buildargs $_1 $_2"
2250     # XXX Arch linux needs to link freetype dynamically...
2251     if [ "$DISTRO" = "ARCH" ]; then
2252       _1="-D FREETYPE_LIBRARY=/usr/lib/libfreetype.so"
2253       INFO "  $_1"
2254       _buildargs="$_buildargs $_1"
2255     fi
2256   fi
2257
2258   if [ -d $INST/boost ]; then
2259     _1="-D BOOST_ROOT=$INST/boost"
2260     _2="-D Boost_NO_SYSTEM_PATHS=ON"
2261     INFO "  $_1"
2262     INFO "  $_2"
2263     _buildargs="$_buildargs $_1 $_2"
2264   elif $ALL_STATIC; then
2265     _1="-D WITH_BOOST_ICU=ON"
2266     INFO "  $_1"
2267     _buildargs="$_buildargs $_1"
2268     # XXX Arch linux fails static linking without these...
2269     if [ "$DISTRO" = "ARCH" ]; then
2270       _1="-D ICU_LIBRARY_DATA=/usr/lib/libicudata.so"
2271       _2="-D ICU_LIBRARY_I18N=/usr/lib/libicui18n.so"
2272       _3="-D ICU_LIBRARY_IO=/usr/lib/libicuio.so"
2273       _4="-D ICU_LIBRARY_LE=/usr/lib/libicule.so"
2274       _5="-D ICU_LIBRARY_LX=/usr/lib/libiculx.so"
2275       _6="-D ICU_LIBRARY_TU=/usr/lib/libicutu.so"
2276       _7="-D ICU_LIBRARY_UC=/usr/lib/libicuuc.so"
2277       INFO "  $_1"
2278       INFO "  $_2"
2279       INFO "  $_3"
2280       INFO "  $_4"
2281       INFO "  $_5"
2282       INFO "  $_6"
2283       INFO "  $_7"
2284       _buildargs="$_buildargs $_1 $_2 $_3 $_4 $_5 $_6 $_7"
2285     fi
2286   fi
2287
2288   if $WITH_OSL; then
2289     _1="-D WITH_CYCLES_OSL=ON"
2290     _2="-D WITH_LLVM=ON"
2291     _3="-D LLVM_VERSION=$LLVM_VERSION_FOUND"
2292     INFO "  $_1"
2293     INFO "  $_2"
2294     INFO "  $_3"
2295     _buildargs="$_buildargs $_1 $_2 $_3"
2296     if [ -d $INST/osl ]; then
2297       _1="-D CYCLES_OSL=$INST/osl"
2298       INFO "  $_1"
2299       _buildargs="$_buildargs $_1"
2300     fi
2301     if [ -d $INST/llvm ]; then
2302       _1="-D LLVM_DIRECTORY=$INST/llvm"
2303       _2="-D LLVM_STATIC=ON"
2304       INFO "  $_1"
2305       INFO "  $_2"
2306       _buildargs="$_buildargs $_1 $_2"
2307     fi
2308   fi
2309
2310   if $WITH_OPENCOLLADA; then
2311     _1="-D WITH_OPENCOLLADA=ON"
2312     INFO "  $_1"
2313     _buildargs="$_buildargs $_1"
2314     if $ALL_STATIC; then
2315       _1="-D XML2_LIBRARY=$_XML2_LIB"
2316       INFO "  $_1"
2317       _buildargs="$_buildargs $_1"
2318     fi
2319   fi
2320
2321   _1="-D WITH_CODEC_FFMPEG=ON"
2322   _2="-D FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;rt;`print_info_ffmpeglink`'"
2323   INFO "  $_1"
2324   INFO "  $_2"
2325   _buildargs="$_buildargs $_1 $_2"
2326   if [ -d $INST/ffmpeg ]; then
2327     _1="-D FFMPEG=$INST/ffmpeg"
2328     INFO "  $_1"
2329     _buildargs="$_buildargs $_1"
2330   fi
2331
2332   INFO ""
2333   INFO "Or even simpler, just run (in your blender-source dir):"
2334   INFO "  make -j$THREADS BUILD_CMAKE_ARGS=\"$_buildargs\""
2335
2336   INFO ""
2337   INFO "If you're using SCons add this to your user-config:"
2338
2339   if [ -d $INST/python-$PYTHON_VERSION_MIN ]; then
2340     INFO "BF_PYTHON = '$INST/python-$PYTHON_VERSION_MIN'"
2341     INFO "BF_PYTHON_ABI_FLAGS = 'm'"
2342   fi
2343
2344   INFO "WITH_BF_OCIO = True"
2345   if [ -d $INST/ocio ]; then
2346     INFO "BF_OCIO = '$INST/ocio'"
2347   fi
2348
2349   INFO "WITH_BF_OIIO = True"
2350   if [ -d $INST/oiio ]; then
2351     INFO "BF_OIIO = '$INST/oiio'"
2352   fi
2353   INFO "WITH_BF_CYCLES = True"
2354
2355   if [ -d $INST/osl ]; then
2356     INFO "BF_OSL = '$INST/osl'"
2357   fi
2358
2359   INFO "WITH_BF_BOOST = True"
2360   if [ -d $INST/boost ]; then
2361     INFO "BF_BOOST = '$INST/boost'"
2362   fi
2363
2364   _ffmpeg_list_sep=" "
2365   INFO "BF_FFMPEG_LIB = 'avformat avcodec swscale avutil avdevice `print_info_ffmpeglink`'"
2366   if [ -d $INST/ffmpeg ]; then
2367     INFO "BF_FFMPEG = '$INST/ffmpeg'"
2368   fi
2369
2370   if ! $WITH_ALL; then
2371     INFO "WITH_BF_3DMOUSE = False"
2372   # No libspacenav in official arch repos...
2373   elif [ "$DISTRO" = "ARCH" ]; then
2374     INFO "WITH_BF_3DMOUSE = False"
2375   fi
2376
2377   INFO ""
2378   INFO ""
2379   INFO "WARNING: If this script had to build boost into $INST, and you are dynamically linking "
2380   INFO "         blender against it, you will have to run those commands as root user:"
2381   INFO ""
2382   INFO "    echo \"$INST/boost/lib\" > /etc/ld.so.conf.d/boost.conf"
2383   INFO "    ldconfig"
2384   INFO ""
2385 }
2386
2387 # Detect distributive type used on this machine
2388 detect_distro
2389
2390 if [ -z "$DISTRO" ]; then
2391   ERROR "Failed to detect distribution type"
2392   exit 1
2393 elif [ "$DISTRO" = "DEB" ]; then
2394   install_DEB
2395 elif [ "$DISTRO" = "RPM" ]; then
2396   install_RPM
2397 elif [ "$DISTRO" = "ARCH" ]; then
2398   install_ARCH
2399 fi
2400
2401 print_info | tee BUILD_NOTES.txt
2402 INFO ""
2403 INFO "This information has been written to BUILD_NOTES.txt"
2404 INFO ""
2405
2406 # Switch back to user language.
2407 LANG=LANG_BACK
2408 export LANG