forked from randombit/botan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.py
executable file
·2041 lines (1573 loc) · 71.8 KB
/
configure.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 python
"""
Configuration program for botan
(C) 2009,2010,2011,2012,2013,2014,2015 Jack Lloyd
(C) 2015 Simon Warta (Kullo GmbH)
Botan is released under the Simplified BSD License (see license.txt)
Tested with CPython 2.6, 2.7, and 3.3
CPython 2.5 and earlier are not supported
Jython - Target detection does not work (use --os and --cpu)
"""
import sys
import os
import os.path
import platform
import re
import shlex
import shutil
import string
import subprocess
import logging
import getpass
import time
import errno
import optparse
# Avoid useless botan_version.pyc (Python 2.6 or higher)
if 'dont_write_bytecode' in sys.__dict__:
sys.dont_write_bytecode = True
import botan_version
def flatten(l):
return sum(l, [])
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i+n]
def get_vc_revision():
def get_vc_revision(cmdlist):
try:
cmdname = cmdlist[0]
vc = subprocess.Popen(cmdlist,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
(stdout, stderr) = vc.communicate()
if vc.returncode != 0:
logging.debug('Error getting rev from %s - %d (%s)'
% (cmdname, vc.returncode, stderr))
return None
rev = str(stdout).strip()
logging.debug('%s reported revision %s' % (cmdname, rev))
return '%s:%s' % (cmdname, rev)
except OSError as e:
logging.debug('Error getting rev from %s - %s' % (cmdname, e.strerror))
return None
except Exception as e:
logging.debug('Error getting rev from %s - %s' % (cmdname, e))
return None
vc_commands = [['mtn', 'automate', 'heads'],
['git', 'rev-parse', 'HEAD']]
for vc_cmd in vc_commands:
rev = get_vc_revision(vc_cmd)
if rev is not None:
return rev
return 'unknown'
class BuildConfigurationInformation(object):
"""
Version information
"""
version_major = botan_version.release_major
version_minor = botan_version.release_minor
version_patch = botan_version.release_patch
version_so_rev = botan_version.release_so_abi_rev
version_release_type = botan_version.release_type
version_datestamp = botan_version.release_datestamp
version_vc_rev = botan_version.release_vc_rev
version_string = '%d.%d.%d' % (version_major, version_minor, version_patch)
"""
Constructor
"""
def __init__(self, options, modules):
if self.version_vc_rev is None:
self.version_vc_rev = get_vc_revision()
self.build_dir = os.path.join(options.with_build_dir, 'build')
self.obj_dir = os.path.join(self.build_dir, 'obj')
self.appobj_dir = os.path.join(self.obj_dir, 'app')
self.libobj_dir = os.path.join(self.obj_dir, 'lib')
self.testobj_dir = os.path.join(self.obj_dir, 'test')
self.doc_output_dir = os.path.join(self.build_dir, 'docs')
self.include_dir = os.path.join(self.build_dir, 'include')
self.botan_include_dir = os.path.join(self.include_dir, 'botan')
self.internal_include_dir = os.path.join(self.botan_include_dir, 'internal')
self.modules = modules
self.sources = sorted(flatten([mod.sources() for mod in modules]))
self.internal_headers = sorted(flatten([m.internal_headers() for m in modules]))
if options.via_amalgamation:
self.build_sources = ['botan_all.cpp']
else:
self.build_sources = self.sources
self.public_headers = sorted(flatten([m.public_headers() for m in modules]))
self.doc_dir = os.path.join(options.base_dir, 'doc')
self.src_dir = os.path.join(options.base_dir, 'src')
def find_sources_in(basedir, srcdir):
for (dirpath, dirnames, filenames) in os.walk(os.path.join(basedir, srcdir)):
for filename in filenames:
if filename.endswith('.cpp') and not filename.startswith('.'):
yield os.path.join(dirpath, filename)
self.app_sources = list(find_sources_in(self.src_dir, 'cmd'))
self.test_sources = list(find_sources_in(self.src_dir, 'tests'))
self.python_dir = os.path.join(options.src_dir, 'python')
def build_doc_commands():
def get_doc_cmd():
if options.with_sphinx:
sphinx = 'sphinx-build -c $(SPHINX_CONFIG) $(SPHINX_OPTS) '
if options.quiet:
sphinx += '-q '
sphinx += '%s %s'
return sphinx
else:
return '$(COPY) %s' + os.sep + '*.rst %s'
doc_cmd = get_doc_cmd()
def cmd_for(src):
return doc_cmd % (os.path.join(self.doc_dir, src),
os.path.join(self.doc_output_dir, src))
yield cmd_for('manual')
if options.with_doxygen:
yield 'doxygen %s%sbotan.doxy' % (self.build_dir, os.sep)
self.build_doc_commands = '\n'.join(['\t' + s for s in build_doc_commands()])
def build_dirs():
yield self.libobj_dir
yield self.appobj_dir
yield self.testobj_dir
yield self.botan_include_dir
yield self.internal_include_dir
yield os.path.join(self.doc_output_dir, 'manual')
if options.with_doxygen:
yield os.path.join(self.doc_output_dir, 'doxygen')
self.build_dirs = list(build_dirs())
def src_info(self, typ):
if typ == 'lib':
return (self.build_sources, self.libobj_dir)
elif typ == 'app':
return (self.app_sources, self.appobj_dir)
elif typ == 'test':
return (self.test_sources, self.testobj_dir)
def pkg_config_file(self):
return 'botan-%d.%d.pc' % (self.version_major, self.version_minor)
def username(self):
return getpass.getuser()
def hostname(self):
return platform.node()
def timestamp(self):
return time.ctime()
"""
Handle command line options
"""
def process_command_line(args):
parser = optparse.OptionParser(
formatter = optparse.IndentedHelpFormatter(max_help_position = 50),
version = BuildConfigurationInformation.version_string)
parser.add_option('--verbose', action='store_true', default=False,
help='Show debug messages')
parser.add_option('--quiet', action='store_true', default=False,
help='Show only warnings and errors')
target_group = optparse.OptionGroup(parser, 'Target options')
target_group.add_option('--cpu',
help='set the target CPU type/model')
target_group.add_option('--os',
help='set the target operating system')
target_group.add_option('--cc', dest='compiler',
help='set the desired build compiler')
target_group.add_option('--cc-bin', dest='compiler_binary',
metavar='BINARY',
help='set path to compiler binary')
target_group.add_option('--cc-abi-flags', metavar='FLAG',
help='set compiler ABI flags',
default='')
target_group.add_option('--chost', help=optparse.SUPPRESS_HELP)
target_group.add_option('--with-endian', metavar='ORDER', default=None,
help='override byte order guess')
target_group.add_option('--with-unaligned-mem',
dest='unaligned_mem', action='store_true',
default=None,
help='use unaligned memory accesses')
target_group.add_option('--without-unaligned-mem',
dest='unaligned_mem', action='store_false',
help=optparse.SUPPRESS_HELP)
target_group.add_option('--with-os-features', action='append', metavar='FEAT',
help='specify OS features to use')
target_group.add_option('--without-os-features', action='append', metavar='FEAT',
help='specify OS features to disable')
for isa_extn_name in ['SSE2', 'SSSE3', 'AVX2', 'AES-NI', 'AltiVec']:
isa_extn = isa_extn_name.lower()
target_group.add_option('--disable-%s' % (isa_extn),
help='disable %s intrinsics' % (isa_extn_name),
action='append_const',
const=isa_extn.replace('-', ''),
dest='disable_intrinsics')
build_group = optparse.OptionGroup(parser, 'Build options')
build_modes = ['release', 'debug', 'coverage', 'sanitizer']
build_group.add_option('--build-mode', default='release', metavar='MODE',
choices=build_modes,
help="Build mode (one of %s; default %%default)" % (', '.join(build_modes)))
build_group.add_option('--debug-mode', action='store_const',
const='debug', dest='build_mode',
help='enable debugging build')
build_group.add_option('--enable-shared', dest='build_shared_lib',
action='store_true', default=True,
help=optparse.SUPPRESS_HELP)
build_group.add_option('--disable-shared', dest='build_shared_lib',
action='store_false',
help='disable building shared library')
build_group.add_option('--enable-asm', dest='asm_ok',
action='store_true', default=True,
help=optparse.SUPPRESS_HELP)
build_group.add_option('--disable-asm', dest='asm_ok',
action='store_false',
help='disallow use of assembler')
build_group.add_option('--no-optimizations', dest='no_optimizations',
action='store_true', default=False,
help=optparse.SUPPRESS_HELP)
build_group.add_option('--gen-amalgamation', dest='gen_amalgamation',
default=False, action='store_true',
help='generate amalgamation files')
build_group.add_option('--via-amalgamation', dest='via_amalgamation',
default=False, action='store_true',
help='build via amalgamation')
build_group.add_option('--single-amalgamation-file',
default=False, action='store_true',
help='build single file instead of splitting on ABI')
build_group.add_option('--with-build-dir', metavar='DIR', default='',
help='setup the build in DIR')
build_group.add_option('--link-method', default=None, metavar='METHOD',
help='choose how links are created')
makefile_styles = ['gmake', 'nmake']
build_group.add_option('--makefile-style', metavar='STYLE', default=None,
choices=makefile_styles,
help='makefile type (%s)' % ' or '.join(makefile_styles))
build_group.add_option('--with-local-config',
dest='local_config', metavar='FILE',
help='include the contents of FILE into build.h')
build_group.add_option('--distribution-info', metavar='STRING',
help='distribution specific version',
default='unspecified')
build_group.add_option('--with-sphinx', action='store_true',
default=None, help='Use Sphinx')
build_group.add_option('--without-sphinx', action='store_false',
dest='with_sphinx', help=optparse.SUPPRESS_HELP)
build_group.add_option('--with-visibility', action='store_true',
default=None, help=optparse.SUPPRESS_HELP)
build_group.add_option('--without-visibility', action='store_false',
dest='with_visibility', help=optparse.SUPPRESS_HELP)
build_group.add_option('--with-doxygen', action='store_true',
default=False, help='Use Doxygen')
build_group.add_option('--without-doxygen', action='store_false',
dest='with_doxygen', help=optparse.SUPPRESS_HELP)
build_group.add_option('--maintainer-mode', dest='maintainer_mode',
action='store_true', default=False,
help="Enable extra warnings")
build_group.add_option('--dirty-tree', dest='clean_build_tree',
action='store_false', default=True,
help=optparse.SUPPRESS_HELP)
wrapper_group = optparse.OptionGroup(parser, 'Python FFI options')
wrapper_group.add_option('--with-python-version', dest='python_version',
metavar='N.M',
default='.'.join(map(str, sys.version_info[0:2])),
help='set Python version (def %default)')
mods_group = optparse.OptionGroup(parser, 'Module selection')
mods_group.add_option('--enable-modules', dest='enabled_modules',
metavar='MODS', action='append',
help='enable specific modules')
mods_group.add_option('--disable-modules', dest='disabled_modules',
metavar='MODS', action='append',
help='disable specific modules')
mods_group.add_option('--list-modules', dest='list_modules',
action='store_true',
help='list available modules')
mods_group.add_option('--no-autoload', action='store_true', default=False,
help='disable automatic loading')
# Should be derived from info.txt but this runs too early
third_party = ['boost', 'bzip2', 'lzma', 'openssl', 'sqlite3', 'zlib']
for mod in third_party:
mods_group.add_option('--with-%s' % (mod),
help=('use %s' % (mod)) if mod in third_party else optparse.SUPPRESS_HELP,
action='append_const',
const=mod,
dest='enabled_modules')
mods_group.add_option('--without-%s' % (mod),
help=optparse.SUPPRESS_HELP,
action='append_const',
const=mod,
dest='disabled_modules')
mods_group.add_option('--with-everything', help=optparse.SUPPRESS_HELP,
action='store_true', default=False)
install_group = optparse.OptionGroup(parser, 'Installation options')
install_group.add_option('--program-suffix', metavar='SUFFIX',
help='append string to program names')
install_group.add_option('--prefix', metavar='DIR',
help='set the install prefix')
install_group.add_option('--destdir', metavar='DIR',
help='set the install directory')
install_group.add_option('--docdir', metavar='DIR',
help='set the doc install dir')
install_group.add_option('--bindir', metavar='DIR',
help='set the binary install dir')
install_group.add_option('--libdir', metavar='DIR',
help='set the library install dir')
install_group.add_option('--includedir', metavar='DIR',
help='set the include file install dir')
parser.add_option_group(target_group)
parser.add_option_group(build_group)
parser.add_option_group(mods_group)
parser.add_option_group(wrapper_group)
parser.add_option_group(install_group)
# These exist only for autoconf compatability (requested by zw for mtn)
compat_with_autoconf_options = [
'datadir',
'datarootdir',
'dvidir',
'exec-prefix',
'htmldir',
'infodir',
'libexecdir',
'localedir',
'localstatedir',
'mandir',
'oldincludedir',
'pdfdir',
'psdir',
'sbindir',
'sharedstatedir',
'sysconfdir'
]
for opt in compat_with_autoconf_options:
parser.add_option('--' + opt, help=optparse.SUPPRESS_HELP)
(options, args) = parser.parse_args(args)
if args != []:
raise Exception('Unhandled option(s): ' + ' '.join(args))
if options.with_endian != None and \
options.with_endian not in ['little', 'big']:
raise Exception('Bad value to --with-endian "%s"' % (
options.with_endian))
def parse_multiple_enable(modules):
if modules is None:
return []
return sorted(set(flatten([s.split(',') for s in modules])))
options.enabled_modules = parse_multiple_enable(options.enabled_modules)
options.disabled_modules = parse_multiple_enable(options.disabled_modules)
options.with_os_features = parse_multiple_enable(options.with_os_features)
options.without_os_features = parse_multiple_enable(options.without_os_features)
options.disable_intrinsics = parse_multiple_enable(options.disable_intrinsics)
return options
"""
Generic lexer function for info.txt and src/build-data files
"""
def lex_me_harder(infofile, to_obj, allowed_groups, name_val_pairs):
# Format as a nameable Python variable
def py_var(group):
return group.replace(':', '_')
class LexerError(Exception):
def __init__(self, msg, line):
self.msg = msg
self.line = line
def __str__(self):
return '%s at %s:%d' % (self.msg, infofile, self.line)
(dirname, basename) = os.path.split(infofile)
to_obj.lives_in = dirname
if basename == 'info.txt':
(obj_dir,to_obj.basename) = os.path.split(dirname)
if os.access(os.path.join(obj_dir, 'info.txt'), os.R_OK):
to_obj.parent_module = os.path.basename(obj_dir)
else:
to_obj.parent_module = None
else:
to_obj.basename = basename.replace('.txt', '')
lexer = shlex.shlex(open(infofile), infofile, posix=True)
lexer.wordchars += '|:.<>/,-!+' # handle various funky chars in info.txt
for group in allowed_groups:
to_obj.__dict__[py_var(group)] = []
for (key,val) in name_val_pairs.items():
to_obj.__dict__[key] = val
def lexed_tokens(): # Convert to an interator
token = lexer.get_token()
while token != None:
yield token
token = lexer.get_token()
for token in lexed_tokens():
match = re.match('<(.*)>', token)
# Check for a grouping
if match is not None:
group = match.group(1)
if group not in allowed_groups:
raise LexerError('Unknown group "%s"' % (group),
lexer.lineno)
end_marker = '</' + group + '>'
token = lexer.get_token()
while token != end_marker:
to_obj.__dict__[py_var(group)].append(token)
token = lexer.get_token()
if token is None:
raise LexerError('Group "%s" not terminated' % (group),
lexer.lineno)
elif token in name_val_pairs.keys():
if type(to_obj.__dict__[token]) is list:
to_obj.__dict__[token].append(lexer.get_token())
# Dirty hack
if token == 'define':
nxt = lexer.get_token()
if not nxt:
raise LexerError('No version set for API', lexer.lineno)
if not re.match('^[0-9]{8}$', nxt):
raise LexerError('Bad API rev "%s"' % (nxt), lexer.lineno)
to_obj.__dict__[token].append(nxt)
else:
to_obj.__dict__[token] = lexer.get_token()
else: # No match -> error
raise LexerError('Bad token "%s"' % (token), lexer.lineno)
"""
Convert a lex'ed map (from build-data files) from a list to a dict
"""
def force_to_dict(l):
return dict(zip(l[::3],l[2::3]))
"""
Represents the information about a particular module
"""
class ModuleInfo(object):
def __init__(self, infofile):
lex_me_harder(infofile, self,
['source', 'header:internal', 'header:public',
'requires', 'os', 'arch', 'cc', 'libs',
'comment', 'warning'],
{
'load_on': 'auto',
'define': [],
'need_isa': '',
'mp_bits': 0 })
def extract_files_matching(basedir, suffixes):
for (dirpath, dirnames, filenames) in os.walk(basedir):
if dirpath == basedir:
for filename in filenames:
if filename.startswith('.'):
continue
for suffix in suffixes:
if filename.endswith(suffix):
yield filename
if self.need_isa == '':
self.need_isa = []
else:
self.need_isa = self.need_isa.split(',')
if self.source == []:
self.source = list(extract_files_matching(self.lives_in, ['.cpp', '.S']))
if self.header_internal == [] and self.header_public == []:
self.header_public = list(extract_files_matching(self.lives_in, ['.h']))
# Coerce to more useful types
def convert_lib_list(l):
result = {}
for (targetlist, vallist) in zip(l[::3], l[2::3]):
vals = vallist.split(',')
for target in targetlist.split(','):
result[target] = result.setdefault(target, []) + vals
return result
self.libs = convert_lib_list(self.libs)
def add_dir_name(filename):
if filename.count(':') == 0:
return os.path.join(self.lives_in, filename)
# modules can request to add files of the form
# MODULE_NAME:FILE_NAME to add a file from another module
# For these, assume other module is always in a
# neighboring directory; this is true for all current uses
return os.path.join(os.path.split(self.lives_in)[0],
*filename.split(':'))
self.source = [add_dir_name(s) for s in self.source]
self.header_internal = [add_dir_name(s) for s in self.header_internal]
self.header_public = [add_dir_name(s) for s in self.header_public]
for src in self.source + self.header_internal + self.header_public:
if os.access(src, os.R_OK) == False:
logging.warning("Missing file %s in %s" % (src, infofile))
self.mp_bits = int(self.mp_bits)
if self.comment != []:
self.comment = ' '.join(self.comment)
else:
self.comment = None
if self.warning != []:
self.warning = ' '.join(self.warning)
else:
self.warning = None
intersection = set(self.header_public) & set(self.header_internal)
if len(intersection) > 0:
logging.warning('Headers %s marked both public and internal' % (' '.join(intersection)))
def sources(self):
return self.source
def public_headers(self):
return self.header_public
def internal_headers(self):
return self.header_internal
def defines(self):
return ['HAS_' + d[0] + ' ' + d[1] for d in chunks(self.define, 2)]
def compatible_cpu(self, archinfo, options):
arch_name = archinfo.basename
cpu_name = options.cpu
for isa in self.need_isa:
if isa in options.disable_intrinsics:
return False # explicitly disabled
if isa not in archinfo.isa_extensions:
return False
if self.arch != []:
if arch_name not in self.arch and cpu_name not in self.arch:
return False
return True
def compatible_os(self, os):
return self.os == [] or os in self.os
def compatible_compiler(self, cc, arch):
if self.cc != [] and cc.basename not in self.cc:
return False
for isa in self.need_isa:
if cc.isa_flags_for(isa, arch) is None:
return False
return True
def dependencies(self):
# base is an implicit dep for all submodules
deps = self.requires + ['base']
if self.parent_module != None:
deps.append(self.parent_module)
return deps
"""
Ensure that all dependencies of this module actually exist, warning
about any that do not
"""
def dependencies_exist(self, modules):
all_deps = [s.split('|') for s in self.dependencies()]
for missing in [s for s in flatten(all_deps) if s not in modules]:
logging.warn("Module '%s', dep of '%s', does not exist" % (
missing, self.basename))
def __cmp__(self, other):
if self.basename < other.basename:
return -1
if self.basename == other.basename:
return 0
return 1
class ArchInfo(object):
def __init__(self, infofile):
lex_me_harder(infofile, self,
['aliases', 'submodels', 'submodel_aliases', 'isa_extensions'],
{ 'endian': None,
'family': None,
'unaligned': 'no',
'wordsize': 32
})
self.submodel_aliases = force_to_dict(self.submodel_aliases)
self.unaligned_ok = (1 if self.unaligned == 'ok' else 0)
self.wordsize = int(self.wordsize)
"""
Return a list of all submodels for this arch, ordered longest
to shortest
"""
def all_submodels(self):
return sorted([(k,k) for k in self.submodels] +
[k for k in self.submodel_aliases.items()],
key = lambda k: len(k[0]), reverse = True)
"""
Return CPU-specific defines for build.h
"""
def defines(self, options):
def form_macro(cpu_name):
return cpu_name.upper().replace('.', '').replace('-', '_')
macros = ['TARGET_ARCH_IS_%s' %
(form_macro(self.basename.upper()))]
if self.basename != options.cpu:
macros.append('TARGET_CPU_IS_%s' % (form_macro(options.cpu)))
enabled_isas = set(self.isa_extensions)
disabled_isas = set(options.disable_intrinsics)
isa_extensions = sorted(enabled_isas - disabled_isas)
for isa in isa_extensions:
macros.append('TARGET_SUPPORTS_%s' % (form_macro(isa)))
endian = options.with_endian or self.endian
if endian != None:
macros.append('TARGET_CPU_IS_%s_ENDIAN' % (endian.upper()))
logging.info('Assuming CPU is %s endian' % (endian))
unaligned_ok = options.unaligned_mem
if unaligned_ok is None:
unaligned_ok = self.unaligned_ok
if unaligned_ok:
logging.info('Assuming unaligned memory access works')
if self.family is not None:
macros.append('TARGET_CPU_IS_%s_FAMILY' % (self.family.upper()))
macros.append('TARGET_CPU_NATIVE_WORD_SIZE %d' % (self.wordsize))
if self.wordsize == 64:
macros.append('TARGET_CPU_HAS_NATIVE_64BIT')
macros.append('TARGET_UNALIGNED_MEMORY_ACCESS_OK %d' % (unaligned_ok))
return macros
class CompilerInfo(object):
def __init__(self, infofile):
lex_me_harder(infofile, self,
['so_link_commands', 'binary_link_commands', 'mach_opt', 'mach_abi_linking', 'isa_flags'],
{ 'binary_name': None,
'linker_name': None,
'macro_name': None,
'output_to_option': '-o ',
'add_include_dir_option': '-I',
'add_lib_dir_option': '-L',
'add_lib_option': '-l',
'compile_flags_release': '',
'compile_flags_debug': '',
'lib_opt_flags_release': '',
'lib_opt_flags_debug': '',
'app_opt_flags_release': '',
'app_opt_flags_debug': '',
'coverage_flags': '',
'sanitizer_flags': '',
'shared_flags': '',
'lang_flags': '',
'warning_flags': '',
'maintainer_warning_flags': '',
'visibility_build_flags': '',
'visibility_attribute': '',
'ar_command': None,
'makefile_style': ''
})
self.so_link_commands = force_to_dict(self.so_link_commands)
self.binary_link_commands = force_to_dict(self.binary_link_commands)
self.mach_abi_linking = force_to_dict(self.mach_abi_linking)
self.isa_flags = force_to_dict(self.isa_flags)
self.infofile = infofile
self.mach_opt_flags = {}
while self.mach_opt != []:
proc = self.mach_opt.pop(0)
if self.mach_opt.pop(0) != '->':
raise Exception('Parsing err in %s mach_opt' % (self.basename))
flags = self.mach_opt.pop(0)
regex = ''
if len(self.mach_opt) > 0 and \
(len(self.mach_opt) == 1 or self.mach_opt[1] != '->'):
regex = self.mach_opt.pop(0)
self.mach_opt_flags[proc] = (flags,regex)
del self.mach_opt
def isa_flags_for(self, isa, arch):
if isa in self.isa_flags:
return self.isa_flags[isa]
arch_isa = '%s:%s' % (arch, isa)
if arch_isa in self.isa_flags:
return self.isa_flags[arch_isa]
return None
"""
Return the shared library build flags, if any
"""
def gen_shared_flags(self, options):
def flag_builder():
if options.build_shared_lib:
yield self.shared_flags
if options.with_visibility:
yield self.visibility_build_flags
return ' '.join(list(flag_builder()))
def gen_visibility_attribute(self, options):
if options.build_shared_lib and options.with_visibility:
return self.visibility_attribute
return ''
"""
Return the machine specific ABI flags
"""
def mach_abi_link_flags(self, options):
def all():
if 'all-debug' in self.mach_abi_linking and options.build_mode == 'debug':
return 'all-debug'
return 'all'
abi_link = set()
for what in [all(), options.os, options.arch, options.cpu]:
flag = self.mach_abi_linking.get(what)
if flag != None and flag != '':
abi_link.add(flag)
for flag in options.cc_abi_flags.split(' '):
if flag != '':
abi_link.add(flag)
if len(abi_link) == 0:
return ''
abi_flags = ' '.join(sorted(list(abi_link)))
if options.build_mode == 'coverage':
if self.coverage_flags == '':
raise Exception('No coverage handling for %s' % (self.basename))
return ' ' + self.coverage_flags + ' ' + abi_flags
elif options.build_mode == 'sanitizer':
if self.sanitizer_flags == '':
raise Exception('No sanitizer handling for %s' % (self.basename))
return ' ' + self.sanitizer_flags + ' ' + abi_flags
return ' ' + abi_flags
"""
Return the optimization flags to use
"""
def opt_flags(self, who, options):
def gen_flags():
if options.build_mode in ['debug', 'coverage']:
yield self.compile_flags_debug
else:
yield self.compile_flags_release
if options.no_optimizations or options.build_mode == 'coverage':
return
if who == 'app':
if options.build_mode == 'release':
yield self.app_opt_flags_release
else:
yield self.app_opt_flags_debug
return
elif who == 'lib':
if options.build_mode == 'release':
yield self.lib_opt_flags_release
else:
yield self.lib_opt_flags_debug
return
else:
raise Exception("Invalid value of parameter 'who'.")
def submodel_fixup(flags, tup):
return tup[0].replace('SUBMODEL', flags.replace(tup[1], ''))
if options.cpu != options.arch:
if options.cpu in self.mach_opt_flags:
yield submodel_fixup(options.cpu, self.mach_opt_flags[options.cpu])
elif options.arch in self.mach_opt_flags:
yield submodel_fixup(options.cpu, self.mach_opt_flags[options.arch])
all_arch = 'all_%s' % (options.arch)
if all_arch in self.mach_opt_flags:
yield self.mach_opt_flags[all_arch][0]
return (' '.join(gen_flags())).strip()
"""
Return the command needed to link a shared object
"""
def so_link_command_for(self, osname, options):
if options.build_mode == 'debug':
search_for = [osname + "-debug", 'default-debug']
else:
search_for = [osname, 'default']
for s in search_for:
if s in self.so_link_commands:
return self.so_link_commands[s]
raise Exception("No shared library link command found for target '%s' in compiler settings '%s'. Searched for: %s" %
(osname, self.infofile, ", ".join(search_for)))
"""
Return the command needed to link an app/test object
"""
def binary_link_command_for(self, osname, options):
if options.build_mode == 'debug':
search_for = [osname + "-debug", 'default-debug']
else:
search_for = [osname, 'default']
for s in search_for:
if s in self.binary_link_commands:
return self.binary_link_commands[s]
raise Exception("No binary link command found for target '%s' in compiler settings '%s'. Searched for: %s" %
(osname, self.infofile, ", ".join(search_for)))
"""
Return defines for build.h
"""
def defines(self):
return ['BUILD_COMPILER_IS_' + self.macro_name]
class OsInfo(object):
def __init__(self, infofile):
lex_me_harder(infofile, self,
['aliases', 'target_features'],
{ 'os_type': None,
'program_suffix': '',
'obj_suffix': 'o',
'so_suffix': 'so',
'static_suffix': 'a',
'ar_command': 'ar crs',
'ar_needs_ranlib': False,
'install_root': '/usr/local',
'header_dir': 'include',
'bin_dir': 'bin',
'lib_dir': 'lib',
'doc_dir': 'share/doc',
'build_shared': 'yes',
'install_cmd_data': 'install -m 644',
'install_cmd_exec': 'install -m 755'
})
self.ar_needs_ranlib = bool(self.ar_needs_ranlib)
self.build_shared = (True if self.build_shared == 'yes' else False)
def ranlib_command(self):
return ('ranlib' if self.ar_needs_ranlib else 'true')
def defines(self, options):
r = []
for feat in self.target_features:
if feat not in options.without_os_features: