Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
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.

Makefile 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # -----------------------------------------------------------------------------
  2. # Makefile for FSFE website build, phase 1
  3. # -----------------------------------------------------------------------------
  4. # This Makefile is executed in the root of the source directory tree, and
  5. # creates some .xml and xhtml files as well as some symlinks, all of which
  6. # serve as input files in phase 2. The whole phase 1 runs within the source
  7. # directory tree and does not touch the target directory tree at all.
  8. # -----------------------------------------------------------------------------
  9. .PHONY: all .FORCE
  10. .FORCE:
  11. # -----------------------------------------------------------------------------
  12. # Update XSL stylesheets
  13. # -----------------------------------------------------------------------------
  14. # This step updates (actually: just touches) all XSL files which depend on
  15. # another XSL file that has changed since the last build run. The phase 2
  16. # Makefile then only has to consider the directly used stylesheet as a
  17. # prerequisite for building each file and doesn't have to worry about other
  18. # stylesheets imported into that one.
  19. # This must run before the "dive into subdirectories" step, because in the news
  20. # and events directories, the XSL files, if updated, will be copied for the
  21. # per-year archives.
  22. .PHONY: stylesheets
  23. all: stylesheets
  24. stylesheets: $(SUBDIRS)
  25. tools/update_stylesheets.sh
  26. # -----------------------------------------------------------------------------
  27. # Dive into subdirectories
  28. # -----------------------------------------------------------------------------
  29. SUBDIRS := $(shell find */* -name "Makefile" | xargs dirname)
  30. all: $(SUBDIRS)
  31. $(SUBDIRS): .FORCE
  32. echo "* Preparing subdirectory $@"
  33. $(MAKE) --silent --directory=$@
  34. # -----------------------------------------------------------------------------
  35. # Handle local menus
  36. # -----------------------------------------------------------------------------
  37. # FIXME: This runs when the makefile is parsed, before maybe new *.xhtml files
  38. # are created in the news/<year>/ and events/<year>/ directories. It would be
  39. # better to move this into a separate script tools/update-localmenus.sh. It
  40. # would also be better if there was a separate .localmenu.en.xml file for each
  41. # directory.
  42. MENUSOURCES := $(shell find -name '*.xhtml' -not -name "*-template.*" | xargs grep -l '<localmenu.*</localmenu>' | sort)
  43. all: localmenuinfo.en.xml
  44. localmenuinfo.en.xml: ./tools/buildmenu.xsl $(MENUSOURCES)
  45. { printf '<localmenuset>'; \
  46. grep -E '<localmenu.*</localmenu>' $^ \
  47. | sed -r 's;(.*/)?(.+)\.([a-z][a-z])\.xhtml:(.+);\
  48. <menuitem language="\3"><dir>/\1</dir><link>\2.html</link>\4</menuitem>;'; \
  49. printf '</localmenuset>'; \
  50. } | xsltproc -o $@ $< -
  51. # -----------------------------------------------------------------------------
  52. # Timestamp files for regular jobs and XML inclusion in various places
  53. # -----------------------------------------------------------------------------
  54. YEAR := <?xml version="1.0" encoding="utf-8"?><dateset><date year="$(shell date +%Y)" /></dateset>
  55. MONTH := <?xml version="1.0" encoding="utf-8"?><dateset><date month="$(shell date +%Y-%m)" /></dateset>
  56. DAY := <?xml version="1.0" encoding="utf-8"?><dateset><date day="$(shell date +%Y-%m-%d)" /></dateset>
  57. all: d_year.en.xml d_month.en.xml d_day.en.xml
  58. d_day.en.xml: $(if $(findstring $(DAY),$(shell cat d_day.en.xml)),,.FORCE)
  59. printf %s\\n '$(DAY)' >$@
  60. d_month.en.xml: $(if $(findstring $(MONTH),$(shell cat d_month.en.xml)),,.FORCE)
  61. printf %s\\n '$(MONTH)' >$@
  62. d_year.en.xml: $(if $(findstring $(YEAR),$(shell cat d_year.en.xml)),,.FORCE)
  63. printf %s\\n '$(YEAR)' >$@
  64. # -----------------------------------------------------------------------------
  65. # Create XML symlinks
  66. # -----------------------------------------------------------------------------
  67. # After this step, the following symlinks will exist:
  68. # * tools/.texts-<lang>.xml for each language
  69. # * ./fundraising.<lang>.xml for each language
  70. # Each of these symlinks will point to the corresponding file without a dot at
  71. # the beginning of the filename, if present, and to the English version
  72. # otherwise. This symlinks make sure that phase 2 can easily use the right file
  73. # for each language, also as a prerequisite in the Makefile.
  74. LANGUAGES := $(shell . build/languages.sh && get_languages)
  75. TEXTS_LINKS := $(foreach lang,$(LANGUAGES),tools/.texts-$(lang).xml)
  76. all: $(TEXTS_LINKS)
  77. tools/.texts-%.xml: .FORCE
  78. if [ -f tools/texts-$*.xml ]; then \
  79. ln -sf texts-$*.xml $@; \
  80. else \
  81. ln -sf texts-en.xml $@; \
  82. fi
  83. FUNDRAISING_LINKS := $(foreach lang,$(LANGUAGES),.fundraising.$(lang).xml)
  84. all: $(FUNDRAISING_LINKS)
  85. .fundraising.%.xml: .FORCE
  86. if [ -f fundraising.$*.xml ]; then \
  87. ln -sf fundraising.$*.xml $@; \
  88. else \
  89. ln -sf fundraising.en.xml $@; \
  90. fi
  91. # -----------------------------------------------------------------------------
  92. # Create XSL symlinks
  93. # -----------------------------------------------------------------------------
  94. # After this step, each directory with source files for HTML pages contains a
  95. # symlink named .default.xsl and pointing to the default.xsl "responsible" for
  96. # this directory. These symlinks make it easier for the phase 2 Makefile to
  97. # determine which XSL script should be used to build a HTML page from a source
  98. # file.
  99. # All directories containing source files for HTML pages.
  100. # FIXME: This runs when the makefile is parsed, before maybe new *.xhtml files
  101. # are created in the news/<year>/ and events/<year>/ directories.
  102. XHTML_DIRS := $(patsubst %/,%,$(sort $(dir $(shell find -name '*.??.xhtml'))))
  103. .PHONY: default_xsl
  104. all: default_xsl
  105. default_xsl:
  106. for directory in $(XHTML_DIRS); do \
  107. dir="$${directory}"; \
  108. prefix=""; \
  109. until [ -f "$${dir}/default.xsl" -o "$${dir}" = "." ]; do \
  110. dir="$${dir%/*}"; \
  111. prefix="$${prefix}../"; \
  112. done; \
  113. ln -sf "$${prefix}default.xsl" "$${directory}/.default.xsl"; \
  114. done
  115. # -----------------------------------------------------------------------------
  116. # Update XML filelists
  117. # -----------------------------------------------------------------------------
  118. # After this step, the following files will be up to date:
  119. # * tags/tagged-<tags>.en.xhtml for each tag used. Apart from being
  120. # automatically created, these are regular source files for HTML pages, and
  121. # in phase 2 are built into pages listing all news items and events for a
  122. # tag.
  123. # * tags/.tags.??.xml with a list of the tags useed.
  124. # * <dir>/.<base>.xmllist for each <dir>/<base>.sources as well as for each
  125. # tags/tagged-<tags>.en.xhtml. These files are used in phase 2 to include the
  126. # correct XML files when generating the HTML pages. It is taken care that
  127. # these files are only updated whenever their content actually changes, so
  128. # they can serve as a prerequisite in the phase 2 Makefile.
  129. # This step is handled in an external script, because the list of files to
  130. # generate is not known when the Makefile starts - some new tags might be
  131. # introduced when generating the .xml files in the news/* subdirectories.
  132. .PHONY: xmllists
  133. all: xmllists
  134. xmllists: $(SUBDIRS)
  135. tools/update_xmllists.sh