068ac6656238a3c9edbbe3346cfe8a6a83416979
[blender-staging.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:,info:,threads:,help,show-deps,no-sudo,no-build,no-confirm,with-all,with-opencollada,\
29 ver-ocio:,ver-oiio:,ver-llvm:,ver-osl:,ver-osd:,ver-openvdb:,\
30 force-all,force-python,force-numpy,force-boost,\
31 force-ocio,force-openexr,force-oiio,force-llvm,force-osl,force-osd,force-openvdb,\
32 force-ffmpeg,force-opencollada,\
33 build-all,build-python,build-numpy,build-boost,\
34 build-ocio,build-openexr,build-oiio,build-llvm,build-osl,build-osd,build-openvdb,\
35 build-ffmpeg,build-opencollada,\
36 skip-python,skip-numpy,skip-boost,\
37 skip-ocio,skip-openexr,skip-oiio,skip-llvm,skip-osl,skip-osd,skip-openvdb,\
38 skip-ffmpeg,skip-opencollada \
39 -- "$@" \
40 )
41
42 COMMANDLINE=$@
43
44 DISTRO=""
45 RPM=""
46 SRC="$HOME/src/blender-deps"
47 INST="/opt/lib"
48 TMP="/tmp"
49 CWD=$PWD
50 INFO_PATH=$CWD
51 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
52
53 # Do not install some optional, potentially conflicting libs by default...
54 WITH_ALL=false
55
56 # Do not yet enable opencollada, use --with-opencollada (or --with-all) option to try it.
57 WITH_OPENCOLLADA=false
58
59 THREADS=$(nproc)
60
61 COMMON_INFO="\"Source code of dependencies needed to be compiled will be downloaded and extracted into '\$SRC'.
62 Built libs of dependencies needed to be compiled will be installed into '\$INST'.
63 Please edit \\\$SRC and/or \\\$INST variables at the beginning of this script,
64 or use --source/--install options, if you want to use other paths!
65
66 Number of threads for building: \$THREADS (automatically detected, use --threads=<nbr> to override it).
67 Full install: \$WITH_ALL (use --with-all option to enable it).
68 Building OpenCOLLADA: \$WITH_OPENCOLLADA (use --with-opencollada option to enable it).
69
70 Example:
71 Full install without OpenCOLLADA: --with-all --skip-opencollada
72
73 Use --help to show all available options!\""
74
75 ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
76     -h, --help
77         Show this message and exit.
78
79     --show-deps
80         Show main dependencies of Blender (including officially supported versions) and exit.
81
82     -s <path>, --source=<path>
83         Use a specific path where to store downloaded libraries sources (defaults to '\$SRC').
84
85     -i <path>, --install=<path>
86         Use a specific path where to install built libraries (defaults to '\$INST').
87
88     --tmp=<path>
89         Use a specific temp path (defaults to '\$TMP').
90
91     --info=<path>
92         Use a specific info path (to store BUILD_NOTES.txt, defaults to '\$INFO_PATH').
93
94     -t n, --threads=n
95         Use a specific number of threads when building the libraries (auto-detected as '\$THREADS').
96
97     --no-sudo
98         Disable use of sudo (this script won't be able to do much though, will just print needed packages...).
99
100     --no-build
101         Do not build (compile) anything, dependencies not installable with the package manager will remain missing.
102
103     --no-confirm
104         Disable any interaction with user (suitable for automated run).
105
106     --with-all
107         By default, a number of optional and not-so-often needed libraries are not installed.
108         This option will try to install them, at the cost of potential conflicts (depending on
109         how your package system is set…).
110         Note this option also implies all other (more specific) --with-foo options below.
111
112     --with-opencollada
113         Build and install the OpenCOLLADA libraries.
114
115     --ver-ocio=<ver>
116         Force version of OCIO library.
117
118     --ver-oiio=<ver>
119         Force version of OIIO library.
120
121     --ver-llvm=<ver>
122         Force version of LLVM library.
123
124     --ver-osl=<ver>
125         Force version of OSL library.
126
127     --ver-osd=<ver>
128         Force version of OSD library.
129
130     --ver-openvdb=<ver>
131         Force version of OpenVDB library.
132
133     Note about the --ver-foo options:
134         It may not always work as expected (some libs are actually checked out from a git rev...), yet it might help
135         to fix some build issues (like LLVM mismatch with the version used by your graphic system).
136
137     --build-all
138         Force the build of all possible libraries.
139
140     --build-python
141         Force the build of Python.
142
143     --build-numpy
144         Force the build of NumPy.
145
146     --build-boost
147         Force the build of Boost.
148
149     --build-ocio
150         Force the build of OpenColorIO.
151
152     --build-openexr
153         Force the build of OpenEXR.
154
155     --build-oiio
156         Force the build of OpenImageIO.
157
158     --build-llvm
159         Force the build of LLVM.
160
161     --build-osl
162         Force the build of OpenShadingLanguage.
163
164     --build-osd
165         Force the build of OpenSubdiv.
166
167     --build-openvdb
168         Force the build of OpenVDB.
169
170     --build-opencollada
171         Force the build of OpenCOLLADA.
172
173     --build-ffmpeg
174         Force the build of FFMpeg.
175
176     Note about the --build-foo options:
177         * They force the script to prefer building dependencies rather than using available packages.
178           This may make things simpler and allow working around some distribution bugs, but on the other hand it will
179           use much more space on your hard drive.
180         * Please be careful with the Blender building options if you have both 'official' dev packages and
181           install_deps' built ones on your system, by default CMake will prefer official packages, which may lead to
182           linking issues. Please ensure your CMake configuration always uses all correct library paths.
183         * If the “force-built” library is a dependency of others, it will force the build
184           of those libraries as well (e.g. --build-boost also implies --build-oiio and --build-osl...).
185
186     --force-all
187         Force the rebuild of all built libraries.
188
189     --force-python
190         Force the rebuild of Python.
191
192     --force-numpy
193         Force the rebuild of NumPy.
194
195     --force-boost
196         Force the rebuild of Boost.
197
198     --force-ocio
199         Force the rebuild of OpenColorIO.
200
201     --force-openexr
202         Force the rebuild of OpenEXR.
203
204     --force-oiio
205         Force the rebuild of OpenImageIO.
206
207     --force-llvm
208         Force the rebuild of LLVM.
209
210     --force-osl
211         Force the rebuild of OpenShadingLanguage.
212
213     --force-osd
214         Force the rebuild of OpenSubdiv.
215
216     --force-openvdb
217         Force the rebuild of OpenVDB.
218
219     --force-opencollada
220         Force the rebuild of OpenCOLLADA.
221
222     --force-ffmpeg
223         Force the rebuild of FFMpeg.
224
225     Note about the --force-foo options:
226         * They obviously only have an effect if those libraries are built by this script
227           (i.e. if there is no available and satisfactory package)!
228         * If the “force-rebuilt” library is a dependency of others, it will force the rebuild
229           of those libraries too (e.g. --force-boost will also rebuild oiio and osl...).
230
231     --skip-python
232         Unconditionally skip Python installation/building.
233
234     --skip-numpy
235         Unconditionally skip NumPy installation/building.
236
237     --skip-boost
238         Unconditionally skip Boost installation/building.
239
240     --skip-ocio
241         Unconditionally skip OpenColorIO installation/building.
242
243     --skip-openexr
244         Unconditionally skip OpenEXR installation/building.
245
246     --skip-oiio
247         Unconditionally skip OpenImageIO installation/building.
248
249     --skip-llvm
250         Unconditionally skip LLVM installation/building.
251
252     --skip-osl
253         Unconditionally skip OpenShadingLanguage installation/building.
254
255     --skip-osd
256         Unconditionally skip OpenSubdiv installation/building.
257
258     --skip-openvdb
259         Unconditionally skip OpenVDB installation/building.
260
261     --skip-opencollada
262         Unconditionally skip OpenCOLLADA installation/building.
263
264     --skip-ffmpeg
265         Unconditionally skip FFMpeg installation/building.\""
266
267 ##### Main Vars #####
268
269 DO_SHOW_DEPS=false
270
271 SUDO="sudo"
272
273 NO_BUILD=false
274 NO_CONFIRM=false
275
276 PYTHON_VERSION="3.5.1"
277 PYTHON_VERSION_MIN="3.5"
278 PYTHON_FORCE_BUILD=false
279 PYTHON_FORCE_REBUILD=false
280 PYTHON_SKIP=false
281
282 NUMPY_VERSION="1.10.1"
283 NUMPY_VERSION_MIN="1.8"
284 NUMPY_FORCE_BUILD=false
285 NUMPY_FORCE_REBUILD=false
286 NUMPY_SKIP=false
287
288 BOOST_VERSION="1.60.0"
289 BOOST_VERSION_MIN="1.49"
290 BOOST_FORCE_BUILD=false
291 BOOST_FORCE_REBUILD=false
292 BOOST_SKIP=false
293
294 OCIO_VERSION="1.0.9"
295 OCIO_VERSION_MIN="1.0"
296 OCIO_FORCE_BUILD=false
297 OCIO_FORCE_REBUILD=false
298 OCIO_SKIP=false
299
300 OPENEXR_VERSION="2.2.0"
301 OPENEXR_VERSION_MIN="2.0.1"
302 ILMBASE_VERSION="2.2.0"
303 ILMBASE_VERSION_MIN="2.2"
304 OPENEXR_FORCE_BUILD=false
305 OPENEXR_FORCE_REBUILD=false
306 OPENEXR_SKIP=false
307 _with_built_openexr=false
308
309 OIIO_VERSION="1.6.9"
310 OIIO_VERSION_MIN="1.6.0"
311 OIIO_VERSION_MAX="1.9.0"  # UNKNOWN currently # Not supported by current OSL...
312 OIIO_FORCE_BUILD=false
313 OIIO_FORCE_REBUILD=false
314 OIIO_SKIP=false
315
316 LLVM_VERSION="3.4"
317 LLVM_VERSION_MIN="3.4"
318 LLVM_VERSION_FOUND=""
319 LLVM_FORCE_BUILD=false
320 LLVM_FORCE_REBUILD=false
321 LLVM_SKIP=false
322
323 # OSL needs to be compiled for now!
324 OSL_VERSION="1.7.3"
325 OSL_VERSION_MIN=$OSL_VERSION
326 OSL_FORCE_BUILD=false
327 OSL_FORCE_REBUILD=false
328 OSL_SKIP=false
329
330 # OpenSubdiv needs to be compiled for now
331 OSD_VERSION="3.0.2"
332 OSD_VERSION_MIN=$OSD_VERSION
333 OSD_FORCE_BUILD=false
334 OSD_FORCE_REBUILD=false
335 OSD_SKIP=false
336
337 # OpenVDB needs to be compiled for now
338 OPENVDB_BLOSC_VERSION="1.7.0"
339
340 OPENVDB_VERSION="3.1.0"
341 OPENVDB_VERSION_MIN=$OPENVDB_VERSION
342 OPENVDB_FORCE_BUILD=false
343 OPENVDB_FORCE_REBUILD=false
344 OPENVDB_SKIP=false
345
346 # Version??
347 OPENCOLLADA_VERSION="1.3"
348 OPENCOLLADA_FORCE_BUILD=false
349 OPENCOLLADA_FORCE_REBUILD=false
350 OPENCOLLADA_SKIP=false
351
352 FFMPEG_VERSION="2.8.4"
353 FFMPEG_VERSION_MIN="2.8.4"
354 FFMPEG_FORCE_BUILD=false
355 FFMPEG_FORCE_REBUILD=false
356 FFMPEG_SKIP=false
357 _ffmpeg_list_sep=";"
358
359 # FFMPEG optional libs.
360 VORBIS_USE=false
361 VORBIS_DEV=""
362 OGG_USE=false
363 OGG_DEV=""
364 THEORA_USE=false
365 THEORA_DEV=""
366 XVID_USE=false
367 XVID_DEV=""
368 X264_USE=false
369 X264_DEV=""
370 X264_VERSION_MIN=0.118
371 VPX_USE=false
372 VPX_VERSION_MIN=0.9.7
373 VPX_DEV=""
374 MP3LAME_USE=false
375 MP3LAME_DEV=""
376 OPENJPEG_USE=false
377 OPENJPEG_DEV=""
378
379 # Whether to use system GLEW or not (OpenSubDiv needs recent glew to work).
380 NO_SYSTEM_GLEW=false
381
382 # Switch to english language, else some things (like check_package_DEB()) won't work!
383 LANG_BACK=$LANG
384 LANG=""
385 export LANG
386
387 ##### Generic Helpers #####
388
389 BLACK=$(tput setaf 0)
390 RED=$(tput setaf 1)
391 GREEN=$(tput setaf 2)
392 YELLOW=$(tput setaf 3)
393 LIME_YELLOW=$(tput setaf 190)
394 POWDER_BLUE=$(tput setaf 153)
395 BLUE=$(tput setaf 4)
396 MAGENTA=$(tput setaf 5)
397 CYAN=$(tput setaf 6)
398 WHITE=$(tput setaf 7)
399 BRIGHT=$(tput bold)
400 NORMAL=$(tput sgr0)
401 BLINK=$(tput blink)
402 REVERSE=$(tput smso)
403 UNDERLINE=$(tput smul)
404
405 _echo() {
406   if [ "X$1" = "X-n" ]; then
407      shift; printf "%s" "$@"
408   else
409      printf "%s\n" "$@"
410   fi
411 }
412
413 ERROR() {
414   _echo "${BRIGHT}${RED}ERROR! ${NORMAL}${RED}$@${NORMAL}"
415 }
416
417 WARNING() {
418   _echo "${BRIGHT}${YELLOW}WARNING! ${NORMAL}${YELLOW}$@${NORMAL}"
419 }
420
421 INFO() {
422   _echo "${GREEN}$@${NORMAL}"
423 }
424
425 PRINT() {
426   _echo "$@"
427 }
428
429 ##### Args Handling #####
430
431 # Finish parsing the commandline args.
432 eval set -- "$ARGS"
433 while true; do
434   case $1 in
435     -s|--source)
436       SRC="$2"; shift; shift; continue
437     ;;
438     -i|--install)
439       INST="$2"; shift; shift; continue
440     ;;
441     --tmp)
442       TMP="$2"; shift; shift; continue
443     ;;
444     --info)
445       INFO_PATH="$2"; shift; shift; continue
446     ;;
447     -t|--threads)
448       THREADS="$2"; shift; shift; continue
449     ;;
450     -h|--help)
451       PRINT ""
452       PRINT "USAGE:"
453       PRINT ""
454       PRINT "`eval _echo "$COMMON_INFO"`"
455       PRINT ""
456       PRINT "`eval _echo "$ARGUMENTS_INFO"`"
457       PRINT ""
458       exit 0
459     ;;
460     --show-deps)
461       # We have to defer...
462       DO_SHOW_DEPS=true; shift; continue
463     ;;
464     --no-sudo)
465       PRINT ""
466       WARNING "--no-sudo enabled, this script might not be able to do much..."
467       PRINT ""
468       SUDO=""; shift; continue
469     ;;
470     --no-build)
471       PRINT ""
472       WARNING "--no-build enabled, this script will not be able to install all dependencies..."
473       PRINT ""
474       NO_BUILD=true; shift; continue
475     ;;
476     --no-confirm)
477       NO_CONFIRM=true; shift; continue
478     ;;
479     --with-all)
480       WITH_ALL=true; shift; continue
481     ;;
482     --with-opencollada)
483       WITH_OPENCOLLADA=true; shift; continue
484     ;;
485     --ver-ocio)
486       OCIO_VERSION="$2"
487       OCIO_VERSION_MIN=$OCIO_VERSION
488       shift; shift; continue
489     ;;
490     --ver-oiio)
491       OIIO_VERSION="$2"
492       OIIO_VERSION_MIN=$OIIO_VERSION
493       shift; shift; continue
494     ;;
495     --ver-llvm)
496       LLVM_VERSION="$2"
497       LLVM_VERSION_MIN=$LLVM_VERSION
498       shift; shift; continue
499     ;;
500     --ver-osl)
501       OSL_VERSION="$2"
502       OSL_VERSION_MIN=$OSL_VERSION
503       shift; shift; continue
504     ;;
505     --ver-osd)
506       OSD_VERSION="$2"
507       OSD_VERSION_MIN=$OSD_VERSION
508       shift; shift; continue
509     ;;
510     --ver-openvdb)
511       OPENVDB_VERSION="$2"
512       OPENVDB_VERSION_MIN=$OPENVDB_VERSION
513       shift; shift; continue
514     ;;
515     --build-all)
516       PYTHON_FORCE_BUILD=true
517       NUMPY_FORCE_BUILD=true
518       BOOST_FORCE_BUILD=true
519       OCIO_FORCE_BUILD=true
520       OPENEXR_FORCE_BUILD=true
521       OIIO_FORCE_BUILD=true
522       LLVM_FORCE_BUILD=true
523       OSL_FORCE_BUILD=true
524       OSD_FORCE_BUILD=true
525       OPENVDB_FORCE_BUILD=true
526       OPENCOLLADA_FORCE_BUILD=true
527       FFMPEG_FORCE_BUILD=true
528       shift; continue
529     ;;
530     --build-python)
531       PYTHON_FORCE_BUILD=true
532       NUMPY_FORCE_BUILD=true
533       shift; continue
534     ;;
535     --build-numpy)
536       PYTHON_FORCE_BUILD=true
537       NUMPY_FORCE_BUILD=true
538       shift; continue
539     ;;
540     --build-boost)
541       BOOST_FORCE_BUILD=true; shift; continue
542     ;;
543     --build-ocio)
544       OCIO_FORCE_BUILD=true; shift; continue
545     ;;
546     --build-openexr)
547       OPENEXR_FORCE_BUILD=true; shift; continue
548     ;;
549     --build-oiio)
550       OIIO_FORCE_BUILD=true; shift; continue
551     ;;
552     --build-llvm)
553       LLVM_FORCE_BUILD=true; shift; continue
554     ;;
555     --build-osl)
556       OSL_FORCE_BUILD=true; shift; continue
557     ;;
558     --build-osd)
559       OSD_FORCE_BUILD=true; shift; continue
560     ;;
561     --build-openvdb)
562       OPENVDB_FORCE_BUILD=true; shift; continue
563     ;;
564     --build-opencollada)
565       OPENCOLLADA_FORCE_BUILD=true; shift; continue
566     ;;
567     --build-ffmpeg)
568       FFMPEG_FORCE_BUILD=true; shift; continue
569     ;;
570     --force-all)
571       PYTHON_FORCE_REBUILD=true
572       NUMPY_FORCE_REBUILD=true
573       BOOST_FORCE_REBUILD=true
574       OCIO_FORCE_REBUILD=true
575       OPENEXR_FORCE_REBUILD=true
576       OIIO_FORCE_REBUILD=true
577       LLVM_FORCE_REBUILD=true
578       OSL_FORCE_REBUILD=true
579       OSD_FORCE_REBUILD=true
580       OPENVDB_FORCE_REBUILD=true
581       OPENCOLLADA_FORCE_REBUILD=true
582       FFMPEG_FORCE_REBUILD=true
583       shift; continue
584     ;;
585     --force-python)
586       PYTHON_FORCE_REBUILD=true
587       NUMPY_FORCE_REBUILD=true
588       shift; continue
589     ;;
590     --force-numpy)
591       NUMPY_FORCE_REBUILD=true; shift; continue
592     ;;
593     --force-boost)
594       BOOST_FORCE_REBUILD=true; shift; continue
595     ;;
596     --force-ocio)
597       OCIO_FORCE_REBUILD=true; shift; continue
598     ;;
599     --force-openexr)
600       OPENEXR_FORCE_REBUILD=true; shift; continue
601     ;;
602     --force-oiio)
603       OIIO_FORCE_REBUILD=true; shift; continue
604     ;;
605     --force-llvm)
606       LLVM_FORCE_REBUILD=true; shift; continue
607     ;;
608     --force-osl)
609       OSL_FORCE_REBUILD=true; shift; continue
610     ;;
611     --force-osd)
612       OSD_FORCE_REBUILD=true; shift; continue
613     ;;
614     --force-openvdb)
615       OPENVDB_FORCE_REBUILD=true; shift; continue
616     ;;
617     --force-opencollada)
618       OPENCOLLADA_FORCE_REBUILD=true; shift; continue
619     ;;
620     --force-ffmpeg)
621       FFMPEG_FORCE_REBUILD=true; shift; continue
622     ;;
623     --skip-python)
624       PYTHON_SKIP=true; shift; continue
625     ;;
626     --skip-numpy)
627       NUMPY_SKIP=true; shift; continue
628     ;;
629     --skip-boost)
630       BOOST_SKIP=true; shift; continue
631     ;;
632     --skip-ocio)
633       OCIO_SKIP=true; shift; continue
634     ;;
635     --skip-openexr)
636       OPENEXR_SKIP=true; shift; continue
637     ;;
638     --skip-oiio)
639       OIIO_SKIP=true; shift; continue
640     ;;
641     --skip-llvm)
642       LLVM_SKIP=true; shift; continue
643     ;;
644     --skip-osl)
645       OSL_SKIP=true; shift; continue
646     ;;
647     --skip-osd)
648       OSD_SKIP=true; shift; continue
649     ;;
650     --skip-openvdb)
651       OPENVDB_SKIP=true; shift; continue
652     ;;
653     --skip-opencollada)
654       OPENCOLLADA_SKIP=true; shift; continue
655     ;;
656     --skip-ffmpeg)
657       FFMPEG_SKIP=true; shift; continue
658     ;;
659     --)
660       # no more arguments to parse
661       break
662     ;;
663     *)
664       PRINT ""
665       ERROR "Wrong parameter! Usage:"
666       PRINT ""
667       PRINT "`eval _echo "$COMMON_INFO"`"
668       PRINT ""
669       exit 1
670     ;;
671   esac
672 done
673
674 if [ "$WITH_ALL" = true -a "$OPENCOLLADA_SKIP" = false ]; then
675   WITH_OPENCOLLADA=true
676 fi
677
678
679
680 # This has to be done here, because user might force some versions...
681 PYTHON_SOURCE=( "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz" )
682 NUMPY_SOURCE=( "http://sourceforge.net/projects/numpy/files/NumPy/$NUMPY_VERSION/numpy-$NUMPY_VERSION.tar.gz" )
683
684 _boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
685 BOOST_SOURCE=( "http://sourceforge.net/projects/boost/files/boost/$BOOST_VERSION/boost_$_boost_version_nodots.tar.bz2/download" )
686 BOOST_BUILD_MODULES="--with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time --with-wave --with-iostreams"
687
688 OCIO_SOURCE=( "https://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION" )
689
690 OPENEXR_USE_REPO=false
691 OPENEXR_SOURCE=( "http://download.savannah.nongnu.org/releases/openexr/openexr-$OPENEXR_VERSION.tar.gz" )
692 OPENEXR_SOURCE_REPO=( "https://github.com/mont29/openexr.git" )
693 OPENEXR_SOURCE_REPO_UID="2787aa1cf652d244ed45ae124eb1553f6cff11ee"
694 ILMBASE_SOURCE=( "http://download.savannah.nongnu.org/releases/openexr/ilmbase-$ILMBASE_VERSION.tar.gz" )
695
696 OIIO_USE_REPO=false
697 OIIO_SOURCE=( "https://github.com/OpenImageIO/oiio/archive/Release-$OIIO_VERSION.tar.gz" )
698 OIIO_SOURCE_REPO=( "https://github.com/OpenImageIO/oiio.git" )
699 OIIO_SOURCE_REPO_UID="c9e67275a0b248ead96152f6d2221cc0c0f278a4"
700
701 LLVM_SOURCE=( "http://llvm.org/releases/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.gz" )
702 LLVM_CLANG_SOURCE=( "http://llvm.org/releases/$LLVM_VERSION/clang-$LLVM_VERSION.src.tar.gz" "http://llvm.org/releases/$LLVM_VERSION/cfe-$LLVM_VERSION.src.tar.gz" )
703
704 OSL_USE_REPO=false
705 OSL_SOURCE=( "https://github.com/imageworks/OpenShadingLanguage/archive/Release-$OSL_VERSION.tar.gz" )
706 #~ OSL_SOURCE=( "https://github.com/Nazg-Gul/OpenShadingLanguage/archive/Release-1.5.11.tar.gz" )
707 #~ OSL_SOURCE_REPO=( "https://github.com/imageworks/OpenShadingLanguage.git" )
708 #~ OSL_SOURCE_REPO=( "https://github.com/mont29/OpenShadingLanguage.git" )
709 #~ OSL_SOURCE_REPO_UID="85179714e1bc69cd25ecb6bb711c1a156685d395"
710 #~ OSL_SOURCE_REPO_BRANCH="master"
711 OSL_SOURCE_REPO=( "https://github.com/Nazg-Gul/OpenShadingLanguage.git" )
712 OSL_SOURCE_REPO_UID="7d40ff5fe8e47b030042afb92d0e955f5aa96f48"
713 OSL_SOURCE_REPO_BRANCH="blender-fixes"
714
715 OSD_USE_REPO=true
716 # Script foo to make the version string compliant with the archive name:
717 # ${Varname//SearchForThisChar/ReplaceWithThisChar}
718 OSD_SOURCE=( "https://github.com/PixarAnimationStudios/OpenSubdiv/archive/v${OSD_VERSION//./_}.tar.gz" )
719 OSD_SOURCE_REPO=( "https://github.com/PixarAnimationStudios/OpenSubdiv.git" )
720 OSD_SOURCE_REPO_UID="404659fffa659da075d1c9416e4fc939139a84ee"
721 OSD_SOURCE_REPO_BRANCH="dev"
722
723 OPENVDB_USE_REPO=false
724 OPENVDB_BLOSC_SOURCE=( "https://github.com/Blosc/c-blosc/archive/v${OPENVDB_BLOSC_VERSION}.tar.gz" )
725 OPENVDB_SOURCE=( "https://github.com/dreamworksanimation/openvdb/archive/v${OPENVDB_VERSION}.tar.gz" )
726 #~ OPENVDB_SOURCE_REPO=( "https:///dreamworksanimation/openvdb.git" )
727 #~ OPENVDB_SOURCE_REPO_UID="404659fffa659da075d1c9416e4fc939139a84ee"
728 #~ OPENVDB_SOURCE_REPO_BRANCH="dev"
729
730 OPENCOLLADA_SOURCE=( "https://github.com/KhronosGroup/OpenCOLLADA.git" )
731 OPENCOLLADA_REPO_UID="3335ac164e68b2512a40914b14c74db260e6ff7d"
732 OPENCOLLADA_REPO_BRANCH="master"
733
734 FFMPEG_SOURCE=( "http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2" )
735
736
737
738 #### Show Dependencies ####
739
740 # Need those to be after we defined versions...
741 DEPS_COMMON_INFO="\"COMMON DEPENDENCIES:
742
743 Those libraries should be available as packages in all recent distributions (optional ones are [between brackets]):
744
745     * Basics of dev environment (cmake, gcc, svn , git, ...).
746     * libjpeg, libpng, libtiff, [libopenjpeg], [libopenal].
747     * libx11, libxcursor, libxi, libxrandr, libxinerama (and other libx... as needed).
748     * libsqlite3, libbz2, libssl, libfftw3, libxml2, libtinyxml, yasm, libyaml-cpp.
749     * libsdl1.2, libglew, libglewmx.\""
750
751 DEPS_SPECIFIC_INFO="\"BUILDABLE DEPENDENCIES:
752
753 The following libraries will probably not all be available as packages in your distribution
754 (install_deps will by default try to install packages, and fall back to building missing ones).
755 You can force install_deps to build those with '--build-all' or relevant 'build-foo' options, see '--help' message.
756 You may also want to build them yourself (optional ones are [between brackets]):
757
758     * Python $PYTHON_VERSION_MIN (from $PYTHON_SOURCE).
759     * [NumPy $NUMPY_VERSION_MIN] (from $NUMPY_SOURCE).
760     * Boost $BOOST_VERSION_MIN (from $BOOST_SOURCE, modules: $BOOST_BUILD_MODULES).
761     * [FFMpeg $FFMPEG_VERSION_MIN (needs libvorbis, libogg, libtheora, libx264, libmp3lame, libxvidcore, libvpx, ...)] (from $FFMPEG_SOURCE).
762     * [OpenColorIO $OCIO_VERSION_MIN] (from $OCIO_SOURCE).
763     * ILMBase $ILMBASE_VERSION_MIN (from $ILMBASE_SOURCE).
764     * OpenEXR $OPENEXR_VERSION_MIN (from $OPENEXR_SOURCE).
765     * OpenImageIO $OIIO_VERSION_MIN (from $OIIO_SOURCE).
766     * [LLVM $LLVM_VERSION_MIN (with clang)] (from $LLVM_SOURCE, and $LLVM_CLANG_SOURCE).
767     * [OpenShadingLanguage $OSL_VERSION_MIN] (from $OSL_SOURCE_REPO, branch $OSL_SOURCE_REPO_BRANCH, commit $OSL_SOURCE_REPO_UID).
768     * [OpenSubDiv $OSD_VERSION_MIN] (from $OSD_SOURCE_REPO, branch $OSD_SOURCE_REPO_BRANCH, commit $OSD_SOURCE_REPO_UID).
769     * [OpenVDB $OPENVDB_VERSION_MIN] (from $OPENVDB_SOURCE), [Blosc $OPENVDB_BLOSC_VERSION] (from $OPENVDB_BLOSC_SOURCE).
770     * [OpenCollada] (from $OPENCOLLADA_SOURCE, branch $OPENCOLLADA_REPO_BRANCH, commit $OPENCOLLADA_REPO_UID).\""
771
772 if [ "$DO_SHOW_DEPS" = true ]; then
773   PRINT ""
774   PRINT "Blender dependencies (libraries needed to build it):"
775   PRINT ""
776   PRINT "`eval _echo "$DEPS_COMMON_INFO"`"
777   PRINT ""
778   PRINT "`eval _echo "$DEPS_SPECIFIC_INFO"`"
779   PRINT ""
780   exit 0
781 fi
782
783
784
785 ##### Generic Helpers #####
786
787 # Check return code of wget for success...
788 download() {
789   declare -a sources=("${!1}")
790   sources_count=${#sources[@]}
791   error=1
792
793   for (( i=0; $i < $sources_count; i++ ))
794   do
795     wget -c ${sources[$i]} -O $2
796     if [ $? -eq 0 ]; then
797       error=0
798       break
799     fi
800   done
801
802   if [ $error -eq 1 ]; then
803     ERROR "wget could not find ${sources[@]}, or could not write it to $2, exiting"
804     exit 1
805   fi
806 }
807
808 # Return 0 if $1 = $2 (i.e. 1.01.0 = 1.1, but 1.1.1 != 1.1), else 1.
809 # $1 and $2 should be version numbers made of numbers only.
810 version_eq() {
811   backIFS=$IFS
812   IFS='.'
813
814   # Split both version numbers into their numeric elements.
815   arr1=( $1 )
816   arr2=( $2 )
817
818   ret=1
819
820   count1=${#arr1[@]}
821   count2=${#arr2[@]}
822   if [ $count2 -ge $count1 ]; then
823     _t=$count1
824     count1=$count2
825     count2=$_t
826     arr1=( $2 )
827     arr2=( $1 )
828   fi
829
830   ret=0
831   for (( i=0; $i < $count2; i++ ))
832   do
833     if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
834       ret=1
835       break
836     fi
837   done
838
839   for (( i=$count2; $i < $count1; i++ ))
840   do
841     if [ $(( 10#${arr1[$i]} )) -ne 0 ]; then
842       ret=1
843       break
844     fi
845   done
846
847   IFS=$backIFS
848   return $ret
849 }
850
851 # Return 0 if $1 >= $2, else 1.
852 # $1 and $2 should be version numbers made of numbers only.
853 version_ge() {
854   version_eq $1 $2
855   if [ $? -eq 1 -a $(_echo "$1" "$2" | sort --version-sort | head --lines=1) = "$1" ]; then
856     return 1
857   else
858     return 0
859   fi
860 }
861
862 # Return 0 if $3 > $1 >= $2, else 1.
863 # $1 and $2 should be version numbers made of numbers only.
864 version_ge_lt() {
865   version_ge $1 $3
866   if [ $? -eq 0 ]; then
867     return 1
868   else
869     version_ge $1 $2
870     return $?
871   fi
872 }
873
874 # 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.
875 # $1 and $2 should be version numbers made of numbers only.
876 # $1 should be at least as long as $2!
877 version_match() {
878   backIFS=$IFS
879   IFS='.'
880
881   # Split both version numbers into their numeric elements.
882   arr1=( $1 )
883   arr2=( $2 )
884
885   ret=1
886
887   count1=${#arr1[@]}
888   count2=${#arr2[@]}
889   if [ $count1 -ge $count2 ]; then
890     ret=0
891     for (( i=0; $i < $count2; i++ ))
892     do
893       if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
894         ret=1
895         break
896       fi
897     done
898   fi
899
900   IFS=$backIFS
901   return $ret
902 }
903
904 ##### Generic compile helpers #####
905 prepare_opt() {
906   INFO "Ensuring $INST exists and is writable by us"
907   if [ ! $SUDO ]; then
908     WARNING "--no-sudo enabled, might be impossible to create install dir..."
909   fi
910   if [ ! -d  $INST ]; then
911     $SUDO mkdir -p $INST
912   fi
913
914   if [ ! -w $INST ]; then
915     $SUDO chown $USER $INST
916     $SUDO chmod 775 $INST
917   fi
918 }
919
920 # Check whether the current package needs to be recompiled, based on a dummy file containing a magic number in its name...
921 magic_compile_check() {
922   if [ -f $INST/.$1-magiccheck-$2 ]; then
923     return 0
924   else
925     return 1
926   fi
927 }
928
929 magic_compile_set() {
930   rm -f $INST/.$1-magiccheck-*
931   touch $INST/.$1-magiccheck-$2
932 }
933
934 # Note: should clean nicely in $INST, but not in $SRC, when we switch to a new version of a lib...
935 _clean() {
936   rm -rf `readlink -f $_inst_shortcut`
937   # Only remove $_src dir when not using git repo (avoids to re-clone the whole repo every time!!!).
938   if [ $_git == false ]; then
939     rm -rf $_src
940   fi
941   rm -rf $_inst
942   rm -rf $_inst_shortcut
943 }
944
945 _create_inst_shortcut() {
946   rm -f $_inst_shortcut
947   ln -s $_inst $_inst_shortcut
948 }
949
950 # ldconfig
951 run_ldconfig() {
952   _lib_path="$INST/$1/lib"
953   _ldconf_path="/etc/ld.so.conf.d/$1.conf"
954   PRINT ""
955   if [ ! $SUDO ]; then
956     WARNING "--no-sudo enabled, impossible to run ldconfig for $1, you'll have to do it yourself..."
957   else
958     INFO "Running ldconfig for $1..."
959     $SUDO sh -c "echo \"$_lib_path\" > $_ldconf_path"
960     $SUDO /sbin/ldconfig  # XXX OpenSuse does not include sbin in command path with sudo!!!
961   fi
962   PRINT ""
963 }
964
965 #### Build Python ####
966 _init_python() {
967   _src=$SRC/Python-$PYTHON_VERSION
968   _git=false
969   _inst=$INST/python-$PYTHON_VERSION
970   _inst_shortcut=$INST/python-$PYTHON_VERSION_MIN
971 }
972
973 clean_Python() {
974   clean_Numpy
975   _init_python
976   _clean
977 }
978
979 compile_Python() {
980   if [ "$NO_BUILD" = true ]; then
981     WARNING "--no-build enabled, Python will not be compiled!"
982     return
983   fi
984
985   # To be changed each time we make edits that would modify the compiled result!
986   py_magic=1
987   _init_python
988
989   # Clean install if needed!
990   magic_compile_check python-$PYTHON_VERSION $py_magic
991   if [ $? -eq 1 -o "$PYTHON_FORCE_REBUILD" = true ]; then
992     clean_Python
993   fi
994
995   if [ ! -d $_inst ]; then
996     INFO "Building Python-$PYTHON_VERSION"
997
998     prepare_opt
999
1000     if [ ! -d $_src ]; then
1001       mkdir -p $SRC
1002       download PYTHON_SOURCE[@] $_src.tgz
1003
1004       INFO "Unpacking Python-$PYTHON_VERSION"
1005       tar -C $SRC -xf $_src.tgz
1006     fi
1007
1008     cd $_src
1009
1010     ./configure --prefix=$_inst --libdir=$_inst/lib --enable-ipv6 \
1011         --enable-loadable-sqlite-extensions --with-dbmliborder=bdb \
1012         --with-computed-gotos --with-pymalloc
1013
1014     make -j$THREADS && make install
1015     make clean
1016
1017     if [ -d $_inst ]; then
1018       _create_inst_shortcut
1019     else
1020       ERROR "Python--$PYTHON_VERSION failed to compile, exiting"
1021       exit 1
1022     fi
1023
1024     magic_compile_set python-$PYTHON_VERSION $py_magic
1025
1026     cd $CWD
1027     INFO "Done compiling Python-$PYTHON_VERSION!"
1028   else
1029     INFO "Own Python-$PYTHON_VERSION is up to date, nothing to do!"
1030     INFO "If you want to force rebuild of this lib, use the --force-python option."
1031   fi
1032 }
1033
1034 ##### Build Numpy #####
1035 _init_numpy() {
1036   _src=$SRC/numpy-$NUMPY_VERSION
1037   _git=false
1038   _inst=$INST/numpy-$NUMPY_VERSION
1039   _python=$INST/python-$PYTHON_VERSION
1040   _site=lib/python$PYTHON_VERSION_MIN/site-packages
1041   _inst_shortcut=$_python/$_site/numpy
1042 }
1043
1044 clean_Numpy() {
1045   _init_numpy
1046   _clean
1047 }
1048
1049 compile_Numpy() {
1050   if [ "$NO_BUILD" = true ]; then
1051     WARNING "--no-build enabled, Numpy will not be compiled!"
1052     return
1053   fi
1054
1055   # To be changed each time we make edits that would modify the compiled result!
1056   numpy_magic=0
1057   _init_numpy
1058
1059   # Clean install if needed!
1060   magic_compile_check numpy-$NUMPY_VERSION $numpy_magic
1061   if [ $? -eq 1 -o "$NUMPY_FORCE_REBUILD" = true ]; then
1062     clean_Numpy
1063   fi
1064
1065   if [ ! -d $_inst ]; then
1066     INFO "Building Numpy-$NUMPY_VERSION"
1067
1068     prepare_opt
1069
1070     if [ ! -d $_src ]; then
1071       mkdir -p $SRC
1072       download NUMPY_SOURCE[@] $_src.tar.gz
1073
1074       INFO "Unpacking Numpy-$NUMPY_VERSION"
1075       tar -C $SRC -xf $_src.tar.gz
1076     fi
1077
1078     cd $_src
1079
1080     $_python/bin/python3 setup.py install --prefix=$_inst
1081
1082     if [ -d $_inst ]; then
1083       # Can't use _create_inst_shortcut here...
1084       rm -f $_inst_shortcut
1085       ln -s $_inst/$_site/numpy $_inst_shortcut
1086     else
1087       ERROR "Numpy-$NUMPY_VERSION failed to compile, exiting"
1088       exit 1
1089     fi
1090
1091     magic_compile_set numpy-$NUMPY_VERSION $numpy_magic
1092
1093     cd $CWD
1094     INFO "Done compiling Numpy-$NUMPY_VERSION!"
1095   else
1096     INFO "Own Numpy-$NUMPY_VERSION is up to date, nothing to do!"
1097     INFO "If you want to force rebuild of this lib, use the --force-numpy option."
1098   fi
1099 }
1100
1101 #### Build Boost ####
1102 _init_boost() {
1103   _src=$SRC/boost-$BOOST_VERSION
1104   _git=false
1105   _inst=$INST/boost-$BOOST_VERSION
1106   _inst_shortcut=$INST/boost
1107 }
1108
1109 clean_Boost() {
1110   _init_boost
1111   _clean
1112 }
1113
1114 compile_Boost() {
1115   if [ "$NO_BUILD" = true ]; then
1116     WARNING "--no-build enabled, Boost will not be compiled!"
1117     return
1118   fi
1119
1120   # To be changed each time we make edits that would modify the compiled result!
1121   boost_magic=10
1122
1123   _init_boost
1124
1125   # Clean install if needed!
1126   magic_compile_check boost-$BOOST_VERSION $boost_magic
1127   if [ $? -eq 1 -o "$BOOST_FORCE_REBUILD" = true ]; then
1128     clean_Boost
1129   fi
1130
1131   if [ ! -d $_inst ]; then
1132     INFO "Building Boost-$BOOST_VERSION"
1133
1134     # Rebuild dependecies as well!
1135     OIIO_FORCE_BUILD=true
1136     OIIO_FORCE_REBUILD=true
1137     OSL_FORCE_BUILD=true
1138     OSL_FORCE_REBUILD=true
1139     OPENVDB_FORCE_BUILD=true
1140     OPENVDB_FORCE_REBUILD=true
1141
1142     prepare_opt
1143
1144     if [ ! -d $_src ]; then
1145       INFO "Downloading Boost-$BOOST_VERSION"
1146       mkdir -p $SRC
1147       download BOOST_SOURCE[@] $_src.tar.bz2
1148       tar -C $SRC --transform "s,\w*,boost-$BOOST_VERSION,x" -xf $_src.tar.bz2
1149     fi
1150
1151     cd $_src
1152     if [ ! -f $_src/b2 ]; then
1153       ./bootstrap.sh
1154     fi
1155     ./b2 -j$THREADS -a $BOOST_BUILD_MODULES \
1156          --prefix=$_inst --disable-icu boost.locale.icu=off install
1157     ./b2 --clean
1158
1159     if [ -d $_inst ]; then
1160       _create_inst_shortcut
1161     else
1162       ERROR "Boost-$BOOST_VERSION failed to compile, exiting"
1163       exit 1
1164     fi
1165
1166     magic_compile_set boost-$BOOST_VERSION $boost_magic
1167
1168     cd $CWD
1169     INFO "Done compiling Boost-$BOOST_VERSION!"
1170   else
1171     INFO "Own Boost-$BOOST_VERSION is up to date, nothing to do!"
1172     INFO "If you want to force rebuild of this lib, use the --force-boost option."
1173   fi
1174
1175   # Just always run it, much simpler this way!
1176   run_ldconfig "boost"
1177 }
1178
1179 #### Build OCIO ####
1180 _init_ocio() {
1181   _src=$SRC/OpenColorIO-$OCIO_VERSION
1182   _git=false
1183   _inst=$INST/ocio-$OCIO_VERSION
1184   _inst_shortcut=$INST/ocio
1185 }
1186
1187 clean_OCIO() {
1188   _init_ocio
1189   _clean
1190 }
1191
1192 compile_OCIO() {
1193   if [ "$NO_BUILD" = true ]; then
1194     WARNING "--no-build enabled, OpenColorIO will not be compiled!"
1195     return
1196   fi
1197
1198   # To be changed each time we make edits that would modify the compiled result!
1199   ocio_magic=1
1200   _init_ocio
1201
1202   # Clean install if needed!
1203   magic_compile_check ocio-$OCIO_VERSION $ocio_magic
1204   if [ $? -eq 1 -o "$OCIO_FORCE_REBUILD" = true ]; then
1205     clean_OCIO
1206   fi
1207
1208   if [ ! -d $_inst ]; then
1209     INFO "Building OpenColorIO-$OCIO_VERSION"
1210
1211     prepare_opt
1212
1213     if [ ! -d $_src ]; then
1214       INFO "Downloading OpenColorIO-$OCIO_VERSION"
1215       mkdir -p $SRC
1216       download OCIO_SOURCE[@] $_src.tar.gz
1217
1218       INFO "Unpacking OpenColorIO-$OCIO_VERSION"
1219       tar -C $SRC --transform "s,(.*/?)imageworks-OpenColorIO[^/]*(.*),\1OpenColorIO-$OCIO_VERSION\2,x" \
1220           -xf $_src.tar.gz
1221     fi
1222
1223     cd $_src
1224     # Always refresh the whole build!
1225     if [ -d build ]; then
1226       rm -rf build
1227     fi
1228     mkdir build
1229     cd build
1230
1231     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1232     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1233     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1234     cmake_d="$cmake_d -D OCIO_BUILD_APPS=OFF"
1235     cmake_d="$cmake_d -D OCIO_BUILD_PYGLUE=OFF"
1236
1237     if file /bin/cp | grep -q '32-bit'; then
1238       cflags="-fPIC -m32 -march=i686"
1239     else
1240       cflags="-fPIC"
1241     fi
1242
1243     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1244
1245     make -j$THREADS && make install
1246
1247     # Force linking against static libs
1248     rm -f $_inst/lib/*.so*
1249
1250     # Additional depencencies
1251     cp ext/dist/lib/libtinyxml.a $_inst/lib
1252     cp ext/dist/lib/libyaml-cpp.a $_inst/lib
1253
1254     make clean
1255
1256     if [ -d $_inst ]; then
1257       _create_inst_shortcut
1258     else
1259       ERROR "OpenColorIO-$OCIO_VERSION failed to compile, exiting"
1260       exit 1
1261     fi
1262
1263     magic_compile_set ocio-$OCIO_VERSION $ocio_magic
1264
1265     cd $CWD
1266     INFO "Done compiling OpenColorIO-$OCIO_VERSION!"
1267   else
1268     INFO "Own OpenColorIO-$OCIO_VERSION is up to date, nothing to do!"
1269     INFO "If you want to force rebuild of this lib, use the --force-ocio option."
1270   fi
1271
1272   run_ldconfig "ocio"
1273 }
1274
1275 #### Build ILMBase ####
1276 _init_ilmbase() {
1277   _src=$SRC/ILMBase-$ILMBASE_VERSION
1278   _git=false
1279   _inst=$TMP/ilmbase-$ILMBASE_VERSION
1280   _inst_shortcut=$TMP/ilmbase
1281 }
1282
1283 clean_ILMBASE() {
1284   _init_ilmbase
1285   _clean
1286 }
1287
1288 compile_ILMBASE() {
1289   if [ "$NO_BUILD" = true ]; then
1290     WARNING "--no-build enabled, ILMBase will not be compiled!"
1291     return
1292   fi
1293
1294   # To be changed each time we make edits that would modify the compiled result!
1295   ilmbase_magic=10
1296   _init_ilmbase
1297
1298   # Clean install if needed!
1299   magic_compile_check ilmbase-$ILMBASE_VERSION $ilmbase_magic
1300   if [ $? -eq 1 -o "$OPENEXR_FORCE_REBUILD" = true ]; then
1301     clean_ILMBASE
1302     rm -rf $_openexr_inst
1303   fi
1304
1305   if [ ! -d $_openexr_inst ]; then
1306     INFO "Building ILMBase-$ILMBASE_VERSION"
1307
1308     # Rebuild dependecies as well!
1309     OPENEXR_FORCE_BUILD=true
1310     OPENEXR_FORCE_REBUILD=true
1311
1312     prepare_opt
1313
1314     if [ ! -d $_src ]; then
1315       INFO "Downloading ILMBase-$ILMBASE_VERSION"
1316       mkdir -p $SRC
1317       download ILMBASE_SOURCE[@] $_src.tar.gz
1318
1319       INFO "Unpacking ILMBase-$ILMBASE_VERSION"
1320       tar -C $SRC --transform "s,(.*/?)ilmbase-[^/]*(.*),\1ILMBase-$ILMBASE_VERSION\2,x" -xf $_src.tar.gz
1321
1322     fi
1323
1324     cd $_src
1325     # Always refresh the whole build!
1326     if [ -d build ]; then
1327       rm -rf build
1328     fi
1329     mkdir build
1330     cd build
1331
1332     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1333     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1334     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1335     cmake_d="$cmake_d -D BUILD_SHARED_LIBS=ON"
1336     cmake_d="$cmake_d -D NAMESPACE_VERSIONING=OFF"  # VERY IMPORTANT!!!
1337
1338     if file /bin/cp | grep -q '32-bit'; then
1339       cflags="-fPIC -m32 -march=i686"
1340     else
1341       cflags="-fPIC"
1342     fi
1343
1344     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1345
1346     make -j$THREADS && make install
1347
1348     make clean
1349
1350     if [ -d $_inst ]; then
1351       _create_inst_shortcut
1352     else
1353       ERROR "ILMBase-$ILMBASE_VERSION failed to compile, exiting"
1354       exit 1
1355     fi
1356     cd $CWD
1357     INFO "Done compiling ILMBase-$ILMBASE_VERSION!"
1358   else
1359     INFO "Own ILMBase-$ILMBASE_VERSION is up to date, nothing to do!"
1360     INFO "If you want to force rebuild of this lib (and openexr), use the --force-openexr option."
1361   fi
1362
1363   magic_compile_set ilmbase-$ILMBASE_VERSION $ilmbase_magic
1364 }
1365
1366 #### Build OpenEXR ####
1367 _init_openexr() {
1368   _src=$SRC/OpenEXR-$OPENEXR_VERSION
1369   _git=true
1370   _inst=$_openexr_inst
1371   _inst_shortcut=$INST/openexr
1372 }
1373
1374 clean_OPENEXR() {
1375   clean_ILMBASE
1376   _init_openexr
1377   _clean
1378 }
1379
1380 compile_OPENEXR() {
1381   if [ "$NO_BUILD" = true ]; then
1382     WARNING "--no-build enabled, OpenEXR will not be compiled!"
1383     return
1384   fi
1385
1386   # To be changed each time we make edits that would modify the compiled result!
1387   openexr_magic=14
1388
1389   # Clean install if needed!
1390   magic_compile_check openexr-$OPENEXR_VERSION $openexr_magic
1391   if [ $? -eq 1 -o "$OPENEXR_FORCE_REBUILD" = true ]; then
1392     clean_OPENEXR
1393   fi
1394
1395   _openexr_inst=$INST/openexr-$OPENEXR_VERSION
1396   compile_ILMBASE
1397   PRINT ""
1398   _ilmbase_inst=$_inst_shortcut
1399   _init_openexr
1400
1401   if [ ! -d $_inst ]; then
1402     INFO "Building OpenEXR-$OPENEXR_VERSION"
1403
1404     # Rebuild dependecies as well!
1405     OIIO_FORCE_BUILD=true
1406     OIIO_FORCE_REBUILD=true
1407
1408     prepare_opt
1409
1410     if [ ! -d $_src ]; then
1411       INFO "Downloading OpenEXR-$OPENEXR_VERSION"
1412       mkdir -p $SRC
1413
1414       if [ "$OPENEXR_USE_REPO" = true ]; then
1415         git clone ${OPENEXR_SOURCE_REPO[0]} $_src
1416       else
1417         download OPENEXR_SOURCE[@] $_src.tar.gz
1418         INFO "Unpacking OpenEXR-$OPENEXR_VERSION"
1419         tar -C $SRC --transform "s,(.*/?)openexr[^/]*(.*),\1OpenEXR-$OPENEXR_VERSION\2,x" -xf $_src.tar.gz
1420       fi
1421
1422     fi
1423
1424     cd $_src
1425
1426     if [ "$OPENEXR_USE_REPO" = true ]; then
1427       # XXX For now, always update from latest repo...
1428       git pull origin master
1429       # Stick to same rev as windows' libs...
1430       git checkout $OPENEXR_SOURCE_REPO_UID
1431       git reset --hard
1432       oiio_src_path="../OpenEXR"
1433     else
1434       oiio_src_path=".."
1435     fi
1436
1437     # Always refresh the whole build!
1438     if [ -d build ]; then
1439       rm -rf build
1440     fi
1441     mkdir build
1442     cd build
1443
1444     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1445     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1446     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1447     cmake_d="$cmake_d -D ILMBASE_PACKAGE_PREFIX=$_ilmbase_inst"
1448     cmake_d="$cmake_d -D BUILD_SHARED_LIBS=ON"
1449     cmake_d="$cmake_d -D NAMESPACE_VERSIONING=OFF"  # VERY IMPORTANT!!!
1450
1451     if file /bin/cp | grep -q '32-bit'; then
1452       cflags="-fPIC -m32 -march=i686"
1453     else
1454       cflags="-fPIC"
1455     fi
1456
1457     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" $oiio_src_path
1458
1459     make -j$THREADS && make install
1460
1461     make clean
1462
1463     if [ -d $_inst ]; then
1464       _create_inst_shortcut
1465       # Copy ilmbase files here (blender expects same dir for ilmbase and openexr :/).
1466       cp -an $_ilmbase_inst/* $_inst_shortcut
1467     else
1468       ERROR "OpenEXR-$OPENEXR_VERSION failed to compile, exiting"
1469       exit 1
1470     fi
1471
1472     magic_compile_set openexr-$OPENEXR_VERSION $openexr_magic
1473
1474     cd $CWD
1475     INFO "Done compiling OpenEXR-$OPENEXR_VERSION!"
1476   else
1477     INFO "Own OpenEXR-$OPENEXR_VERSION is up to date, nothing to do!"
1478     INFO "If you want to force rebuild of this lib, use the --force-openexr option."
1479   fi
1480
1481   _with_built_openexr=true
1482
1483   # Just always run it, much simpler this way!
1484   run_ldconfig "openexr"
1485 }
1486
1487 #### Build OIIO ####
1488 _init_oiio() {
1489   _src=$SRC/OpenImageIO-$OIIO_VERSION
1490   _git=true
1491   _inst=$INST/oiio-$OIIO_VERSION
1492   _inst_shortcut=$INST/oiio
1493 }
1494
1495 clean_OIIO() {
1496   _init_oiio
1497   _clean
1498 }
1499
1500 compile_OIIO() {
1501   if [ "$NO_BUILD" = true ]; then
1502     WARNING "--no-build enabled, OpenImageIO will not be compiled!"
1503     return
1504   fi
1505
1506   # To be changed each time we make edits that would modify the compiled result!
1507   oiio_magic=16
1508   _init_oiio
1509
1510   # Clean install if needed!
1511   magic_compile_check oiio-$OIIO_VERSION $oiio_magic
1512   if [ $? -eq 1 -o "$OIIO_FORCE_REBUILD" = true ]; then
1513     clean_OIIO
1514   fi
1515
1516   if [ ! -d $_inst ]; then
1517     INFO "Building OpenImageIO-$OIIO_VERSION"
1518
1519     # Rebuild dependecies as well!
1520     OSL_FORCE_BUILD=true
1521     OSL_FORCE_REBUILD=true
1522
1523     prepare_opt
1524
1525     if [ ! -d $_src ]; then
1526       mkdir -p $SRC
1527
1528       if [ "$OIIO_USE_REPO" = true ]; then
1529         git clone ${OIIO_SOURCE_REPO[0]} $_src
1530       else
1531         download OIIO_SOURCE[@] "$_src.tar.gz"
1532         INFO "Unpacking OpenImageIO-$OIIO_VERSION"
1533         tar -C $SRC --transform "s,(.*/?)oiio-Release-[^/]*(.*),\1OpenImageIO-$OIIO_VERSION\2,x" -xf $_src.tar.gz
1534       fi
1535     fi
1536
1537     cd $_src
1538
1539     if [ "$OIIO_USE_REPO" = true ]; then
1540       # XXX For now, always update from latest repo...
1541       git pull origin master
1542       # Stick to same rev as windows' libs...
1543       git checkout $OIIO_SOURCE_REPO_UID
1544       git reset --hard
1545     fi
1546
1547     # Always refresh the whole build!
1548     if [ -d build ]; then
1549       rm -rf build
1550     fi
1551     mkdir build
1552     cd build
1553
1554     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1555     cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
1556     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1557     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1558     cmake_d="$cmake_d -D BUILDSTATIC=OFF"
1559     cmake_d="$cmake_d -D LINKSTATIC=OFF"
1560     cmake_d="$cmake_d -D USE_SIMD=sse2"
1561
1562     cmake_d="$cmake_d -D ILMBASE_VERSION=$ILMBASE_VERSION"
1563     cmake_d="$cmake_d -D OPENEXR_VERSION=$OPENEXR_VERSION"
1564
1565     if [ "$_with_built_openexr" = true ]; then
1566       cmake_d="$cmake_d -D ILMBASE_HOME=$INST/openexr"
1567       cmake_d="$cmake_d -D OPENEXR_HOME=$INST/openexr"
1568       INFO "ILMBASE_HOME=$INST/openexr"
1569     fi
1570
1571     # Optional tests and cmd tools
1572     cmake_d="$cmake_d -D USE_QT=OFF"
1573     cmake_d="$cmake_d -D USE_PYTHON=OFF"
1574     cmake_d="$cmake_d -D USE_FFMPEG=OFF"
1575     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1576     cmake_d="$cmake_d -D OIIO_BUILD_TESTS=OFF"
1577     cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=OFF"
1578     #cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1579     #cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1580
1581     if [ -d $INST/boost ]; then
1582       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1583     fi
1584
1585     # Looks like we do not need ocio in oiio for now...
1586 #    if [ -d $INST/ocio ]; then
1587 #      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
1588 #    fi
1589     cmake_d="$cmake_d -D USE_OCIO=OFF"
1590
1591     if file /bin/cp | grep -q '32-bit'; then
1592       cflags="-fPIC -m32 -march=i686"
1593     else
1594       cflags="-fPIC"
1595     fi
1596
1597     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1598
1599     make -j$THREADS && make install
1600     make clean
1601
1602     if [ -d $_inst ]; then
1603       _create_inst_shortcut
1604     else
1605       ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
1606       exit 1
1607     fi
1608
1609     magic_compile_set oiio-$OIIO_VERSION $oiio_magic
1610
1611     cd $CWD
1612     INFO "Done compiling OpenImageIO-$OIIO_VERSION!"
1613   else
1614     INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
1615     INFO "If you want to force rebuild of this lib, use the --force-oiio option."
1616   fi
1617
1618   # Just always run it, much simpler this way!
1619   run_ldconfig "oiio"
1620 }
1621
1622 #### Build LLVM ####
1623 _init_llvm() {
1624   _src=$SRC/LLVM-$LLVM_VERSION
1625   _src_clang=$SRC/CLANG-$LLVM_VERSION
1626   _git=false
1627   _inst=$INST/llvm-$LLVM_VERSION
1628   _inst_shortcut=$INST/llvm
1629 }
1630
1631 clean_LLVM() {
1632   _init_llvm
1633   _clean
1634 }
1635
1636 compile_LLVM() {
1637   if [ "$NO_BUILD" = true ]; then
1638     WARNING "--no-build enabled, LLVM will not be compiled!"
1639     return
1640   fi
1641
1642   # To be changed each time we make edits that would modify the compiled result!
1643   llvm_magic=3
1644   _init_llvm
1645
1646   # Clean install if needed!
1647   magic_compile_check llvm-$LLVM_VERSION $llvm_magic
1648   if [ $? -eq 1 -o "$LLVM_FORCE_REBUILD" = true ]; then
1649     clean_LLVM
1650   fi
1651
1652   if [ ! -d $_inst ]; then
1653     INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
1654
1655     # Rebuild dependecies as well!
1656     OSL_FORCE_BUILD=true
1657     OSL_FORCE_REBUILD=true
1658
1659     prepare_opt
1660
1661     if [ ! -d $_src -o true ]; then
1662       mkdir -p $SRC
1663       download LLVM_SOURCE[@] "$_src.tar.gz"
1664       download LLVM_CLANG_SOURCE[@] "$_src_clang.tar.gz"
1665
1666       INFO "Unpacking LLVM-$LLVM_VERSION"
1667       tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
1668           -xf $_src.tar.gz
1669       INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
1670       # Stupid clang guys renamed 'clang' to 'cfe' for now handle both cases... :(
1671       tar -C $_src/tools \
1672           --transform "s,([^/]*/?)(clang|cfe)-[^/]*(.*),\1clang\3,x" \
1673           -xf $_src_clang.tar.gz
1674
1675       cd $_src
1676
1677       # XXX Ugly patching hack!
1678       patch -p1 -i "$SCRIPT_DIR/install_deps_patches/llvm.patch"
1679
1680       cd $CWD
1681
1682     fi
1683
1684     cd $_src
1685
1686     # Always refresh the whole build!
1687     if [ -d build ]; then
1688       rm -rf build
1689     fi
1690     mkdir build
1691     cd build
1692
1693     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1694     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1695     cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
1696     cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
1697     cmake_d="$cmake_d -D LLVM_ENABLE_TERMINFO=OFF"
1698
1699     if [ -d $_FFI_INCLUDE_DIR ]; then
1700       cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
1701     fi
1702
1703     cmake $cmake_d ..
1704
1705     make -j$THREADS && make install
1706     make clean
1707
1708     if [ -d $_inst ]; then
1709       _create_inst_shortcut
1710     else
1711       ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
1712       exit 1
1713     fi
1714
1715     magic_compile_set llvm-$LLVM_VERSION $llvm_magic
1716
1717     cd $CWD
1718     INFO "Done compiling LLVM-$LLVM_VERSION (CLANG included)!"
1719   else
1720     INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
1721     INFO "If you want to force rebuild of this lib, use the --force-llvm option."
1722   fi
1723 }
1724
1725 #### Build OSL ####
1726 _init_osl() {
1727   _src=$SRC/OpenShadingLanguage-$OSL_VERSION
1728   _git=true
1729   _inst=$INST/osl-$OSL_VERSION
1730   _inst_shortcut=$INST/osl
1731 }
1732
1733 clean_OSL() {
1734   _init_osl
1735   _clean
1736 }
1737
1738 compile_OSL() {
1739   if [ "$NO_BUILD" = true ]; then
1740     WARNING "--no-build enabled, OpenShadingLanguage will not be compiled!"
1741     return
1742   fi
1743
1744   # To be changed each time we make edits that would modify the compiled result!
1745   osl_magic=21
1746   _init_osl
1747
1748   # Clean install if needed!
1749   magic_compile_check osl-$OSL_VERSION $osl_magic
1750   if [ $? -eq 1 -o "$OSL_FORCE_REBUILD" = true ]; then
1751     #~ rm -Rf $_src  # XXX Radical, but not easy to change remote repo fully automatically
1752     clean_OSL
1753   fi
1754
1755   if [ ! -d $_inst ]; then
1756     INFO "Building OpenShadingLanguage-$OSL_VERSION"
1757
1758     prepare_opt
1759
1760     if [ ! -d $_src ]; then
1761       mkdir -p $SRC
1762
1763       if [ "$OSL_USE_REPO" = true ]; then
1764         git clone ${OSL_SOURCE_REPO[0]} $_src
1765       else
1766         download OSL_SOURCE[@] "$_src.tar.gz"
1767         INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
1768         tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
1769             -xf $_src.tar.gz
1770       fi
1771     fi
1772
1773     cd $_src
1774
1775     if [ "$OSL_USE_REPO" = true ]; then
1776       git remote set-url origin ${OSL_SOURCE_REPO[0]}
1777       # XXX For now, always update from latest repo...
1778       git pull --no-edit -X theirs origin $OSL_SOURCE_REPO_BRANCH
1779       # Stick to same rev as windows' libs...
1780       git checkout $OSL_SOURCE_REPO_UID
1781       git reset --hard
1782
1783       # XXX Ugly patching hack!
1784       patch -p1 -i "$SCRIPT_DIR/install_deps_patches/osl.patch"
1785     fi
1786
1787     # Always refresh the whole build!
1788     if [ -d build ]; then
1789       rm -rf build
1790     fi
1791     mkdir build
1792     cd build
1793
1794     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1795     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1796     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1797     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1798     cmake_d="$cmake_d -D BUILDSTATIC=OFF"
1799     cmake_d="$cmake_d -D OSL_BUILD_PLUGINS=OFF"
1800     cmake_d="$cmake_d -D OSL_BUILD_TESTS=OFF"
1801     cmake_d="$cmake_d -D USE_SIMD=sse2"
1802
1803     #~ cmake_d="$cmake_d -D ILMBASE_VERSION=$ILMBASE_VERSION"
1804
1805     if [ "$_with_built_openexr" = true ]; then
1806       INFO "ILMBASE_HOME=$INST/openexr"
1807       cmake_d="$cmake_d -D ILMBASE_HOME=$INST/openexr"
1808       # XXX Temp workaround... sigh, ILMBase really messed the things up by defining their custom names ON by default :(
1809       cmake_d="$cmake_d -D ILMBASE_CUSTOM=ON"
1810       cmake_d="$cmake_d -D ILMBASE_CUSTOM_LIBRARIES='Half;Iex;Imath;IlmThread'"
1811     fi
1812
1813     if [ -d $INST/boost ]; then
1814       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1815     fi
1816
1817     if [ -d $INST/oiio ]; then
1818       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
1819     fi
1820
1821     if [ ! -z $LLVM_VERSION_FOUND ]; then
1822       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1823       if [ -d $INST/llvm ]; then
1824         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
1825         cmake_d="$cmake_d -D LLVM_STATIC=ON"
1826       fi
1827     fi
1828
1829     #~ cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1830     #~ cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1831
1832     cmake $cmake_d ..
1833
1834     make -j$THREADS && make install
1835     make clean
1836
1837     if [ -d $_inst ]; then
1838       _create_inst_shortcut
1839     else
1840       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
1841       exit 1
1842     fi
1843
1844     magic_compile_set osl-$OSL_VERSION $osl_magic
1845
1846     cd $CWD
1847     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
1848   else
1849     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
1850     INFO "If you want to force rebuild of this lib, use the --force-osl option."
1851   fi
1852
1853   run_ldconfig "osl"
1854 }
1855
1856 #### Build OSD ####
1857 _init_osd() {
1858   _src=$SRC/OpenSubdiv-$OSD_VERSION
1859   _git=true
1860   _inst=$INST/osd-$OSD_VERSION
1861   _inst_shortcut=$INST/osd
1862 }
1863
1864 clean_OSD() {
1865   _init_osd
1866   _clean
1867 }
1868
1869 compile_OSD() {
1870   if [ "$NO_BUILD" = true ]; then
1871     WARNING "--no-build enabled, OpenSubdiv will not be compiled!"
1872     return
1873   fi
1874
1875   # To be changed each time we make edits that would modify the compiled result!
1876   osd_magic=1
1877   _init_osd
1878
1879   # Clean install if needed!
1880   magic_compile_check osd-$OSD_VERSION $osd_magic
1881   if [ $? -eq 1 -o "$OSD_FORCE_REBUILD" = true ]; then
1882     clean_OSD
1883   fi
1884
1885   if [ ! -d $_inst ]; then
1886     INFO "Building OpenSubdiv-$OSD_VERSION"
1887
1888     prepare_opt
1889
1890     if [ ! -d $_src ]; then
1891       mkdir -p $SRC
1892
1893       if [ "$OSD_USE_REPO" = true ]; then
1894         git clone ${OSD_SOURCE_REPO[0]} $_src
1895       else
1896         download OSD_SOURCE[@] "$_src.tar.gz"
1897         INFO "Unpacking OpenSubdiv-$OSD_VERSION"
1898         tar -C $SRC --transform "s,(.*/?)OpenSubdiv-[^/]*(.*),\1OpenSubdiv-$OSD_VERSION\2,x" \
1899             -xf $_src.tar.gz
1900       fi
1901     fi
1902
1903     cd $_src
1904
1905     if [ "$OSD_USE_REPO" = true ]; then
1906       git remote set-url origin ${OSD_SOURCE_REPO[0]}
1907       # XXX For now, always update from latest repo...
1908       git pull --no-edit -X theirs origin $OSD_SOURCE_REPO_BRANCH
1909       # Stick to same rev as windows' libs...
1910       git checkout $OSD_SOURCE_REPO_UID
1911       git reset --hard
1912     fi
1913
1914     # Always refresh the whole build!
1915     if [ -d build ]; then
1916       rm -rf build
1917     fi
1918     mkdir build
1919     cd build
1920
1921     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1922     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1923     # ptex is only needed when nicholas bishop is ready
1924     cmake_d="$cmake_d -D NO_PTEX=1"
1925     cmake_d="$cmake_d -D NO_CLEW=1 -D NO_CUDA=1 -D NO_OPENCL=1"
1926     # maya plugin, docs, tutorials, regression tests and examples are not needed
1927     cmake_d="$cmake_d -D NO_MAYA=1 -D NO_DOC=1 -D NO_TUTORIALS=1 -D NO_REGRESSION=1 -DNO_EXAMPLES=1"
1928
1929     cmake $cmake_d ..
1930
1931     make -j$THREADS && make install
1932     make clean
1933
1934     if [ -d $_inst ]; then
1935       _create_inst_shortcut
1936     else
1937       ERROR "OpenSubdiv-$OSD_VERSION failed to compile, exiting"
1938       exit 1
1939     fi
1940
1941     magic_compile_set osd-$OSD_VERSION $osd_magic
1942
1943     cd $CWD
1944     INFO "Done compiling OpenSubdiv-$OSD_VERSION!"
1945   else
1946     INFO "Own OpenSubdiv-$OSD_VERSION is up to date, nothing to do!"
1947     INFO "If you want to force rebuild of this lib, use the --force-osd option."
1948   fi
1949
1950   run_ldconfig "osd"
1951 }
1952
1953 #### Build Blosc ####
1954 _init_blosc() {
1955   _src=$SRC/c-blosc-$OPENVDB_BLOSC_VERSION
1956   _git=false
1957   _inst=$INST/blosc-$OPENVDB_BLOSC_VERSION
1958   _inst_shortcut=$INST/blosc
1959 }
1960
1961 clean_BLOSC() {
1962   _init_blosc
1963   _clean
1964 }
1965
1966 compile_BLOSC() {
1967   if [ "$NO_BUILD" = true ]; then
1968     WARNING "--no-build enabled, Blosc will not be compiled!"
1969     return
1970   fi
1971
1972   # To be changed each time we make edits that would modify the compiled result!
1973   blosc_magic=0
1974   _init_blosc
1975
1976   # Clean install if needed!
1977   magic_compile_check blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
1978   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
1979     clean_BLOSC
1980     rm -rf $_inst
1981   fi
1982
1983   if [ ! -d $_inst ]; then
1984     INFO "Building Blosc-$OPENVDB_BLOSC_VERSION"
1985
1986     # Rebuild dependecies as well!
1987     OPENVDB_FORCE_BUILD=true
1988     OPENVDB_FORCE_REBUILD=true
1989
1990     prepare_opt
1991
1992     if [ ! -d $_src ]; then
1993       INFO "Downloading Blosc-$OPENVDB_BLOSC_VERSION"
1994       mkdir -p $SRC
1995       download OPENVDB_BLOSC_SOURCE[@] $_src.tar.gz
1996
1997       INFO "Unpacking Blosc-$OPENVDB_BLOSC_VERSION"
1998       tar -C $SRC -xf $_src.tar.gz
1999     fi
2000
2001     cd $_src
2002     # Always refresh the whole build!
2003     if [ -d build ]; then
2004       rm -rf build
2005     fi
2006     mkdir build
2007     cd build
2008
2009     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2010     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2011     cmake_d="$cmake_d -D BUILD_STATIC=OFF"
2012     cmake_d="$cmake_d -D BUILD_TESTS=OFF"
2013     cmake_d="$cmake_d -D BUILD_BENCHMARKS=OFF"
2014     INFO "$cmake_d"
2015
2016     cmake $cmake_d ..
2017
2018     make -j$THREADS && make install
2019
2020     make clean
2021
2022     if [ -d $_inst ]; then
2023       _create_inst_shortcut
2024     else
2025       ERROR "Blosc-$OPENVDB_BLOSC_VERSION failed to compile, exiting"
2026       exit 1
2027     fi
2028     cd $CWD
2029     INFO "Done compiling Blosc-$OPENVDB_BLOSC_VERSION!"
2030   else
2031     INFO "Own Blosc-$OPENVDB_BLOSC_VERSION is up to date, nothing to do!"
2032     INFO "If you want to force rebuild of this lib (and openvdb), use the --force-openvdb option."
2033   fi
2034
2035   magic_compile_set blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
2036
2037   run_ldconfig "blosc"
2038 }
2039
2040 #### Build OpenVDB ####
2041 _init_openvdb() {
2042   _src=$SRC/openvdb-$OPENVDB_VERSION
2043   _git=false
2044   _inst=$INST/openvdb-$OPENVDB_VERSION
2045   _inst_shortcut=$INST/openvdb
2046 }
2047
2048 clean_OPENVDB() {
2049   _init_openvdb
2050   _clean
2051 }
2052
2053 compile_OPENVDB() {
2054   if [ "$NO_BUILD" = true ]; then
2055     WARNING "--no-build enabled, OpenVDB will not be compiled!"
2056     return
2057   fi
2058
2059   compile_BLOSC
2060   PRINT ""
2061
2062   # To be changed each time we make edits that would modify the compiled result!
2063   openvdb_magic=1
2064   _init_openvdb
2065
2066   # Clean install if needed!
2067   magic_compile_check openvdb-$OPENVDB_VERSION $openvdb_magic
2068   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
2069     clean_OPENVDB
2070   fi
2071
2072   if [ ! -d $_inst ]; then
2073     INFO "Building OpenVDB-$OPENVDB_VERSION"
2074
2075     prepare_opt
2076
2077     if [ ! -d $_src -o true ]; then
2078       mkdir -p $SRC
2079       download OPENVDB_SOURCE[@] "$_src.tar.gz"
2080
2081       INFO "Unpacking OpenVDB-$OPENVDB_VERSION"
2082       tar -C $SRC -xf $_src.tar.gz
2083     fi
2084
2085     cd $_src
2086
2087     #~ if [ "$OPENVDB_USE_REPO" = true ]; then
2088       #~ git remote set-url origin ${OPENVDB_SOURCE_REPO[0]}
2089       #~ # XXX For now, always update from latest repo...
2090       #~ git pull --no-edit -X theirs origin $OPENVDB_SOURCE_REPO_BRANCH
2091       #~ # Stick to same rev as windows' libs...
2092       #~ git checkout $OPENVDB_SOURCE_REPO_UID
2093       #~ git reset --hard
2094     #~ fi
2095
2096     # Source builds here
2097     cd openvdb
2098
2099     make_d="DESTDIR=$_inst"
2100     make_d="$make_d HDSO=/usr"
2101
2102     if [ -d $INST/boost ]; then
2103       make_d="$make_d BOOST_INCL_DIR=$INST/boost/include BOOST_LIB_DIR=$INST/boost/lib"
2104     fi
2105
2106     if [ "$_with_built_openexr" = true ]; then
2107       make_d="$make_d ILMBASE_INCL_DIR=$INST/openexr/include ILMBASE_LIB_DIR=$INST/openexr/lib"
2108       make_d="$make_d EXR_INCL_DIR=$INST/openexr/include EXR_LIB_DIR=$INST/openexr/lib"
2109       INFO "ILMBASE_HOME=$INST/openexr"
2110     fi
2111
2112     if [ -d $INST/blosc ]; then
2113       make_d="$make_d BLOSC_INCL_DIR=$INST/blosc/include BLOSC_LIB_DIR=$INST/blosc/lib"
2114     fi
2115
2116     # Build without log4cplus, glfw, python module & docs
2117     make_d="$make_d LOG4CPLUS_INCL_DIR= GLFW_INCL_DIR= PYTHON_VERSION= DOXYGEN="
2118
2119     make -j$THREADS lib $make_d install
2120     make clean
2121
2122     if [ -d $_inst ]; then
2123       _create_inst_shortcut
2124     else
2125       ERROR "OpenVDB-$OPENVDB_VERSION failed to compile, exiting"
2126       exit 1
2127     fi
2128
2129     magic_compile_set openvdb-$OPENVDB_VERSION $openvdb_magic
2130
2131     cd $CWD
2132     INFO "Done compiling OpenVDB-$OPENVDB_VERSION!"
2133   else
2134     INFO "Own OpenVDB-$OPENVDB_VERSION is up to date, nothing to do!"
2135     INFO "If you want to force rebuild of this lib, use the --force-openvdb option."
2136   fi
2137
2138   run_ldconfig "openvdb"
2139 }
2140
2141 #### Build OpenCOLLADA ####
2142 _init_opencollada() {
2143   _src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
2144   _git=true
2145   _inst=$INST/opencollada-$OPENCOLLADA_VERSION
2146   _inst_shortcut=$INST/opencollada
2147 }
2148
2149 clean_OpenCOLLADA() {
2150   _init_opencollada
2151   _clean
2152 }
2153
2154 compile_OpenCOLLADA() {
2155   if [ "$NO_BUILD" = true ]; then
2156     WARNING "--no-build enabled, OpenCOLLADA will not be compiled!"
2157     return
2158   fi
2159
2160   # To be changed each time we make edits that would modify the compiled results!
2161   opencollada_magic=9
2162   _init_opencollada
2163
2164   # Clean install if needed!
2165   magic_compile_check opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2166   if [ $? -eq 1 -o "$OPENCOLLADA_FORCE_REBUILD" = true ]; then
2167     clean_OpenCOLLADA
2168   fi
2169
2170   if [ ! -d $_inst ]; then
2171     INFO "Building OpenCOLLADA-$OPENCOLLADA_VERSION"
2172
2173     prepare_opt
2174
2175     if [ ! -d $_src ]; then
2176       mkdir -p $SRC
2177       git clone $OPENCOLLADA_SOURCE $_src
2178     fi
2179
2180     cd $_src
2181
2182     # XXX For now, always update from latest repo...
2183     git pull origin $OPENCOLLADA_REPO_BRANCH
2184
2185     # Stick to same rev as windows' libs...
2186     git checkout $OPENCOLLADA_REPO_UID
2187     git reset --hard
2188
2189     # Always refresh the whole build!
2190     if [ -d build ]; then
2191       rm -rf build
2192     fi
2193     mkdir build
2194     cd build
2195
2196     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2197     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2198     cmake_d="$cmake_d -D USE_EXPAT=OFF"
2199     cmake_d="$cmake_d -D USE_LIBXML=ON"
2200     # XXX Does not work!
2201 #    cmake_d="$cmake_d -D USE_STATIC=OFF"
2202     cmake_d="$cmake_d -D USE_STATIC=ON"
2203
2204     cmake $cmake_d ../
2205
2206     make -j$THREADS && make install
2207     make clean
2208
2209     if [ -d $_inst ]; then
2210       _create_inst_shortcut
2211     else
2212       ERROR "OpenCOLLADA-$OPENCOLLADA_VERSION failed to compile, exiting"
2213       exit 1
2214     fi
2215
2216     magic_compile_set opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2217
2218     cd $CWD
2219     INFO "Done compiling OpenCOLLADA-$OPENCOLLADA_VERSION!"
2220   else
2221     INFO "Own OpenCOLLADA-$OPENCOLLADA_VERSION is up to date, nothing to do!"
2222     INFO "If you want to force rebuild of this lib, use the --force-opencollada option."
2223   fi
2224 }
2225
2226 #### Build FFMPEG ####
2227 _init_ffmpeg() {
2228   _src=$SRC/ffmpeg-$FFMPEG_VERSION
2229   _inst=$INST/ffmpeg-$FFMPEG_VERSION
2230   _inst_shortcut=$INST/ffmpeg
2231 }
2232
2233 clean_FFmpeg() {
2234   _init_ffmpeg
2235   _clean
2236 }
2237
2238 compile_FFmpeg() {
2239   if [ "$NO_BUILD" = true ]; then
2240     WARNING "--no-build enabled, ffmpeg will not be compiled!"
2241     return
2242   fi
2243
2244   # To be changed each time we make edits that would modify the compiled result!
2245   ffmpeg_magic=5
2246   _init_ffmpeg
2247
2248   # Clean install if needed!
2249   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2250   if [ $? -eq 1 -o "$FFMPEG_FORCE_REBUILD" = true ]; then
2251     clean_FFmpeg
2252   fi
2253
2254   if [ ! -d $_inst ]; then
2255     INFO "Building ffmpeg-$FFMPEG_VERSION"
2256
2257     prepare_opt
2258
2259     if [ ! -d $_src ]; then
2260       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
2261       mkdir -p $SRC
2262       download FFMPEG_SOURCE[@] "$_src.tar.bz2"
2263
2264       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
2265       tar -C $SRC -xf $_src.tar.bz2
2266     fi
2267
2268     cd $_src
2269
2270     extra=""
2271
2272     if [ "$VORBIS_USE" = true ]; then
2273       extra="$extra --enable-libvorbis"
2274     fi
2275
2276     if [ "$THEORA_USE" = true ]; then
2277       extra="$extra --enable-libtheora"
2278     fi
2279
2280     if [ "$XVID_USE" = true ]; then
2281       extra="$extra --enable-libxvid"
2282     fi
2283
2284     if [ "$X264_USE" = true ]; then
2285       extra="$extra --enable-libx264"
2286     fi
2287
2288     if [ "$VPX_USE" = true ]; then
2289       extra="$extra --enable-libvpx"
2290     fi
2291
2292     if [ "$MP3LAME_USE" = true ]; then
2293       extra="$extra --enable-libmp3lame"
2294     fi
2295
2296     if [ "$OPENJPEG_USE" = true ]; then
2297       extra="$extra --enable-libopenjpeg"
2298     fi
2299
2300     ./configure --cc="gcc -Wl,--as-needed" \
2301         --extra-ldflags="-pthread -static-libgcc" \
2302         --prefix=$_inst --enable-static \
2303         --disable-ffplay --disable-ffserver --disable-doc \
2304         --enable-gray \
2305         --enable-avfilter --disable-vdpau \
2306         --disable-bzlib --disable-libgsm --disable-libspeex \
2307         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
2308         --disable-vaapi --disable-libfaac --disable-nonfree --enable-gpl \
2309         --disable-postproc --disable-librtmp --disable-libopencore-amrnb \
2310         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3 --disable-outdev=sdl \
2311         --disable-libxcb \
2312         --disable-outdev=xv --disable-indev=sndio --disable-outdev=sndio \
2313         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
2314         --disable-indev=lavfi $extra
2315
2316     make -j$THREADS && make install
2317     make clean
2318
2319     if [ -d $_inst ]; then
2320       _create_inst_shortcut
2321     else
2322       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
2323       exit 1
2324     fi
2325
2326     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2327
2328     cd $CWD
2329     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
2330   else
2331     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
2332     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
2333   fi
2334 }
2335
2336
2337 #### Install on DEB-like ####
2338 get_package_version_DEB() {
2339     dpkg-query -W -f '${Version}' $1 | sed -r 's/([0-9]+:)?(([0-9]+\.?)+([0-9]+)).*/\2/'
2340 }
2341
2342 check_package_DEB() {
2343   r=`apt-cache show $1 | grep -c 'Package:'`
2344
2345   if [ $r -ge 1 ]; then
2346     return 0
2347   else
2348     return 1
2349   fi
2350 }
2351
2352 check_package_installed_DEB() {
2353   r=`dpkg-query -W -f='${Status}' $1 | grep -c "install ok"`
2354
2355   if [ $r -ge 1 ]; then
2356     return 0
2357   else
2358     return 1
2359   fi
2360 }
2361
2362 check_package_version_match_DEB() {
2363   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
2364
2365   if [ -z "$v" ]; then
2366     return 1
2367   fi
2368
2369   version_match $v $2
2370   return $?
2371 }
2372
2373 check_package_version_ge_DEB() {
2374   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2375
2376   if [ -z "$v" ]; then
2377     return 1
2378   fi
2379
2380   version_ge $v $2
2381   return $?
2382 }
2383
2384 check_package_version_ge_lt_DEB() {
2385   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2386
2387   if [ -z "$v" ]; then
2388     return 1
2389   fi
2390
2391   version_ge_lt $v $2 $3
2392   return $?
2393 }
2394
2395 install_packages_DEB() {
2396   if [ ! $SUDO ]; then
2397     WARNING "--no-sudo enabled, impossible to run apt-get install for $@, you'll have to do it yourself..."
2398   else
2399     $SUDO apt-get install -y $@
2400     if [ $? -ge 1 ]; then
2401       ERROR "apt-get failed to install requested packages, exiting."
2402       exit 1
2403     fi
2404   fi
2405 }
2406
2407 install_DEB() {
2408   PRINT ""
2409   INFO "Installing dependencies for DEB-based distribution"
2410   PRINT ""
2411   PRINT "`eval _echo "$COMMON_INFO"`"
2412   PRINT ""
2413
2414   if [ "$NO_CONFIRM" = false ]; then
2415     read -p "Do you want to continue (Y/n)?"
2416     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
2417   fi
2418
2419   if [ ! $SUDO ]; then
2420     WARNING "--no-sudo enabled, impossible to run apt-get update, you'll have to do it yourself..."
2421   else
2422     $SUDO apt-get update
2423   fi
2424
2425   # These libs should always be available in debian/ubuntu official repository...
2426   OPENJPEG_DEV="libopenjpeg-dev"
2427   VORBIS_DEV="libvorbis-dev"
2428   OGG_DEV="libogg-dev"
2429   THEORA_DEV="libtheora-dev"
2430
2431   _packages="gawk cmake cmake-curses-gui build-essential libjpeg-dev libpng-dev libtiff-dev \
2432              git libfreetype6-dev libx11-dev flex bison libtbb-dev libxxf86vm-dev \
2433              libxcursor-dev libxi-dev wget libsqlite3-dev libxrandr-dev libxinerama-dev \
2434              libbz2-dev libncurses5-dev libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV \
2435              libopenal-dev libglew-dev libglewmx-dev yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV \
2436              libsdl1.2-dev libfftw3-dev patch bzip2 libxml2-dev libtinyxml-dev libjemalloc-dev"
2437
2438   OPENJPEG_USE=true
2439   VORBIS_USE=true
2440   OGG_USE=true
2441   THEORA_USE=true
2442
2443   PRINT ""
2444   # Some not-so-old distro (ubuntu 12.4) do not have it, do not fail in this case, just warn.
2445   YAMLCPP_DEV="libyaml-cpp-dev"
2446   check_package_DEB $YAMLCPP_DEV
2447   if [ $? -eq 0 ]; then
2448     _packages="$_packages $YAMLCPP_DEV"
2449   else
2450     PRINT ""
2451     WARNING "libyaml-cpp-dev not found, you may have to install it by hand to get Blender compiling..."
2452     PRINT ""
2453   fi
2454
2455   if [ "$WITH_ALL" = true ]; then
2456     _packages="$_packages libspnav-dev"
2457     # Only install jack if jack2 is not already installed!
2458     JACK="libjack-dev"
2459     JACK2="libjack-jackd2-dev"
2460     check_package_installed_DEB $JACK2
2461     if [ $? -eq 0 ]; then
2462       _packages="$_packages $JACK2"
2463     else
2464       _packages="$_packages $JACK"
2465     fi
2466   fi
2467
2468   PRINT ""
2469   install_packages_DEB $_packages
2470
2471   PRINT""
2472   SNDFILE_DEV="libsndfile1-dev"
2473   check_package_DEB $SNDFILE_DEV
2474   if [ $? -eq 0 ]; then
2475     install_packages_DEB $SNDFILE_DEV
2476   fi
2477
2478   PRINT ""
2479   X264_DEV="libx264-dev"
2480   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
2481   if [ $? -eq 0 ]; then
2482     install_packages_DEB $X264_DEV
2483     X264_USE=true
2484   fi
2485
2486   if [ "$WITH_ALL" = true ]; then
2487     PRINT ""
2488     XVID_DEV="libxvidcore-dev"
2489     check_package_DEB $XVID_DEV
2490     if [ $? -eq 0 ]; then
2491       install_packages_DEB $XVID_DEV
2492       XVID_USE=true
2493     fi
2494
2495     PRINT ""
2496     MP3LAME_DEV="libmp3lame-dev"
2497     check_package_DEB $MP3LAME_DEV
2498     if [ $? -eq 0 ]; then
2499       install_packages_DEB $MP3LAME_DEV
2500       MP3LAME_USE=true
2501     fi
2502
2503     PRINT ""
2504     VPX_DEV="libvpx-dev"
2505     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
2506     if [ $? -eq 0 ]; then
2507       install_packages_DEB $VPX_DEV
2508       VPX_USE=true
2509     fi
2510   fi
2511
2512   # Check cmake/glew versions and disable features for older distros.
2513   # This is so Blender can at least compile.
2514   PRINT ""
2515   _cmake=`get_package_version_DEB cmake`
2516   version_ge $_cmake "2.8.10"
2517   if [ $? -eq 1 ]; then
2518     version_ge $_cmake "2.8.8"
2519     if [ $? -eq 1 ]; then
2520       WARNING "OpenVDB and OpenCOLLADA disabled because cmake-$_cmake is not enough"
2521       OPENVDB_SKIP=true
2522       OPENCOLLADA_SKIP=true
2523     else
2524       WARNING "OpenVDB disabled because cmake-$_cmake is not enough"
2525       OPENVDB_SKIP=true
2526     fi
2527   fi
2528
2529   PRINT ""
2530   _glew=`get_package_version_DEB libglew-dev`
2531   if [ -z $_glew ]; then
2532     # Stupid virtual package in Ubuntu 12.04 doesn't show version number...
2533     _glew=`apt-cache showpkg libglew-dev|tail -n1|awk '{print $2}'|sed 's/-.*//'`
2534   fi
2535   version_ge $_glew "1.9.0"
2536   if [ $? -eq 1 ]; then
2537     version_ge $_glew "1.7.0"
2538     if [ $? -eq 1 ]; then
2539       WARNING "OpenSubdiv disabled because GLEW-$_glew is not enough"
2540       WARNING "Blender will not use system GLEW library"
2541       OSD_SKIP=true
2542       NO_SYSTEM_GLEW=true
2543     else
2544       WARNING "OpenSubdiv will compile with GLEW-$_glew but with limited capability"
2545       WARNING "Blender will not use system GLEW library"
2546       NO_SYSTEM_GLEW=true
2547     fi
2548   fi
2549
2550
2551   PRINT ""
2552   _do_compile_python=false
2553   if [ "$PYTHON_SKIP" = true ]; then
2554     WARNING "Skipping Python/NumPy installation, as requested..."
2555   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
2556     INFO "Forced Python/NumPy building, as requested..."
2557     _do_compile_python=true
2558   else
2559     check_package_DEB python$PYTHON_VERSION_MIN-dev
2560     if [ $? -eq 0 ]; then
2561       install_packages_DEB python$PYTHON_VERSION_MIN-dev
2562       clean_Python
2563       PRINT ""
2564       if [ "$NUMPY_SKIP" = true ]; then
2565         WARNING "Skipping NumPy installation, as requested..."
2566       else
2567         check_package_DEB python3-numpy
2568         if [ $? -eq 0 ]; then
2569           install_packages_DEB python3-numpy
2570         else
2571           WARNING "Sorry, using python package but no valid numpy package available!" \
2572                   "    Use --build-numpy to force building of both Python and NumPy."
2573         fi
2574       fi
2575     else
2576       _do_compile_python=true
2577     fi
2578   fi
2579
2580   if $_do_compile_python; then
2581     compile_Python
2582     PRINT ""
2583     if [ "$NUMPY_SKIP" = true ]; then
2584       WARNING "Skipping NumPy installation, as requested..."
2585     else
2586       compile_Numpy
2587     fi
2588   fi
2589
2590
2591   PRINT ""
2592   if [ "$BOOST_SKIP" = true ]; then
2593     WARNING "Skipping Boost installation, as requested..."
2594   elif [ "$BOOST_FORCE_BUILD" = true ]; then
2595     INFO "Forced Boost building, as requested..."
2596     compile_Boost
2597   else
2598     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
2599     if [ $? -eq 0 ]; then
2600       install_packages_DEB libboost-dev
2601
2602       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
2603
2604       install_packages_DEB libboost-{filesystem,iostreams,locale,regex,system,thread,wave}$boost_version-dev
2605       clean_Boost
2606     else
2607       compile_Boost
2608     fi
2609   fi
2610
2611
2612   PRINT ""
2613   if [ "$OCIO_SKIP" = true ]; then
2614     WARNING "Skipping OpenColorIO installation, as requested..."
2615   elif [ "$OCIO_FORCE_BUILD" = true ]; then
2616     INFO "Forced OpenColorIO building, as requested..."
2617     compile_OCIO
2618   else
2619     # XXX Always force build of own OCIO, until linux distro guys update their package to default libyaml-cpp ver (0.5)!
2620     #check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
2621     #if [ $? -eq 0 ]; then
2622       #install_packages_DEB libopencolorio-dev
2623       #clean_OCIO
2624     #else
2625       compile_OCIO
2626     #fi
2627   fi
2628
2629
2630   PRINT ""
2631   if [ "$OPENEXR_SKIP" = true ]; then
2632     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
2633   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
2634     INFO "Forced ILMBase/OpenEXR building, as requested..."
2635     compile_OPENEXR
2636   else
2637     check_package_version_ge_DEB libopenexr-dev $OPENEXR_VERSION_MIN
2638     if [ $? -eq 0 ]; then
2639       install_packages_DEB libopenexr-dev
2640       OPENEXR_VERSION=`get_package_version_DEB libopenexr-dev`
2641       ILMBASE_VERSION=$OPENEXR_VERSION
2642       clean_OPENEXR
2643     else
2644       compile_OPENEXR
2645     fi
2646   fi
2647
2648
2649   PRINT ""
2650   if [ "$OIIO_SKIP" = true ]; then
2651     WARNING "Skipping OpenImageIO installation, as requested..."
2652   elif [ "$OIIO_FORCE_BUILD" = true ]; then
2653     INFO "Forced OpenImageIO building, as requested..."
2654     compile_OIIO
2655   else
2656     # XXX Debian Testing / Ubuntu 16.04 pulls in WAY too many deps (gtk2/opencv ?!) incl. OCIO build against libyaml-cpp0.3 so build for now...
2657     #check_package_version_ge_lt_DEB libopenimageio-dev $OIIO_VERSION_MIN $OIIO_VERSION_MAX
2658     #if [ $? -eq 0 -a "$_with_built_openexr" = false ]; then
2659     #  install_packages_DEB libopenimageio-dev
2660     #  clean_OIIO
2661     #else
2662       compile_OIIO
2663     #fi
2664   fi
2665
2666
2667   PRINT ""
2668   have_llvm=false
2669   _do_compile_llvm=false
2670   if [ "$LLVM_SKIP" = true ]; then
2671     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
2672     OSL_SKIP=true
2673   elif [ "$LLVM_FORCE_BUILD" = true ]; then
2674     INFO "Forced LLVM building, as requested..."
2675     _do_compile_llvm=true
2676   else
2677     check_package_DEB clang-$LLVM_VERSION
2678     if [ $? -eq 0 ]; then
2679       install_packages_DEB llvm-$LLVM_VERSION-dev clang-$LLVM_VERSION
2680       have_llvm=true
2681       LLVM_VERSION_FOUND=$LLVM_VERSION
2682       clean_LLVM
2683     else
2684       _do_compile_llvm=true
2685     fi
2686   fi
2687
2688   if [ "$_do_compile_llvm" = true ]; then
2689     install_packages_DEB libffi-dev
2690     # LLVM can't find the debian ffi header dir
2691     _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
2692     PRINT ""
2693     compile_LLVM
2694     have_llvm=true
2695     LLVM_VERSION_FOUND=$LLVM_VERSION
2696   fi
2697
2698
2699   PRINT ""
2700   _do_compile_osl=false
2701   if [ "$OSL_SKIP" = true ]; then
2702     WARNING "Skipping OpenShadingLanguage installation, as requested..."
2703   elif [ "$OSL_FORCE_BUILD" = true ]; then
2704     INFO "Forced OpenShadingLanguage building, as requested..."
2705     _do_compile_osl=true
2706   else
2707     # No package currently!
2708     _do_compile_osl=true
2709   fi
2710
2711   if [ "$_do_compile_osl" = true ]; then
2712     if [ "$have_llvm" = true ]; then
2713       PRINT ""
2714       compile_OSL
2715     else
2716       WARNING "No LLVM available, cannot build OSL!"
2717     fi
2718   fi
2719
2720
2721   PRINT ""
2722   if [ "$OSD_SKIP" = true ]; then
2723     WARNING "Skipping OpenSubdiv installation, as requested..."
2724   elif [ "$OSD_FORCE_BUILD" = true ]; then
2725     INFO "Forced OpenSubdiv building, as requested..."
2726     compile_OSD
2727   else
2728     # No package currently!
2729     PRINT ""
2730     compile_OSD
2731   fi
2732
2733   PRINT ""
2734   if [ "$OPENVDB_SKIP" = true ]; then
2735     WARNING "Skipping OpenVDB installation, as requested..."
2736   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
2737     INFO "Forced OpenVDB building, as requested..."
2738     compile_OPENVDB
2739   else
2740     check_package_version_ge_DEB libopenvdb-dev $OPENVDB_VERSION_MIN
2741     if [ $? -eq 0 ]; then
2742       install_packages_DEB libopenvdb-dev libblosc-dev
2743       clean_OPENVDB
2744     else
2745       compile_OPENVDB
2746     fi
2747   fi
2748
2749
2750   if [ "$WITH_OPENCOLLADA" = true ]; then
2751     _do_compile_collada=false
2752     PRINT ""
2753     if [ "$OPENCOLLADA_SKIP" = true ]; then
2754       WARNING "Skipping OpenCOLLADA installation, as requested..."
2755     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
2756       INFO "Forced OpenCollada building, as requested..."
2757       _do_compile_collada=true
2758     else
2759       # No package currently!
2760       _do_compile_collada=true
2761     fi
2762
2763     if [ "$_do_compile_collada" = true ]; then
2764       install_packages_DEB libpcre3-dev
2765       # Find path to libxml shared lib...
2766       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
2767       # No package
2768       PRINT ""
2769       compile_OpenCOLLADA
2770     fi
2771   fi
2772
2773
2774   PRINT ""
2775   if [ "$FFMPEG_SKIP" = true ]; then
2776     WARNING "Skipping FFMpeg installation, as requested..."
2777   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
2778     INFO "Forced FFMpeg building, as requested..."
2779     compile_FFmpeg
2780   else
2781     # XXX Debian Testing / Ubuntu 16.04 finally includes FFmpeg, so check as usual
2782     check_package_DEB ffmpeg
2783     if [ $? -eq 0 ]; then
2784       check_package_version_ge_DEB ffmpeg $FFMPEG_VERSION_MIN
2785       if [ $? -eq 0 ]; then
2786         install_packages_DEB libavdevice-dev
2787         clean_FFmpeg
2788       else
2789         compile_FFmpeg
2790       fi
2791     else
2792       compile_FFmpeg
2793     fi
2794   fi
2795 }
2796
2797
2798 #### Install on RPM-like ####
2799 rpm_flavour() {
2800   if [ -f /etc/redhat-release ]; then
2801     if [ "`grep '[6-7]\.' /etc/redhat-release`" ]; then
2802       RPM="RHEL"
2803     else
2804       RPM="FEDORA"
2805     fi
2806   elif [ -f /etc/SuSE-release ]; then
2807     RPM="SUSE"
2808   fi
2809 }
2810
2811 get_package_version_RPM() {
2812   rpm_flavour
2813   if [ "$RPM" = "RHEL" ]; then
2814     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
2815   elif [ "$RPM" = "FEDORA" ]; then
2816     dnf info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
2817   elif [ "$RPM" = "SUSE" ]; then
2818     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
2819   fi
2820 }
2821
2822 check_package_RPM() {
2823   rpm_flavour
2824   if [ "$RPM" = "RHEL" ]; then
2825     r=`yum info $1 | grep -c 'Summary'`
2826   elif [ "$RPM" = "FEDORA" ]; then
2827     r=`dnf info $1 | grep -c 'Summary'`
2828   elif [ "$RPM" = "SUSE" ]; then
2829     r=`zypper info $1 | grep -c 'Summary'`
2830   fi
2831
2832   if [ $r -ge 1 ]; then
2833     return 0
2834   else
2835     return 1
2836   fi
2837 }
2838
2839 check_package_version_match_RPM() {
2840   v=`get_package_version_RPM $1`
2841
2842   if [ -z "$v" ]; then
2843     return 1
2844   fi
2845
2846   version_match $v $2
2847   return $?
2848 }
2849
2850 check_package_version_ge_RPM() {
2851   v=`get_package_version_RPM $1`
2852
2853   if [ -z "$v" ]; then
2854     return 1
2855   fi
2856
2857   version_ge $v $2
2858   return $?
2859 }
2860
2861 check_package_version_ge_lt_RPM() {
2862   v=`get_package_version_RPM $1`
2863
2864   if [ -z "$v" ]; then
2865     return 1
2866   fi
2867
2868   version_ge_lt $v $2 $3
2869   return $?
2870 }
2871
2872 install_packages_RPM() {
2873   rpm_flavour
2874   if [ ! $SUDO ]; then
2875     WARNING "--no-sudo enabled, impossible to install $@, you'll have to do it yourself..."
2876   fi
2877   if [ "$RPM" = "RHEL" ]; then
2878     $SUDO yum install -y $@
2879     if [ $? -ge 1 ]; then
2880       ERROR "yum failed to install requested packages, exiting."
2881       exit 1
2882     fi
2883
2884   elif [ "$RPM" = "FEDORA" ]; then
2885     $SUDO dnf install -y $@
2886     if [ $? -ge 1 ]; then
2887       ERROR "dnf failed to install requested packages, exiting."
2888       exit 1
2889     fi
2890
2891   elif [ "$RPM" = "SUSE" ]; then
2892     $SUDO zypper --non-interactive install --auto-agree-with-licenses $@
2893     if [ $? -ge 1 ]; then
2894       ERROR "zypper failed to install requested packages, exiting."
2895       exit 1
2896     fi
2897   fi
2898 }
2899
2900 install_RPM() {
2901   PRINT ""
2902   INFO "Installing dependencies for RPM-based distribution"
2903   PRINT ""
2904   PRINT "`eval _echo "$COMMON_INFO"`"
2905   PRINT ""
2906
2907   if [ "$NO_CONFIRM" = false ]; then
2908     read -p "Do you want to continue (Y/n)?"
2909     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
2910   fi
2911
2912   # Enable non-free repositories for all flavours
2913   if [ ! $SUDO ]; then
2914     WARNING "--no-sudo enabled, impossible to install third party repositories, you'll have to do it yourself..."
2915   else
2916     rpm_flavour
2917     if [ "$RPM" = "FEDORA" ]; then
2918       _fedora_rel="`egrep "[0-9]{1,}" /etc/fedora-release -o`"
2919       $SUDO dnf -y install --nogpgcheck \
2920       http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$_fedora_rel.noarch.rpm \
2921       http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$_fedora_rel.noarch.rpm
2922
2923       $SUDO dnf -y update
2924
2925     elif [ "$RPM" = "RHEL" ]; then
2926       if [ "`grep '6\.' /etc/redhat-release`" ]; then
2927         ERROR "Building with GCC 4.4 is not supported!"
2928         exit 1
2929       else
2930         $SUDO yum -y install --nogpgcheck \
2931         http://download.fedoraproject.org/pub/epel/7/$(uname -i)/e/epel-release-7-6.noarch.rpm \
2932         http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
2933
2934         $SUDO yum -y update
2935       fi
2936
2937     elif [ "$RPM" = "SUSE" ]; then
2938       # Packman repo now includes name in link...
2939       _suse_rel="`grep -w VERSION /etc/os-release | sed 's/[^0-9.]*//g'`"
2940       _suse_name="`grep -w NAME /etc/os-release | gawk '{print $2}' | sed 's/\"//'`"
2941       if [ $_suse_name ]; then
2942         _suse_rel="${_suse_name}_${_suse_rel}"
2943       fi
2944
2945       PRINT ""
2946       INFO "About to add 'packman' repository from http://packman.inode.at/suse/openSUSE_$_suse_rel/"
2947       INFO "This is only needed if you do not already have a packman repository enabled..."
2948       read -p "Do you want to add this repo (Y/n)?"
2949       if [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" == "y" ]; then
2950         INFO "    Installing packman..."
2951         $SUDO zypper ar -f -n packman http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_$_suse_rel/ packman
2952         INFO "    Done."
2953       else
2954         INFO "    Skipping packman installation."
2955       fi
2956       $SUDO zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
2957     fi
2958   fi
2959
2960   # These libs should always be available in fedora/suse official repository...
2961   OPENJPEG_DEV="openjpeg-devel"
2962   VORBIS_DEV="libvorbis-devel"
2963   OGG_DEV="libogg-devel"
2964   THEORA_DEV="libtheora-devel"
2965
2966   _packages="gcc gcc-c++ git make cmake tar bzip2 xz findutils flex bison \
2967              libtiff-devel libjpeg-devel libpng-devel sqlite-devel fftw-devel SDL-devel \
2968              libX11-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel \
2969              wget ncurses-devel readline-devel $OPENJPEG_DEV openal-soft-devel \
2970              glew-devel yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV patch \
2971              libxml2-devel yaml-cpp-devel tinyxml-devel jemalloc-devel"
2972
2973   OPENJPEG_USE=true
2974   VORBIS_USE=true
2975   OGG_USE=true
2976   THEORA_USE=true
2977
2978   if [ "$RPM" = "FEDORA" -o "$RPM" = "RHEL" ]; then
2979     _packages="$_packages freetype-devel tbb-devel"
2980
2981     if [ "$WITH_ALL" = true ]; then
2982       _packages="$_packages jack-audio-connection-kit-devel"
2983     fi
2984
2985     PRINT ""
2986     install_packages_RPM $_packages
2987
2988     PRINT ""
2989     X264_DEV="x264-devel"
2990     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
2991     if [ $? -eq 0 ]; then
2992       install_packages_RPM $X264_DEV
2993       X264_USE=true
2994     fi
2995
2996     if [ "$WITH_ALL" = true ]; then
2997       PRINT ""
2998       XVID_DEV="xvidcore-devel"
2999       check_package_RPM $XVID_DEV
3000       if [ $? -eq 0 ]; then
3001         install_packages_RPM $XVID_DEV
3002         XVID_USE=true
3003       fi
3004
3005       PRINT ""
3006       MP3LAME_DEV="lame-devel"
3007       check_package_RPM $MP3LAME_DEV
3008       if [ $? -eq 0 ]; then
3009         install_packages_RPM $MP3LAME_DEV
3010         MP3LAME_USE=true
3011       fi
3012     fi
3013
3014   elif [ "$RPM" = "SUSE" ]; then
3015     _packages="$_packages freetype2-devel"
3016
3017     PRINT ""
3018     install_packages_RPM $_packages
3019
3020     PRINT ""
3021     # Install TBB on openSUSE, from temporary repo
3022     check_package_RPM tbb-devel
3023     if [ $? -eq 0 ]; then
3024       install_packages_RPM tbb-devel
3025     else
3026       $SUDO zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$_suse_rel/devel:libraries:c_c++.repo
3027       $SUDO zypper -n --gpg-auto-import-keys install tbb-devel
3028       $SUDO zypper rr devel_libraries_c_c++
3029     fi
3030
3031     PRINT ""
3032     X264_DEV="libx264-devel"
3033     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
3034     if [ $? -eq 0 ]; then
3035       install_packages_RPM $X264_DEV
3036       X264_USE=true
3037     fi
3038
3039     if [ "$WITH_ALL" = true ]; then
3040       PRINT ""
3041       XVID_DEV="libxvidcore-devel"
3042       check_package_RPM $XVID_DEV
3043       if [ $? -eq 0 ]; then
3044         install_packages_RPM $XVID_DEV
3045         XVID_USE=true
3046       fi
3047
3048       PRINT ""
3049       MP3LAME_DEV="libmp3lame-devel"
3050       check_package_RPM $MP3LAME_DEV
3051       if [ $? -eq 0 ]; then
3052         install_packages_RPM $MP3LAME_DEV
3053         MP3LAME_USE=true
3054       fi
3055     fi
3056   fi
3057
3058   PRINT""
3059   SNDFILE_DEV="libsndfile-devel"
3060   check_package_RPM $SNDFILE_DEV
3061   if [ $? -eq 0 ]; then
3062     install_packages_RPM $SNDFILE_DEV
3063   fi
3064
3065   if [ "$WITH_ALL" = true ]; then
3066     PRINT ""
3067     VPX_DEV="libvpx-devel"
3068     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
3069     if [ $? -eq 0 ]; then
3070       install_packages_RPM $VPX_DEV
3071       VPX_USE=true
3072     fi
3073     PRINT ""
3074     install_packages_RPM libspnav-devel
3075   fi
3076
3077
3078   PRINT ""
3079   _do_compile_python=false
3080   if [ "$PYTHON_SKIP" = true ]; then
3081     WARNING "Skipping Python installation, as requested..."
3082   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3083     INFO "Forced Python/NumPy building, as requested..."
3084     _do_compile_python=true
3085   else
3086     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
3087     if [ $? -eq 0 ]; then
3088       install_packages_RPM python3-devel
3089       clean_Python
3090       PRINT ""
3091       if [ "$NUMPY_SKIP" = true ]; then
3092         WARNING "Skipping NumPy installation, as requested..."
3093       else
3094         check_package_version_ge_RPM python3-numpy $NUMPY_VERSION_MIN
3095         if [ $? -eq 0 ]; then
3096           install_packages_RPM python3-numpy
3097         else
3098           WARNING "Sorry, using python package but no valid numpy package available!" \
3099                   "    Use --build-numpy to force building of both Python and NumPy."
3100         fi
3101       fi
3102     else
3103       _do_compile_python=true
3104     fi
3105   fi
3106
3107   if [ "$_do_compile_python" = true ]; then
3108     compile_Python
3109     PRINT ""
3110     if [ "$NUMPY_SKIP" = true ]; then
3111       WARNING "Skipping NumPy installation, as requested..."
3112     else
3113       compile_Numpy
3114     fi
3115   fi
3116
3117
3118   PRINT ""
3119   _do_compile_boost=false
3120   if [ "$BOOST_SKIP" = true ]; then
3121     WARNING "Skipping Boost installation, as requested..."
3122   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3123     INFO "Forced Boost building, as requested..."
3124     _do_compile_boost=true
3125   else
3126     check_package_version_ge_RPM boost-devel $BOOST_VERSION_MIN
3127     if [ $? -eq 0 ]; then
3128       install_packages_RPM boost-devel
3129       clean_Boost
3130     else
3131       _do_compile_boost=true
3132     fi
3133   fi
3134
3135   if [ "$_do_compile_boost" = true ]; then
3136     if [ "$RPM" = "SUSE" ]; then
3137       install_packages_RPM gcc-fortran
3138     else
3139       install_packages_RPM libquadmath-devel bzip2-devel
3140     fi
3141     PRINT ""
3142     compile_Boost
3143   fi
3144
3145
3146   PRINT ""
3147   if [ "$OCIO_SKIP" = true ]; then
3148     WARNING "Skipping OpenColorIO installation, as requested..."
3149   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3150     INFO "Forced OpenColorIO building, as requested..."
3151     compile_OCIO
3152   else
3153     if [ "$RPM" = "SUSE" ]; then
3154       check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
3155       if [ $? -eq 0 ]; then
3156         install_packages_RPM OpenColorIO-devel
3157         clean_OCIO
3158       else
3159         compile_OCIO
3160       fi
3161     # XXX Fedora/RHEL OCIO still depends on libyaml-cpp v0.3 even when system default is v0.5!
3162     else
3163       compile_OCIO
3164     fi
3165   fi
3166
3167   PRINT ""
3168   if [ "$OPENEXR_SKIP" = true ]; then
3169     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
3170   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
3171     INFO "Forced ILMBase/OpenEXR building, as requested..."
3172     compile_OPENEXR
3173   else
3174     check_package_version_ge_RPM openexr-devel $OPENEXR_VERSION_MIN
3175     if [ $? -eq 0 ]; then
3176       install_packages_RPM openexr-devel
3177       OPENEXR_VERSION=`get_package_version_RPM openexr-devel`
3178       ILMBASE_VERSION=$OPENEXR_VERSION
3179       clean_OPENEXR
3180     else
3181       compile_OPENEXR
3182     fi
3183   fi
3184
3185   PRINT ""
3186   if [ "$OIIO_SKIP" = true ]; then
3187     WARNING "Skipping OpenImageIO installation, as requested..."
3188   elif [ "$OIIO_FORCE_BUILD" = true ]; then
3189     INFO "Forced OpenImageIO building, as requested..."
3190     compile_OIIO
3191   else
3192     # XXX RPM distros pulls in too much and depends on old libs, so better to build for now...
3193     #check_package_version_ge_lt_RPM OpenImageIO-devel $OIIO_VERSION_MIN $OIIO_VERSION_MAX
3194     #if [ $? -eq 0 -a $_with_built_openexr == false ]; then
3195     #  install_packages_RPM OpenImageIO-devel
3196     #  clean_OIIO
3197     #else
3198       compile_OIIO
3199     #fi
3200   fi
3201
3202
3203   PRINT ""
3204   have_llvm=false
3205   _do_compile_llvm=false
3206   if [ "$LLVM_SKIP" = true ]; then
3207     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
3208     OSL_SKIP=true
3209   elif [ "$LLVM_FORCE_BUILD" = true ]; then
3210     INFO "Forced LLVM building, as requested..."
3211     _do_compile_llvm=true
3212   else
3213     if [ "$RPM" = "SUSE" ]; then
3214       CLANG_DEV="llvm-clang-devel"
3215     else
3216       CLANG_DEV="clang-devel"
3217     fi
3218     # XXX RHEL has 3.4 in repo but OSL complains about not finding MCJIT_LIBRARY, so compile for now...
3219     #check_package_version_match_RPM $CLANG_DEV $LLVM_VERSION
3220     #if [ $? -eq 0 ]; then
3221     #  install_packages_RPM llvm-devel $CLANG_DEV
3222     #  have_llvm=true
3223     #  LLVM_VERSION_FOUND=$LLVM_VERSION
3224     #  clean_LLVM
3225     #else
3226       _do_compile_llvm=true
3227     #fi
3228   fi
3229
3230   if [ "$_do_compile_llvm" = true ]; then
3231     install_packages_RPM libffi-devel
3232     # LLVM can't find the fedora ffi header dir...
3233     _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
3234     PRINT ""
3235     compile_LLVM
3236     have_llvm=true
3237     LLVM_VERSION_FOUND=$LLVM_VERSION
3238   fi
3239
3240
3241   PRINT ""
3242   _do_compile_osl=false
3243   if [ "$OSL_SKIP" = true ]; then
3244     WARNING "Skipping OpenShadingLanguage installation, as requested..."
3245   elif [ "$OSL_FORCE_BUILD" = true ]; then
3246     INFO "Forced OpenShadingLanguage building, as requested..."
3247     _do_compile_osl=true
3248   else
3249     # No package currently!
3250     _do_compile_osl=true
3251   fi
3252
3253   if [ "$_do_compile_osl" = true ]; then
3254     if [ "$have_llvm" = true ]; then
3255       PRINT ""
3256       compile_OSL
3257     else
3258       WARNING "No LLVM available, cannot build OSL!"
3259     fi
3260   fi
3261
3262
3263   PRINT ""
3264   if [ "$OSD_SKIP" = true ]; then
3265     WARNING "Skipping OpenSubdiv installation, as requested..."
3266   elif [ "$OSD_FORCE_BUILD" = true ]; then
3267     INFO "Forced OpenSubdiv building, as requested..."
3268     compile_OSD
3269   else
3270     # No package currently!
3271     compile_OSD
3272   fi
3273
3274
3275   PRINT ""
3276   if [ "$OPENVDB_SKIP" = true ]; then
3277     WARNING "Skipping OpenVDB installation, as requested..."
3278   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
3279     INFO "Forced OpenVDB building, as requested..."
3280     compile_OPENVDB
3281   else
3282     # No package currently!
3283     compile_OPENVDB
3284   fi
3285
3286
3287   if [ "$WITH_OPENCOLLADA" = true ]; then
3288     PRINT ""
3289     _do_compile_collada=false
3290     if [ "$OPENCOLLADA_SKIP" = true ]; then
3291       WARNING "Skipping OpenCOLLADA installation, as requested..."
3292     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
3293       INFO "Forced OpenCollada building, as requested..."
3294       _do_compile_collada=true
3295     else
3296       # No package...
3297       _do_compile_collada=true
3298     fi
3299
3300     if [ "$_do_compile_collada" = true ]; then
3301       install_packages_RPM pcre-devel
3302       # Find path to libxml shared lib...
3303       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
3304       PRINT ""
3305       compile_OpenCOLLADA
3306     fi
3307   fi
3308
3309
3310   PRINT ""
3311   if [ "$FFMPEG_SKIP" = true ]; then
3312     WARNING "Skipping FFMpeg installation, as requested..."
3313   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
3314     INFO "Forced FFMpeg building, as requested..."
3315     compile_FFmpeg
3316   else
3317     check_package_version_ge_RPM ffmpeg-devel $FFMPEG_VERSION_MIN
3318     if [ $? -eq 0 ]; then
3319       install_packages_RPM ffmpeg ffmpeg-devel
3320       clean_FFmpeg
3321     else
3322       compile_FFmpeg
3323     fi
3324   fi
3325 }
3326
3327
3328 #### Install on ARCH-like ####
3329 get_package_version_ARCH() {
3330   pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+?(([0-9]+\.?)+).*/\1/'
3331 }
3332
3333 check_package_ARCH() {
3334   r=`pacman -Si $1 | grep -c 'Description'`
3335
3336   if [ $r -ge 1 ]; then
3337     return 0
3338   else
3339     return 1
3340   fi
3341 }
3342
3343 check_package_version_match_ARCH() {
3344   v=`get_package_version_ARCH $1`
3345
3346   if [ -z "$v" ]; then
3347     return 1
3348   fi
3349
3350   version_match $v $2
3351   return $?
3352 }
3353
3354 check_package_version_ge_ARCH() {
3355   v=`get_package_version_ARCH $1`
3356
3357   if [ -z "$v" ]; then
3358     return 1
3359   fi
3360
3361   version_ge $v $2
3362   return $?
3363 }
3364
3365 check_package_version_ge_lt_ARCH() {
3366   v=`get_package_version_ARCH $1`
3367
3368   if [ -z "$v" ]; then
3369     return 1
3370   fi
3371
3372   version_ge_lt $v $2 $3
3373   return $?
3374 }
3375
3376 install_packages_ARCH() {
3377   if [ ! $SUDO ]; then
3378     WARNING "--no-sudo enabled, impossible to run pacman for $@, you'll have to do it yourself..."
3379   else
3380     $SUDO pacman -S --needed --noconfirm $@
3381     if [ $? -ge 1 ]; then
3382       ERROR "pacman failed to install requested packages, exiting."
3383       exit 1
3384     fi
3385   fi
3386 }
3387
3388 install_ARCH() {
3389   PRINT ""
3390   INFO "Installing dependencies for ARCH-based distribution"
3391   PRINT ""
3392   PRINT "`eval _echo "$COMMON_INFO"`"
3393   PRINT ""
3394
3395   if [ "$NO_CONFIRM" = false ]; then
3396     read -p "Do you want to continue (Y/n)?"
3397     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
3398   fi
3399
3400   # Check for sudo...
3401   if [ $SUDO ]; then
3402     if [ ! -x "/usr/bin/sudo" ]; then
3403       PRINT ""
3404       ERROR "This script requires sudo but it is not installed."
3405       PRINT "Please setup sudo according to:"
3406       PRINT "https://wiki.archlinux.org/index.php/Sudo"
3407       PRINT "and try again."
3408       PRINT ""
3409       exit
3410     fi
3411   fi
3412
3413   if [ ! $SUDO ]; then
3414     WARNING "--no-sudo enabled, impossible to run pacman -Sy, you'll have to do it yourself..."
3415   else
3416     $SUDO pacman -Sy
3417   fi
3418
3419   # These libs should always be available in arch official repository...
3420   OPENJPEG_DEV="openjpeg"
3421   VORBIS_DEV="libvorbis"
3422   OGG_DEV="libogg"
3423   THEORA_DEV="libtheora"
3424
3425   BASE_DEVEL="base-devel"
3426
3427   # Avoid conflicts when gcc-multilib is installed
3428   pacman -Qi gcc-multilib &>/dev/null
3429   if [ $? -eq 0 ]; then
3430     BASE_DEVEL=`pacman -Sgq base-devel | sed -e 's/^gcc$/gcc-multilib/g' | paste -s -d' '`
3431   fi
3432
3433   _packages="$BASE_DEVEL git cmake \
3434              libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \
3435              $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw intel-tbb \
3436              libxml2 yaml-cpp tinyxml python-requests jemalloc"
3437
3438   OPENJPEG_USE=true
3439   VORBIS_USE=true
3440   OGG_USE=true
3441   THEORA_USE=true
3442
3443   if [ "$WITH_ALL" = true ]; then
3444     _packages="$_packages jack libspnav"
3445   fi
3446
3447   PRINT ""
3448   install_packages_ARCH $_packages
3449
3450   PRINT""
3451   SNDFILE_DEV="libsndfile"
3452   check_package_ARCH $SNDFILE_DEV
3453   if [ $? -eq 0 ]; then
3454     install_packages_ARCH $SNDFILE_DEV
3455   fi
3456
3457   PRINT ""
3458   X264_DEV="x264"
3459   check_package_version_ge_ARCH $X264_DEV $X264_VERSION_MIN
3460   if [ $? -eq 0 ]; then
3461     install_packages_ARCH $X264_DEV
3462     X264_USE=true
3463   fi
3464
3465   if [ "$WITH_ALL" = true ]; then
3466     PRINT ""
3467     XVID_DEV="xvidcore"
3468     check_package_ARCH $XVID_DEV
3469     if [ $? -eq 0 ]; then
3470       install_packages_ARCH $XVID_DEV
3471       XVID_USE=true
3472     fi
3473
3474     PRINT ""
3475     MP3LAME_DEV="lame"
3476     check_package_ARCH $MP3LAME_DEV
3477     if [ $? -eq 0 ]; then
3478       install_packages_ARCH $MP3LAME_DEV
3479       MP3LAME_USE=true
3480     fi
3481
3482     PRINT ""
3483     VPX_DEV="libvpx"
3484     check_package_version_ge_ARCH $VPX_DEV $VPX_VERSION_MIN
3485     if [ $? -eq 0 ]; then
3486       install_packages_ARCH $VPX_DEV
3487       VPX_USE=true
3488     fi
3489   fi
3490
3491
3492   PRINT ""
3493   _do_compile_python=false
3494   if [ "$PYTHON_SKIP" = true ]; then
3495     WARNING "Skipping Python installation, as requested..."
3496   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3497     INFO "Forced Python/NumPy building, as requested..."
3498     _do_compile_python=true
3499   else
3500     check_package_version_ge_ARCH python $PYTHON_VERSION_MIN
3501     if [ $? -eq 0 ]; then
3502       install_packages_ARCH python
3503       clean_Python
3504       PRINT ""
3505       if [ "$NUMPY_SKIP" = true ]; then
3506         WARNING "Skipping NumPy installation, as requested..."
3507       else
3508         check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
3509         if [ $? -eq 0 ]; then
3510           install_packages_ARCH python-numpy
3511         else
3512           WARNING "Sorry, using python package but no valid numpy package available!" \
3513                   "Use --build-numpy to force building of both Python and NumPy."
3514         fi
3515       fi
3516     else
3517       _do_compile_python=true
3518     fi
3519   fi
3520
3521   if [ "$_do_compile_python" = true ]; then
3522     compile_Python
3523     PRINT ""
3524     if [ "$NUMPY_SKIP" = true ]; then
3525       WARNING "Skipping NumPy installation, as requested..."
3526     else
3527       compile_Numpy
3528     fi
3529   fi
3530
3531
3532   PRINT ""
3533   if [ "$BOOST_SKIP" = true ]; then
3534     WARNING "Skipping Boost installation, as requested..."
3535   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3536     INFO "Forced Boost building, as requested..."
3537     compile_Boost
3538   else
3539     check_package_version_ge_ARCH boost $BOOST_VERSION_MIN
3540     if [ $? -eq 0 ]; then
3541       install_packages_ARCH boost
3542       clean_Boost
3543     else
3544       compile_Boost
3545     fi
3546   fi
3547
3548
3549   PRINT ""
3550   if [ "$OCIO_SKIP" = true ]; then
3551     WARNING "Skipping OpenColorIO installation, as requested..."
3552   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3553     INFO "Forced OpenColorIO building, as requested..."
3554     compile_OCIO
3555   else
3556     check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
3557     if [ $? -eq 0 ]; then
3558       install_packages_ARCH opencolorio
3559       clean_OCIO
3560     else
3561       compile_OCIO
3562     fi
3563   fi
3564
3565
3566   PRINT ""
3567   if [ "$OPENEXR_SKIP" = true ]; then
3568     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
3569   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
3570     INFO "Forced ILMBase/OpenEXR building, as requested..."
3571     compile_OPENEXR
3572   else
3573     check_package_version_ge_ARCH openexr $OPENEXR_VERSION_MIN
3574     if [ $? -eq 0 ]; then
3575       install_packages_ARCH openexr
3576       OPENEXR_VERSION=`get_package_version_ARCH openexr`
3577       ILMBASE_VERSION=$OPENEXR_VERSION
3578       clean_OPENEXR
3579     else
3580       compile_OPENEXR
3581     fi
3582   fi
3583
3584
3585   PRINT ""
3586   if [ "$OIIO_SKIP" = true ]; then
3587     WARNING "Skipping OpenImageIO installation, as requested..."
3588   elif [ "$OIIO_FORCE_BUILD" = true ]; then
3589     INFO "Forced OpenImageIO building, as requested..."
3590     compile_OIIO
3591   else
3592     check_package_version_ge_lt_ARCH openimageio $OIIO_VERSION_MIN $OIIO_VERSION_MAX
3593     if [ $? -eq 0 ]; then
3594       install_packages_ARCH openimageio
3595       clean_OIIO
3596     else
3597       compile_OIIO
3598     fi
3599   fi
3600
3601
3602   PRINT ""
3603   have_llvm=false
3604   _do_compile_llvm=false
3605   if [ "$LLVM_SKIP" = true ]; then
3606     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
3607     OSL_SKIP=true
3608   elif [ "$LLVM_FORCE_BUILD" = true ]; then
3609     INFO "Forced LLVM building, as requested..."
3610     _do_compile_llvm=true
3611   else
3612     check_package_version_match_ARCH llvm35 $LLVM_VERSION_MIN
3613     if [ $? -eq 0 ]; then
3614       install_packages_ARCH llvm35 clang35
3615       have_llvm=true
3616       LLVM_VERSION=`get_package_version_ARCH llvm35`
3617       LLVM_VERSION_FOUND=$LLVM_VERSION
3618       clean_LLVM
3619     else
3620       _do_compile_llvm=true
3621     fi
3622   fi
3623
3624   if [ "$_do_compile_llvm" = true ]; then
3625     install_packages_ARCH libffi
3626     # LLVM can't find the arch ffi header dir...
3627     _FFI_INCLUDE_DIR=`pacman -Ql libffi | grep -e ".*/ffi.h" | awk '{print $2}' | sed -r 's/(.*)\/ffi.h/\1/'`
3628     PRINT ""
3629     compile_LLVM
3630     have_llvm=true
3631     LLVM_VERSION_FOUND=$LLVM_VERSION
3632   fi
3633
3634
3635   PRINT ""
3636   _do_compile_osl=false
3637   if [ "$OSL_SKIP" = true ]; then
3638     WARNING "Skipping OpenShadingLanguage installation, as requested..."
3639   elif [ "$OSL_FORCE_BUILD" = true ]; then
3640     INFO "Forced OpenShadingLanguage building, as requested..."
3641     _do_compile_osl=true
3642   else
3643     # XXX Compile for now due to requirement of LLVM 3.4 ...
3644     #check_package_version_ge_ARCH openshadinglanguage $OSL_VERSION_MIN
3645     #if [ $? -eq 0 ]; then
3646     #  install_packages_ARCH openshadinglanguage
3647     #  clean_OSL
3648     #else
3649       _do_compile_osl=true
3650     #fi
3651   fi
3652
3653   if [ "$_do_compile_osl" = true ]; then
3654     if [ "$have_llvm" = true ]; then
3655       PRINT ""
3656       compile_OSL
3657     else
3658       WARNING "No LLVM available, cannot build OSL!"
3659     fi
3660   fi
3661
3662
3663   PRINT ""
3664   if [ "$OSD_SKIP" = true ]; then
3665     WARNING "Skipping OpenSubdiv installation, as requested..."
3666   elif [ "$OSD_FORCE_BUILD" = true ]; then
3667     INFO "Forced OpenSubdiv building, as requested..."
3668     compile_OSD
3669   else
3670     check_package_version_ge_ARCH opensubdiv $OSD_VERSION_MIN
3671     if [ $? -eq 0 ]; then
3672       install_packages_ARCH opensubdiv
3673       clean_OSD
3674     else
3675       compile_OSD
3676     fi
3677   fi
3678
3679
3680   PRINT ""
3681   if [ "$OPENVDB_SKIP" = true ]; then
3682     WARNING "Skipping OpenVDB installation, as requested..."
3683   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
3684     INFO "Forced OpenVDB building, as requested..."