diff options
Diffstat (limited to 'mesonbuild/utils/universal.py')
-rw-r--r-- | mesonbuild/utils/universal.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 7f0f385..1d0e382 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -1351,7 +1351,7 @@ CONF_C_PRELUDE = '''/* * Do not edit, your changes will be lost. */ -#pragma once +{} ''' @@ -1360,10 +1360,16 @@ CONF_NASM_PRELUDE = '''; Autogenerated by the Meson build system. ''' -def _dump_c_header(ofile: T.TextIO, cdata: ConfigurationData, output_format: Literal['c', 'nasm']) -> None: +def _dump_c_header(ofile: T.TextIO, + cdata: ConfigurationData, + output_format: Literal['c', 'nasm'], + macro_name: T.Optional[str]) -> None: format_desc: T.Callable[[str], str] if output_format == 'c': - prelude = CONF_C_PRELUDE + if macro_name: + prelude = CONF_C_PRELUDE.format('#ifndef {0}\n#define {0}'.format(macro_name)) + else: + prelude = CONF_C_PRELUDE.format('#pragma once') prefix = '#' format_desc = lambda desc: f'/* {desc} */\n' else: # nasm @@ -1385,17 +1391,20 @@ def _dump_c_header(ofile: T.TextIO, cdata: ConfigurationData, output_format: Lit ofile.write(f'{prefix}define {k} {v}\n\n') else: raise MesonException('Unknown data type in configuration file entry: ' + k) + if output_format == 'c' and macro_name: + ofile.write('#endif\n') def dump_conf_header(ofilename: str, cdata: ConfigurationData, - output_format: Literal['c', 'nasm', 'json']) -> None: + output_format: Literal['c', 'nasm', 'json'], + macro_name: T.Optional[str]) -> None: ofilename_tmp = ofilename + '~' with open(ofilename_tmp, 'w', encoding='utf-8') as ofile: if output_format == 'json': data = {k: v[0] for k, v in cdata.values.items()} json.dump(data, ofile, sort_keys=True) else: # c, nasm - _dump_c_header(ofile, cdata, output_format) + _dump_c_header(ofile, cdata, output_format, macro_name) replace_if_different(ofilename, ofilename_tmp) |