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