xref: /openbmc/linux/tools/net/ynl/ynl-regen.sh (revision ae6385af)
1#!/bin/bash
2# SPDX-License-Identifier: 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\)')
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
23    if [ $f -nt ${params[0]} -a -z "$force" ]; then
24	echo -e "\tSKIP $f"
25	continue
26    fi
27
28    echo -e "\tGEN ${params[2]}\t$f"
29    $TOOL --mode ${params[2]} --${params[3]} --spec $KDIR/${params[0]} -o $f
30done
31