xref: /dpdk/doc/api/generate_examples.py (revision 53bb9a073f4f905edaba81bc17eb9c33903242bc)
1*53bb9a07SDmitry Kozlyuk#!/usr/bin/env python3
2*53bb9a07SDmitry Kozlyuk# SPDX-License-Identifier: BSD-3-Clause
3*53bb9a07SDmitry Kozlyuk# (c) 2018 Luca Boccassi <bluca@debian.org>
4*53bb9a07SDmitry Kozlyuk# (c) 2022 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
5*53bb9a07SDmitry Kozlyuk
6*53bb9a07SDmitry Kozlyukimport os, sys
7*53bb9a07SDmitry Kozlyuk
8*53bb9a07SDmitry Kozlyukexamples_dir, api_examples = sys.argv[1:]
9*53bb9a07SDmitry Kozlyuk
10*53bb9a07SDmitry Kozlyuksources = []
11*53bb9a07SDmitry Kozlyukwith open(f'{api_examples}.d', 'w') as dep:
12*53bb9a07SDmitry Kozlyuk    print(f'{api_examples}:', end=' ', file=dep)
13*53bb9a07SDmitry Kozlyuk    for root, _, files in os.walk(examples_dir):
14*53bb9a07SDmitry Kozlyuk        for name in files:
15*53bb9a07SDmitry Kozlyuk            is_source = name.endswith('.c')
16*53bb9a07SDmitry Kozlyuk            if is_source or name == 'meson.build':
17*53bb9a07SDmitry Kozlyuk                path = os.path.join(root, name)
18*53bb9a07SDmitry Kozlyuk                if is_source:
19*53bb9a07SDmitry Kozlyuk                    sources.append(path)
20*53bb9a07SDmitry Kozlyuk                print(path , end=' ', file=dep)
21*53bb9a07SDmitry Kozlyuk
22*53bb9a07SDmitry Kozlyukwith open(api_examples, 'w') as out:
23*53bb9a07SDmitry Kozlyuk    print('''/**
24*53bb9a07SDmitry Kozlyuk@page examples DPDK Example Programs
25*53bb9a07SDmitry Kozlyuk''', file=out)
26*53bb9a07SDmitry Kozlyuk    for path in sources:
27*53bb9a07SDmitry Kozlyuk        # Produce consistent output with forward slashes on all systems.
28*53bb9a07SDmitry Kozlyuk        # Every \ in paths within examples directory is a separator, not escape.
29*53bb9a07SDmitry Kozlyuk        relpath = os.path.relpath(path, examples_dir).replace('\\', '/')
30*53bb9a07SDmitry Kozlyuk        print(f'@example examples/{relpath}', file=out)
31*53bb9a07SDmitry Kozlyuk    print('*/', file=out)
32