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