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>
27 if isinstance(compiler
, str):
29 out
= run([*compiler
, '-E', '-dM', '-'], input=inp
,
30 check
=True, stdout
=PIPE
, encoding
='utf-8').stdout
31 def_start
= '#define '
33 for define
in out
.splitlines():
34 assert define
.startswith(def_start
)
35 define
= define
[len(def_start
):]
36 name
, space
, value
= define
.partition(' ')
38 if not name
.isidentifier():
41 # resolve things defined in terms of other things
42 more_substitutions
= True
43 while more_substitutions
:
44 more_substitutions
= False
45 for name
, value
in defines
.items():
46 new_value
= defines
.get(value
)
47 if new_value
is not None and new_value
!= value
:
48 defines
[name
] = new_value
49 more_substitutions
= True
50 for name
, value
in defines
.items():
51 if value
.startswith('(') and value
.endswith(')'):
53 if len(value
) > 1 and value
.startswith('0') and value
[1].isdigit():
54 value
= '0o' + value
[1:]
56 flags
[name
] = int(value
, 0)
61 parse_defines(globals(), 'powerpc64le-linux-gnu-gcc')
65 return parse_defines({}, sysconfig
.get_config_var('CC').split(' '))
67 host_defines
= _host_defines()