Welcome to mirror list, hosted at ThFree Co, Russian Federation.

install_deps.sh « build_environment « build_files - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 935f37b53dac3183e0d780698e793ce5383343f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
#!/bin/bash

DISTRO=""
SRC="$HOME/src/blender-deps"
INST="/opt/lib"
CWD=$PWD

# OSL is horror for manual building even
# i would want it to be setteled for manual build first,
# and only then do it automatically
BUILD_OSL=false

# Try to link everything statically. Use this to produce protable versions of blender.
ALL_STATIC=false

THREADS=`cat /proc/cpuinfo | grep cores | uniq | sed -e "s/.*: *\(.*\)/\\1/"`
if [ -z "$THREADS" ]; then
  THREADS=1
fi

COMMON_INFO="Source code of dependencies needed to be compiled will be downloaded and extracted into '$SRC'.
Built libs of dependencies needed to be compiled will be installed into '$INST'.
Please edit \$SRC and/or \$INST variables at the begining of this script if you want to use other paths!

Number of threads for building: $THREADS.
Building OSL: $BUILD_OSL (edit \$BUILD_OSL var to change this).
All static linking: $ALL_STATIC (edit \$ALL_STATIC var to change this)."


PYTHON_VERSION="3.3.0"
PYTHON_VERSION_MIN="3.3"
PYTHON_SOURCE="http://python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.bz2"

BOOST_VERSION="1.51.0"
_boost_version_nodots=`echo "$BOOST_VERSION" | sed -r 's/\./_/g'`
BOOST_SOURCE="http://sourceforge.net/projects/boost/files/boost/$BOOST_VERSION/boost_$_boost_version_nodots.tar.bz2/download"
BOOST_VERSION_MIN="1.49"

OCIO_VERSION="1.0.7"
OCIO_SOURCE="https://github.com/imageworks/OpenColorIO/tarball/v$OCIO_VERSION"
OCIO_VERSION_MIN="1.0"

OIIO_VERSION="1.1.1"
OIIO_SOURCE="https://github.com/OpenImageIO/oiio/tarball/Release-$OIIO_VERSION"
OIIO_VERSION_MIN="1.1"

LLVM_VERSION="3.1"
LLVM_VERSION_MIN="3.0"
LLVM_VERSION_FOUND=""
LLVM_SOURCE="http://llvm.org/releases/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.gz"
LLVM_CLANG_SOURCE="http://llvm.org/releases/$LLVM_VERSION/clang-$LLVM_VERSION.src.tar.gz"

# OSL needs to be compiled for now!
OSL_VERSION="1.2.0"
OSL_SOURCE="https://github.com/mont29/OpenShadingLanguage/archive/blender-fixes.tar.gz"

FFMPEG_VERSION="1.0"
FFMPEG_SOURCE="http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2"
FFMPEG_VERSION_MIN="0.7.6"
_ffmpeg_list_sep=";"

# FFMPEG optional libs.
VORBIS_USE=false
VORBIS_DEV=""
SCHRO_USE=false
SCRHO_DEV=""
THEORA_USE=false
THEORA_DEV=""
XVID_USE=false
XVID_DEV=""
X264_USE=false
X264_DEV=""
X264_VERSION_MIN=0.118
VPX_USE=false
VPX_VERSION_MIN=0.9.7
VPX_DEV=""
MP3LAME_USE=false
MP3LAME_DEV=""
OPENJPEG_USE=false
OPENJPEG_DEV=""

# Switch to english language, else some things (like check_package_DEB()) won't work!
LANG_BACK=$LANG
LANG=""
export LANG

ERROR() {
  echo "${@}"
}

INFO() {
  echo "${@}"
}

# Return 0 if $1 = $2 (i.e. 1.01.0 = 1.1, but 1.1.1 != 1.1), else 1.
# $1 and $2 should be version numbers made of numbers only.
version_eq() {
  backIFS=$IFS
  IFS='.'

  # Split both version numbers into their numeric elements.
  arr1=( $1 )
  arr2=( $2 )

  ret=1

  count1=${#arr1[@]}
  count2=${#arr2[@]}
  if [ $count2 -ge $count1 ]; then
    _t=$count1
    count1=$count2
    count2=$_t
    arr1=( $2 )
    arr2=( $1 )
  fi

  ret=0
  for (( i=0; $i < $count2; i++ ))
  do
    if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
      ret=1
      break
    fi
  done

  for (( i=$count2; $i < $count1; i++ ))
  do
    if [ $(( 10#${arr1[$i]} )) -ne 0 ]; then
      ret=1
      break
    fi
  done

  IFS=$backIFS
  return $ret
}

# Return 0 if $1 >= $2, else 1.
# $1 and $2 should be version numbers made of numbers only.
version_ge() {
  version_eq $1 $2
  if [ $? -eq 1 -a $(echo -e "$1\n$2" | sort --version-sort | head --lines=1) = "$1" ]; then
    return 1
  else
    return 0
  fi
}

# 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.
# $1 and $2 should be version numbers made of numbers only.
# $1 should be at least as long as $2!
version_match() {
  backIFS=$IFS
  IFS='.'

  # Split both version numbers into their numeric elements.
  arr1=( $1 )
  arr2=( $2 )

  ret=1

  count1=${#arr1[@]}
  count2=${#arr2[@]}
  if [ $count1 -ge $count2 ]; then
    ret=0
    for (( i=0; $i < $count2; i++ ))
    do
      if [ $(( 10#${arr1[$i]} )) -ne $(( 10#${arr2[$i]} )) ]; then
        ret=1
        break
      fi
    done
  fi

  IFS=$backIFS
  return $ret
}

detect_distro() {
  if [ -f /etc/debian_version ]; then
    DISTRO="DEB"
  elif [ -f /etc/redhat-release ]; then
    DISTRO="RPM"
  elif [ -f /etc/SuSE-release ]; then
    DISTRO="SUSE"
  fi
}

prepare_opt() {
  INFO "Ensuring $INST exists and is writable by us"
  sudo mkdir -p $INST
  sudo chown $USER $INST
  sudo chmod 775 $INST
}

# Check whether the current package needs to be recompiled, based on a dummy file containing a magic number in its name...
magic_compile_check() {
  if [ -f $INST/.$1-magiccheck-$2 ]; then
    return 0
  else
    return 1
  fi
}

magic_compile_set() {
  rm -f $INST/.$1-magiccheck-*
  touch $INST/.$1-magiccheck-$2
}

compile_Python() {
  # To be changed each time we make edits that would modify the compiled result!
  py_magic=0

  _src=$SRC/Python-$PYTHON_VERSION
  _inst=$INST/python-$PYTHON_VERSION

  # Clean install if needed!
  magic_compile_check python-$PYTHON_VERSION $py_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building Python-$PYTHON_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      mkdir -p $SRC
      wget -c $PYTHON_SOURCE -O $_src.tar.bz2

      INFO "Unpacking Python-$PYTHON_VERSION"
      tar -C $SRC -xf $_src.tar.bz2
    fi

    cd $_src

    ./configure --prefix=$_inst --enable-ipv6 \
        --enable-loadable-sqlite-extensions --with-dbmliborder=bdb \
        --with-computed-gotos --with-pymalloc

    make -j$THREADS && make install
    make clean

    if [ -d $_inst ]; then
      rm -f $INST/python-3.3
      ln -s python-$PYTHON_VERSION $INST/python-3.3
    else
      ERROR "Python--$PYTHON_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set python-$PYTHON_VERSION $py_magic

    cd $CWD
  else
    INFO "Own Python-$PYTHON_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_Boost() {
  # To be changed each time we make edits that would modify the compiled result!
  boost_magic=7

  _src=$SRC/boost-$BOOST_VERSION
  _inst=$INST/boost-$BOOST_VERSION

  # Clean install if needed!
  magic_compile_check boost-$BOOST_VERSION $boost_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building Boost-$BOOST_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      INFO "Downloading Boost-$BOOST_VERSION"
      mkdir -p $SRC
      wget -c $BOOST_SOURCE -O $_src.tar.bz2
      tar -C $SRC --transform "s,(.*/?)boost_1_[^/]+(.*),\1boost-$BOOST_VERSION\2,x" -xf $_src.tar.bz2
    fi

    cd $_src
    if [ ! -f $_src/b2 ]; then
      ./bootstrap.sh
    fi
    ./b2 -j$THREADS -a --with-system --with-filesystem --with-thread --with-regex --with-locale --with-date_time \
         --prefix=$_inst --disable-icu boost.locale.icu=off install
    ./b2 --clean

    if [ -d $_inst ]; then
      rm -f $INST/boost
      ln -s boost-$BOOST_VERSION $INST/boost
    else
      ERROR "Boost-$BOOST_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set boost-$BOOST_VERSION $boost_magic

    cd $CWD
  else
    INFO "Own Boost-$BOOST_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_OCIO() {
  # To be changed each time we make edits that would modify the compiled result!
  ocio_magic=1

  _src=$SRC/OpenColorIO-$OCIO_VERSION
  _inst=$INST/ocio-$OCIO_VERSION

  # Clean install if needed!
  magic_compile_check ocio-$OCIO_VERSION $ocio_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building OpenColorIO-$OCIO_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      INFO "Downloading OpenColorIO-$OCIO_VERSION"
      mkdir -p $SRC
      wget -c $OCIO_SOURCE -O $_src.tar.gz

      INFO "Unpacking OpenColorIO-$OCIO_VERSION"
      tar -C $SRC --transform "s,(.*/?)imageworks-OpenColorIO[^/]*(.*),\1OpenColorIO-$OCIO_VERSION\2,x" \
          -xf $_src.tar.gz
    fi

    cd $_src
    # Always refresh the whole build!
    if [ -d build ]; then
      rm -rf build
    fi    
    mkdir build
    cd build

    if file /bin/cp | grep -q '32-bit'; then
      cflags="-fPIC -m32 -march=i686"
    else
      cflags="-fPIC"
    fi

    cmake -D CMAKE_BUILD_TYPE=Release \
          -D CMAKE_PREFIX_PATH=$_inst \
          -D CMAKE_INSTALL_PREFIX=$_inst \
          -D CMAKE_CXX_FLAGS="$cflags" \
          -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" \
          -D OCIO_BUILD_APPS=OFF \
          -D OCIO_BUILD_PYGLUE=OFF \
          ..

    make -j$THREADS && make install

    # Force linking against static libs
    rm -f $_inst/lib/*.so*

    # Additional depencencies
    cp ext/dist/lib/libtinyxml.a $_inst/lib
    cp ext/dist/lib/libyaml-cpp.a $_inst/lib

    make clean

    if [ -d $_inst ]; then
      rm -f $INST/ocio
      ln -s ocio-$OCIO_VERSION $INST/ocio
    else
      ERROR "OpenColorIO-$OCIO_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set ocio-$OCIO_VERSION $ocio_magic

    cd $CWD
  else
    INFO "Own OpenColorIO-$OCIO_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_OIIO() {
  # To be changed each time we make edits that would modify the compiled result!
  oiio_magic=6

  _src=$SRC/OpenImageIO-$OIIO_VERSION
  _inst=$INST/oiio-$OIIO_VERSION

  # Clean install if needed!
  magic_compile_check oiio-$OIIO_VERSION $oiio_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building OpenImageIO-$OIIO_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      wget -c $OIIO_SOURCE -O "$_src.tar.gz"

      INFO "Unpacking OpenImageIO-$OIIO_VERSION"
      tar -C $SRC --transform "s,(.*/?)OpenImageIO-oiio[^/]*(.*),\1OpenImageIO-$OIIO_VERSION\2,x" \
          -xf $_src.tar.gz

      cd $_src

      # XXX Ugly patching hack!
      cat << EOF | patch -p1
diff --git a/src/libutil/SHA1.cpp b/src/libutil/SHA1.cpp
index b9e6c8b..c761185 100644
--- a/src/libutil/SHA1.cpp
+++ b/src/libutil/SHA1.cpp
@@ -8,9 +8,9 @@
 
 // If compiling with MFC, you might want to add #include "StdAfx.h"
 
+#include "SHA1.h"
 #include "hash.h"
 #include "dassert.h"
-#include "SHA1.h"
 
 #ifdef SHA1_UTILITY_FUNCTIONS
 #define SHA1_MAX_FILE_BUFFER 8000
EOF

      cd $CWD

    fi

    cd $_src
    # Always refresh the whole build!
    if [ -d build ]; then
      rm -rf build
    fi    
    mkdir build
    cd build

    cmake_d="-D CMAKE_BUILD_TYPE=Release"
    cmake_d="$cmake_d -D CMAKE_PREFIX_PATH=$_inst"
    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
    cmake_d="$cmake_d -D BUILDSTATIC=ON"
    cmake_d="$cmake_d -D LINKSTATIC=ON"

    if [ -d $INST/boost ]; then
      cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
      if $ALL_STATIC; then
        cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
      fi
    fi

    # Looks like we do not need ocio in oiio for now...
#    if [ -d $INST/ocio ]; then
#      cmake_d="$cmake_d -D OCIO_PATH=$INST/ocio"
#    fi

    if file /bin/cp | grep -q '32-bit'; then
      cflags="-fPIC -m32 -march=i686"
    else
      cflags="-fPIC"
    fi

    cmake $cmake_d -D CMAKE_CXX_FLAGS="$cflags" -D CMAKE_EXE_LINKER_FLAGS="-lgcc_s -lgcc" ../src

    make -j$THREADS && make install
    make clean

    if [ -d $_inst ]; then
      rm -f $INST/oiio
      ln -s oiio-$OIIO_VERSION $INST/oiio
    else
      ERROR "OpenImageIO-$OIIO_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set oiio-$OIIO_VERSION $oiio_magic

    cd $CWD
  else
    INFO "Own OpenImageIO-$OIIO_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_LLVM() {
  # To be changed each time we make edits that would modify the compiled result!
  llvm_magic=1

  _src=$SRC/LLVM-$LLVM_VERSION
  _inst=$INST/llvm-$LLVM_VERSION
  _src_clang=$SRC/CLANG-$LLVM_VERSION

  # Clean install if needed!
  magic_compile_check llvm-$LLVM_VERSION $llvm_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
    rm -rf $_inst_clang
  fi

  if [ ! -d $_inst ]; then
    INFO "Building LLVM-$LLVM_VERSION (CLANG included!)"

    prepare_opt

    if [ ! -d $_src -o true ]; then
      wget -c $LLVM_SOURCE -O "$_src.tar.gz"
      wget -c $LLVM_CLANG_SOURCE -O "$_src_clang.tar.gz"

      INFO "Unpacking LLVM-$LLVM_VERSION"
      tar -C $SRC --transform "s,([^/]*/?)llvm-[^/]*(.*),\1LLVM-$LLVM_VERSION\2,x" \
          -xf $_src.tar.gz
      INFO "Unpacking CLANG-$LLVM_VERSION to $_src/tools/clang"
      tar -C $_src/tools \
          --transform "s,([^/]*/?)clang-[^/]*(.*),\1clang\2,x" \
          -xf $_src_clang.tar.gz

      cd $_src

      # XXX Ugly patching hack!
      cat << EOF | patch -p1
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@
 set(LLVM_VERSION_MAJOR 3)
 set(LLVM_VERSION_MINOR 1)
 
-set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}svn")
+set(PACKAGE_VERSION "\${LLVM_VERSION_MAJOR}.\${LLVM_VERSION_MINOR}")
 
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
EOF

      cd $CWD

    fi

    cd $_src

    # Always refresh the whole build!
    if [ -d build ]; then
      rm -rf build
    fi    
    mkdir build
    cd build

    cmake_d="-D CMAKE_BUILD_TYPE=Release"
    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
    cmake_d="$cmake_d -D LLVM_ENABLE_FFI=ON"

    if [ -d $_FFI_INCLUDE_DIR ]; then
      cmake_d="$cmake_d -D FFI_INCLUDE_DIR=$_FFI_INCLUDE_DIR"
    fi

    cmake $cmake_d ..

    make -j$THREADS && make install
    make clean

    if [ -d $_inst ]; then
      rm -f $INST/llvm
      ln -s llvm-$LLVM_VERSION $INST/llvm
    else
      ERROR "LLVM-$LLVM_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set llvm-$LLVM_VERSION $llvm_magic

    cd $CWD
  else
    INFO "Own LLVM-$LLVM_VERSION (CLANG included) is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_OSL() {
  # To be changed each time we make edits that would modify the compiled result!
  osl_magic=7

  _src=$SRC/OpenShadingLanguage-$OSL_VERSION
  _inst=$INST/osl-$OSL_VERSION

  # Clean install if needed!
  magic_compile_check osl-$OSL_VERSION $osl_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building OpenShadingLanguage-$OSL_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      # XXX Using git on my own repo for now, looks like archives are not updated immediately... :/
#      wget -c $OSL_SOURCE -O "$_src.tar.gz"

#      INFO "Unpacking OpenShadingLanguage-$OSL_VERSION"
#      tar -C $SRC --transform "s,(.*/?)OpenShadingLanguage-[^/]*(.*),\1OpenShadingLanguage-$OSL_VERSION\2,x" \
#          -xf $_src.tar.gz
      git clone https://github.com/mont29/OpenShadingLanguage.git $_src
      cd $_src
      git checkout blender-fixes
      cd $CWD
    fi

    cd $_src
    # XXX For now, always update from latest repo...
    git pull origin

    # Always refresh the whole build!
    if [ -d build ]; then
      rm -rf build
    fi    
    mkdir build
    cd build

    cmake_d="-D CMAKE_BUILD_TYPE=Release"
    cmake_d="$cmake_d -D CMAKE_INSTALL_PREFIX=$_inst"
    cmake_d="$cmake_d -D BUILDSTATIC=ON"
    cmake_d="$cmake_d -D BUILD_TESTING=OFF"

    if [ -d $INST/boost ]; then
      cmake_d="$cmake_d -D BOOST_ROOT=$INST/boost -D Boost_NO_SYSTEM_PATHS=ON"
      if $ALL_STATIC; then
        cmake_d="$cmake_d -D Boost_USE_STATIC_LIBS=ON"        
      fi
    fi

    if [ -d $INST/oiio ]; then
      cmake_d="$cmake_d -D OPENIMAGEIOHOME=$INST/oiio"
    fi

    if [ ! -z $LLVM_VERSION_FOUND ]; then
      cmake_d="$cmake_d -D LLVM_VERSION=$LLVM_VERSION_FOUND"
      if [ -d $INST/llvm ]; then
        cmake_d="$cmake_d -D LLVM_DIRECTORY=$INST/llvm"
        cmake_d="$cmake_d -D LLVM_STATIC=ON"
      fi
    fi

    cmake $cmake_d ../src

    make -j$THREADS && make install
    make clean

    if [ -d $_inst ]; then
      rm -f $INST/osl
      ln -s osl-$OSL_VERSION $INST/osl
    else
      ERROR "OpenShadingLanguage-$OSL_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set osl-$OSL_VERSION $osl_magic

    cd $CWD
  else
    INFO "Own OpenShadingLanguage-$OSL_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

compile_FFmpeg() {
  # To be changed each time we make edits that would modify the compiled result!
  ffmpeg_magic=3

  _src=$SRC/ffmpeg-$FFMPEG_VERSION
  _inst=$INST/ffmpeg-$FFMPEG_VERSION

  # Clean install if needed!
  magic_compile_check ffmpeg-$FFMPEG_VERSION $ffmpeg_magic
  if [ $? -eq 1 ]; then
    rm -rf $_inst
  fi

  if [ ! -d $_inst ]; then
    INFO "Building ffmpeg-$FFMPEG_VERSION"

    prepare_opt

    if [ ! -d $_src ]; then
      INFO "Downloading ffmpeg-$FFMPEG_VERSION"
      wget -c $FFMPEG_SOURCE -O "$_src.tar.bz2"

      INFO "Unpacking ffmpeg-$FFMPEG_VERSION"
      tar -C $SRC -xf $_src.tar.bz2
    fi

    cd $_src

    extra=""

    if $VORBIS_USE; then
      extra="$extra --enable-libvorbis"
    fi

    if $THEORA_USE; then
      extra="$extra --enable-libtheora"
    fi

    # XXX At least under Debian, static schro gives problem at blender linking time... :/
    if $SCHRO_USE && ! $ALL_STATIC; then
      extra="$extra --enable-libschroedinger"
    fi

    if $XVID_USE; then
      extra="$extra --enable-libxvid"
    fi

    if $X264_USE; then
      extra="$extra --enable-libx264"
    fi

    if $VPX_USE; then
      extra="$extra --enable-libvpx"
    fi

    if $MP3LAME_USE; then
      extra="$extra --enable-libmp3lame"
    fi

    if $OPENJPEG_USE; then
      extra="$extra --enable-libopenjpeg"
    fi

    ./configure --cc="gcc -Wl,--as-needed" \
        --extra-ldflags="-pthread -static-libgcc" \
        --prefix=$_inst --enable-static \
        --disable-ffplay --disable-ffserver --disable-doc \
        --enable-gray \
        --enable-avfilter --disable-vdpau \
        --disable-bzlib --disable-libgsm --disable-libspeex \
        --enable-pthreads --enable-zlib --enable-stripping --enable-runtime-cpudetect \
        --disable-vaapi  --disable-libfaac --disable-nonfree --enable-gpl \
        --disable-postproc --disable-x11grab  --disable-librtmp  --disable-libopencore-amrnb \
        --disable-libopencore-amrwb --disable-libdc1394 --disable-version3  --disable-outdev=sdl \
        --disable-outdev=alsa --disable-indev=sdl --disable-indev=alsa --disable-indev=jack \
        --disable-indev=lavfi $extra

    make -j$THREADS && make install
    make clean

    if [ -d $_inst ]; then
      rm -f $INST/ffmpeg
      ln -s ffmpeg-$FFMPEG_VERSION $INST/ffmpeg
    else
      ERROR "FFmpeg-$FFMPEG_VERSION failed to compile, exiting"
      exit 1
    fi

    magic_compile_set ffmpeg-$FFMPEG_VERSION $ffmpeg_magic

    cd $CWD
  else
    INFO "Own ffmpeg-$FFMPEG_VERSION is up to date, nothing to do!"
    INFO "If you want to force rebuild of this lib, delete the '$_src' and '$_inst' directories."
  fi
}

get_package_version_DEB() {
    dpkg-query -W -f '${Version}' $1 | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'
}

check_package_DEB() {
  r=`apt-cache policy $1 | grep -c 'Candidate:'`

  if [ $r -ge 1 ]; then
    return 0
  else
    return 1
  fi
}

check_package_version_match_DEB() {
  v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)(([0-9]+\.?)+).*/\2/'`

  if [ -z "$v" ]; then
    return 1
  fi

  version_match $v $2
  return $?
}

check_package_version_ge_DEB() {
  v=`apt-cache policy $1 | grep 'Candidate:' | sed -r 's/.*:\s*([0-9]+:)?(([0-9]+\.?)+).*/\2/'`

  if [ -z "$v" ]; then
    return 1
  fi

  version_ge $v $2
  return $?
}

install_DEB() {
  INFO ""
  INFO "Installing dependencies for DEB-based distribution"
  INFO "$COMMON_INFO"
  INFO ""

  sudo apt-get update
# XXX Why in hell? Let's let this stuff to the user's responsability!!!
#  sudo apt-get -y upgrade

  # These libs should always be available in debian/ubuntu official repository...
  OPENJPEG_DEV="libopenjpeg-dev"
  SCHRO_DEV="libschroedinger-dev"
  VORBIS_DEV="libvorbis-dev"
  THEORA_DEV="libtheora-dev"

  sudo apt-get install -y gawk cmake scons gcc g++ libjpeg-dev libpng-dev libtiff-dev \
    libfreetype6-dev libx11-dev libxi-dev wget libsqlite3-dev libbz2-dev libncurses5-dev \
    libssl-dev liblzma-dev libreadline-dev $OPENJPEG_DEV libopenexr-dev libopenal-dev \
    libglew-dev yasm $SCHRO_DEV $THEORA_DEV $VORBIS_DEV libsdl1.2-dev \
    libfftw3-dev libjack-dev python-dev patch

  OPENJPEG_USE=true
  SCHRO_USE=true
  VORBIS_USE=true
  THEORA_USE=true

  # Grmpf, debian is libxvidcore-dev and ubuntu libxvidcore4-dev!
  XVID_DEV="libxvidcore-dev"
  check_package_DEB $XVID_DEV
  if [ $? -eq 0 ]; then
    sudo apt-get install -y $XVID_DEV
    XVID_USE=true
  else
    XVID_DEV="libxvidcore4-dev"
    check_package_DEB $XVID_DEV
    if [ $? -eq 0 ]; then
      sudo apt-get install -y $XVID_DEV
      XVID_USE=true
    fi
  fi

  MP3LAME_DEV="libmp3lame-dev"
  check_package_DEB $MP3LAME_DEV
  if [ $? -eq 0 ]; then
    sudo apt-get install -y $MP3LAME_DEV
    MP3LAME_USE=true
  fi

  X264_DEV="libx264-dev"
  check_package_version_ge_DEB $X264_DEV $X264_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo apt-get install -y $X264_DEV
    X264_USE=true
  fi

  VPX_DEV="libvpx-dev"
  check_package_version_ge_DEB $VPX_DEV $VPX_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo apt-get install -y $VPX_DEV
    VPX_USE=true
  fi

  check_package_DEB libspnav-dev
  if [ $? -eq 0 ]; then
    sudo apt-get install -y libspnav-dev
  fi

  check_package_DEB python3.3-dev
  if [ $? -eq 0 ]; then
    sudo apt-get install -y python3.3-dev
  else
    compile_Python
  fi

  check_package_version_ge_DEB libboost-dev $BOOST_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo apt-get install -y libboost-dev

    boost_version=$(echo `get_package_version_DEB libboost-dev` | sed -r 's/^([0-9]+\.[0-9]+).*/\1/')

    check_package_DEB libboost-locale$boost_version-dev
    if [ $? -eq 0 ]; then
      sudo apt-get install -y libboost-locale$boost_version-dev libboost-filesystem$boost_version-dev \
                              libboost-regex$boost_version-dev libboost-system$boost_version-dev \
                              libboost-thread$boost_version-dev
    else
      compile_Boost
    fi
  else
    compile_Boost
  fi

  check_package_version_ge_DEB libopencolorio-dev $OCIO_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo apt-get install -y libopencolorio-dev
  else
    compile_OCIO
  fi

  check_package_version_ge_DEB libopenimageio-dev $OIIO_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo apt-get install -y libopenimageio-dev
  else
    compile_OIIO
  fi

  if $BUILD_OSL; then
    have_llvm=false

    check_package_DEB llvm-$LLVM_VERSION-dev
    if [ $? -eq 0 ]; then
      sudo apt-get install -y llvm-$LLVM_VERSION-dev
      have_llvm=true
      LLVM_VERSION_FOUND=$LLVM_VERSION
    else
      check_package_DEB llvm-$LLVM_VERSION_MIN-dev
      if [ $? -eq 0 ]; then
        sudo apt-get install -y llvm-$LLVM_VERSION_MIN-dev
        have_llvm=true
        LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
      fi
    fi

    if $have_llvm; then
      sudo apt-get install -y clang flex bison libtbb-dev git
      # No package currently!
      compile_OSL
    fi
  fi

#  XXX Debian features libav packages as ffmpeg, those are not really compatible with blender code currently :/
#      So for now, always build our own ffmpeg.
#  check_package_DEB ffmpeg
#  if [ $? -eq 0 ]; then
#    sudo apt-get install -y ffmpeg
#    ffmpeg_version=`get_package_version_DEB ffmpeg`
#    INFO "ffmpeg version: $ffmpeg_version"
#    if [ ! -z "$ffmpeg_version" ]; then
#      if  dpkg --compare-versions $ffmpeg_version gt 0.7.2; then
#        sudo apt-get install -y libavfilter-dev libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev libswscale-dev
#      else
#        compile_FFmpeg
#      fi
#    fi
#  fi
  compile_FFmpeg
}

get_package_version_RPM() {
  yum info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
}

check_package_RPM() {
  r=`yum info $1 | grep -c 'Summary'`

  if [ $r -ge 1 ]; then
    return 0
  else
    return 1
  fi
}

check_package_version_match_RPM() {
  v=`get_package_version_RPM $1`

  if [ -z "$v" ]; then
    return 1
  fi

  version_match $v $2
  return $?
}

check_package_version_ge_RPM() {
  v=`get_package_version_RPM $1`

  if [ -z "$v" ]; then
    return 1
  fi

  version_ge $v $2
  return $?
}

install_RPM() {
  INFO ""
  INFO "Installing dependencies for RPM-based distribution"
  INFO "$COMMON_INFO"
  INFO ""

  sudo yum -y update

  # These libs should always be available in debian/ubuntu official repository...
  OPENJPEG_DEV="openjpeg-devel"
  SCHRO_DEV="schroedinger-devel"
  VORBIS_DEV="libvorbis-devel"
  THEORA_DEV="libtheora-devel"

  sudo yum -y install gawk gcc gcc-c++ cmake scons libpng-devel libtiff-devel \
    freetype-devel libX11-devel libXi-devel wget libsqlite3x-devel ncurses-devel \
    readline-devel $OPENJPEG_DEV openexr-devel openal-soft-devel \
    glew-devel yasm $SCHRO_DEV $THEORA_DEV $VORBIS_DEV SDL-devel \
    fftw-devel lame-libs jack-audio-connection-kit-devel libspnav-devel \
    libjpeg-devel patch python-devel

  OPENJPEG_USE=true
  SCHRO_USE=true
  VORBIS_USE=true
  THEORA_USE=true

  X264_DEV="x264-devel"
  check_package_version_ge_RPM $X264_DEV $X264_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y $X264_DEV
    X264_USE=true
  fi

  XVID_DEV="xvidcore-devel"
  check_package_RPM $XVID_DEV
  if [ $? -eq 0 ]; then
    sudo yum install -y $XVID_DEV
    XVID_USE=true
  fi

  VPX_DEV="libvpx-devel"
  check_package_version_ge_RPM $VPX_DEV $VPX_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y $VPX_DEV
    VPX_USE=true
  fi

  MP3LAME_DEV="lame-devel"
  check_package_RPM $MP3LAME_DEV
  if [ $? -eq 0 ]; then
    sudo yum install -y $MP3LAME_DEV
    MP3LAME_USE=true
  fi

  check_package_version_match_RPM python3-devel $PYTHON_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y python3-devel
  else
    compile_Python
  fi

  check_package_version_ge_RPM boost-devel $BOOST_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y boost-devel
  else
    compile_Boost
  fi

  check_package_version_ge_RPM OpenColorIO-devel $OCIO_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y OpenColorIO-devel
  else
    compile_OCIO
  fi

  check_package_version_ge_RPM OpenImageIO-devel $OIIO_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo yum install -y OpenImageIO-devel
  else
    compile_OIIO
  fi

  if $BUILD_OSL; then
    have_llvm=false

    check_package_RPM llvm-$LLVM_VERSION-devel
    if [ $? -eq 0 ]; then
      sudo yum install -y llvm-$LLVM_VERSION-devel
      have_llvm=true
      LLVM_VERSION_FOUND=$LLVM_VERSION
    else
#      check_package_RPM llvm-$LLVM_VERSION_MIN-devel
#      if [ $? -eq 0 ]; then
#        sudo yum install -y llvm-$LLVM_VERSION_MIN-devel
#        have_llvm=true
#        LLVM_VERSION_FOUND=$LLVM_VERSION_MIN
#      else
#        check_package_version_ge_RPM llvm-devel $LLVM_VERSION_MIN
#        if [ $? -eq 0 ]; then
#          sudo yum install -y llvm-devel
#          have_llvm=true
#          LLVM_VERSION_FOUND=`get_package_version_RPM llvm-devel`
#        fi
#      fi
    sudo yum install -y libffi-devel
    # XXX Stupid fedora puts ffi header into a darn stupid dir!
    _FFI_INCLUDE_DIR=`rpm -ql libffi-devel | grep -e ".*/ffi.h" | sed -r 's/(.*)\/ffi.h/\1/'`
    compile_LLVM
    have_llvm=true
    LLVM_VERSION_FOUND=$LLVM_VERSION
    fi

    if $have_llvm; then
      sudo yum install -y flex bison clang tbb-devel git
      # No package currently!
      compile_OSL
    fi
  fi

  # Always for now, not sure which packages should be installed
  compile_FFmpeg
}

get_package_version_SUSE() {
  zypper info $1 | grep Version | tail -n 1 | sed -r 's/.*:\s+(([0-9]+\.?)+).*/\1/'
}

check_package_SUSE() {
  r=`zypper info $1 | grep -c 'Summary'`

  if [ $r -ge 1 ]; then
    return 0
  else
    return 1
  fi
}

check_package_version_match_SUSE() {
  v=`get_package_version_SUSE $1`

  if [ -z "$v" ]; then
    return 1
  fi

  version_match $v $2
  return $?
}

check_package_version_ge_SUSE() {
  v=`get_package_version_SUSE $1`

  if [ -z "$v" ]; then
    return 1
  fi

  version_ge $v $2
  return $?
}

install_SUSE() {
  INFO ""
  INFO "Installing dependencies for SuSE-based distribution"
  INFO "$COMMON_INFO"
  INFO ""

  sudo zypper --non-interactive update --auto-agree-with-licenses

  # These libs should always be available in debian/ubuntu official repository...
  OPENJPEG_DEV="openjpeg-devel"
  SCHRO_DEV="schroedinger-devel"
  VORBIS_DEV="libvorbis-devel"
  THEORA_DEV="libtheora-devel"

  sudo zypper --non-interactive install --auto-agree-with-licenses \
    gawk gcc gcc-c++ cmake scons libpng12-devel libtiff-devel \
    freetype-devel libX11-devel libXi-devel wget sqlite3-devel ncurses-devel \
    readline-devel $OPENJPEG_DEV libopenexr-devel openal-soft-devel \
    glew-devel yasm $SCHRO_DEV $THEORA_DEV $VORBIS_DEV libSDL-devel \
    fftw3-devel libjack-devel libspnav-devel \
    libjpeg62-devel patch python-devel

  OPENJPEG_USE=true
  SCHRO_USE=true
  VORBIS_USE=true
  THEORA_USE=true

  X264_DEV="x264-devel"
  check_package_version_ge_SUSE $X264_DEV $X264_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo zypper --non-interactive install --auto-agree-with-licenses $X264_DEV
    X264_USE=true
  fi

  XVID_DEV="xvidcore-devel"
  check_package_SUSE $XVID_DEV
  if [ $? -eq 0 ]; then
    sudo zypper --non-interactive install --auto-agree-with-licenses $XVID_DEV
    XVID_USE=true
  fi

  VPX_DEV="libvpx-devel"
  check_package_version_ge_SUSE $VPX_DEV $VPX_VERSION_MIN
  if [ $? -eq 0 ]; then
    sudo zypper --non-interactive install --auto-agree-with-licenses $VPX_DEV
    VPX_USE=true
  fi

  # No mp3 in suse, it seems.
  MP3LAME_DEV="lame-devel"
  check_package_SUSE $MP3LAME_DEV
  if [ $? -eq 0 ]; then
    sudo zypper --non-interactive install --auto-agree-with-licenses $MP3LAME_DEV
    MP3LAME_USE=true
  fi

  check_package_version_match_SUSE python3-devel 3.3.
  if [ $? -eq 0 ]; then
    sudo zypper --non-interactive install --auto-agree-with-licenses python3-devel
  else
    compile_Python
  fi

  # No boost_locale currently available, so let's build own boost.
  compile_Boost

  # No ocio currently available, so let's build own boost.
  compile_OCIO

  # No oiio currently available, so let's build own boost.
  compile_OIIO

  if $BUILD_OSL; then
    have_llvm=false

    # Suse llvm package *_$SUCKS$_* (tm) !!!
#    check_package_version_ge_SUSE llvm-devel $LLVM_VERSION_MIN
#    if [ $? -eq 0 ]; then
#      sudo zypper --non-interactive install --auto-agree-with-licenses llvm-devel
#      have_llvm=true
#      LLVM_VERSION_FOUND=`get_package_version_SUSE llvm-devel`
#    fi

    sudo zypper --non-interactive install --auto-agree-with-licenses libffi47-devel
    compile_LLVM
    have_llvm=true
    LLVM_VERSION_FOUND=$LLVM_VERSION

    if $have_llvm; then
      # XXX No tbb lib!
      sudo zypper --non-interactive install --auto-agree-with-licenses flex bison git
      # No package currently!
      compile_OSL
    fi
  fi

  # No ffmpeg currently available, so let's build own boost.
  compile_FFmpeg
}

print_info_ffmpeglink_DEB() {
  if $ALL_STATIC; then
    dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
  else
    dpkg -L $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
  fi
}

print_info_ffmpeglink_RPM() {
  if $ALL_STATIC; then
    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
  else
    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
  fi
}

print_info_ffmpeglink_SUSE() {
  if $ALL_STATIC; then
    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.a" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", $0); nlines++ }'
  else
    rpm -ql $_packages | grep -e ".*\/lib[^\/]\+\.so" | gawk '{ printf(nlines ? "'"$_ffmpeg_list_sep"'%s" : "%s", gensub(/.*lib([^\/]+)\.so/, "\\1", "g", $0)); nlines++ }'
  fi
}

print_info_ffmpeglink() {
  # This func must only print a ';'-separated list of libs...
  if [ -z "$DISTRO" ]; then
    ERROR "Failed to detect distribution type"
    exit 1
  fi

  # Create list of packages from which to get libs names...
  _packages=""

  if $THEORA_USE; then
    _packages="$_packages $THEORA_DEV"
  fi

  if $VORBIS_USE; then
    _packages="$_packages $VORBIS_DEV"
  fi

  if $XVID_USE; then
    _packages="$_packages $XVID_DEV"
  fi

  if $VPX_USE; then
    _packages="$_packages $VPX_DEV"
  fi

  if $MP3LAME_USE; then
    _packages="$_packages $MP3LAME_DEV"
  fi

  if $X264_USE; then
    _packages="$_packages $X264_DEV"
  fi

  if $OPENJPEG_USE; then
    _packages="$_packages $OPENJPEG_DEV"
  fi

  # XXX At least under Debian, static schro give problem at blender linking time... :/
  if $SCHRO_USE && ! $ALL_STATIC; then
    _packages="$_packages $SCHRO_DEV"
  fi

  if [ "$DISTRO" = "DEB" ]; then
    print_info_ffmpeglink_DEB
  elif [ "$DISTRO" = "RPM" ]; then
    print_info_ffmpeglink_RPM
  elif [ "$DISTRO" = "SUSE" ]; then
    print_info_ffmpeglink_SUSE
  # XXX TODO!
  else INFO "<Could not determine additional link libraries needed for ffmpeg, replace this by valid list of libs...>"
  fi
}

print_info() {
  INFO ""
  INFO "If you're using CMake add this to your configuration flags:"

  if $ALL_STATIC; then
    INFO "  -D WITH_STATIC_LIBS=ON"
  fi

  if [ -d $INST/boost ]; then
    INFO "  -D BOOST_ROOT=$INST/boost"
    INFO "  -D Boost_NO_SYSTEM_PATHS=ON"
  elif $ALL_STATIC; then
    INFO "  -D Boost_USE_ICU=ON"
  fi

  if [ -d $INST/osl ]; then
    INFO "  -D CYCLES_OSL=$INST/osl"
    INFO "  -D WITH_CYCLES_OSL=ON"
    INFO "  -D LLVM_VERSION=$LLVM_VERSION_FOUND"
    if [ -d $INST/llvm ]; then
      INFO "  -D LLVM_DIRECTORY=$INST/llvm"
      INFO "  -D LLVM_STATIC=ON"
    fi
  fi

  if [ -d $INST/ffmpeg ]; then
    INFO "  -D WITH_CODEC_FFMPEG=ON"
    INFO "  -D FFMPEG=$INST/ffmpeg"
    INFO "  -D FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;rt;`print_info_ffmpeglink`'"
  fi

  INFO ""
  INFO "If you're using SCons add this to your user-config:"

  if [ -d $INST/python-3.3 ]; then
    INFO "BF_PYTHON = '$INST/python-3.3'"
    INFO "BF_PYTHON_ABI_FLAGS = 'm'"
  fi

  if [ -d $INST/ocio ]; then
    INFO "BF_OCIO = '$INST/ocio'"
  fi

  if [ -d $INST/oiio ]; then
    INFO "BF_OIIO = '$INST/oiio'"
  fi

  if [ -d $INST/boost ]; then
    INFO "BF_BOOST = '$INST/boost'"
  fi

  if [ -d $INST/ffmpeg ]; then
    INFO "BF_FFMPEG = '$INST/ffmpeg'"
    _ffmpeg_list_sep=" "
    INFO "BF_FFMPEG_LIB = 'avformat avcodec swscale avutil avdevice `print_info_ffmpeglink`'"
  fi

  INFO ""
  INFO ""
  INFO "WARNING: If this script had to build boost into $INST, and you are dynamically linking "
  INFO "         blender against it, you will have to run those commands as root user:"
  INFO ""
  INFO "    echo \"$INST/boost/lib\" > /etc/ld.so.conf.d/boost.conf"
  INFO "    ldconfig"
  INFO ""
}

# Detect distributive type used on this machine
detect_distro

if [ -z "$DISTRO" ]; then
  ERROR "Failed to detect distribution type"
  exit 1
elif [ "$DISTRO" = "DEB" ]; then
  install_DEB
elif [ "$DISTRO" = "RPM" ]; then
  install_RPM
elif [ "$DISTRO" = "SUSE" ]; then
  install_SUSE
fi

print_info

# Switch back to user language.
LANG=LANG_BACK
export LANG