2 # SPDX-FileCopyrightText: Copyright © 2023 Nedko Arnaudov
3 # SPDX-FileCopyrightText: Copyright © 2016-2017 Karl Linden
4 # SPDX-License-Identifier: BSD-2-Clause
6 class WafToolchainFlags
:
8 Waf helper class for handling set of CFLAGS
9 and related. The flush() method will
10 prepend so to allow supplied by (downstream/distro/builder) waf caller flags
11 to override the upstream flags in wscript.
12 TODO: upstream this or find alternative easy way of doing the same
14 def __init__(self
, conf
):
16 :param conf: Waf configuration object
20 for x
in ('CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LINKFLAGS'):
25 Flush flags to the configuration object
26 Prepend is used so to allow supplied by
27 (downstream/distro/builder) waf caller flags
28 to override the upstream flags in wscript.
30 for key
, val
in self
.flags
.items():
31 self
.conf
.env
.prepend_value(key
, val
)
33 def add(self
, key
, val
):
35 :param key: Set to add flags to. 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS' or 'LINKFLAGS'
36 :param val: string or list of strings
38 flags
= self
.flags
[key
]
39 if isinstance(val
, list):
42 if not isinstance(x
, str):
43 raise Exception("value must be string or list of strings. ", type(x
))
45 elif isinstance(val
, str):
48 raise Exception("value must be string or list of strings")
50 def add_cpp(self
, value
):
52 Add flag or list of flags to CPPFLAGS
53 :param value: string or list of strings
55 self
.add('CPPFLAGS', value
)
57 def add_c(self
, value
):
59 Add flag or list of flags to CFLAGS
60 :param value: string or list of strings
62 self
.add('CFLAGS', value
)
64 def add_cxx(self
, value
):
66 Add flag or list of flags to CXXFLAGS
67 :param value: string or list of strings
69 self
.add('CXXFLAGS', value
)
71 def add_candcxx(self
, value
):
73 Add flag or list of flags to CFLAGS and CXXFLAGS
74 :param value: string or list of strings
79 def add_link(self
, value
):
81 Add flag or list of flags to LINKFLAGS
82 :param value: string or list of strings
84 self
.add('LINKFLAGS', value
)
88 Print via conf.msg all non-empty flags
91 ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
92 ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
93 ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
95 for name
, vars in tool_flags
:
98 flags
+= self
.conf
.all_envs
[''][var
]
100 self
.conf
.msg(name
, repr(flags
), color
='NORMAL')