gen-doc.sh 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. #
  3. # Generate documentation
  4. #
  5. basedir="$(dirname "$0")"
  6. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  7. srcdir="$basedir/.."
  8. die()
  9. {
  10. echo "$*" >&2
  11. exit 1
  12. }
  13. gen()
  14. {
  15. local rst="$1"
  16. local docname="$(basename "$rst" .rst)"
  17. local dir="$(dirname "$rst")"
  18. local html="$dir/$docname.html"
  19. local tmpfile="$(mktemp --tmpdir=/tmp --suffix=.rst)"
  20. echo "Generating $(realpath --relative-to="$srcdir" "$html") from $(realpath --relative-to="$srcdir" "$rst") ..."
  21. sed -e 's|\.rst>`_|.html>`_|g' "$rst" > "$tmpfile" ||\
  22. die "Failed to generate"
  23. python3 -m readme_renderer -o "$html" "$tmpfile" ||\
  24. die "Failed to generate"
  25. rm "$tmpfile" ||\
  26. die "Failed to delete temporary file"
  27. }
  28. for i in $(find "$srcdir" \( -name submodules -prune \) -o \( -name release-archives -prune \) -o \( -name build -prune \) -o \( -name toolchain-build -prune \) -o \( -name crcgen -prune \) -o \( -name '*.rst' -print \)); do
  29. gen "$i"
  30. done
  31. exit 0