You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2KB

  1. .SILENT:
  2. OUTDIR?=build
  3. RESOURCESDIR=$(OUTDIR)/resources
  4. TEMPDIR?=$(OUTDIR)/xepbuild
  5. XMLDEPS=xep.xsl xep.xsd xep.ent xep.dtd ref.xsl $(OUTDIR)
  6. TEXMLDEPS=xep2texml.xsl $(OUTDIR)/xmpp.pdf $(OUTDIR)/xmpp-text.pdf
  7. XMPPIMAGESURL=https://xmpp.org/images
  8. XEPDIRS=. inbox
  9. .PHONY: help
  10. help:
  11. @echo 'XEP makefile targets:'
  12. @echo ' '
  13. @echo ' help - (this message)'
  14. @echo ' all - build all XEPs (same as make html)'
  15. @echo ' html - build all XEPs'
  16. @echo ' clean - recursively unlink the build tree'
  17. @echo ' preview - builds html whenever an XEP changes (requires inotify-tools)'
  18. @echo ' xep-xxxx - build xep-xxxx.html'
  19. @echo ' xep-xxxx.pdf - build xep-xxxx.pdf (requires xelatex and texml)'
  20. @echo ' xep-xxxx.html - build xep-xxxx.html'
  21. @echo ' '
  22. @echo 'Output directory: "$(OUTDIR)/"'
  23. .PHONY: all
  24. all: html
  25. .PHONY: html
  26. html: $(patsubst %.xml, $(OUTDIR)/%.html, $(wildcard *.xml))
  27. .PHONY: pdf
  28. pdf: $(patsubst %.xml, $(OUTDIR)/%.pdf, $(wildcard *.xml))
  29. .PHONY: xep-%
  30. xep-%: $(OUTDIR)/xep-%.html ;
  31. .PHONY: xep-%.html
  32. xep-%.html: $(OUTDIR)/xep-%.html ;
  33. .PHONY: xep-%.pdf
  34. xep-%.pdf: $(OUTDIR)/xep-%.pdf ;
  35. .PHONY: dependencies
  36. dependencies: $(OUTDIR)/prettify.css $(OUTDIR)/prettify.js $(OUTDIR)/xmpp.css ;
  37. $(OUTDIR)/%.html: %.xml $(XMLDEPS) dependencies
  38. # TODO: After existing issues are worked out this and the ratcheting CI build
  39. # should be removed and become an error, not just a warning.
  40. xmllint --nonet --noout --noent --loaddtd --valid "$<" || true
  41. # Check for non-data URIs
  42. ! xmllint --nonet --noout --noent --loaddtd --xpath "//img/@src[not(starts-with(., 'data:'))]" $< 2>/dev/null && true
  43. # Actually build the HTML
  44. xsltproc --path $(CURDIR) xep.xsl "$<" > "$@" && echo "Finished building $@"
  45. $(OUTDIR)/xmpp.pdf $(OUTDIR)/xmpp-text.pdf:
  46. cp "resources/$(notdir $@)" "$@"
  47. $(OUTDIR)/%.pdf: %.xml $(TEXMLDEPS) $(XMLDEPS) dependencies
  48. # TODO: After existing issues are worked out this and the ratcheting CI build
  49. # should be removed and become an error, not just a warning.
  50. xmllint --nonet --noout --noent --loaddtd --valid "$<" || true
  51. # Check for non-data URIs
  52. ! xmllint --nonet --noout --noent --loaddtd --xpath "//img/@src[not(starts-with(., 'data:'))]" $< 2>/dev/null && true
  53. xsltproc --path $(CURDIR) xep2texml.xsl "$<" > "$(@:.pdf=.tex.xml)"
  54. texml -e utf8 "$(@:.pdf=.tex.xml)" "$(@:.pdf=.tex)"
  55. sed -i -e 's|\([\s"]\)\([^"]http://[^ "]*\)|\1\\path{\2}|g' \
  56. -e 's|\\hyperref\[#\([^}]*\)\]|\\hyperref\[\1\]|g' \
  57. -e 's|\\pageref{#\([^}]*\)}|\\pageref{\1}|g' "$(@:.pdf=.tex)"
  58. cd $(OUTDIR); xelatex -interaction=batchmode -no-shell-escape "$(notdir $(basename $@)).tex" && echo "Finished building $@"
  59. $(OUTDIR)/%.js: %.js
  60. cp "$<" "$@"
  61. $(OUTDIR)/%.css: %.css
  62. cp "$<" "$@"
  63. $(TEMPDIR) $(OUTDIR) $(RESOURCESDIR):
  64. mkdir -p $@
  65. .PHONY: clean
  66. clean:
  67. rm -rf $(OUTDIR)
  68. .PHONY: preview
  69. preview:
  70. inotifywait -m -e close_write,moved_to --format '%e %w %f' $(XEPDIRS) | \
  71. while read -r event dir file; do \
  72. if [ "$${file: -4}" == ".xml" ]; then \
  73. xsltproc --path $(CURDIR) xep.xsl "$${dir}/$${file}" > "$(OUTDIR)/$${file%.*}.html" && echo "Built $${file%.*}.html $${event}"; \
  74. fi \
  75. done