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=17
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     # ptex is only needed when nicholas bishop is ready
1659     cmake_d="$cmake_d -D USE_PTEX=OFF"
1660
1661     # Optional tests and cmd tools
1662     cmake_d="$cmake_d -D USE_QT=OFF"
1663     cmake_d="$cmake_d -D USE_PYTHON=OFF"
1664     cmake_d="$cmake_d -D USE_FFMPEG=OFF"
1665     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1666     cmake_d="$cmake_d -D OIIO_BUILD_TESTS=OFF"
1667     cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=OFF"
1668     #cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1669     #cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1670
1671     if [ -d $INST/boost ]; then
1672       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1673     fi
1674
1675     # Looks like we do not need ocio in oiio for now...
1676 #    if [ -d $INST/ocio ]; then
1677 #      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
1678 #    fi
1679     cmake_d="$cmake_d -D USE_OCIO=OFF"
1680
1681     if [ "$USE_CXX11" = true ]; then
1682       cmake_d="$cmake_d -D OIIO_BUILD_CPP11=ON"
1683     fi
1684
1685     if file /bin/cp | grep -q '32-bit'; then
1686       cflags="-fPIC -m32 -march=i686"
1687     else
1688       cflags="-fPIC"
1689     fi
1690
1691     cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ..
1692
1693     make -j$THREADS && make install
1694     make clean
1695
1696     if [ -d $_inst ]; then
1697       _create_inst_shortcut
1698     else
1699       ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
1700       exit 1
1701     fi
1702
1703     magic_compile_set oiio-$OIIO_VERSION $oiio_magic
1704
1705     cd $CWD
1706     INFO "Done compiling OpenImageIO-$OIIO_VERSION!"
1707   else
1708     INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
1709     INFO "If you want to force rebuild of this lib, use the --force-oiio option."
1710   fi
1711
1712   # Just always run it, much simpler this way!
1713   run_ldconfig "oiio"
1714 }
1715
1716 #### Build LLVM ####
1717 _init_llvm() {
1718   _src=$SRC/LLVM-$LLVM_VERSION
1719   _src_clang=$SRC/CLANG-$LLVM_VERSION
1720   _git=false
1721   _inst=$INST/llvm-$LLVM_VERSION
1722   _inst_shortcut=$INST/llvm
1723 }
1724
1725 clean_LLVM() {
1726   _init_llvm
1727   _clean
1728 }
1729
1730 compile_LLVM() {
1731   if [ "$NO_BUILD" = true ]; then
1732     WARNING "--no-build enabled, LLVM will not be compiled!"
1733     return
1734   fi
1735
1736   # To be changed each time we make edits that would modify the compiled result!
1737   llvm_magic=3
1738   _init_llvm
1739
1740   # Clean install if needed!
1741   magic_compile_check llvm-$LLVM_VERSION $llvm_magic
1742   if [ $? -eq 1 -o "$LLVM_FORCE_REBUILD" = true ]; then
1743     clean_LLVM
1744   fi
1745
1746   if [ ! -d $_inst ]; then
1747     INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"
1748
1749     # Rebuild dependecies as well!
1750     OSL_FORCE_BUILD=true
1751     OSL_FORCE_REBUILD=true
1752
1753     prepare_opt
1754
1755     if [ ! -d $_src -o true ]; then
1756       mkdir -p $SRC
1757       download LLVM_SOURCE[@] "$_src.tar.gz"
1758       download LLVM_CLANG_SOURCE[@] "$_src_clang.tar.gz"
1759
1760       INFO "Unpacking LLVM-$LLVM_VERSION"
1761       tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
1762           -xf $_src.tar.gz
1763       INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
1764       # Stupid clang guys renamed 'clang' to 'cfe' for now handle both cases... :(
1765       tar -C $_src/tools \
1766           --transform "s,([^/]*/?)(clang|cfe)-[^/]*(.*),\1clang\3,x" \
1767           -xf $_src_clang.tar.gz
1768
1769       cd $_src
1770
1771       # XXX Ugly patching hack!
1772       patch -p1 -i "$SCRIPT_DIR/patches/install_deps_llvm.patch"
1773
1774       cd $CWD
1775
1776     fi
1777
1778     cd $_src
1779
1780     # Always refresh the whole build!
1781     if [ -d build ]; then
1782       rm -rf build
1783     fi
1784     mkdir build
1785     cd build
1786
1787     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1788     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1789     cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"
1790     cmake_d="$cmake_d -D LLVM_TARGETS_TO_BUILD=X86"
1791     cmake_d="$cmake_d -D LLVM_ENABLE_TERMINFO=OFF"
1792
1793     if [ -d $_FFI_INCLUDE_DIR ]; then
1794       cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
1795     fi
1796
1797     cmake $cmake_d ..
1798
1799     make -j$THREADS && make install
1800     make clean
1801
1802     if [ -d $_inst ]; then
1803       _create_inst_shortcut
1804     else
1805       ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
1806       exit 1
1807     fi
1808
1809     magic_compile_set llvm-$LLVM_VERSION $llvm_magic
1810
1811     cd $CWD
1812     INFO "Done compiling LLVM-$LLVM_VERSION (CLANG included)!"
1813   else
1814     INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
1815     INFO "If you want to force rebuild of this lib, use the --force-llvm option."
1816   fi
1817 }
1818
1819 #### Build OSL ####
1820 _init_osl() {
1821   _src=$SRC/OpenShadingLanguage-$OSL_VERSION
1822   _git=true
1823   _inst=$INST/osl-$OSL_VERSION
1824   _inst_shortcut=$INST/osl
1825 }
1826
1827 clean_OSL() {
1828   _init_osl
1829   _clean
1830 }
1831
1832 compile_OSL() {
1833   if [ "$NO_BUILD" = true ]; then
1834     WARNING "--no-build enabled, OpenShadingLanguage will not be compiled!"
1835     return
1836   fi
1837
1838   # To be changed each time we make edits that would modify the compiled result!
1839   osl_magic=21
1840   _init_osl
1841
1842   # Clean install if needed!
1843   magic_compile_check osl-$OSL_VERSION $osl_magic
1844   if [ $? -eq 1 -o "$OSL_FORCE_REBUILD" = true ]; then
1845     #~ rm -Rf $_src  # XXX Radical, but not easy to change remote repo fully automatically
1846     clean_OSL
1847   fi
1848
1849   if [ ! -d $_inst ]; then
1850     INFO "Building OpenShadingLanguage-$OSL_VERSION"
1851
1852     prepare_opt
1853
1854     if [ ! -d $_src ]; then
1855       mkdir -p $SRC
1856
1857       if [ "$OSL_USE_REPO" = true ]; then
1858         git clone ${OSL_SOURCE_REPO[0]} $_src
1859       else
1860         download OSL_SOURCE[@] "$_src.tar.gz"
1861         INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
1862         tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
1863             -xf $_src.tar.gz
1864       fi
1865     fi
1866
1867     cd $_src
1868
1869     if [ "$OSL_USE_REPO" = true ]; then
1870       git remote set-url origin ${OSL_SOURCE_REPO[0]}
1871       # XXX For now, always update from latest repo...
1872       git pull --no-edit -X theirs origin $OSL_SOURCE_REPO_BRANCH
1873       # Stick to same rev as windows' libs...
1874       git checkout $OSL_SOURCE_REPO_UID
1875       git reset --hard
1876
1877       # XXX Ugly patching hack!
1878       patch -p1 -i "$SCRIPT_DIR/patches/install_deps_osl.patch"
1879     fi
1880
1881     # Always refresh the whole build!
1882     if [ -d build ]; then
1883       rm -rf build
1884     fi
1885     mkdir build
1886     cd build
1887
1888     cmake_d="-D CMAKE_BUILD_TYPE=Release"
1889     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
1890     cmake_d="$cmake_d -D BUILD_TESTING=OFF"
1891     cmake_d="$cmake_d -D STOP_ON_WARNING=OFF"
1892     cmake_d="$cmake_d -D BUILDSTATIC=OFF"
1893     cmake_d="$cmake_d -D OSL_BUILD_PLUGINS=OFF"
1894     cmake_d="$cmake_d -D OSL_BUILD_TESTS=OFF"
1895     cmake_d="$cmake_d -D USE_SIMD=sse2"
1896     if [ "$USE_CXX11" = true ]; then
1897         cmake_d="$cmake_d -D OSL_BUILD_CPP11=1"
1898     fi
1899
1900     #~ cmake_d="$cmake_d -D ILMBASE_VERSION=$ILMBASE_VERSION"
1901
1902     if [ "$_with_built_openexr" = true ]; then
1903       INFO "ILMBASE_HOME=$INST/openexr"
1904       cmake_d="$cmake_d -D ILMBASE_HOME=$INST/openexr"
1905       # XXX Temp workaround... sigh, ILMBase really messed the things up by defining their custom names ON by default :(
1906       cmake_d="$cmake_d -D ILMBASE_CUSTOM=ON"
1907       cmake_d="$cmake_d -D ILMBASE_CUSTOM_LIBRARIES='Half;Iex;Imath;IlmThread'"
1908     fi
1909
1910     if [ -d $INST/boost ]; then
1911       cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
1912     fi
1913
1914     if [ -d $INST/oiio ]; then
1915       cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
1916     fi
1917
1918     if [ ! -z $LLVM_VERSION_FOUND ]; then
1919       cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
1920       if [ -d $INST/llvm ]; then
1921         cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
1922         cmake_d="$cmake_d -D LLVM_STATIC=ON"
1923       fi
1924     fi
1925
1926     #~ cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
1927     #~ cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
1928
1929     cmake $cmake_d ..
1930
1931     make -j$THREADS && make install
1932     make clean
1933
1934     if [ -d $_inst ]; then
1935       _create_inst_shortcut
1936     else
1937       ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
1938       exit 1
1939     fi
1940
1941     magic_compile_set osl-$OSL_VERSION $osl_magic
1942
1943     cd $CWD
1944     INFO "Done compiling OpenShadingLanguage-$OSL_VERSION!"
1945   else
1946     INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
1947     INFO "If you want to force rebuild of this lib, use the --force-osl option."
1948   fi
1949
1950   run_ldconfig "osl"
1951 }
1952
1953 #### Build OSD ####
1954 _init_osd() {
1955   _src=$SRC/OpenSubdiv-$OSD_VERSION
1956   _git=true
1957   _inst=$INST/osd-$OSD_VERSION
1958   _inst_shortcut=$INST/osd
1959 }
1960
1961 clean_OSD() {
1962   _init_osd
1963   _clean
1964 }
1965
1966 compile_OSD() {
1967   if [ "$NO_BUILD" = true ]; then
1968     WARNING "--no-build enabled, OpenSubdiv will not be compiled!"
1969     return
1970   fi
1971
1972   # To be changed each time we make edits that would modify the compiled result!
1973   osd_magic=2
1974   _init_osd
1975
1976   # Clean install if needed!
1977   magic_compile_check osd-$OSD_VERSION $osd_magic
1978   if [ $? -eq 1 -o "$OSD_FORCE_REBUILD" = true ]; then
1979     clean_OSD
1980   fi
1981
1982   if [ ! -d $_inst ]; then
1983     INFO "Building OpenSubdiv-$OSD_VERSION"
1984
1985     prepare_opt
1986
1987     if [ ! -d $_src ]; then
1988       mkdir -p $SRC
1989
1990       if [ "$OSD_USE_REPO" = true ]; then
1991         git clone ${OSD_SOURCE_REPO[0]} $_src
1992       else
1993         download OSD_SOURCE[@] "$_src.tar.gz"
1994         INFO "Unpacking OpenSubdiv-$OSD_VERSION"
1995         tar -C $SRC --transform "s,(.*/?)OpenSubdiv-[^/]*(.*),\1OpenSubdiv-$OSD_VERSION\2,x" \
1996             -xf $_src.tar.gz
1997       fi
1998     fi
1999
2000     cd $_src
2001
2002     if [ "$OSD_USE_REPO" = true ]; then
2003       git remote set-url origin ${OSD_SOURCE_REPO[0]}
2004       # XXX For now, always update from latest repo...
2005       git pull --no-edit -X theirs origin $OSD_SOURCE_REPO_BRANCH
2006       # Stick to same rev as windows' libs...
2007       git checkout $OSD_SOURCE_REPO_UID
2008       git reset --hard
2009     fi
2010
2011     # Always refresh the whole build!
2012     if [ -d build ]; then
2013       rm -rf build
2014     fi
2015     mkdir build
2016     cd build
2017
2018     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2019     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2020     # ptex is only needed when nicholas bishop is ready
2021     cmake_d="$cmake_d -D NO_PTEX=1"
2022     cmake_d="$cmake_d -D NO_CLEW=1 -D NO_CUDA=1 -D NO_OPENCL=1"
2023     # maya plugin, docs, tutorials, regression tests and examples are not needed
2024     cmake_d="$cmake_d -D NO_MAYA=1 -D NO_DOC=1 -D NO_TUTORIALS=1 -D NO_REGRESSION=1 -DNO_EXAMPLES=1"
2025
2026     cmake $cmake_d ..
2027
2028     make -j$THREADS && make install
2029     make clean
2030
2031     if [ -d $_inst ]; then
2032       _create_inst_shortcut
2033     else
2034       ERROR "OpenSubdiv-$OSD_VERSION failed to compile, exiting"
2035       exit 1
2036     fi
2037
2038     magic_compile_set osd-$OSD_VERSION $osd_magic
2039
2040     cd $CWD
2041     INFO "Done compiling OpenSubdiv-$OSD_VERSION!"
2042   else
2043     INFO "Own OpenSubdiv-$OSD_VERSION is up to date, nothing to do!"
2044     INFO "If you want to force rebuild of this lib, use the --force-osd option."
2045   fi
2046
2047   run_ldconfig "osd"
2048 }
2049
2050 #### Build Blosc ####
2051 _init_blosc() {
2052   _src=$SRC/c-blosc-$OPENVDB_BLOSC_VERSION
2053   _git=false
2054   _inst=$INST/blosc-$OPENVDB_BLOSC_VERSION
2055   _inst_shortcut=$INST/blosc
2056 }
2057
2058 clean_BLOSC() {
2059   _init_blosc
2060   _clean
2061 }
2062
2063 compile_BLOSC() {
2064   if [ "$NO_BUILD" = true ]; then
2065     WARNING "--no-build enabled, Blosc will not be compiled!"
2066     return
2067   fi
2068
2069   # To be changed each time we make edits that would modify the compiled result!
2070   blosc_magic=0
2071   _init_blosc
2072
2073   # Clean install if needed!
2074   magic_compile_check blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
2075   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
2076     clean_BLOSC
2077     rm -rf $_inst
2078   fi
2079
2080   if [ ! -d $_inst ]; then
2081     INFO "Building Blosc-$OPENVDB_BLOSC_VERSION"
2082
2083     # Rebuild dependecies as well!
2084     OPENVDB_FORCE_BUILD=true
2085     OPENVDB_FORCE_REBUILD=true
2086
2087     prepare_opt
2088
2089     if [ ! -d $_src ]; then
2090       INFO "Downloading Blosc-$OPENVDB_BLOSC_VERSION"
2091       mkdir -p $SRC
2092       download OPENVDB_BLOSC_SOURCE[@] $_src.tar.gz
2093
2094       INFO "Unpacking Blosc-$OPENVDB_BLOSC_VERSION"
2095       tar -C $SRC -xf $_src.tar.gz
2096     fi
2097
2098     cd $_src
2099     # Always refresh the whole build!
2100     if [ -d build ]; then
2101       rm -rf build
2102     fi
2103     mkdir build
2104     cd build
2105
2106     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2107     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2108     cmake_d="$cmake_d -D BUILD_STATIC=OFF"
2109     cmake_d="$cmake_d -D BUILD_TESTS=OFF"
2110     cmake_d="$cmake_d -D BUILD_BENCHMARKS=OFF"
2111     INFO "$cmake_d"
2112
2113     cmake $cmake_d ..
2114
2115     make -j$THREADS && make install
2116
2117     make clean
2118
2119     if [ -d $_inst ]; then
2120       _create_inst_shortcut
2121     else
2122       ERROR "Blosc-$OPENVDB_BLOSC_VERSION failed to compile, exiting"
2123       exit 1
2124     fi
2125     cd $CWD
2126     INFO "Done compiling Blosc-$OPENVDB_BLOSC_VERSION!"
2127   else
2128     INFO "Own Blosc-$OPENVDB_BLOSC_VERSION is up to date, nothing to do!"
2129     INFO "If you want to force rebuild of this lib (and openvdb), use the --force-openvdb option."
2130   fi
2131
2132   magic_compile_set blosc-$OPENVDB_BLOSC_VERSION $blosc_magic
2133
2134   run_ldconfig "blosc"
2135 }
2136
2137 #### Build OpenVDB ####
2138 _init_openvdb() {
2139   _src=$SRC/openvdb-$OPENVDB_VERSION
2140   _git=false
2141   _inst=$INST/openvdb-$OPENVDB_VERSION
2142   _inst_shortcut=$INST/openvdb
2143 }
2144
2145 clean_OPENVDB() {
2146   _init_openvdb
2147   _clean
2148 }
2149
2150 compile_OPENVDB() {
2151   if [ "$NO_BUILD" = true ]; then
2152     WARNING "--no-build enabled, OpenVDB will not be compiled!"
2153     return
2154   fi
2155
2156   compile_BLOSC
2157   PRINT ""
2158
2159   # To be changed each time we make edits that would modify the compiled result!
2160   openvdb_magic=1
2161   _init_openvdb
2162
2163   # Clean install if needed!
2164   magic_compile_check openvdb-$OPENVDB_VERSION $openvdb_magic
2165   if [ $? -eq 1 -o "$OPENVDB_FORCE_REBUILD" = true ]; then
2166     clean_OPENVDB
2167   fi
2168
2169   if [ ! -d $_inst ]; then
2170     INFO "Building OpenVDB-$OPENVDB_VERSION"
2171
2172     prepare_opt
2173
2174     if [ ! -d $_src -o true ]; then
2175       mkdir -p $SRC
2176       download OPENVDB_SOURCE[@] "$_src.tar.gz"
2177
2178       INFO "Unpacking OpenVDB-$OPENVDB_VERSION"
2179       tar -C $SRC -xf $_src.tar.gz
2180     fi
2181
2182     cd $_src
2183
2184     #~ if [ "$OPENVDB_USE_REPO" = true ]; then
2185       #~ git remote set-url origin ${OPENVDB_SOURCE_REPO[0]}
2186       #~ # XXX For now, always update from latest repo...
2187       #~ git pull --no-edit -X theirs origin $OPENVDB_SOURCE_REPO_BRANCH
2188       #~ # Stick to same rev as windows' libs...
2189       #~ git checkout $OPENVDB_SOURCE_REPO_UID
2190       #~ git reset --hard
2191     #~ fi
2192
2193     # Source builds here
2194     cd openvdb
2195
2196     make_d="DESTDIR=$_inst"
2197     make_d="$make_d HDSO=/usr"
2198
2199     if [ -d $INST/boost ]; then
2200       make_d="$make_d BOOST_INCL_DIR=$INST/boost/include BOOST_LIB_DIR=$INST/boost/lib"
2201     fi
2202
2203     if [ "$_with_built_openexr" = true ]; then
2204       make_d="$make_d ILMBASE_INCL_DIR=$INST/openexr/include ILMBASE_LIB_DIR=$INST/openexr/lib"
2205       make_d="$make_d EXR_INCL_DIR=$INST/openexr/include EXR_LIB_DIR=$INST/openexr/lib"
2206       INFO "ILMBASE_HOME=$INST/openexr"
2207     fi
2208
2209     if [ -d $INST/blosc ]; then
2210       make_d="$make_d BLOSC_INCL_DIR=$INST/blosc/include BLOSC_LIB_DIR=$INST/blosc/lib"
2211     fi
2212
2213     # Build without log4cplus, glfw, python module & docs
2214     make_d="$make_d LOG4CPLUS_INCL_DIR= GLFW_INCL_DIR= PYTHON_VERSION= DOXYGEN="
2215
2216     make -j$THREADS lib $make_d install
2217     make clean
2218
2219     if [ -d $_inst ]; then
2220       _create_inst_shortcut
2221     else
2222       ERROR "OpenVDB-$OPENVDB_VERSION failed to compile, exiting"
2223       exit 1
2224     fi
2225
2226     magic_compile_set openvdb-$OPENVDB_VERSION $openvdb_magic
2227
2228     cd $CWD
2229     INFO "Done compiling OpenVDB-$OPENVDB_VERSION!"
2230   else
2231     INFO "Own OpenVDB-$OPENVDB_VERSION is up to date, nothing to do!"
2232     INFO "If you want to force rebuild of this lib, use the --force-openvdb option."
2233   fi
2234
2235   run_ldconfig "openvdb"
2236 }
2237
2238 #### Build Alembic ####
2239 _init_alembic() {
2240   _src=$SRC/alembic-$ALEMBIC_VERSION
2241   _git=false
2242   _inst=$INST/alembic-$ALEMBIC_VERSION
2243   _inst_shortcut=$INST/alembic
2244 }
2245
2246 clean_ALEMBIC() {
2247   _init_alembic
2248   _clean
2249 }
2250
2251 compile_ALEMBIC() {
2252   if [ "$NO_BUILD" = true ]; then
2253     WARNING "--no-build enabled, Alembic will not be compiled!"
2254     return
2255   fi
2256
2257   # To be changed each time we make edits that would modify the compiled result!
2258   alembic_magic=2
2259   _init_alembic
2260
2261   # Clean install if needed!
2262   magic_compile_check alembic-$ALEMBIC_VERSION $alembic_magic
2263   if [ $? -eq 1 -o "$ALEMBIC_FORCE_REBUILD" = true ]; then
2264     clean_ALEMBIC
2265   fi
2266
2267   if [ ! -d $_inst ]; then
2268     INFO "Building Alembic-$ALEMBIC_VERSION"
2269
2270     prepare_opt
2271
2272     if [ ! -d $_src -o true ]; then
2273       mkdir -p $SRC
2274       download ALEMBIC_SOURCE[@] "$_src.tar.gz"
2275
2276       INFO "Unpacking Alembic-$ALEMBIC_VERSION"
2277       tar -C $SRC -xf $_src.tar.gz
2278     fi
2279
2280     cd $_src
2281
2282     cmake_d="-D CMAKE_INSTALL_PREFIX=$_inst"
2283
2284     # Without Boost or TR1, Alembic requires C++11.
2285     if [ "$USE_CXX11" != true ]; then
2286       cmake_d="$cmake_d -D ALEMBIC_LIB_USES_BOOST=ON"
2287       cmake_d="$cmake_d -D ALEMBIC_LIB_USES_TR1=OFF"
2288     fi
2289
2290     if [ -d $INST/boost ]; then
2291       if [ -d $INST/boost ]; then
2292         cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost"
2293       fi
2294       cmake_d="$cmake_d -D USE_STATIC_BOOST=ON"
2295     else
2296       cmake_d="$cmake_d -D USE_STATIC_BOOST=OFF"
2297     fi
2298
2299     if [ "$_with_built_openexr" = true ]; then
2300       cmake_d="$cmake_d -D ILMBASE_ROOT=$INST/openexr"
2301       cmake_d="$cmake_d -D USE_ARNOLD=OFF"
2302       cmake_d="$cmake_d -D USE_BINARIES=OFF"
2303       cmake_d="$cmake_d -D USE_EXAMPLES=OFF"
2304       cmake_d="$cmake_d -D USE_HDF5=OFF"
2305       cmake_d="$cmake_d -D USE_MAYA=OFF"
2306       cmake_d="$cmake_d -D USE_PRMAN=OFF"
2307       cmake_d="$cmake_d -D USE_PYALEMBIC=OFF"
2308       cmake_d="$cmake_d -D USE_STATIC_HDF5=OFF"
2309       cmake_d="$cmake_d -D ALEMBIC_ILMBASE_LINK_STATIC=OFF"
2310       cmake_d="$cmake_d -D ALEMBIC_SHARED_LIBS=OFF"
2311       INFO "ILMBASE_ROOT=$INST/openexr"
2312     fi
2313
2314     cmake $cmake_d ./
2315     make -j$THREADS install
2316     make clean
2317
2318     if [ -d $_inst ]; then
2319       _create_inst_shortcut
2320     else
2321       ERROR "Alembic-$ALEMBIC_VERSION failed to compile, exiting"
2322       exit 1
2323     fi
2324
2325     magic_compile_set alembic-$ALEMBIC_VERSION $alembic_magic
2326
2327     cd $CWD
2328     INFO "Done compiling Alembic-$ALEMBIC_VERSION!"
2329   else
2330     INFO "Own Alembic-$ALEMBIC_VERSION is up to date, nothing to do!"
2331     INFO "If you want to force rebuild of this lib, use the --force-alembic option."
2332   fi
2333
2334   run_ldconfig "alembic"
2335 }
2336
2337 #### Build OpenCOLLADA ####
2338 _init_opencollada() {
2339   _src=$SRC/OpenCOLLADA-$OPENCOLLADA_VERSION
2340   _git=true
2341   _inst=$INST/opencollada-$OPENCOLLADA_VERSION
2342   _inst_shortcut=$INST/opencollada
2343 }
2344
2345 clean_OpenCOLLADA() {
2346   _init_opencollada
2347   _clean
2348 }
2349
2350 compile_OpenCOLLADA() {
2351   if [ "$NO_BUILD" = true ]; then
2352     WARNING "--no-build enabled, OpenCOLLADA will not be compiled!"
2353     return
2354   fi
2355
2356   # To be changed each time we make edits that would modify the compiled results!
2357   opencollada_magic=9
2358   _init_opencollada
2359
2360   # Clean install if needed!
2361   magic_compile_check opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2362   if [ $? -eq 1 -o "$OPENCOLLADA_FORCE_REBUILD" = true ]; then
2363     clean_OpenCOLLADA
2364   fi
2365
2366   if [ ! -d $_inst ]; then
2367     INFO "Building OpenCOLLADA-$OPENCOLLADA_VERSION"
2368
2369     prepare_opt
2370
2371     if [ ! -d $_src ]; then
2372       mkdir -p $SRC
2373       git clone $OPENCOLLADA_SOURCE $_src
2374     fi
2375
2376     cd $_src
2377
2378     # XXX For now, always update from latest repo...
2379     git pull origin $OPENCOLLADA_REPO_BRANCH
2380
2381     # Stick to same rev as windows' libs...
2382     git checkout $OPENCOLLADA_REPO_UID
2383     git reset --hard
2384
2385     # Always refresh the whole build!
2386     if [ -d build ]; then
2387       rm -rf build
2388     fi
2389     mkdir build
2390     cd build
2391
2392     cmake_d="-D CMAKE_BUILD_TYPE=Release"
2393     cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
2394     cmake_d="$cmake_d -D USE_EXPAT=OFF"
2395     cmake_d="$cmake_d -D USE_LIBXML=ON"
2396     # XXX Does not work!
2397 #    cmake_d="$cmake_d -D USE_STATIC=OFF"
2398     cmake_d="$cmake_d -D USE_STATIC=ON"
2399
2400     cmake $cmake_d ../
2401
2402     make -j$THREADS && make install
2403     make clean
2404
2405     if [ -d $_inst ]; then
2406       _create_inst_shortcut
2407     else
2408       ERROR "OpenCOLLADA-$OPENCOLLADA_VERSION failed to compile, exiting"
2409       exit 1
2410     fi
2411
2412     magic_compile_set opencollada-$OPENCOLLADA_VERSION $opencollada_magic
2413
2414     cd $CWD
2415     INFO "Done compiling OpenCOLLADA-$OPENCOLLADA_VERSION!"
2416   else
2417     INFO "Own OpenCOLLADA-$OPENCOLLADA_VERSION is up to date, nothing to do!"
2418     INFO "If you want to force rebuild of this lib, use the --force-opencollada option."
2419   fi
2420 }
2421
2422 #### Build FFMPEG ####
2423 _init_ffmpeg() {
2424   _src=$SRC/ffmpeg-$FFMPEG_VERSION
2425   _inst=$INST/ffmpeg-$FFMPEG_VERSION
2426   _inst_shortcut=$INST/ffmpeg
2427 }
2428
2429 clean_FFmpeg() {
2430   _init_ffmpeg
2431   _clean
2432 }
2433
2434 compile_FFmpeg() {
2435   if [ "$NO_BUILD" = true ]; then
2436     WARNING "--no-build enabled, ffmpeg will not be compiled!"
2437     return
2438   fi
2439
2440   # To be changed each time we make edits that would modify the compiled result!
2441   ffmpeg_magic=5
2442   _init_ffmpeg
2443
2444   # Clean install if needed!
2445   magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2446   if [ $? -eq 1 -o "$FFMPEG_FORCE_REBUILD" = true ]; then
2447     clean_FFmpeg
2448   fi
2449
2450   if [ ! -d $_inst ]; then
2451     INFO "Building ffmpeg-$FFMPEG_VERSION"
2452
2453     prepare_opt
2454
2455     if [ ! -d $_src ]; then
2456       INFO "Downloading ffmpeg-$FFMPEG_VERSION"
2457       mkdir -p $SRC
2458       download FFMPEG_SOURCE[@] "$_src.tar.bz2"
2459
2460       INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
2461       tar -C $SRC -xf $_src.tar.bz2
2462     fi
2463
2464     cd $_src
2465
2466     extra=""
2467
2468     if [ "$VORBIS_USE" = true ]; then
2469       extra="$extra --enable-libvorbis"
2470     fi
2471
2472     if [ "$THEORA_USE" = true ]; then
2473       extra="$extra --enable-libtheora"
2474     fi
2475
2476     if [ "$XVID_USE" = true ]; then
2477       extra="$extra --enable-libxvid"
2478     fi
2479
2480     if [ "$X264_USE" = true ]; then
2481       extra="$extra --enable-libx264"
2482     fi
2483
2484     if [ "$VPX_USE" = true ]; then
2485       extra="$extra --enable-libvpx"
2486     fi
2487
2488     if [ "$MP3LAME_USE" = true ]; then
2489       extra="$extra --enable-libmp3lame"
2490     fi
2491
2492     if [ "$OPENJPEG_USE" = true ]; then
2493       extra="$extra --enable-libopenjpeg"
2494     fi
2495
2496     ./configure --cc="gcc -Wl,--as-needed" \
2497         --extra-ldflags="-pthread -static-libgcc" \
2498         --prefix=$_inst --enable-static \
2499         --disable-ffplay --disable-ffserver --disable-doc \
2500         --enable-gray \
2501         --enable-avfilter --disable-vdpau \
2502         --disable-bzlib --disable-libgsm --disable-libspeex \
2503         --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
2504         --disable-vaapi --disable-nonfree --enable-gpl \
2505         --disable-postproc --disable-librtmp --disable-libopencore-amrnb \
2506         --disable-libopencore-amrwb --disable-libdc1394 --disable-version3 --disable-outdev=sdl \
2507         --disable-libxcb \
2508         --disable-outdev=xv --disable-indev=sndio --disable-outdev=sndio \
2509         --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
2510         --disable-indev=lavfi $extra
2511
2512     make -j$THREADS && make install
2513     make clean
2514
2515     if [ -d $_inst ]; then
2516       _create_inst_shortcut
2517     else
2518       ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
2519       exit 1
2520     fi
2521
2522     magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
2523
2524     cd $CWD
2525     INFO "Done compiling ffmpeg-$FFMPEG_VERSION!"
2526   else
2527     INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
2528     INFO "If you want to force rebuild of this lib, use the --force-ffmpeg option."
2529   fi
2530 }
2531
2532
2533 #### Install on DEB-like ####
2534 get_package_version_DEB() {
2535     dpkg-query -W -f '${Version}' $1 | sed -r 's/([0-9]+:)?(([0-9]+\.?)+([0-9]+)).*/\2/'
2536 }
2537
2538 check_package_DEB() {
2539   r=`apt-cache show $1 | grep -c 'Package:'`
2540
2541   if [ $r -ge 1 ]; then
2542     return 0
2543   else
2544     return 1
2545   fi
2546 }
2547
2548 check_package_installed_DEB() {
2549   r=`dpkg-query -W -f='${Status}' $1 | grep -c "install ok"`
2550
2551   if [ $r -ge 1 ]; then
2552     return 0
2553   else
2554     return 1
2555   fi
2556 }
2557
2558 check_package_version_match_DEB() {
2559   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`
2560
2561   if [ -z "$v" ]; then
2562     return 1
2563   fi
2564
2565   version_match $v $2
2566   return $?
2567 }
2568
2569 check_package_version_ge_DEB() {
2570   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2571
2572   if [ -z "$v" ]; then
2573     return 1
2574   fi
2575
2576   version_ge $v $2
2577   return $?
2578 }
2579
2580 check_package_version_ge_lt_DEB() {
2581   v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`
2582
2583   if [ -z "$v" ]; then
2584     return 1
2585   fi
2586
2587   version_ge_lt $v $2 $3
2588   return $?
2589 }
2590
2591 install_packages_DEB() {
2592   if [ ! $SUDO ]; then
2593     WARNING "--no-sudo enabled, impossible to run apt-get install for $@, you'll have to do it yourself..."
2594   else
2595     $SUDO apt-get install -y $@
2596     if [ $? -ge 1 ]; then
2597       ERROR "apt-get failed to install requested packages, exiting."
2598       exit 1
2599     fi
2600   fi
2601 }
2602
2603 install_DEB() {
2604   PRINT ""
2605   INFO "Installing dependencies for DEB-based distribution"
2606   PRINT ""
2607   PRINT "`eval _echo "$COMMON_INFO"`"
2608   PRINT ""
2609
2610   if [ "$NO_CONFIRM" = false ]; then
2611     read -p "Do you want to continue (Y/n)?"
2612     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
2613   fi
2614
2615   if [ ! $SUDO ]; then
2616     WARNING "--no-sudo enabled, impossible to run apt-get update, you'll have to do it yourself..."
2617   else
2618     $SUDO apt-get update
2619   fi
2620
2621   # These libs should always be available in debian/ubuntu official repository...
2622   VORBIS_DEV="libvorbis-dev"
2623   OGG_DEV="libogg-dev"
2624   THEORA_DEV="libtheora-dev"
2625
2626   _packages="gawk cmake cmake-curses-gui build-essential libjpeg-dev libpng-dev libtiff-dev \
2627              git libfreetype6-dev libx11-dev flex bison libtbb-dev libxxf86vm-dev \
2628              libxcursor-dev libxi-dev wget libsqlite3-dev libxrandr-dev libxinerama-dev \
2629              libbz2-dev libncurses5-dev libssl-dev liblzma-dev libreadline-dev \
2630              libopenal-dev libglew-dev yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV \
2631              libsdl1.2-dev libfftw3-dev patch bzip2 libxml2-dev libtinyxml-dev libjemalloc-dev"
2632              # libglewmx-dev  (broken in deb testing currently...)
2633
2634   VORBIS_USE=true
2635   OGG_USE=true
2636   THEORA_USE=true
2637
2638   PRINT ""
2639   # New Ubuntu crap (17.04 and more) have no openjpeg lib!
2640   OPENJPEG_DEV="libopenjpeg-dev"
2641   check_package_DEB $OPENJPEG_DEV
2642   if [ $? -eq 0 ]; then
2643     _packages="$_packages $OPENJPEG_DEV"
2644     OPENJPEG_USE=true
2645   fi
2646
2647   PRINT ""
2648   # Some not-so-old distro (ubuntu 12.4) do not have it, do not fail in this case, just warn.
2649   YAMLCPP_DEV="libyaml-cpp-dev"
2650   check_package_DEB $YAMLCPP_DEV
2651   if [ $? -eq 0 ]; then
2652     _packages="$_packages $YAMLCPP_DEV"
2653   else
2654     PRINT ""
2655     WARNING "libyaml-cpp-dev not found, you may have to install it by hand to get Blender compiling..."
2656     PRINT ""
2657   fi
2658
2659   if [ "$WITH_JACK" = true ]; then
2660     _packages="$_packages libspnav-dev"
2661     # Only install jack if jack2 is not already installed!
2662     JACK="libjack-dev"
2663     JACK2="libjack-jackd2-dev"
2664     check_package_installed_DEB $JACK2
2665     if [ $? -eq 0 ]; then
2666       _packages="$_packages $JACK2"
2667     else
2668       _packages="$_packages $JACK"
2669     fi
2670   fi
2671
2672   PRINT ""
2673   install_packages_DEB $_packages
2674
2675   PRINT""
2676   SNDFILE_DEV="libsndfile1-dev"
2677   check_package_DEB $SNDFILE_DEV
2678   if [ $? -eq 0 ]; then
2679     install_packages_DEB $SNDFILE_DEV
2680   fi
2681
2682   PRINT ""
2683   X264_DEV="libx264-dev"
2684   check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
2685   if [ $? -eq 0 ]; then
2686     install_packages_DEB $X264_DEV
2687     X264_USE=true
2688   fi
2689
2690   if [ "$WITH_ALL" = true ]; then
2691     PRINT ""
2692     XVID_DEV="libxvidcore-dev"
2693     check_package_DEB $XVID_DEV
2694     if [ $? -eq 0 ]; then
2695       install_packages_DEB $XVID_DEV
2696       XVID_USE=true
2697     fi
2698
2699     PRINT ""
2700     MP3LAME_DEV="libmp3lame-dev"
2701     check_package_DEB $MP3LAME_DEV
2702     if [ $? -eq 0 ]; then
2703       install_packages_DEB $MP3LAME_DEV
2704       MP3LAME_USE=true
2705     fi
2706
2707     PRINT ""
2708     VPX_DEV="libvpx-dev"
2709     check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
2710     if [ $? -eq 0 ]; then
2711       install_packages_DEB $VPX_DEV
2712       VPX_USE=true
2713     fi
2714   fi
2715
2716   # Check cmake/glew versions and disable features for older distros.
2717   # This is so Blender can at least compile.
2718   PRINT ""
2719   _cmake=`get_package_version_DEB cmake`
2720   version_ge $_cmake "2.8.10"
2721   if [ $? -eq 1 ]; then
2722     version_ge $_cmake "2.8.8"
2723     if [ $? -eq 1 ]; then
2724       WARNING "OpenVDB and OpenCOLLADA disabled because cmake-$_cmake is not enough"
2725       OPENVDB_SKIP=true
2726       OPENCOLLADA_SKIP=true
2727     else
2728       WARNING "OpenVDB disabled because cmake-$_cmake is not enough"
2729       OPENVDB_SKIP=true
2730     fi
2731   fi
2732
2733   PRINT ""
2734   _glew=`get_package_version_DEB libglew-dev`
2735   if [ -z $_glew ]; then
2736     # Stupid virtual package in Ubuntu 12.04 doesn't show version number...
2737     _glew=`apt-cache showpkg libglew-dev|tail -n1|awk '{print $2}'|sed 's/-.*//'`
2738   fi
2739   version_ge $_glew "1.9.0"
2740   if [ $? -eq 1 ]; then
2741     version_ge $_glew "1.7.0"
2742     if [ $? -eq 1 ]; then
2743       WARNING "OpenSubdiv disabled because GLEW-$_glew is not enough"
2744       WARNING "Blender will not use system GLEW library"
2745       OSD_SKIP=true
2746       NO_SYSTEM_GLEW=true
2747     else
2748       WARNING "OpenSubdiv will compile with GLEW-$_glew but with limited capability"
2749       WARNING "Blender will not use system GLEW library"
2750       NO_SYSTEM_GLEW=true
2751     fi
2752   fi
2753
2754
2755   PRINT ""
2756   _do_compile_python=false
2757   if [ "$PYTHON_SKIP" = true ]; then
2758     WARNING "Skipping Python/NumPy installation, as requested..."
2759   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
2760     INFO "Forced Python/NumPy building, as requested..."
2761     _do_compile_python=true
2762   else
2763     check_package_DEB python$PYTHON_VERSION_MIN-dev
2764     if [ $? -eq 0 ]; then
2765       install_packages_DEB python$PYTHON_VERSION_MIN-dev
2766       clean_Python
2767       PRINT ""
2768       if [ "$NUMPY_SKIP" = true ]; then
2769         WARNING "Skipping NumPy installation, as requested..."
2770       else
2771         check_package_DEB python3-numpy
2772         if [ $? -eq 0 ]; then
2773           install_packages_DEB python3-numpy
2774         else
2775           WARNING "Sorry, using python package but no valid numpy package available!" \
2776                   "    Use --build-numpy to force building of both Python and NumPy."
2777         fi
2778       fi
2779     else
2780       _do_compile_python=true
2781     fi
2782   fi
2783
2784   if $_do_compile_python; then
2785     compile_Python
2786     PRINT ""
2787     if [ "$NUMPY_SKIP" = true ]; then
2788       WARNING "Skipping NumPy installation, as requested..."
2789     else
2790       compile_Numpy
2791     fi
2792   fi
2793
2794
2795   PRINT ""
2796   if [ "$BOOST_SKIP" = true ]; then
2797     WARNING "Skipping Boost installation, as requested..."
2798   elif [ "$BOOST_FORCE_BUILD" = true ]; then
2799     INFO "Forced Boost building, as requested..."
2800     compile_Boost
2801   else
2802     check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
2803     if [ $? -eq 0 ]; then
2804       install_packages_DEB libboost-dev
2805
2806       boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')
2807
2808       install_packages_DEB libboost-{filesystem,iostreams,locale,regex,system,thread,wave,program-options}$boost_version-dev
2809       clean_Boost
2810     else
2811       compile_Boost
2812     fi
2813   fi
2814
2815
2816   PRINT ""
2817   if [ "$OCIO_SKIP" = true ]; then
2818     WARNING "Skipping OpenColorIO installation, as requested..."
2819   elif [ "$OCIO_FORCE_BUILD" = true ]; then
2820     INFO "Forced OpenColorIO building, as requested..."
2821     compile_OCIO
2822   else
2823     # XXX Always force build of own OCIO, until linux distro guys update their package to default libyaml-cpp ver (0.5)!
2824     #check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
2825     #if [ $? -eq 0 ]; then
2826       #install_packages_DEB libopencolorio-dev
2827       #clean_OCIO
2828     #else
2829       compile_OCIO
2830     #fi
2831   fi
2832
2833
2834   PRINT ""
2835   if [ "$OPENEXR_SKIP" = true ]; then
2836     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
2837   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
2838     INFO "Forced ILMBase/OpenEXR building, as requested..."
2839     compile_OPENEXR
2840   else
2841     check_package_version_ge_DEB libopenexr-dev $OPENEXR_VERSION_MIN
2842     if [ $? -eq 0 ]; then
2843       install_packages_DEB libopenexr-dev
2844       OPENEXR_VERSION=`get_package_version_DEB libopenexr-dev`
2845       ILMBASE_VERSION=$OPENEXR_VERSION
2846       clean_OPENEXR
2847     else
2848       compile_OPENEXR
2849     fi
2850   fi
2851
2852
2853   PRINT ""
2854   if [ "$OIIO_SKIP" = true ]; then
2855     WARNING "Skipping OpenImageIO installation, as requested..."
2856   elif [ "$OIIO_FORCE_BUILD" = true ]; then
2857     INFO "Forced OpenImageIO building, as requested..."
2858     compile_OIIO
2859   else
2860     # 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...
2861     #check_package_version_ge_lt_DEB libopenimageio-dev $OIIO_VERSION_MIN $OIIO_VERSION_MAX
2862     #if [ $? -eq 0 -a "$_with_built_openexr" = false ]; then
2863     #  install_packages_DEB libopenimageio-dev
2864     #  clean_OIIO
2865     #else
2866       compile_OIIO
2867     #fi
2868   fi
2869
2870
2871   PRINT ""
2872   have_llvm=false
2873   _do_compile_llvm=false
2874   if [ "$LLVM_SKIP" = true ]; then
2875     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
2876     OSL_SKIP=true
2877   elif [ "$LLVM_FORCE_BUILD" = true ]; then
2878     INFO "Forced LLVM building, as requested..."
2879     _do_compile_llvm=true
2880   else
2881     check_package_DEB clang-$LLVM_VERSION
2882     if [ $? -eq 0 ]; then
2883       install_packages_DEB llvm-$LLVM_VERSION-dev clang-$LLVM_VERSION
2884       have_llvm=true
2885       LLVM_VERSION_FOUND=$LLVM_VERSION
2886       clean_LLVM
2887     else
2888       _do_compile_llvm=true
2889     fi
2890   fi
2891
2892   if [ "$_do_compile_llvm" = true ]; then
2893     install_packages_DEB libffi-dev
2894     # LLVM can't find the debian ffi header dir
2895     _FFI_INCLUDE_DIR=`dpkg -L libffi-dev | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
2896     PRINT ""
2897     compile_LLVM
2898     have_llvm=true
2899     LLVM_VERSION_FOUND=$LLVM_VERSION
2900   fi
2901
2902
2903   PRINT ""
2904   _do_compile_osl=false
2905   if [ "$OSL_SKIP" = true ]; then
2906     WARNING "Skipping OpenShadingLanguage installation, as requested..."
2907   elif [ "$OSL_FORCE_BUILD" = true ]; then
2908     INFO "Forced OpenShadingLanguage building, as requested..."
2909     _do_compile_osl=true
2910   else
2911     # No package currently!
2912     _do_compile_osl=true
2913   fi
2914
2915   if [ "$_do_compile_osl" = true ]; then
2916     if [ "$have_llvm" = true ]; then
2917       PRINT ""
2918       compile_OSL
2919     else
2920       WARNING "No LLVM available, cannot build OSL!"
2921     fi
2922   fi
2923
2924
2925   PRINT ""
2926   if [ "$OSD_SKIP" = true ]; then
2927     WARNING "Skipping OpenSubdiv installation, as requested..."
2928   elif [ "$OSD_FORCE_BUILD" = true ]; then
2929     INFO "Forced OpenSubdiv building, as requested..."
2930     compile_OSD
2931   else
2932     # No package currently!
2933     PRINT ""
2934     compile_OSD
2935   fi
2936
2937   PRINT ""
2938   if [ "$OPENVDB_SKIP" = true ]; then
2939     WARNING "Skipping OpenVDB installation, as requested..."
2940   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
2941     INFO "Forced OpenVDB building, as requested..."
2942     compile_OPENVDB
2943   else
2944     check_package_version_ge_DEB libopenvdb-dev $OPENVDB_VERSION_MIN
2945     if [ $? -eq 0 ]; then
2946       install_packages_DEB libopenvdb-dev libblosc-dev
2947       clean_OPENVDB
2948     else
2949       compile_OPENVDB
2950     fi
2951   fi
2952
2953   PRINT ""
2954   if [ "$ALEMBIC_SKIP" = true ]; then
2955     WARNING "Skipping Alembic installation, as requested..."
2956   elif [ "$ALEMBIC_FORCE_BUILD" = true ]; then
2957     INFO "Forced Alembic building, as requested..."
2958     compile_ALEMBIC
2959   else
2960     # No package currently, only HDF5!
2961     compile_ALEMBIC
2962   fi
2963
2964
2965   if [ "$WITH_OPENCOLLADA" = true ]; then
2966     _do_compile_collada=false
2967     PRINT ""
2968     if [ "$OPENCOLLADA_SKIP" = true ]; then
2969       WARNING "Skipping OpenCOLLADA installation, as requested..."
2970     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
2971       INFO "Forced OpenCollada building, as requested..."
2972       _do_compile_collada=true
2973     else
2974       # No package currently!
2975       _do_compile_collada=true
2976     fi
2977
2978     if [ "$_do_compile_collada" = true ]; then
2979       install_packages_DEB libpcre3-dev
2980       # Find path to libxml shared lib...
2981       _XML2_LIB=`dpkg -L libxml2-dev | grep -e ".*/libxml2.so"`
2982       # No package
2983       PRINT ""
2984       compile_OpenCOLLADA
2985     fi
2986   fi
2987
2988
2989   PRINT ""
2990   if [ "$FFMPEG_SKIP" = true ]; then
2991     WARNING "Skipping FFMpeg installation, as requested..."
2992   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
2993     INFO "Forced FFMpeg building, as requested..."
2994     compile_FFmpeg
2995   else
2996     # XXX Debian Testing / Ubuntu 16.04 finally includes FFmpeg, so check as usual
2997     check_package_DEB ffmpeg
2998     if [ $? -eq 0 ]; then
2999       check_package_version_ge_DEB ffmpeg $FFMPEG_VERSION_MIN
3000       if [ $? -eq 0 ]; then
3001         install_packages_DEB libavdevice-dev
3002         clean_FFmpeg
3003       else
3004         compile_FFmpeg
3005       fi
3006     else
3007       compile_FFmpeg
3008     fi
3009   fi
3010 }
3011
3012
3013 #### Install on RPM-like ####
3014 rpm_flavour() {
3015   if [ -f /etc/redhat-release ]; then
3016     if [ "`grep '[6-7]\.' /etc/redhat-release`" ]; then
3017       RPM="RHEL"
3018     else
3019       RPM="FEDORA"
3020     fi
3021   elif [ -f /etc/SuSE-release ]; then
3022     RPM="SUSE"
3023   fi
3024 }
3025
3026 get_package_version_RPM() {
3027   rpm_flavour
3028   if [ "$RPM" = "RHEL" ]; then
3029     yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
3030   elif [ "$RPM" = "FEDORA" ]; then
3031     dnf info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
3032   elif [ "$RPM" = "SUSE" ]; then
3033     zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
3034   fi
3035 }
3036
3037 check_package_RPM() {
3038   rpm_flavour
3039   if [ "$RPM" = "RHEL" ]; then
3040     r=`yum info $1 | grep -c 'Summary'`
3041   elif [ "$RPM" = "FEDORA" ]; then
3042     r=`dnf info $1 | grep -c 'Summary'`
3043   elif [ "$RPM" = "SUSE" ]; then
3044     r=`zypper info $1 | grep -c 'Summary'`
3045   fi
3046
3047   if [ $r -ge 1 ]; then
3048     return 0
3049   else
3050     return 1
3051   fi
3052 }
3053
3054 check_package_version_match_RPM() {
3055   v=`get_package_version_RPM $1`
3056
3057   if [ -z "$v" ]; then
3058     return 1
3059   fi
3060
3061   version_match $v $2
3062   return $?
3063 }
3064
3065 check_package_version_ge_RPM() {
3066   v=`get_package_version_RPM $1`
3067
3068   if [ -z "$v" ]; then
3069     return 1
3070   fi
3071
3072   version_ge $v $2
3073   return $?
3074 }
3075
3076 check_package_version_ge_lt_RPM() {
3077   v=`get_package_version_RPM $1`
3078
3079   if [ -z "$v" ]; then
3080     return 1
3081   fi
3082
3083   version_ge_lt $v $2 $3
3084   return $?
3085 }
3086
3087 install_packages_RPM() {
3088   rpm_flavour
3089   if [ ! $SUDO ]; then
3090     WARNING "--no-sudo enabled, impossible to install $@, you'll have to do it yourself..."
3091   fi
3092   if [ "$RPM" = "RHEL" ]; then
3093     $SUDO yum install -y $@
3094     if [ $? -ge 1 ]; then
3095       ERROR "yum failed to install requested packages, exiting."
3096       exit 1
3097     fi
3098
3099   elif [ "$RPM" = "FEDORA" ]; then
3100     $SUDO dnf install -y $@
3101     if [ $? -ge 1 ]; then
3102       ERROR "dnf failed to install requested packages, exiting."
3103       exit 1
3104     fi
3105
3106   elif [ "$RPM" = "SUSE" ]; then
3107     $SUDO zypper --non-interactive install --auto-agree-with-licenses $@
3108     if [ $? -ge 1 ]; then
3109       ERROR "zypper failed to install requested packages, exiting."
3110       exit 1
3111     fi
3112   fi
3113 }
3114
3115 install_RPM() {
3116   PRINT ""
3117   INFO "Installing dependencies for RPM-based distribution"
3118   PRINT ""
3119   PRINT "`eval _echo "$COMMON_INFO"`"
3120   PRINT ""
3121
3122   if [ "$NO_CONFIRM" = false ]; then
3123     read -p "Do you want to continue (Y/n)?"
3124     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
3125   fi
3126
3127   # Enable non-free repositories for all flavours
3128   if [ ! $SUDO ]; then
3129     WARNING "--no-sudo enabled, impossible to install third party repositories, you'll have to do it yourself..."
3130   else
3131     rpm_flavour
3132     if [ "$RPM" = "FEDORA" ]; then
3133       _fedora_rel="`egrep "[0-9]{1,}" /etc/fedora-release -o`"
3134       $SUDO dnf -y install --nogpgcheck \
3135       http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$_fedora_rel.noarch.rpm \
3136       http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$_fedora_rel.noarch.rpm
3137
3138       $SUDO dnf -y update
3139
3140     elif [ "$RPM" = "RHEL" ]; then
3141       if [ "`grep '6\.' /etc/redhat-release`" ]; then
3142         ERROR "Building with GCC 4.4 is not supported!"
3143         exit 1
3144       else
3145         $SUDO yum -y install --nogpgcheck \
3146         http://download.fedoraproject.org/pub/epel/7/$(uname -i)/e/epel-release-7-6.noarch.rpm \
3147         http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
3148
3149         $SUDO yum -y update
3150       fi
3151
3152     elif [ "$RPM" = "SUSE" ]; then
3153       # Packman repo now includes name in link...
3154       _suse_rel="`grep -w VERSION /etc/os-release | sed 's/[^0-9.]*//g'`"
3155       _suse_name="`grep -w NAME /etc/os-release | gawk '{print $2}' | sed 's/\"//'`"
3156       if [ $_suse_name ]; then
3157         _suse_rel="${_suse_name}_${_suse_rel}"
3158       fi
3159
3160       PRINT ""
3161       INFO "About to add 'packman' repository from http://packman.inode.at/suse/openSUSE_$_suse_rel/"
3162       INFO "This is only needed if you do not already have a packman repository enabled..."
3163       read -p "Do you want to add this repo (Y/n)?"
3164       if [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" == "y" ]; then
3165         INFO "    Installing packman..."
3166         $SUDO zypper ar -f -n packman http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_$_suse_rel/ packman
3167         INFO "    Done."
3168       else
3169         INFO "    Skipping packman installation."
3170       fi
3171       $SUDO zypper --non-interactive --gpg-auto-import-keys update --auto-agree-with-licenses
3172     fi
3173   fi
3174
3175   # These libs should always be available in fedora/suse official repository...
3176   OPENJPEG_DEV="openjpeg-devel"
3177   VORBIS_DEV="libvorbis-devel"
3178   OGG_DEV="libogg-devel"
3179   THEORA_DEV="libtheora-devel"
3180
3181   _packages="gcc gcc-c++ git make cmake tar bzip2 xz findutils flex bison \
3182              libtiff-devel libjpeg-devel libpng-devel sqlite-devel fftw-devel SDL-devel \
3183              libX11-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel \
3184              wget ncurses-devel readline-devel $OPENJPEG_DEV openal-soft-devel \
3185              glew-devel yasm $THEORA_DEV $VORBIS_DEV $OGG_DEV patch \
3186              libxml2-devel yaml-cpp-devel tinyxml-devel jemalloc-devel"
3187
3188   OPENJPEG_USE=true
3189   VORBIS_USE=true
3190   OGG_USE=true
3191   THEORA_USE=true
3192
3193   if [ "$RPM" = "FEDORA" -o "$RPM" = "RHEL" ]; then
3194     _packages="$_packages freetype-devel tbb-devel"
3195
3196     if [ "$WITH_JACK" = true ]; then
3197       _packages="$_packages jack-audio-connection-kit-devel"
3198     fi
3199
3200     PRINT ""
3201     install_packages_RPM $_packages
3202
3203     PRINT ""
3204     X264_DEV="x264-devel"
3205     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
3206     if [ $? -eq 0 ]; then
3207       install_packages_RPM $X264_DEV
3208       X264_USE=true
3209     fi
3210
3211     if [ "$WITH_ALL" = true ]; then
3212       PRINT ""
3213       XVID_DEV="xvidcore-devel"
3214       check_package_RPM $XVID_DEV
3215       if [ $? -eq 0 ]; then
3216         install_packages_RPM $XVID_DEV
3217         XVID_USE=true
3218       fi
3219
3220       PRINT ""
3221       MP3LAME_DEV="lame-devel"
3222       check_package_RPM $MP3LAME_DEV
3223       if [ $? -eq 0 ]; then
3224         install_packages_RPM $MP3LAME_DEV
3225         MP3LAME_USE=true
3226       fi
3227     fi
3228
3229   elif [ "$RPM" = "SUSE" ]; then
3230     _packages="$_packages freetype2-devel"
3231
3232     PRINT ""
3233     install_packages_RPM $_packages
3234
3235     PRINT ""
3236     # Install TBB on openSUSE, from temporary repo
3237     check_package_RPM tbb-devel
3238     if [ $? -eq 0 ]; then
3239       install_packages_RPM tbb-devel
3240     else
3241       $SUDO zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$_suse_rel/devel:libraries:c_c++.repo
3242       $SUDO zypper -n --gpg-auto-import-keys install tbb-devel
3243       $SUDO zypper rr devel_libraries_c_c++
3244     fi
3245
3246     PRINT ""
3247     X264_DEV="libx264-devel"
3248     check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
3249     if [ $? -eq 0 ]; then
3250       install_packages_RPM $X264_DEV
3251       X264_USE=true
3252     fi
3253
3254     if [ "$WITH_ALL" = true ]; then
3255       PRINT ""
3256       XVID_DEV="libxvidcore-devel"
3257       check_package_RPM $XVID_DEV
3258       if [ $? -eq 0 ]; then
3259         install_packages_RPM $XVID_DEV
3260         XVID_USE=true
3261       fi
3262
3263       PRINT ""
3264       MP3LAME_DEV="libmp3lame-devel"
3265       check_package_RPM $MP3LAME_DEV
3266       if [ $? -eq 0 ]; then
3267         install_packages_RPM $MP3LAME_DEV
3268         MP3LAME_USE=true
3269       fi
3270     fi
3271   fi
3272
3273   PRINT""
3274   SNDFILE_DEV="libsndfile-devel"
3275   check_package_RPM $SNDFILE_DEV
3276   if [ $? -eq 0 ]; then
3277     install_packages_RPM $SNDFILE_DEV
3278   fi
3279
3280   if [ "$WITH_ALL" = true ]; then
3281     PRINT ""
3282     VPX_DEV="libvpx-devel"
3283     check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
3284     if [ $? -eq 0 ]; then
3285       install_packages_RPM $VPX_DEV
3286       VPX_USE=true
3287     fi
3288     PRINT ""
3289     install_packages_RPM libspnav-devel
3290   fi
3291
3292
3293   PRINT ""
3294   _do_compile_python=false
3295   if [ "$PYTHON_SKIP" = true ]; then
3296     WARNING "Skipping Python installation, as requested..."
3297   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3298     INFO "Forced Python/NumPy building, as requested..."
3299     _do_compile_python=true
3300   else
3301     check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
3302     if [ $? -eq 0 ]; then
3303       install_packages_RPM python3-devel
3304       clean_Python
3305       PRINT ""
3306       if [ "$NUMPY_SKIP" = true ]; then
3307         WARNING "Skipping NumPy installation, as requested..."
3308       else
3309         check_package_version_ge_RPM python3-numpy $NUMPY_VERSION_MIN
3310         if [ $? -eq 0 ]; then
3311           install_packages_RPM python3-numpy
3312         else
3313           WARNING "Sorry, using python package but no valid numpy package available!" \
3314                   "    Use --build-numpy to force building of both Python and NumPy."
3315         fi
3316       fi
3317     else
3318       _do_compile_python=true
3319     fi
3320   fi
3321
3322   if [ "$_do_compile_python" = true ]; then
3323     compile_Python
3324     PRINT ""
3325     if [ "$NUMPY_SKIP" = true ]; then
3326       WARNING "Skipping NumPy installation, as requested..."
3327     else
3328       compile_Numpy
3329     fi
3330   fi
3331
3332
3333   PRINT ""
3334   _do_compile_boost=false
3335   if [ "$BOOST_SKIP" = true ]; then
3336     WARNING "Skipping Boost installation, as requested..."
3337   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3338     INFO "Forced Boost building, as requested..."
3339     _do_compile_boost=true
3340   else
3341     check_package_version_ge_RPM boost-devel $BOOST_VERSION_MIN
3342     if [ $? -eq 0 ]; then
3343       install_packages_RPM boost-devel
3344       clean_Boost
3345     else
3346       _do_compile_boost=true
3347     fi
3348   fi
3349
3350   if [ "$_do_compile_boost" = true ]; then
3351     if [ "$RPM" = "SUSE" ]; then
3352       install_packages_RPM gcc-fortran
3353     else
3354       install_packages_RPM libquadmath-devel bzip2-devel
3355     fi
3356     PRINT ""
3357     compile_Boost
3358   fi
3359
3360
3361   PRINT ""
3362   if [ "$OCIO_SKIP" = true ]; then
3363     WARNING "Skipping OpenColorIO installation, as requested..."
3364   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3365     INFO "Forced OpenColorIO building, as requested..."
3366     compile_OCIO
3367   else
3368     if [ "$RPM" = "SUSE" ]; then
3369       check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
3370       if [ $? -eq 0 ]; then
3371         install_packages_RPM OpenColorIO-devel
3372         clean_OCIO
3373       else
3374         compile_OCIO
3375       fi
3376     # XXX Fedora/RHEL OCIO still depends on libyaml-cpp v0.3 even when system default is v0.5!
3377     else
3378       compile_OCIO
3379     fi
3380   fi
3381
3382   PRINT ""
3383   if [ "$OPENEXR_SKIP" = true ]; then
3384     WARNING "Skipping ILMBase/OpenEXR installation, as requested..."
3385   elif [ "$OPENEXR_FORCE_BUILD" = true ]; then
3386     INFO "Forced ILMBase/OpenEXR building, as requested..."
3387     compile_OPENEXR
3388   else
3389     check_package_version_ge_RPM openexr-devel $OPENEXR_VERSION_MIN
3390     if [ $? -eq 0 ]; then
3391       install_packages_RPM openexr-devel
3392       OPENEXR_VERSION=`get_package_version_RPM openexr-devel`
3393       ILMBASE_VERSION=$OPENEXR_VERSION
3394       clean_OPENEXR
3395     else
3396       compile_OPENEXR
3397     fi
3398   fi
3399
3400   PRINT ""
3401   if [ "$OIIO_SKIP" = true ]; then
3402     WARNING "Skipping OpenImageIO installation, as requested..."
3403   elif [ "$OIIO_FORCE_BUILD" = true ]; then
3404     INFO "Forced OpenImageIO building, as requested..."
3405     compile_OIIO
3406   else
3407     # XXX RPM distros pulls in too much and depends on old libs, so better to build for now...
3408     #check_package_version_ge_lt_RPM OpenImageIO-devel $OIIO_VERSION_MIN $OIIO_VERSION_MAX
3409     #if [ $? -eq 0 -a $_with_built_openexr == false ]; then
3410     #  install_packages_RPM OpenImageIO-devel
3411     #  clean_OIIO
3412     #else
3413       compile_OIIO
3414     #fi
3415   fi
3416
3417
3418   PRINT ""
3419   have_llvm=false
3420   _do_compile_llvm=false
3421   if [ "$LLVM_SKIP" = true ]; then
3422     WARNING "Skipping LLVM installation, as requested (this also implies skipping OSL!)..."
3423     OSL_SKIP=true
3424   elif [ "$LLVM_FORCE_BUILD" = true ]; then
3425     INFO "Forced LLVM building, as requested..."
3426     _do_compile_llvm=true
3427   else
3428     if [ "$RPM" = "SUSE" ]; then
3429       CLANG_DEV="llvm-clang-devel"
3430     else
3431       CLANG_DEV="clang-devel"
3432     fi
3433     # XXX RHEL has 3.4 in repo but OSL complains about not finding MCJIT_LIBRARY, so compile for now...
3434     #check_package_version_match_RPM $CLANG_DEV $LLVM_VERSION
3435     #if [ $? -eq 0 ]; then
3436     #  install_packages_RPM llvm-devel $CLANG_DEV
3437     #  have_llvm=true
3438     #  LLVM_VERSION_FOUND=$LLVM_VERSION
3439     #  clean_LLVM
3440     #else
3441       _do_compile_llvm=true
3442     #fi
3443   fi
3444
3445   if [ "$_do_compile_llvm" = true ]; then
3446     install_packages_RPM libffi-devel
3447     # LLVM can't find the fedora ffi header dir...
3448     _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
3449     PRINT ""
3450     compile_LLVM
3451     have_llvm=true
3452     LLVM_VERSION_FOUND=$LLVM_VERSION
3453   fi
3454
3455
3456   PRINT ""
3457   _do_compile_osl=false
3458   if [ "$OSL_SKIP" = true ]; then
3459     WARNING "Skipping OpenShadingLanguage installation, as requested..."
3460   elif [ "$OSL_FORCE_BUILD" = true ]; then
3461     INFO "Forced OpenShadingLanguage building, as requested..."
3462     _do_compile_osl=true
3463   else
3464     # No package currently!
3465     _do_compile_osl=true
3466   fi
3467
3468   if [ "$_do_compile_osl" = true ]; then
3469     if [ "$have_llvm" = true ]; then
3470       PRINT ""
3471       compile_OSL
3472     else
3473       WARNING "No LLVM available, cannot build OSL!"
3474     fi
3475   fi
3476
3477
3478   PRINT ""
3479   if [ "$OSD_SKIP" = true ]; then
3480     WARNING "Skipping OpenSubdiv installation, as requested..."
3481   elif [ "$OSD_FORCE_BUILD" = true ]; then
3482     INFO "Forced OpenSubdiv building, as requested..."
3483     compile_OSD
3484   else
3485     # No package currently!
3486     compile_OSD
3487   fi
3488
3489
3490   PRINT ""
3491   if [ "$OPENVDB_SKIP" = true ]; then
3492     WARNING "Skipping OpenVDB installation, as requested..."
3493   elif [ "$OPENVDB_FORCE_BUILD" = true ]; then
3494     INFO "Forced OpenVDB building, as requested..."
3495     compile_OPENVDB
3496   else
3497     # No package currently!
3498     compile_OPENVDB
3499   fi
3500
3501   PRINT ""
3502   if [ "$ALEMBIC_SKIP" = true ]; then
3503     WARNING "Skipping Alembic installation, as requested..."
3504   elif [ "$ALEMBIC_FORCE_BUILD" = true ]; then
3505     INFO "Forced Alembic building, as requested..."
3506     compile_ALEMBIC
3507   else
3508     # No package currently!
3509     compile_ALEMBIC
3510   fi
3511
3512
3513   if [ "$WITH_OPENCOLLADA" = true ]; then
3514     PRINT ""
3515     _do_compile_collada=false
3516     if [ "$OPENCOLLADA_SKIP" = true ]; then
3517       WARNING "Skipping OpenCOLLADA installation, as requested..."
3518     elif [ "$OPENCOLLADA_FORCE_BUILD" = true ]; then
3519       INFO "Forced OpenCollada building, as requested..."
3520       _do_compile_collada=true
3521     else
3522       # No package...
3523       _do_compile_collada=true
3524     fi
3525
3526     if [ "$_do_compile_collada" = true ]; then
3527       install_packages_RPM pcre-devel
3528       # Find path to libxml shared lib...
3529       _XML2_LIB=`rpm -ql libxml2-devel | grep -e ".*/libxml2.so"`
3530       PRINT ""
3531       compile_OpenCOLLADA
3532     fi
3533   fi
3534
3535
3536   PRINT ""
3537   if [ "$FFMPEG_SKIP" = true ]; then
3538     WARNING "Skipping FFMpeg installation, as requested..."
3539   elif [ "$FFMPEG_FORCE_BUILD" = true ]; then
3540     INFO "Forced FFMpeg building, as requested..."
3541     compile_FFmpeg
3542   else
3543     check_package_version_ge_RPM ffmpeg-devel $FFMPEG_VERSION_MIN
3544     if [ $? -eq 0 ]; then
3545       install_packages_RPM ffmpeg ffmpeg-devel
3546       clean_FFmpeg
3547     else
3548       compile_FFmpeg
3549     fi
3550   fi
3551 }
3552
3553
3554 #### Install on ARCH-like ####
3555 get_package_version_ARCH() {
3556   pacman -Si $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+?(([0-9]+\.?)+).*/\1/'
3557 }
3558
3559 check_package_ARCH() {
3560   r=`pacman -Si $1 | grep -c 'Description'`
3561
3562   if [ $r -ge 1 ]; then
3563     return 0
3564   else
3565     return 1
3566   fi
3567 }
3568
3569 check_package_version_match_ARCH() {
3570   v=`get_package_version_ARCH $1`
3571
3572   if [ -z "$v" ]; then
3573     return 1
3574   fi
3575
3576   version_match $v $2
3577   return $?
3578 }
3579
3580 check_package_version_ge_ARCH() {
3581   v=`get_package_version_ARCH $1`
3582
3583   if [ -z "$v" ]; then
3584     return 1
3585   fi
3586
3587   version_ge $v $2
3588   return $?
3589 }
3590
3591 check_package_version_ge_lt_ARCH() {
3592   v=`get_package_version_ARCH $1`
3593
3594   if [ -z "$v" ]; then
3595     return 1
3596   fi
3597
3598   version_ge_lt $v $2 $3
3599   return $?
3600 }
3601
3602 install_packages_ARCH() {
3603   if [ ! $SUDO ]; then
3604     WARNING "--no-sudo enabled, impossible to run pacman for $@, you'll have to do it yourself..."
3605   else
3606     $SUDO pacman -S --needed --noconfirm $@
3607     if [ $? -ge 1 ]; then
3608       ERROR "pacman failed to install requested packages, exiting."
3609       exit 1
3610     fi
3611   fi
3612 }
3613
3614 install_ARCH() {
3615   PRINT ""
3616   INFO "Installing dependencies for ARCH-based distribution"
3617   PRINT ""
3618   PRINT "`eval _echo "$COMMON_INFO"`"
3619   PRINT ""
3620
3621   if [ "$NO_CONFIRM" = false ]; then
3622     read -p "Do you want to continue (Y/n)?"
3623     [ "$(echo ${REPLY:=Y} | tr [:upper:] [:lower:])" != "y" ] && exit
3624   fi
3625
3626   # Check for sudo...
3627   if [ $SUDO ]; then
3628     if [ ! -x "/usr/bin/sudo" ]; then
3629       PRINT ""
3630       ERROR "This script requires sudo but it is not installed."
3631       PRINT "Please setup sudo according to:"
3632       PRINT "https://wiki.archlinux.org/index.php/Sudo"
3633       PRINT "and try again."
3634       PRINT ""
3635       exit
3636     fi
3637   fi
3638
3639   if [ ! $SUDO ]; then
3640     WARNING "--no-sudo enabled, impossible to run pacman -Sy, you'll have to do it yourself..."
3641   else
3642     $SUDO pacman -Sy
3643   fi
3644
3645   # These libs should always be available in arch official repository...
3646   OPENJPEG_DEV="openjpeg"
3647   VORBIS_DEV="libvorbis"
3648   OGG_DEV="libogg"
3649   THEORA_DEV="libtheora"
3650
3651   BASE_DEVEL="base-devel"
3652
3653   # Avoid conflicts when gcc-multilib is installed
3654   pacman -Qi gcc-multilib &>/dev/null
3655   if [ $? -eq 0 ]; then
3656     BASE_DEVEL=`pacman -Sgq base-devel | sed -e 's/^gcc$/gcc-multilib/g' | paste -s -d' '`
3657   fi
3658
3659   _packages="$BASE_DEVEL git cmake \
3660              libxi libxcursor libxrandr libxinerama glew libpng libtiff wget openal \
3661              $OPENJPEG_DEV $VORBIS_DEV $OGG_DEV $THEORA_DEV yasm sdl fftw intel-tbb \
3662              libxml2 yaml-cpp tinyxml python-requests jemalloc"
3663
3664   OPENJPEG_USE=true
3665   VORBIS_USE=true
3666   OGG_USE=true
3667   THEORA_USE=true
3668
3669   if [ "$WITH_ALL" = true ]; then
3670     _packages="$_packages libspnav"
3671   fi
3672
3673   if [ "$WITH_JACK" = true ]; then
3674     _packages="$_packages jack"
3675   fi
3676
3677   PRINT ""
3678   install_packages_ARCH $_packages
3679
3680   PRINT""
3681   SNDFILE_DEV="libsndfile"
3682   check_package_ARCH $SNDFILE_DEV
3683   if [ $? -eq 0 ]; then
3684     install_packages_ARCH $SNDFILE_DEV
3685   fi
3686
3687   PRINT ""
3688   X264_DEV="x264"
3689   check_package_version_ge_ARCH $X264_DEV $X264_VERSION_MIN
3690   if [ $? -eq 0 ]; then
3691     install_packages_ARCH $X264_DEV
3692     X264_USE=true
3693   fi
3694
3695   if [ "$WITH_ALL" = true ]; then
3696     PRINT ""
3697     XVID_DEV="xvidcore"
3698     check_package_ARCH $XVID_DEV
3699     if [ $? -eq 0 ]; then
3700       install_packages_ARCH $XVID_DEV
3701       XVID_USE=true
3702     fi
3703
3704     PRINT ""
3705     MP3LAME_DEV="lame"
3706     check_package_ARCH $MP3LAME_DEV
3707     if [ $? -eq 0 ]; then
3708       install_packages_ARCH $MP3LAME_DEV
3709       MP3LAME_USE=true
3710     fi
3711
3712     PRINT ""
3713     VPX_DEV="libvpx"
3714     check_package_version_ge_ARCH $VPX_DEV $VPX_VERSION_MIN
3715     if [ $? -eq 0 ]; then
3716       install_packages_ARCH $VPX_DEV
3717       VPX_USE=true
3718     fi
3719   fi
3720
3721
3722   PRINT ""
3723   _do_compile_python=false
3724   if [ "$PYTHON_SKIP" = true ]; then
3725     WARNING "Skipping Python installation, as requested..."
3726   elif [ "$PYTHON_FORCE_BUILD" = true ]; then
3727     INFO "Forced Python/NumPy building, as requested..."
3728     _do_compile_python=true
3729   else
3730     check_package_version_ge_ARCH python $PYTHON_VERSION_MIN
3731     if [ $? -eq 0 ]; then
3732       install_packages_ARCH python
3733       clean_Python
3734       PRINT ""
3735       if [ "$NUMPY_SKIP" = true ]; then
3736         WARNING "Skipping NumPy installation, as requested..."
3737       else
3738         check_package_version_ge_ARCH python-numpy $NUMPY_VERSION_MIN
3739         if [ $? -eq 0 ]; then
3740           install_packages_ARCH python-numpy
3741         else
3742           WARNING "Sorry, using python package but no valid numpy package available!" \
3743                   "Use --build-numpy to force building of both Python and NumPy."
3744         fi
3745       fi
3746     else
3747       _do_compile_python=true
3748     fi
3749   fi
3750
3751   if [ "$_do_compile_python" = true ]; then
3752     compile_Python
3753     PRINT ""
3754     if [ "$NUMPY_SKIP" = true ]; then
3755       WARNING "Skipping NumPy installation, as requested..."
3756     else
3757       compile_Numpy
3758     fi
3759   fi
3760
3761
3762   PRINT ""
3763   if [ "$BOOST_SKIP" = true ]; then
3764     WARNING "Skipping Boost installation, as requested..."
3765   elif [ "$BOOST_FORCE_BUILD" = true ]; then
3766     INFO "Forced Boost building, as requested..."
3767     compile_Boost
3768   else
3769     check_package_version_ge_ARCH boost $BOOST_VERSION_MIN
3770     if [ $? -eq 0 ]; then
3771       install_packages_ARCH boost
3772       clean_Boost
3773     else
3774       compile_Boost
3775     fi
3776   fi
3777
3778
3779   PRINT ""
3780   if [ "$OCIO_SKIP" = true ]; then
3781     WARNING "Skipping OpenColorIO installation, as requested..."
3782   elif [ "$OCIO_FORCE_BUILD" = true ]; then
3783     INFO "Forced OpenColorIO building, as requested..."
3784     compile_OCIO
3785   else
3786     check_package_version_ge_ARCH opencolorio $OCIO_VERSION_MIN
3787     if [ $? -eq 0 ]; then
3788       install_packages_ARCH opencolorio
3789       clean_OCIO
3790     else
3791       compile_OCIO
3792     fi
3793   fi
3794
3795
3796   PRINT ""
3797   if [ "$OPENEXR_SKIP" = true ]; then