-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·1067 lines (810 loc) · 32 KB
/
build.py
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 python3
import subprocess
import shutil
import os
import multiprocessing
import argparse
import glob
import re
from contextlib import AbstractContextManager
from typing import Dict
quiet = False
verbose = False
def nproc() -> int:
return multiprocessing.cpu_count()
def get_top() -> str:
return os.path.abspath(os.path.dirname(__file__))
def get_install_dir() -> str:
return f'{get_top()}/install'
def get_inc_dir() -> str:
return f'{get_install_dir()}/include'
def get_lib_dir() -> str:
return f'{get_install_dir()}/lib'
def get_pkgconf_dir() -> str:
return f'{get_lib_dir()}/pkgconfig'
def get_global_subs() -> dict:
return {
'INSTALLDIR': f'{get_install_dir()}',
'INCDIR': f'{get_install_dir()}/include',
'LIBDIR': f'{get_lib_dir()}',
'VERSION_SCRIPT': f'-Wl,--version-script={get_top()}/version_script.txt'
}
def get_global_env() -> dict:
return {
'CC': 'gcc',
'CXX': 'g++',
'PKG_CONFIG': 'pkg-config --static',
'PATH': f'{get_install_dir()}/bin:{os.getenv("PATH")}',
'PKG_CONFIG_PATH': f'{get_lib_dir()}/pkgconfig',
'HOME': f'{os.getenv("HOME")}'
}
def download_and_extract(url: str, type: str, path: str) -> bool:
r = subprocess.run(['curl', '-L', '-o', f'download-1.{type}', url])
if r.returncode != 0:
os.unlink(f'download-1.{type}')
return False
with WorkDir(f'{get_top()}/repos'):
if type == 'tar.gz' or type == 'tar' or type == 'tar.bz2' or type == 'tgz':
os.mkdir(path)
r = subprocess.run(['tar', '--verbose', '--strip-components=1', '-xf', f'../download-1.{type}', '-C', path])
elif type == 'zip':
r = subprocess.run(['unzip', f'../download-1.{type}', '-d', path])
else:
assert False
os.unlink(f'download-1.{type}')
return r.returncode == 0
def add_pc_lib(pc: str, libs: list[str]) -> bool:
"""
Hack to add libs to a .pc pkg config file
Parameters
----------
pc: str
Path to the pkg config file
libs: list[str]
Libs to add, including the -l part. These are just flags
Returns
-------
True if ok
"""
subst = ' '.join(libs)
l = []
with open(pc, 'r') as fp:
l = fp.readlines()
for i in range(0,len(l)):
if l[i].startswith('Libs:') and not l[i].endswith(subst):
l[i] = f'{l[i].strip()} {subst}\n'
# Write it out
with open(pc, 'w') as fp:
fp.writelines(l)
return True
class WorkDir(AbstractContextManager):
def __init__(self, dir: str) -> None:
self.dir = dir
def __enter__(self):
self.saved = os.getcwd()
os.chdir(self.dir)
return self
def __exit__(self, __exc_type, __exc_value, __traceback) -> bool | None:
os.chdir(self.saved)
class Dependency:
"""
Base for all dependencies
"""
def download(self) -> bool:
"""
Called if the directory returned by get_directory() does not exist
Returns
-------
True if download + extract succeeded
"""
return False
def configure(self) -> bool:
"""
Configures the build
Returns
-------
True if configure succeeded
"""
raise NotImplementedError
def build(self) -> bool:
"""
Runs the build
This is where you'll run ninja, make, etc.
Returns
-------
True if build passed
"""
raise NotImplementedError
def get_artifacts(self) -> list[str]:
"""
Returns a list of artifacts, relative to the install/lib folder.
For release artifacts, the SONAME property of the specified library is read and used. So, you may
specify libcairo.so, but libcairo.so.2 will end up in bin/linux64.
For the engine repo zip (which is for lib/external/linux64), the files returned from this method are used directly
"""
return []
def get_headers(self) -> list[str]:
"""
Returns a list of directories that contain headers that should be installed
These will be copied into release/include
"""
return []
def get_directory(self) -> str:
"""
Returns the directory this dependency resides in
"""
raise NotImplementedError
def execute(self) -> bool:
"""
Runs all build steps associated with this dependency
Applies patches, configures and builds
"""
dir = f'{get_top()}/repos/{self.get_directory()}'
if not os.path.exists(dir):
if not self.download():
print('Download failed!')
return False
with WorkDir(dir):
if not self.apply_patches():
print('Failed to apply patches')
return False
if not self.configure():
print('Configure failed!')
return False
if not self.build():
print('Build failed!')
return False
return True
def apply_patches(self) -> bool:
"""
Apply any patches to your dependency here
Returns
-------
True if patches were applied successfully
"""
return True
@staticmethod
def _apply_patch(patch: str) -> bool:
"""
Apply a single patch from file, only if it needs to be applied
Parameters
----------
patch : str
Path to the patch, relative to the top directory.
Returns
-------
True if the patch is already applied or was successfully applied
"""
if Dependency._execute_cmds(['git', 'apply', '--reverse', '--check', f'{get_top()}/{patch}']):
return True
return Dependency._execute_cmds(
['git', 'apply', f'{get_top()}/{patch}']
)
@staticmethod
def _apply_patches(patches: list[str]) -> bool:
"""
Applies a list of patches. See _apply_patch
"""
for p in patches:
if not Dependency._apply_patch(p):
return False
return True
@staticmethod
def _execute_cmds(*args, **kwargs) -> bool:
"""
Executes a command list, bailing out if any fails
Parameters
----------
*args :
List of lists to invoke as commands. These are passed directly to subprocess.run
**kwargs :
Additional key'ed arguments.
For now only 'env' is supported. This is a dict that is merged with get_global_env() and
passed to subprocess.run
Returns
-------
True if execution succeeded
"""
for a in args:
e = get_global_env()
if 'env' in kwargs:
e.update(kwargs['env'])
if verbose:
print(f'args={a}, env={e}')
if subprocess.run(a, shell=kwargs['shell'] if 'shell' in kwargs else False, env=e, capture_output=quiet).returncode != 0:
return False
return True
class Dep_autoconf(Dependency):
def get_directory(self) -> str:
return 'autoconf'
def configure(self) -> bool:
return self._execute_cmds(
['./bootstrap'],
['./configure', f'--prefix={get_install_dir()}']
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_libffi(Dependency):
def get_directory(self) -> str:
return 'libffi'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--enable-static', '--enable-shared=no', '--enable-tools=no', '--enable-tests=no',
'--enable-samples=no', '--disable-docs', f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_zlib(Dependency):
def get_directory(self) -> str:
return 'zlib'
def configure(self) -> bool:
return self._execute_cmds(
['./configure', '--static', '--64', f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_pcre(Dependency):
def get_directory(self) -> str:
return 'pcre'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--enable-static', '--enable-shared=no', f'--prefix={get_install_dir()}',
'--enable-utf', '--enable-pcre16', '--enable-pcre32'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_bzip2(Dependency):
def get_directory(self) -> str:
return 'bzip2'
def get_artifacts(self) -> list[str]:
return ['libbz2.so.1.0']
def configure(self) -> bool:
return True
def build(self) -> bool:
return self._execute_cmds(
['make', 'install', f'-j{nproc()}', 'CFLAGS=-fPIC', f'PREFIX={get_install_dir()}'],
# Build shared too. Needed for the precompiled libav that we already have. (No install rule for this makefile either)
['make', '-f', 'Makefile-libbz2_so', f'-j{nproc()}', 'CFLAGS=-fPIC', f'PREFIX={get_install_dir()}'],
['cp', 'libbz2.so.1.0', f'{get_lib_dir()}/libbz2.so.1.0'],
env={'CFLAGS': '-fPIC'}
)
class Dep_curl(Dependency):
def get_directory(self) -> str:
return 'curl'
def get_artifacts(self) -> list[str]:
return ['libcurl.a']
def configure(self) -> bool:
return self._execute_cmds(
['cmake', '-Bbuild', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', f'-DCMAKE_INSTALL_PREFIX={get_install_dir()}',
'-DBUILD_SHARED_LIBS=OFF', '-DCMAKE_C_FLAGS=-fPIC', '-DCMAKE_CXX_FLAGS=-fPIC']
)
def build(self) -> bool:
return self._execute_cmds(
['ninja', '-C', 'build', 'install']
)
class Dep_glib(Dependency):
def get_directory(self) -> str:
return 'glib'
def configure(self) -> bool:
return self._execute_cmds(
['meson', 'build', '--buildtype', 'release', '--default-library', 'static', '--prefix',
get_install_dir(), '--libdir', get_lib_dir()],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
if not self._execute_cmds(['ninja', '-C', 'build', 'install']):
return False
shutil.copy(f'{get_install_dir()}/lib/glib-2.0/include/glibconfig.h',
f'{get_install_dir()}/include/glib-2.0/glibconfig.h')
return True
class Dep_pixman(Dependency):
def get_directory(self) -> str:
return 'pixman'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh', '--enable-gtk=no', '--enable-png=no', '--enable-shared=no', '--enable-static',
f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_brotli(Dependency):
def get_directory(self) -> str:
return 'brotli'
def configure(self) -> bool:
return self._execute_cmds(
['./bootstrap'],
['./configure', '--enable-static', '--disable-shared', f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_libpng(Dependency):
def get_directory(self) -> str:
return 'libpng'
def configure(self) -> bool:
return self._execute_cmds(
['./configure', '--enable-static', '--disable-shared', f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
if not self._execute_cmds(['make', 'install', f'-j{nproc()}']):
return False
# --disable-shared does nothing!
for s in glob.glob(f'{get_install_dir()}/lib/libpng*.so'):
os.remove(s)
return True
class Dep_freetype(Dependency):
def get_directory(self) -> str:
return 'freetype'
def get_artifacts(self) -> list[str]:
return ['libfreetype.so']
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--with-harfbuzz=no', '--disable-static', '--enable-shared',
f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC',
'LDFLAGS': f'-L{get_lib_dir()} -Wl,--no-undefined',
'ZLIB_LIBS': '' ,
'BZIP2_LIBS': '',
'LIBPNG_LIBS': f'{get_lib_dir()}/libpng.a -lbz2 -lz -lm',
'BROTLI_LIBS': f'{get_lib_dir()}/libbrotlidec.a {get_lib_dir()}/libbrotlienc.a {get_lib_dir()}/libbrotlicommon.a'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_jsonc(Dependency):
def get_directory(self) -> str:
return 'json-c'
def configure(self) -> bool:
return self._execute_cmds(
['cmake', '.', '-B', 'build', '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_STATIC_LIBS=ON', '-DBUILD_SHARED_LIBS=OFF', f'-DCMAKE_INSTALL_PREFIX={get_install_dir()}', '-DDISABLE_EXTRA_LIBS=ON'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', '-C', 'build', 'install', f'-j{nproc()}'])
class Dep_expat(Dependency):
def get_directory(self) -> str:
return 'libexpat/expat'
def configure(self) -> bool:
return self._execute_cmds(
['./buildconf.sh'],
['./configure', '--without-docbook', '--without-examples', '--without-tests', '--enable-static', '--enable-shared=no', f'--prefix={get_install_dir()}'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_fontconfig(Dependency):
def get_directory(self) -> str:
return 'fontconfig'
def get_artifacts(self) -> list[str]:
return ['libfontconfig.so']
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh', '--enable-static=no', f'--prefix={get_install_dir()}', f'--with-expat={get_install_dir()}', '--sysconfdir=/etc', '--disable-docs',
f'--datadir={get_install_dir()}/share', '--disable-cache-build', '--with-baseconfigdir=/etc/fonts'],
env={
'CFLAGS': f'-fPIC -I{get_inc_dir()}',
'LDFLAGS': f'-L{get_lib_dir()} -Wl,--no-undefined',
'FREETYPE_CFLAGS': f'-I{get_inc_dir()}/freetype2 -I{get_inc_dir()}/freetype2/freetype',
'FREETYPE_LIBS': f'-L{get_lib_dir()} -lfreetype',
'EXPAT_CFLAGS': '',
'EXPAT_LIBS': f'{get_lib_dir()}/libexpat.a',
'JSONC_CFLAGS': f'-I{get_inc_dir()}/json-c',
'JSONC_LIBS': f'{get_lib_dir()}/libjson-c.a'
}
)
def apply_patches(self) -> bool:
return self._apply_patches([
'patches/fontconfig/002-add-face-sub.patch',
'patches/fontconfig/fontpattern.diff'
])
def build(self) -> bool:
return all([
# build only!
self._execute_cmds(['make', f'-j{nproc()}', 'install-exec']),
# Manually copy the fontconfig headers and libs... can't use make install because that tries to put stuff in /etc!
#self._execute_cmds([f'cp -vf libfontconfig.so* "{get_lib_dir()}/lib"'])
])
# Needed for fribidi
class Dep_c2man(Dependency):
def get_directory(self) -> str:
return 'c2man'
def configure(self) -> bool:
return self._execute_cmds(
['./Configure', '-s', '-d', '-e'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
if not self._execute_cmds(['make', f'-j{nproc()}']):
return False
# No install rules for some reason, gotta manually copy
shutil.copy('c2man', f'{get_install_dir()}/bin/c2man')
return True
class Dep_fribidi(Dependency):
def get_directory(self) -> str:
return 'fribidi'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh', f'--prefix={get_install_dir()}', '--enable-shared=no', '--enable-static'],
env={'CFLAGS': '-fPIC'}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_cairo(Dependency):
def get_directory(self) -> str:
return 'cairo'
def get_artifacts(self) -> list[str]:
return ['libcairo.so']
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh', '--enable-xlib=yes', '--enable-xlib-xrender=yes', '--enable-xlib-xcb=yes',
'--enable-xcb-shm=no', '--enable-ft', '--enable-egl=no', '--enable-glx=no',
'--enable-wgl=no', '--enable-quartz=no', '--enable-svg=yes', '--enable-pdf=yes',
'--enable-ps=yes', '--enable-gobject=no', '--enable-png', '--disable-static', f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC',
'LDFLAGS': f'-L{get_lib_dir()} -Wl,--no-undefined',
'pixman_LIBS': f'{get_lib_dir()}/libpixman-1.a',
'png_LIBS': f'{get_lib_dir()}/libpng.a',
'FREETYPE_LIBS': f'-L{get_lib_dir()} -lfreetype',
'FREETYPE_CFLAGS': f'-I{get_inc_dir()}/freetype2',
'FONTCONFIG_LIBS': f'-L{get_lib_dir()} -lfontconfig'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_harfbuzz(Dependency):
def get_directory(self) -> str:
return 'harfbuzz'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh', f'--prefix={get_install_dir()}', '--enable-shared=no', '--enable-static'],
env={
'CFLAGS': f'-fPIC',
'LDFLAGS': f'-L{get_lib_dir()} -L{get_lib_dir()}',
'FREETYPE_CFLAGS': f'-I{get_inc_dir()}/freetype2'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_libdatrie(Dependency):
def get_directory(self) -> str:
return 'libdatrie'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--enable-shared=no', '--enable-static', f'--prefix={get_install_dir()}'],
env={
# The build setup for datrie is a bit messed up it seems. First time you build it you get an error with VERSION being undefined
# but the second pass works. As a workaround we'll just define VERSION here
'CFLAGS': '-fPIC -DVERSION=\\"HACK\\"'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_libthai(Dependency):
def get_directory(self) -> str:
return 'libthai'
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--enable-shared=no', '--enable-static', f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_pango(Dependency):
def get_directory(self) -> str:
return 'pango'
def get_artifacts(self) -> list[str]:
return [
'libpango-1.0.so',
'libpangocairo-1.0.so',
'libpangoft2-1.0.so'
]
def apply_patches(self) -> bool:
return self._apply_patches([
'patches/pango/001-add-face-sub.patch',
'patches/pango/meson-cairo.patch'
])
def configure(self) -> bool:
return self._execute_cmds(
['meson', 'build', '--prefix', get_install_dir(), '--buildtype', 'release',
'--libdir', 'lib', '--pkg-config-path', f'{get_lib_dir()}/pkgconfig',
'--build.pkg-config-path', f'{get_lib_dir()}/pkgconfig'
],
env={
'CFLAGS': f'-fPIC -I{get_inc_dir()}/freetype2 -w -Wno-error', # Disable errors...
'LDFLAGS': f'-L{get_lib_dir()} -Wl,--no-undefined -L{get_lib_dir()}',
}
)
def build(self) -> bool:
return self._execute_cmds(['ninja', '-C', 'build', 'install'])
class Dep_Xiph(Dependency):
"""
Common base class for all Xiph-maintained dependencies, since they all share the
same build facility
"""
def __init__(self, dep: str):
self.dep = dep
def get_directory(self) -> str:
return self.dep
def configure(self) -> bool:
return self._execute_cmds(
['./autogen.sh'],
['./configure', '--enable-shared=no', '--enable-static', f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC'
}
)
def build(self) -> bool:
if not self._execute_cmds(['make', 'install', f'-j{nproc()}']):
return False
match self.dep:
case 'ogg':
return add_pc_lib(f'{get_pkgconf_dir()}/ogg.pc', ['-lm'])
case 'vorbis':
return all([
add_pc_lib(f'{get_pkgconf_dir()}/vorbis.pc', ['-logg', '-lm']),
add_pc_lib(f'{get_pkgconf_dir()}/vorbisenc.pc', ['-lvorbis', '-logg', '-lm']),
add_pc_lib(f'{get_pkgconf_dir()}/vorbisfile.pc', ['-lvorbis', '-logg', '-lm']),
])
case 'opus':
return add_pc_lib(f'{get_pkgconf_dir()}/opus.pc', ['-lm'])
return True
class Dep_mpg123(Dependency):
def get_directory(self) -> str:
return 'mpg123'
def configure(self) -> bool:
return self._execute_cmds(
['autoreconf', '-iv'],
['./configure', '--with-optimization=2', '--enable-shared=no', '--enable-static', f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_mp3lame(Dependency):
def download(self) -> bool:
return download_and_extract('https://sourceforge.net/projects/lame/files/lame/3.100/lame-3.100.tar.gz/download', 'tar.gz', 'mp3lame')
def get_directory(self) -> str:
return 'mp3lame'
def configure(self) -> bool:
return self._execute_cmds(
['./configure', '--enable-shared=no', '--enable-static', f'--prefix={get_install_dir()}'],
env={
'CFLAGS': '-fPIC'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_libsndfile(Dependency):
def get_directory(self) -> str:
return 'libsndfile'
def get_artifacts(self) -> list[str]:
return ['libsndfile.so']
def configure(self) -> bool:
return self._execute_cmds(
#['autoreconf', '-iv'],
['rm', '-rf', 'build'],
['cmake', '-Bbuild', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_TESTING=OFF',
'-DBUILD_SHARED_LIBS=ON', '-DBUILD_PROGRAMS=OFF', '-DBUILD_EXAMPLES=OFF', f'-DCMAKE_INSTALL_PREFIX={get_install_dir()}',
'-DENABLE_PACKAGE_CONFIG=OFF'],
#['./configure', '--enable-shared', '--disable-static', '--disable-full-suite', f'--prefix={get_install_dir()}'],
# TODO: Can't get it to build with cmake yet, but the library is looking to remove autotools. fix this!
#['cmake', '.', '-B', 'build', '-DBUILD_SHARED_LIBS=ON', '-DCMAKE_BUILD_TYPE=Release', '-DBUILD_TESTING=OFF',
# '-DCMAKE_SHARED_LINKER_FLAGS=-lmvec', '-DCMAKE_C_FLAGS=-ffast-math', f'-DCMAKE_INSTALL_PREFIX={get_install_dir()}'],
env={
'CFLAGS': f'-fPIC -ffast-math -I{get_inc_dir()}',
'LDFLAGS': f'-L{get_lib_dir()}',
'LIBS': '-lmp3lame -lm',
#'FLAC_CFLAGS': '',
#'FLAC_LIBS': '-Wl,-Bstatic -lflac',
#'OGG_CFLAGS': '',
#'OGG_LIBS': '-Wl,-Bstatic -logg',
#'VORBIS_CFLAGS': '',
#'VORBIS_LIBS': '-Wl,-Bstatic -lvorbis',
#'VORBISENC_CFLAGS': '',
#'VORBISENC_LIBS': '-Wl,-Bstatic -lvorbisenc',
'OPUS_CFLAGS': f'-I{get_inc_dir()}/include/opus',
'OPUS_LIBS': '-Wl,-Bstatic -lopus -Wl,-Bdynamic',
'MPG123_CFLAGS': '',
'MPG123_LIBS': '-Wl,-Bstatic -lmpg123 -Wl,-Bdynamic'
}
)
def build(self) -> bool:
# TODO: cmake
#return self._execute_cmds(['make', '-C', 'build', 'install', f'-j{nproc()}'])
return self._execute_cmds(['ninja', '-C', 'build', 'install'])
class Dep_ffmpeg(Dependency):
def get_directory(self) -> str:
return 'ffmpeg'
def get_artifacts(self) -> list[str]:
return [
'libavcodec.a',
'libavformat.a',
#'libavdevice.a', # Probably don't need this
'libavfilter.a',
'libavutil.a',
'libswscale.a',
'libswresample.a'
]
def get_headers(self) -> list[str]:
return [
'libavcodec',
'libavformat',
'libavdevice',
'libavfilter',
'libavutil',
'libswresample',
'libswscale'
]
def configure(self) -> bool:
return self._execute_cmds(
['./configure', '--disable-avx', '--disable-avx2', '--disable-sse42', '--disable-sse4',
f'--prefix={get_install_dir()}', '--enable-libvorbis', '--enable-libopus', '--disable-programs',
'--disable-doc']
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
class Dep_icu(Dependency):
def __init__(self, version: str):
self.version = version
def get_directory(self) -> str:
return 'icu'
def get_artifacts(self):
artifacts = []
bins = ['libicudata', 'libicui18n', 'libicuio', 'libicutu', 'libicuuc']
artifacts += [f'{b}.so.{self.version}' for b in bins]
artifacts += [f'{b}.so.{self.version.split(".")[0]}' for b in bins]
return artifacts
def configure(self) -> bool:
return self._execute_cmds(
['./icu4c/source/configure', f'--prefix={get_install_dir()}'],
env={
# The build setup for datrie is a bit messed up it seems. First time you build it you get an error with VERSION being undefined
# but the second pass works. As a workaround we'll just define VERSION here
#'CFLAGS': '-fPIC -DVERSION=\\"HACK\\"'
}
)
def build(self) -> bool:
return self._execute_cmds(['make', 'install', f'-j{nproc()}'])
def get_soname(lib: str) -> str|None:
"""
Returns the SONAME attribute of the ELF file, if it exists. Otherwise returns None
"""
result = subprocess.run(['readelf', '-d', f'{get_lib_dir()}/{lib}'], capture_output=True)
if result.returncode != 0:
return None
data = result.stdout.decode('utf-8')
try:
matches = re.search(r'soname: \[(.*)]$', data, re.MULTILINE)
return matches.group(1)
except:
return None
def mkdir_p(path: str) -> bool:
comps = path.split('/')
if len(comps) <= 0:
return False
p = comps[0]
for i in range(1, len(comps)):
if not os.path.exists(p):
os.mkdir(p)
p += '/' + comps[i]
if not os.path.exists(p):
os.mkdir(p)
return True
def install_lib(lib: str):
soname = get_soname(lib)
if soname is None:
soname = lib
if not lib.endswith('.a'):
shutil.copy(f'{get_lib_dir()}/{soname}', f'release/bin/linux64/{soname}')
shutil.copy(f'{get_lib_dir()}/{lib}', f'release/lib/external/linux64/{lib}')
def install_headers(dir: str, dst: str):
shutil.copytree(f'{get_inc_dir()}/{dir}', f'{dst}/{dir}', dirs_exist_ok=True)
def create_release(deps: Dict[str, Dependency]):
mkdir_p('release/bin/linux64')
mkdir_p('release/lib/external/linux64')
mkdir_p('release/include')
for d in deps:
# Install binary artifacts
artifacts = deps[d].get_artifacts()
for a in artifacts:
install_lib(a)
# Install headers
headers = deps[d].get_headers()
for h in headers:
install_headers(h, 'release/include')
# Strip everything
for c in glob.glob('release/**/*.so*', recursive=True):
subprocess.run(['strip', '-x', c])
subprocess.run(['chrpath', '-d', c])
if verbose:
print(f'strip -x {c}')
print(f'chrpath -d {c}')
# Create a tarball
name = shutil.make_archive('release-linux-x86_64', 'gztar', 'release')
print(f'Created {name}')
def main():
deps: Dict[str,Dependency] = {
'autoconf': Dep_autoconf(),
'curl': Dep_curl(),
'pcre': Dep_pcre(),
'zlib': Dep_zlib(),
'libffi': Dep_libffi(),
'bzip2': Dep_bzip2(),
'glib': Dep_glib(),
'pixman': Dep_pixman(),
'brotli': Dep_brotli(),
'libpng': Dep_libpng(),
'freetype': Dep_freetype(),
'json-c': Dep_jsonc(),