diff options
author | Mathieu Duponchelle <MathieuDuponchelle@users.noreply.github.com> | 2018-06-01 19:53:07 +0200 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-06-01 17:53:07 +0000 |
commit | 14750b50ea9c9f53237bed59a79365e1ebbdacda (patch) | |
tree | 9497bd107cc4889bdb6daf60094bf650c1315e82 /mesonbuild/mesonlib.py | |
parent | 17cb364046661c2d72193b4d8691070fd0fb276b (diff) | |
download | meson-14750b50ea9c9f53237bed59a79365e1ebbdacda.zip meson-14750b50ea9c9f53237bed59a79365e1ebbdacda.tar.gz meson-14750b50ea9c9f53237bed59a79365e1ebbdacda.tar.bz2 |
configure_file: Add output_format kwarg (#3636)
* configure_file: Add output_format kwarg
* docs: Reference-manual.md output_format was added in 0.47 [skip ci]
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r-- | mesonbuild/mesonlib.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index fe426c5..6a38479 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -634,28 +634,46 @@ def do_conf_file(src, dst, confdata, format): replace_if_different(dst, dst_tmp) return missing_variables -def dump_conf_header(ofilename, cdata): - ofilename_tmp = ofilename + '~' - with open(ofilename_tmp, 'w', encoding='utf-8') as ofile: - ofile.write('''/* +CONF_C_PRELUDE = '''/* * Autogenerated by the Meson build system. * Do not edit, your changes will be lost. */ #pragma once -''') +''' + +CONF_NASM_PRELUDE = '''; Autogenerated by the Meson build system. +; Do not edit, your changes will be lost. + +''' + +def dump_conf_header(ofilename, cdata, output_format): + if output_format == 'c': + prelude = CONF_C_PRELUDE + prefix = '#' + elif output_format == 'nasm': + prelude = CONF_NASM_PRELUDE + prefix = '%' + + ofilename_tmp = ofilename + '~' + with open(ofilename_tmp, 'w', encoding='utf-8') as ofile: + ofile.write(prelude) for k in sorted(cdata.keys()): (v, desc) = cdata.get(k) if desc: - ofile.write('/* %s */\n' % desc) + if output_format == 'c': + ofile.write('/* %s */\n' % desc) + elif output_format == 'nasm': + for line in desc.split('\n'): + ofile.write('; %s\n' % line) if isinstance(v, bool): if v: - ofile.write('#define %s\n\n' % k) + ofile.write('%sdefine %s\n\n' % (prefix, k)) else: - ofile.write('#undef %s\n\n' % k) + ofile.write('%sundef %s\n\n' % (prefix, k)) elif isinstance(v, (int, str)): - ofile.write('#define %s %s\n\n' % (k, v)) + ofile.write('%sdefine %s %s\n\n' % (prefix, k, v)) else: raise MesonException('Unknown data type in configuration file entry: ' + k) replace_if_different(ofilename, ofilename_tmp) |