7f2fe507efc5983f48d92759ba4f115525ae6af5
1 # SPDX-License-Identifier: LGPLv3+
2 # Copyright (C) 2023 Jacob Lifshay <programmerjake@gmail.com>
3 # Funded by NLnet http://nlnet.nl
4 """ flags for PowerPC syscalls
8 * https://bugs.libre-soc.org/show_bug.cgi?id=1169
11 def parse_defines(flags
, compiler
):
12 """ parse `#define`s into the dict `flags` using the given `compiler`
14 from subprocess
import run
, PIPE
19 #include <sys/syscall.h>
20 #include <sys/types.h>
23 #include <linux/utsname.h>
24 #include <linux/auxvec.h>
26 if isinstance(compiler
, str):
28 out
= run([*compiler
, '-E', '-dM', '-'], input=inp
,
29 check
=True, stdout
=PIPE
, encoding
='utf-8').stdout
30 def_start
= '#define '
32 for define
in out
.splitlines():
33 assert define
.startswith(def_start
)
34 define
= define
[len(def_start
):]
35 name
, space
, value
= define
.partition(' ')
37 if not name
.isidentifier():
40 # resolve things defined in terms of other things
41 more_substitutions
= True
42 while more_substitutions
:
43 more_substitutions
= False
44 for name
, value
in defines
.items():
45 new_value
= defines
.get(value
)
46 if new_value
is not None and new_value
!= value
:
47 defines
[name
] = new_value
48 more_substitutions
= True
49 for name
, value
in defines
.items():
50 if value
.startswith('(') and value
.endswith(')'):
52 if len(value
) > 1 and value
.startswith('0') and value
[1].isdigit():
53 value
= '0o' + value
[1:]
55 flags
[name
] = int(value
, 0)
60 parse_defines(globals(), 'powerpc64le-linux-gnu-gcc')
64 return parse_defines({}, sysconfig
.get_config_var('CC').split(' '))
66 host_defines
= _host_defines()