xref: /linux/tools/net/ynl/ynl-regen.sh (revision f9bff0e31881d03badf191d3b0005839391f5f2b)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3
4TOOL=$(dirname $(realpath $0))/ynl-gen-c.py
5
6force=
7
8while [ ! -z "$1" ]; do
9  case "$1" in
10    -f ) force=yes; shift ;;
11    * )  echo "Unrecognized option '$1'"; exit 1 ;;
12  esac
13done
14
15KDIR=$(dirname $(dirname $(dirname $(dirname $(realpath $0)))))
16
17files=$(git grep --files-with-matches '^/\* YNL-GEN \(kernel\|uapi\|user\)')
18for f in $files; do
19    # params:     0       1      2     3
20    #         $YAML YNL-GEN kernel $mode
21    params=( $(git grep -B1 -h '/\* YNL-GEN' $f | sed 's@/\*\(.*\)\*/@\1@') )
22    args=$(sed -n 's@/\* YNL-ARG \(.*\) \*/@\1@p' $f)
23
24    if [ $f -nt ${params[0]} -a -z "$force" ]; then
25	echo -e "\tSKIP $f"
26	continue
27    fi
28
29    echo -e "\tGEN ${params[2]}\t$f"
30    $TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} \
31	  $args -o $f
32done
33