forked from zimbatm/ffmpeg-static
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·1173 lines (1010 loc) · 47.2 KB
/
build.py
File metadata and controls
executable file
·1173 lines (1010 loc) · 47.2 KB
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
#!/usr/bin/env python
import os
import sys
import urllib2
import tarfile
import time
import subprocess
import argparse
import multiprocessing
# check python ver 2.6+
if sys.version_info < (2, 6):
print('need python 2.6+')
sys.exit(0)
# check python ver < 3
if sys.version_info > (3, 0):
print('need python 2')
sys.exit(0)
# TODO - tidy this up/move into class
# check for git
p = subprocess.Popen('which git', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
git_check_data = p.communicate()[0]
# noinspection PyTypeChecker
if git_check_data.count('which') > 0:
print('unable to find git')
sys.exit(0)
# noinspection PyAttributeOutsideInit
class ffmpeg_build:
# TODO - check for git
# TODO - check for library file output, so we can stop build on failure
# TODO - have libraries build both shared and static?
def __init__(self, nonfree=False, cflags='', build_static=True, init_args=None):
self.nonfree = nonfree
self.cflags = cflags
self.build_static = build_static
self.args = init_args
self.web_server = 'http://www.ghosttoast.com/pub/ffmpeg'
self.cpuCount = multiprocessing.cpu_count()
# native
#self.cflags += ' -march=native -mtune=native'
#self.cflags += ' -march=corei7 -mtune=corei7'
#self.cflags += ' -march=corei7 -mtune=corei7-avx'
#self.cflags += ' -mtune=broadwell'
self.cflags += ' -mtune=corei7'
self.cflags += ' -O3'
# GCC CFLAGS
self.ENV_CFLAGS_GCC = '-mtune=corei7 -O3'
self.CUDA_SDK = '/usr/local/cuda-9.0'
self.app_list()
self.setup_folder_vars()
self.setup_env_vars()
def app_list(self):
self.downloadList = []
self.downloadAuxList = []
self.gitList = []
self.fileList = []
self.downloadListGz = []
self.fileListGz = []
self.xz = 'xz-5.2.4'
self.downloadListGz.append(self.xz)
self.yasm = 'yasm-1.3.0'
self.downloadListGz.append(self.yasm)
self.nasm = 'nasm-2.13.03'
self.downloadList.append(self.nasm)
self.downloadAuxList.append('nasm_213.patch')
self.autoconf = 'autoconf-2.69'
self.downloadList.append(self.autoconf)
self.openssl = 'openssl-1.0.2q'
self.downloadList.append(self.openssl)
self.curl = 'curl-7.62.0'
self.downloadList.append(self.curl)
self.cmake = 'cmake-3.13.0'
self.downloadList.append(self.cmake)
self.zlib = 'zlib-1.2.11'
self.downloadList.append(self.zlib)
self.bzip2 = 'bzip2-1.0.6'
self.downloadList.append(self.bzip2)
self.ncurses = 'ncurses-6.1'
self.downloadList.append(self.ncurses)
self.libpng = 'libpng-1.6.35'
self.downloadList.append(self.libpng)
#self.openjpeg = 'openjpeg-1.5.2' # ffmpeg works with 1.x, not 2.x
self.openjpeg = 'openjpeg-2.3.0'
self.downloadList.append(self.openjpeg)
self.libtiff = 'tiff-4.0.10'
self.downloadList.append(self.libtiff)
self.libogg = 'libogg-1.3.3'
self.downloadList.append(self.libogg)
self.libvorbis = 'libvorbis-1.3.6'
self.downloadList.append(self.libvorbis)
self.libtheora = 'libtheora-1.1.1'
self.downloadList.append(self.libtheora)
self.libvpx = 'libvpx-1.7.0'
self.downloadList.append(self.libvpx)
self.lame = 'lame-3.100'
self.downloadList.append(self.lame)
self.twolame = 'twolame-0.3.13'
self.downloadList.append(self.twolame)
self.soxr = 'soxr-0.1.2'
self.downloadList.append(self.soxr)
self.fdkaac = 'fdk-aac-0.1.6'
self.downloadList.append(self.fdkaac)
self.x264 = 'https://git.videolan.org/git/x264.git'
self.gitList.append(['x264', self.x264])
self.x264BitDepth = '8'
self.x264Chroma = 'all'
self.x265 = 'https://github.com/videolan/x265.git'
self.gitList.append(['x265', self.x265])
self.xvid = 'xvid-1.3.5'
self.downloadList.append(self.xvid)
self.downloadAuxList.append('xvid_Makefile.patch')
#self.nvenc = 'nvidia_video_sdk_8.0.14'
#self.downloadList.append(self.nvenc)
self.aom = 'https://aomedia.googlesource.com/aom'
self.gitList.append(['aom', self.aom])
self.opus = 'opus-1.2.1'
self.downloadList.append(self.opus)
self.expat = 'expat-2.2.6'
self.downloadList.append(self.expat)
self.gperf = 'gperf-3.1'
self.downloadList.append(self.gperf)
self.glib = 'glib-2.58.0'
self.downloadList.append(self.glib)
self.freetype = 'freetype-2.9.1'
self.downloadList.append(self.freetype)
self.fontconfig = 'fontconfig-2bd559f7'
self.downloadList.append(self.fontconfig)
self.fribidi = 'fribidi-1.0.5'
self.downloadList.append(self.fribidi)
self.libxml2 = 'libxml2-2.9.8'
self.downloadList.append(self.libxml2)
self.gcc_binutils = 'binutils-2.31.1'
self.downloadList.append(self.gcc_binutils)
self.gcc_glibc = 'glibc-2.28'
self.downloadList.append(self.gcc_glibc)
self.gcc_mpfr = 'mpfr-4.0.1'
self.downloadList.append(self.gcc_mpfr)
self.gcc_gmp = 'gmp-6.1.2'
self.downloadList.append(self.gcc_gmp)
self.gcc_mpc = 'mpc-1.1.0'
self.downloadList.append(self.gcc_mpc)
self.gcc_isl = 'isl-0.19' # isl 0.20 has broken headers
self.downloadList.append(self.gcc_isl)
self.gcc_cloog = 'cloog-0.18.4'
self.downloadList.append(self.gcc_cloog)
self.gcc_gcc = 'gcc-7.3.0'
self.gcc_gcc = 'gcc-8.2.0'
self.downloadList.append(self.gcc_gcc)
self.ffmpeg = 'git://source.ffmpeg.org/ffmpeg.git'
self.ffmpeg = 'https://bitbucket.org/jaystevens/ffmpeg.git'
self.gitList.append(['ffmpeg', self.ffmpeg])
for item in self.downloadList:
self.fileList.append('%s.tar.xz' % item)
for item in self.downloadAuxList:
self.fileList.append('%s.xz' % item)
for item in self.downloadListGz:
itemFn = '%s.tar.gz' % item
self.fileList.append(itemFn)
self.fileListGz.append(itemFn)
def setup_folder_vars(self):
self.ENV_ROOT = os.getcwd()
self.TARGET_DIR = os.path.join(self.ENV_ROOT, 'sandbox', 'sys')
self.TARGET_GCC_DIR = os.path.join(self.ENV_ROOT, 'sandbox', 'sys_gcc')
self.BUILD_DIR = os.path.join(self.ENV_ROOT, 'sandbox', 'build')
self.SRC_GIT_DIR = os.path.join(self.ENV_ROOT, 'src')
self.SRC_TAR_DIR = os.path.join(self.ENV_ROOT, 'src')
self.OUT_DIR = os.path.join(self.ENV_ROOT, 'result')
def setup_env_vars(self):
# setup ENV
self.ENV_PATH_ORIG = os.getenv('PATH')
self.ENV_LD_ORIG = os.getenv('LD_LIBRARY_PATH')
#if sys.platform.startswith('darwin'): # TODO - fix darwin vars
# addpath += ':/opt/local/bin'
# PATH
PATH_FULL = self.ENV_PATH_ORIG
# add gcc/bin to PATH
PATH_GCC_BIN = os.path.join(self.TARGET_GCC_DIR, 'bin')
PATH_FULL = '%s:%s' % (PATH_GCC_BIN, PATH_FULL)
# add sys/bin to PATH
PATH_TARGET_BIN = os.path.join(self.TARGET_DIR, 'bin')
PATH_FULL = '%s:%s' % (PATH_TARGET_BIN, PATH_FULL)
# add cuda/bin to PATH
if self.args.cuda is True:
if os.path.exists(self.CUDA_SDK):
PATH_FULL = '%s:%s' % (os.path.join(self.CUDA_SDK, 'bin'), PATH_FULL)
# export PATH
os.putenv('PATH', PATH_FULL)
# LD_LIBRARY_PATH
LD_LIB_FULL = self.ENV_LD_ORIG
# add gcc/lib to LD_LIB
PATH_GCC_LIB = os.path.join(self.TARGET_GCC_DIR, 'lib')
LD_LIB_FULL = '%s:%s' % (PATH_GCC_LIB, LD_LIB_FULL)
# add gcc/lib64 to LD_LIB
PATH_GCC_LIB64 = os.path.join(self.TARGET_GCC_DIR, 'lib64')
LD_LIB_FULL = '%s:%s' % (PATH_GCC_LIB64, LD_LIB_FULL)
# add sys/lib to LD_LIB
PATH_TARGET_LIB = os.path.join(self.TARGET_DIR, 'lib')
LD_LIB_FULL = '%s:%s' % (PATH_TARGET_LIB, LD_LIB_FULL)
# add cuda/lib to LD_LIB
if self.args.cuda is True:
if os.path.exists(self.CUDA_SDK):
LD_LIB_FULL = '%s:%s' % (os.path.join(self.CUDA_SDK, 'lib64'), LD_LIB_FULL)
os.putenv('LD_LIBRARY_PATH', LD_LIB_FULL)
# PKG CONFIG
os.putenv('PKG_CONFIG_PATH', os.path.join(self.TARGET_DIR, 'lib', 'pkgconfig'))
# CFLAG
self.ENV_CFLAGS_STD = ''
self.ENV_CFLAGS_STD += ' -I%s' % os.path.join(self.TARGET_GCC_DIR, 'include')
self.ENV_CFLAGS_STD += ' -I%s' % os.path.join(self.TARGET_DIR, 'include')
if self.args.cuda is True:
if os.path.exists(self.CUDA_SDK):
self.ENV_CFLAGS_STD += ' -I%s' % os.path.join(self.CUDA_SDK, 'include')
self.ENV_CFLAGS_STD += ' %s' % self.cflags
self.ENV_CFLAGS_STD = self.ENV_CFLAGS_STD.strip()
self.ENV_CFLAGS = self.ENV_CFLAGS_STD
os.putenv('CFLAGS', self.ENV_CFLAGS)
os.putenv('CPPFLAGS', self.ENV_CFLAGS)
os.putenv('CXXFLAGS', self.ENV_CFLAGS)
# LDFLAGS
self.ENV_LDFLAGS_STD = ''
self.ENV_LDFLAGS_STD += ' -L%s' % os.path.join(self.TARGET_GCC_DIR, 'lib')
self.ENV_LDFLAGS_STD += ' -L%s' % os.path.join(self.TARGET_GCC_DIR, 'lib64')
self.ENV_LDFLAGS_STD += ' -L%s' % os.path.join(self.TARGET_DIR, 'lib')
if self.args.cuda is True:
if os.path.exists(self.CUDA_SDK):
self.ENV_LDFLAGS_STD += ' -L%s' % os.path.join(self.CUDA_SDK, 'lib64')
self.ENV_LDFLAGS_STD = self.ENV_LDFLAGS_STD.strip()
self.ENV_LDFLAGS = self.ENV_LDFLAGS_STD
if self.build_static is True:
self.ENV_LDFLAGS += ''
self.ENV_LDFLAGS += ' -static'
#self.ENV_LDFLAGS += ' -static-libgcc -static-libstdc++'
os.putenv('LDFLAGS', self.ENV_LDFLAGS)
# EXPORT
os.system('hash -r')
os.system('export')
def cflags_reset(self):
print('\nResetting CFLAGS\n')
print('CFLAGS: {}'.format(self.ENV_CFLAGS))
os.putenv('CFLAGS', self.ENV_CFLAGS)
os.putenv('CPPFLAGS', self.ENV_CFLAGS)
os.putenv('CXXFLAGS', self.ENV_CFLAGS)
os.system('hash -r')
def cflags_reset_gcc(self):
print('\nResetting CFLAGS for gcc build\n')
print('CFLAGS: {}'.format(self.ENV_CFLAGS))
os.putenv('CFLAGS', self.ENV_CFLAGS_GCC)
os.putenv('CPPFLAGS', self.ENV_CFLAGS_GCC)
os.putenv('CXXFLAGS', self.ENV_CFLAGS_GCC)
os.system('hash -r')
def flags_cmake_gcc(self):
gcc_path = os.path.join(self.TARGET_GCC_DIR, 'bin', 'gcc')
gxx_path = os.path.join(self.TARGET_GCC_DIR, 'bin', 'g++')
if os.path.exists(gcc_path):
print('\nCC: {}\n'.format(gcc_path))
os.putenv('CC', gcc_path)
os.putenv('CMAKE_C_COMPILER', gcc_path)
if os.path.exists(gxx_path):
print('\nCXX: {}\n'.format(gxx_path))
os.putenv('CMAKE_CXX_COMPILER', gxx_path)
os.putenv('CXX', gxx_path)
os.system('hash -r')
@staticmethod
def cflags_clear():
print('\nClearing CFLAGS\n')
os.putenv('CFLAGS', '')
os.putenv('CPPFLAGS', '')
os.putenv('CXXFLAGS', '')
os.system('hash -r')
def setupDIR(self):
for item in [self.ENV_ROOT, self.TARGET_DIR, self.BUILD_DIR, self.SRC_GIT_DIR, self.SRC_TAR_DIR, self.OUT_DIR, self.TARGET_GCC_DIR]:
os.system('mkdir -p %s' % item)
old_dir = os.getcwd()
os.chdir(self.TARGET_DIR)
os.system('mkdir -p lib')
os.system('ln -s lib lib64')
os.chdir(old_dir)
def cleanTARGET_DIR(self):
os.system('rm -rf %s' % self.TARGET_DIR)
def cleanBUILD_DIR(self):
os.system('rm -rf %s' % self.BUILD_DIR)
def cleanBUILDGIT_DIR(self):
os.system('rm -rf %s' % self.SRC_GIT_DIR)
def cleanTAR_DIR(self):
os.system('rm -rf %s' % self.SRC_TAR_DIR)
def cleanOUT_DIR(self):
os.system('rm -rf %s' % self.OUT_DIR)
def cleanOUT_DIR_FILES(self):
os.system('rm -f %s.tar' % self.OUT_DIR)
os.system('rm -f %s.tar.xz' % self.OUT_DIR)
def cleanGCC_DIR(self):
os.system('rm -rf %s' % self.TARGET_GCC_DIR)
def cleanALL(self):
self.cleanTARGET_DIR()
self.cleanBUILD_DIR()
self.cleanTAR_DIR()
self.cleanOUT_DIR()
self.cleanOUT_DIR_FILES()
#self.cleanGCC_DIR()
@staticmethod
def prewarn():
print('\nneeded packages:\ngcc git glibc-static (libstdc++-static on some os-es)\n\n')
x = 2
while x > 0:
print(x)
x = x - 1
time.sleep(1)
# noinspection PyBroadException
def f_getfiles(self):
print('\n*** Downloading files ***\n')
os.chdir(self.SRC_TAR_DIR)
for fileName in self.fileList:
fileNamePre, fileNameExt = os.path.splitext(fileName)
if os.path.exists(os.path.join(self.SRC_TAR_DIR, fileName.rstrip('.%s' % fileNameExt))) is False:
try:
print('%s/%s' % (self.web_server, fileName))
response = urllib2.urlopen('%s/%s' % (self.web_server, fileName))
f_data = response.read()
except urllib2.HTTPError as e:
print('error downloading %s/%s %s' % (self.web_server, fileName, e))
sys.exit(1)
try:
f = open(fileName, 'wb')
f.write(f_data)
f.close()
except:
print('error writing downloaded data to file: {}'.format(fileName))
sys.exit(1)
else:
print('%s already downloaded' % fileName.rstrip('.%s' % fileNameExt))
self.f_sync()
def f_decompressfiles_gz(self):
print('\n*** Decompressing gz files ***\n')
os.chdir(self.BUILD_DIR)
for fileName in self.fileListGz:
if os.path.exists(os.path.join(self.SRC_TAR_DIR, fileName.rstrip('.gz'))) is False:
os.system('gunzip -v %s' % os.path.join(self.SRC_TAR_DIR, fileName))
else:
print('%s already uncompressed' % fileName)
self.f_sync()
def f_decompressfiles_xz(self):
print('\n*** Decompressing xz files ***\n')
os.chdir(self.BUILD_DIR)
for fileName in self.fileList:
if fileName.endswith('.xz'):
if os.path.exists(os.path.join(self.SRC_TAR_DIR, fileName.rstrip('.xz'))) is False:
os.system('%s -dv %s' % (os.path.join(self.TARGET_DIR, 'bin', 'xz'), os.path.join(self.SRC_TAR_DIR, fileName)))
else:
print('%s already uncompressed' % fileName)
self.f_sync()
def f_repo_clone(self):
# clone git repos
for item in self.gitList:
self.git_clone(item[0], item[1])
self.f_sync()
# noinspection PyPep8Naming
def f_extractfiles(self, gzipMode=False):
print('\n*** Extracting tar files ***\n')
os.chdir(self.BUILD_DIR)
if gzipMode is True:
fileList = self.fileListGz
else:
fileList = self.fileList
for fileName in fileList:
fileNamePre, fileNameExt = os.path.splitext(fileName)
if fileNamePre.lower().endswith('.tar'):
print(fileNamePre)
tar = tarfile.open(os.path.join(self.SRC_TAR_DIR, fileNamePre))
tar.extractall()
tar.close()
def f_repo_deploy(self):
for item in self.gitList:
self.git_deploy(item[0])
self.f_sync()
def git_clone(self, name, url):
print('\n*** Cloning %s ***\n' % name)
if os.path.exists(os.path.join(self.SRC_GIT_DIR, name)):
print('git pull')
os.chdir(os.path.join(self.SRC_GIT_DIR, name))
os.system('git pull')
else:
print('git clone')
os.chdir(self.SRC_GIT_DIR)
os.system('git clone %s' % url)
def git_deploy(self, name):
print('\n*** Deploy %s git to BUILD_DIR ***\n' % name)
os.chdir(self.SRC_GIT_DIR)
os.system('cp -rf ./%s %s' % (name, self.BUILD_DIR))
@staticmethod
def f_sync():
print('\n*** Syncinig Hard Drive ***\n')
os.system('sync')
def check_lib(self, lib_name, lib_display):
if self.build_static is True:
lib_ext = 'a'
else:
lib_ext = 'so'
check_lib_path = os.path.join(self.TARGET_DIR, 'lib', '{}.{}'.format(lib_name, lib_ext))
if not os.path.exists(check_lib_path):
print('\n{} LIBRARY BUILD FAILED'.format(lib_display))
print('lib path: {}'.format(check_lib_path))
sys.exit(1)
def check_bin(self, bin_name):
check_bin_path = os.path.join(self.TARGET_DIR, 'bin', bin_name)
if not os.path.exists(check_bin_path):
print('\n{} BINARY BUILD FAILED'.format(bin_name))
print('bin path: {}'.format(check_bin_path))
sys.exit(1)
def build_gcc_binutils(self):
print('\n*** Building gcc binutils ***\n')
self.cflags_reset_gcc()
os.chdir(os.path.join(self.BUILD_DIR, self.gcc_binutils))
os.system('./configure --prefix=%s' % self.TARGET_GCC_DIR)
os.system('make -j %s && make install' % self.cpuCount)
def build_gcc(self):
print('\n*** Building gcc ***\n')
self.cflags_reset_gcc()
os.chdir(os.path.join(self.BUILD_DIR, self.gcc_gcc))
os.system('ln -sf %s mpfr' % (os.path.join(self.BUILD_DIR, self.gcc_mpfr)))
os.system('ln -sf %s gmp' % (os.path.join(self.BUILD_DIR, self.gcc_gmp)))
os.system('ln -sf %s mpc' % (os.path.join(self.BUILD_DIR, self.gcc_mpc)))
os.system('ln -sf %s isl' % (os.path.join(self.BUILD_DIR, self.gcc_isl)))
os.system('ln -sf %s cloog' % (os.path.join(self.BUILD_DIR, self.gcc_cloog)))
os.system('mkdir builddir')
os.chdir(os.path.join(self.BUILD_DIR, self.gcc_gcc, 'builddir'))
os.system('../configure --prefix=%s --enable-languages=c,c++,fortran --disable-multilib' % self.TARGET_GCC_DIR)
os.system('make -j %s && make install' % self.cpuCount)
def build_yasm(self, build_new_gcc=False):
print('\n*** Building yasm ***\n')
if build_new_gcc is False:
# this is build before gcc so use "basic" CFLAGS
self.cflags_reset_gcc()
else:
print('\n*** REBUILDING with new GCC ***\n')
self.cflags_reset()
os.chdir(os.path.join(self.BUILD_DIR, self.yasm))
os.system('./configure --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libyasm', 'YASM')
self.check_bin('yasm')
def build_xz(self, build_new_gcc=False):
print('\n*** Building xz/liblzma ***\n')
if build_new_gcc is False:
# this is build before gcc so use "basic" CFLAGS
self.cflags_reset_gcc()
else:
print('\n*** REBUILDING with new GCC ***\n')
self.cflags_reset()
os.chdir(os.path.join(self.BUILD_DIR, self.xz))
os.system('./configure --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('liblzma', 'XZ/LZMA')
self.check_bin('xz')
def build_curl(self):
print('\n*** Building curl ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.curl))
os.system('./configure --prefix=%s --enable-shared=no --enable-static=yes' % (self.TARGET_DIR))
os.system('make -j %s && make install' % self.cpuCount)
self.check_bin('curl')
self.check_lib('libcurl', 'CURL')
def build_autoconf(self):
print('\n*** Building autoconf ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.autoconf))
os.system('./configure --prefix=%s' % (self.TARGET_DIR))
os.system('make -j %s && make install' % self.cpuCount)
self.check_bin('autoconf')
def build_cmake(self):
print('\n*** Building cmake ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.cmake))
os.putenv('LDFLAGS', self.ENV_LDFLAGS_STD)
os.system('./configure --prefix=%s --parallel=%s' % (self.TARGET_DIR, self.cpuCount))
os.system('make -j %s && make install' % self.cpuCount)
os.putenv('LDFLAGS', self.ENV_LDFLAGS)
self.check_bin('cmake')
def build_zlib(self):
print('\n*** Building zlib ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.zlib))
cfgcmd = 'export CFLAGS="$CFLAGS -fPIC";./configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --static'
os.system(cfgcmd)
os.system('export CFLAGS="$CFLAGS -fPIC";make -j %s && make install' % self.cpuCount)
self.check_lib('libz', 'ZLIB')
def build_bzip2(self):
print('\n*** Building bzip2 ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.bzip2))
os.system('make CFLAGS="-Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64 -fPIC"')
os.system('make install PREFIX=%s' % self.TARGET_DIR)
self.check_lib('libbz2', 'BZIP2')
def build_ncurses(self):
print('\n*** Building ncurses ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.ncurses))
os.system('./configure --with-termlib --with-ticlib --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libncurses', 'NCURSES')
def build_nasm(self):
print('\n*** Building nasm ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.nasm))
# apply patch for 2.13 pure bullshit
os.system('cp -f %s ./' % os.path.join(self.SRC_TAR_DIR, 'nasm_213.patch'))
os.system('patch -f -p0 < nasm_213.patch')
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_bin('nasm')
def build_openssl(self):
print('\n*** Building openssl ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.openssl))
cfgcmd = './Configure --prefix=%s linux-x86_64' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' no-shared'
else:
cfgcmd += ' shared'
os.system(cfgcmd)
os.system('make depend')
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libssl', 'OPENSSL')
def build_libpng(self):
print('\n*** Building libpng ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libpng))
os.system('./configure --prefix={0}'.format(self.TARGET_DIR))
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libpng', 'LIBPNG')
def build_openjpeg(self):
print('\n*** Building openjpeg ***\n')
print('OPENJPEG 2.x is still a work in progress')
return
os.chdir(os.path.join(self.BUILD_DIR, self.openjpeg))
# v1
#os.system('./bootstrap.sh')
#os.system('./configure --disable-png --prefix=%s' % self.TARGET_DIR)
#os.system('make -j %s && make install' % self.cpuCount)
# v2
os.system('mkdir build')
os.chdir(os.path.join(self.BUILD_DIR, self.openjpeg, 'build'))
os.system('cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 -DBUILD_CODEC=1 -DCMAKE_INSTALL_PREFIX:PATH=%s' % self.TARGET_DIR)
os.system('make install')
self.check_lib('libopenjp2', 'OPENJPEG')
def build_libtiff(self):
# TODO 2017-10-27 is this needed to build ffmpeg?
print('\n*** Building libtiff ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libtiff))
if self.build_static is True:
os.system('export CFLAGS="--static -I%s";export LDFLAGS="-L%s -static -static-libgcc";./configure --prefix=%s --enable-shared=no --enable-static=yes' % (os.path.join(self.TARGET_DIR, 'include'), os.path.join(self.TARGET_DIR, 'lib'), self.TARGET_DIR))
os.system('export CFLAGS="--static -I%s";export LDFLAGS="-L%s -static -static-libgcc";make -j %s && make install' % (os.path.join(self.TARGET_DIR, 'include'), os.path.join(self.TARGET_DIR, 'lib'), self.cpuCount))
else:
os.system('export CFLAGS="-I%s";export LDFLAGS="-L%s";./configure --prefix=%s --enable-shared=yes --enable-static=no' % (os.path.join(self.TARGET_DIR, 'include'), os.path.join(self.TARGET_DIR, 'lib'), self.TARGET_DIR))
os.system('export CFLAGS="-I%s";export LDFLAGS="-L%s";make -j %s && make install' % (os.path.join(self.TARGET_DIR, 'include'), os.path.join(self.TARGET_DIR, 'lib'), self.cpuCount))
self.check_lib('libtiff', 'LIBTIFF')
def build_libogg(self):
print('\n*** Building libogg ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libogg))
os.system('./configure --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libogg', 'LIBOGG')
def build_libvorbis(self):
print('\n*** Building libvorbis ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libvorbis))
os.system('./configure --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libvorbis', 'LIBVORBIS')
def build_libtheora(self):
print('\n*** Building libtheora ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libtheora))
cfgcmd = './configure --prefix=%s --disable-examples' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --enable-static --disable-shared'
else:
cfgcmd += ' --disable-static'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libtheora', 'LIBTHEORA')
def build_libvpx(self):
print('\n*** Building libvpx ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libvpx))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --enable-static --disable-shared'
else:
cfgcmd += ' --disable-static --enable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libvpx', 'LIBVPX')
def build_lame(self):
print('\n*** Building lame ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.lame))
cfgcmd = './configure --disable-frontend --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --enable-shared=no --enable-static=yes'
else:
cfgcmd += ' --enable-shared=yes --enable-static=no'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libmp3lame', 'LAME/MP3')
def build_twolame(self):
print('\n*** Building twolame ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.twolame))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libtwolame', 'TWOLAME/MP2')
def build_soxr(self):
print('\n*** Building soxr ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.soxr))
os.system('mkdir Release')
os.chdir(os.path.join(self.BUILD_DIR, self.soxr, 'Release'))
b_cmd = 'cmake'
b_cmd +=' -DCMAKE_BUILD_TYPE=Release'
b_cmd +=' -Wno-dev'
b_cmd +=' -DCMAKE_INSTALL_PREFIX="%s"' % self.TARGET_DIR
b_cmd +=' -DHAVE_WORDS_BIGENDIAN_EXITCODE=0'
b_cmd +=' -DWITH_OPENMP=0' # openMP?
b_cmd +=' -DBUILD_TESTS=0'
b_cmd +=' -DBUILD_EXAMPLES=0'
if self.build_static is True:
b_cmd +=' -DBUILD_SHARED_LIBS=0'
b_cmd +=' ..'
print('b_cmd: {}'.format(b_cmd))
os.system(b_cmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libsoxr', 'SOXR')
def build_fdkaac(self):
print('\n*** Building fdk-aac ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.fdkaac))
os.system('./autogen.sh')
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
# TODO - 2017-10-27 add lib check
def build_x264(self):
print('\n*** Building x264 ***\n')
os.chdir(os.path.join(self.BUILD_DIR, 'x264')) # for git checkout
cfgcmd = './configure --prefix=%s --enable-static --disable-cli --disable-opencl --disable-swscale --disable-lavf --disable-ffms --disable-gpac --bit-depth=%s --chroma-format=%s' % (self.TARGET_DIR, self.x264BitDepth, self.x264Chroma)
if self.build_static is True:
cfgcmd += ' --enable-static'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libx264', 'X264')
def build_x265(self):
print('\n*** Build x265 ***\n')
os.chdir(os.path.join(self.BUILD_DIR, 'x265', 'build', 'linux')) # for git checkout
if self.build_static is True:
os.system('cmake -G "Unix Makefiles" -Wno-dev -DCMAKE_INSTALL_PREFIX="%s" -DENABLE_SHARED:bool=off ../../source' % self.TARGET_DIR)
else:
os.system('cmake -G "Unix Makefiles" -Wno-dev -DCMAKE_INSTALL_PREFIX="%s" ../../source' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libx265', 'X265')
def build_aom(self):
print('\n*** Build aom ***\n')
aom_src_folder = os.path.join(self.BUILD_DIR, 'aom')
os.chdir(aom_src_folder)
cmake_bin = os.path.join(self.TARGET_DIR, 'bin', 'cmake')
build_folder = os.path.join(self.BUILD_DIR, 'aom', 'aom_build')
if os.path.exists(build_folder):
os.system('rm -rf {}'.format(build_folder))
if not os.path.exists(build_folder):
os.makedirs(build_folder)
os.chdir(build_folder)
if self.build_static is True:
cmake_static_opt = '-DENABLE_STATIC_RUNTIME=1'
else:
cmake_static_opt = ''
cmake_cmd = '{} -G"Unix Makefiles" {} {} -DCMAKE_INSTALL_PREFIX={} -DAOM_TARGET_CPU=x86_64'.format(
cmake_bin, aom_src_folder, cmake_static_opt, self.TARGET_DIR)
os.system(cmake_cmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libaom', 'AOM (AV1)')
def build_xvid(self):
print('\n*** Building xvid ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.xvid, 'build', 'generic'))
if self.build_static is True:
# apply patch for static only build
os.system('cp -f %s ./' % os.path.join(self.SRC_TAR_DIR, 'xvid_Makefile.patch'))
os.system('patch -f < xvid_Makefile.patch')
os.system('./configure --prefix=%s' % self.TARGET_DIR)
os.system('make -j %s && make install' % self.cpuCount)
#os.system('rm -f %s' % os.path.join(TARGET_DIR, 'lib', 'libxvidcore.so.*'))
self.check_lib('libxvidcore', 'XVID')
#def build_nvenc(self):
# # TODO - 2017-10-27 is this still needed to build ffmpeg?
# print('\n*** Deploying nvenc (Nvidia Video SDK) ***\n')
# os.chdir(os.path.join(self.BUILD_DIR, self.nvenc, 'Samples', 'common', 'inc'))
# os.system('cp -f ./nvEncodeAPI.h %s' % os.path.join(self.TARGET_DIR, 'include'))
def build_opus(self):
print('\n*** Building opus ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.opus))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libopus', 'OPUS')
def build_expat(self):
print('\n*** Building expat ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.expat))
cfgcmd = './configure --without-docbook --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' '
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libexpat', 'EXPAT')
def build_gperf(self):
print('\n*** Building gperf ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.gperf))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' '
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
# TODO - 2017-10-27 add check output [check_lib/check_bin]
def build_glib(self):
print('\n*** Building glib ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.glib))
if not os.path.exists(os.path.join(self.BUILD_DIR, self.glib, 'configure')):
os.system('./autogen.sh')
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
cfgcmd += ' --enable-libmount=no'
cfgcmd += ' --with-pcre=internal'
if self.build_static is True:
cfgcmd += ' --enable-shared=no'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libglib-2.0', 'GLIB')
def build_freetype(self):
print('\n*** Building freetype ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.freetype))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
# harfbuzz is a bitch to compile
cfgcmd += ' --with-harfbuzz=no'
if self.build_static is True:
cfgcmd += ' --enable-shared=no'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libfreetype', 'FREETYPE')
def build_fontconfig(self):
print('\n*** Building fontconfig ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.fontconfig))
if not os.path.exists(os.path.join(self.BUILD_DIR, self.fontconfig, 'configure')):
os.system('./autogen.sh')
cfgcmd = './configure --disable-docs --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libfontconfig', 'FONTCONFIG')
def build_fribidi(self):
print('\n*** Building fribidi ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.fribidi))
if not os.path.exists(os.path.join(self.BUILD_DIR, self.fribidi, 'configure')):
os.system('./autogen.sh')
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -C lib -j %s && make -C lib install' % self.cpuCount)
self.check_lib('libfribidi', 'FRIBIDI')
def build_cuda(self):
print('\n*** Setup cuda ***\n')
# libcuda.so fix
CUDA_SO = '/usr/lib64/nvidia/libcuda.so'
CUDA_SO1 = '/usr/lib64/nvidia/libcuda.so.1'
if os.path.exists(CUDA_SO):
os.system('ln -s {} {}'.format(CUDA_SO, os.path.join(self.TARGET_DIR, 'lib')))
if os.path.exists(CUDA_SO1):
os.system('ln -s {} {}'.format(CUDA_SO1, os.path.join(self.TARGET_DIR, 'lib64')))
def build_libxml2(self):
print('\n*** Building libxml2 ***\n')
os.chdir(os.path.join(self.BUILD_DIR, self.libxml2))
cfgcmd = './configure --prefix=%s' % self.TARGET_DIR
if self.build_static is True:
cfgcmd += ' --disable-shared'
os.system(cfgcmd)
os.system('make -j %s && make install' % self.cpuCount)
self.check_lib('libxml2', 'LIBXML2')
def build_ffmpeg(self):
print('\n*** Building ffmpeg ***\n')
os.chdir(os.path.join(self.BUILD_DIR, 'ffmpeg'))
os.system('git clean -fdx')
os.system('git checkout jason')
self.cflags_reset()
self.flags_cmake_gcc()
# modify env
ENV_CFLAGS_FF = self.ENV_CFLAGS
if self.build_static is True:
ENV_CFLAGS_FF += ' --static'
if self.args.taco is True:
ENV_CFLAGS_FF = ENV_CFLAGS_FF.replace(' --static ', ' ') # disable static for taco build
os.putenv('CFLAGS', ENV_CFLAGS_FF)
os.putenv('CPPFLAGS', ENV_CFLAGS_FF)
os.putenv('CXXFLAGS', ENV_CFLAGS_FF)
ENV_LDFLAGS_FF = self.ENV_LDFLAGS
ENV_LDFLAGS_FF += ' -fopenmp -lm' # openmp is needed by soxr [this should be removeable 2017-10-25]
# CUDA can not be LD static, it needs runtime linking :(
if (self.args.cuda is True) or (self.args.taco is True):
ENV_LDFLAGS_FF = ENV_LDFLAGS_FF.replace(' -static ', ' ')
os.putenv('LDFLAGS', ENV_LDFLAGS_FF)
os.putenv('LDLIBFLAGS', '-fopenmp -lm')
os.system('hash -r')
os.system('export')
confcmd = './configure'
confcmd += ' --prefix=%s' % self.TARGET_DIR
confcmd += ' --extra-version=static'
if self.build_static is True:
confcmd += ' --pkg-config-flags="--static"'
confcmd += ' --enable-gpl'
confcmd += ' --enable-version3'
if self.nonfree:
confcmd += ' --enable-nonfree'
if self.build_static is True:
confcmd += ' --enable-static'
confcmd += ' --disable-shared'
else:
confcmd += ' --disable-static'
confcmd += ' --enable-static'
#confcmd += ' --disable-debug' # disable debugging
confcmd += ' --enable-runtime-cpudetect' # should be on all the time
confcmd += ' --disable-doc' # disable building doc
confcmd += ' --disable-ffplay' # do not compile ffplay
#confcmd += ' --disable-ffserver' # do not compile ffserver
confcmd += ' --enable-bzlib' # bz2
confcmd += ' --enable-zlib' # zlib
confcmd += ' --enable-lzma' # lzma (xz)
#confcmd += ' --enable-libmp3lame' # AUDIO - mp3
#confcmd += ' --enable-libopenjpeg' # VIDEO - jpeg2000 # v2 WIP
confcmd += ' --enable-libopus' # AUDIO - opus
#confcmd += ' --enable-libvorbis' # - vorbis
#confcmd += ' --enable-libtheora' # - theora
confcmd += ' --enable-libvpx' # VIDEO - VP8/VP9
confcmd += ' --enable-libx264' # VIDEO - H264
confcmd += ' --enable-libx265' # VIDEO - H265/HEVC
confcmd += ' --enable-libaom' # VIDEO - AV1
confcmd += ' --enable-libsoxr' # AUDIO - RESMAPLE
confcmd += ' --enable-libtwolame' # AUDIO - MP2
#confcmd += ' --enable-libfreetype' # VF - fonts/drawtext
#confcmd += ' --enable-libfontconfig' # VF - fonts/drawtext
#confcmd += ' --enable-libfribidi' # VF - fonts/drawtext
# confcmd += ' --enable-zimg' # VF - resize zscale
# confcmd += ' --enable-libbluray' # FORMAT- reading bluray
# confcmd += ' --disable-devices' #
confcmd += ' --enable-hardcoded-tables' # Hardcoded tables - speeds up start a little
confcmd += ' --enable-avresample' # FILTER- RESAMPLE
confcmd += ' --disable-cuvid' # nVidia Cuvid Decoder - Broken/bad - nonfree
#confcmd += ' --enable-nvenc' # nVidia NVENC h264/h265 encoder
confcmd += ' --disable-nvenc' # nVidia NVENC - seg faults on linux
#confcmd += ' --enable-opencl' # OpenCL is used for some filters [no-encode/decode support]
if self.args.taco is True:
confcmd += ' --enable-mainconcept'
confcmd += ' --extra-ldflags="-L/myproj/mainconcept/lib"'
confcmd += ' --extra-cflags="-I/myproj/FFmpeg/mainconcept/include"'
#confcmd += ' --extra-cflags="{}"'.format(ENV_CFLAGS_NEW)
confcmd += ' --extra-ldlibflags="-lm"' # this fixes 3rd party libs