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