def generate(relnotes, to_version, source_dir, output_dir):
    '''
       Generate notes for Meson build next release.
    '''
    title_suffix = ' (in development)' if output_dir else ''
    title = f'{to_version}{title_suffix}'
    output = Path(output_dir, relnotes) if output_dir else Path('markdown', relnotes)
    output.parent.mkdir(exist_ok=True, parents=True)
    with output.open('w', encoding='utf-8') as ofile:
        ofile.write(RELNOTE_TEMPLATE.format(title, to_version, title_suffix))
        if not output_dir:
            date = datetime.date.today()
            date_str = date.strftime("%d %B %Y")
            ofile.write(f'Meson {to_version} was released on {date_str}\n')
        for snippetfile in sorted(Path(source_dir, 'markdown/snippets').glob('*.md')):
            snippet = snippetfile.read_text(encoding='utf-8')
            ofile.write(snippet)
            if not snippet.endswith('\n'):
                ofile.write('\n')
            ofile.write('\n')

    if not output_dir:
        subprocess.check_call(['git', 'rm', 'markdown/snippets/*.md'])
        subprocess.check_call(['git', 'add', output])

       Generate notes for Meson build next release.
    
docs/genrelnotes.py