ynl-regen.sh 973 B

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