yacc-wrapper 934 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. # Run yacc such that the working directory is the source root.
  3. # This is needed for various reasons (e.g. #line references).
  4. # Do not use directly.
  5. set -eu
  6. YACC="$1"
  7. PARSER="$2"
  8. IMPLEMENTATION="$3"
  9. HEADER="$4"
  10. ABS_TOP_SRCDIR="$5"
  11. [ $# -eq 5 ] || {
  12. echo "Usage: $0 YACC PARSER IMPLEMENTATION HEADER ABS_TOP_SRCDIR" >&2;
  13. exit 1;
  14. }
  15. cd "$ABS_TOP_SRCDIR" || exit 1
  16. # Generate the parser
  17. "$YACC" --defines="$HEADER" \
  18. --output="$IMPLEMENTATION" \
  19. --name-prefix=_xkbcommon_ \
  20. "$PARSER"
  21. # Add the license of the .y file
  22. PARSER_HEADER=$(awk '/^\/\*/{found=1} found{print} /\*\//{if(found) exit}' "$PARSER")
  23. DO_NOT_EDIT="/* DO NOT EDIT DIRECTLY: This file is generated from $PARSER. */"
  24. for f in "$IMPLEMENTATION" "$HEADER"; do
  25. [ -f "$f" ] || continue
  26. content=$(cat "$f"; echo x)
  27. content=${content%x}
  28. printf '%s\n\n%s\n\n%s' "$PARSER_HEADER" "$DO_NOT_EDIT" "$content" > "$f"
  29. done