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