summaryrefslogtreecommitdiff
path: root/make/rules.mk
blob: 5369cd0ad3cf16adb72712585e398f3b79aa5190 (plain)
  1. # use markdown template for po4a, or some custom one?
  2. HTMLTEMPLATE = text
  3. # 1:source 2:locales
  4. define SOURCE_template
  5. $(1): $$($(1)_MODULES) $(dummy_MODULES)
  6. .PHONY: $(1)
  7. endef
  8. $(foreach source,$(SOURCES),$(eval $(call SOURCE_template,$(source),$($(source)_LOCALES))))
  9. # Initially clone, and later pull, all Git repositories:
  10. # * Clone master branches from remote origin
  11. # * Clone each non-master from local master
  12. # 1:moduledir 2:locale 3:mastermodule 4:source
  13. define MODULE_template
  14. $(3)_BRANCHES += $$(subst -LOCALE,$(2:%=-$(2)),$$($(4)_BRANCH))
  15. $(4): $(1)
  16. ifneq ($(2),)
  17. $(1): $$(subst module,$(3),$$(masterdir))
  18. endif
  19. $(1): origin = $$(if $(2),$(3),$$(subst MODULE,$(3),$$($(4)_ORIGIN)))
  20. $(1): master = $$(subst -LOCALE,$(2:%=-$(2)),$$($(4)_BRANCH))
  21. $(1): branches = $$(if $(2),,$$(filter-out $$(master),$$($(3)_BRANCHES)))
  22. $(1):
  23. @[ -d "$$(dir $$@)" ] || ( echo mkdir -p "$$(dir $$@)" && mkdir -p "$$(dir $$@)" )
  24. @[ -d "$$@" ] || ( echo git clone -o "$(4)" "$$(origin)" "$$@" && git clone -o "$(4)" "$$(origin)" "$$@" )
  25. @$(MAKE) -f "$$(CURDIR)/make/git.mk" -C "$$@" master="$$(master)" branches="$$(branches)" origin="$(4)" update
  26. # WARNING: this may wipe unrelated files too!
  27. ultraclean::
  28. rm -rf "$(1)"
  29. ifneq ($(2),)
  30. rm -rf "$(dir $(1))"
  31. endif
  32. .PHONY: $(1)
  33. endef
  34. $(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(eval $(call MODULE_template,$(masterdir),,$(module),$(source)))))
  35. $(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(foreach locale,$($(source)_LOCALES),$(eval $(call MODULE_template,$(l10ndir),$(locale),$(module),$(source))))))
  36. # Override po4a with local Markdown-supportive text module
  37. export PERL5LIB = $(CURDIR)/perl
  38. # 1:moduledir 2:locale 3:mastermodule 4:source
  39. define POT_template
  40. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  41. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  42. ALL_POTFILES += $(podir)/$(3).pot
  43. $(3)_L10NFILES = $$(patsubst $(1)/%,%,$$(shell find $(1) -type f -name '*.$$(filetype)' | LANG=C sort))
  44. MASTER_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  45. $(podir)/$(3).pot: $(1)
  46. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(1)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" potfile="$(CURDIR)/$$@" mkpot; \
  47. .PHONY: $(1)
  48. endef
  49. $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(eval $(call POT_template,$(masterdir),,$(module),$(source)))))
  50. # 1:moduledir 2:locale 3:mastermodule 4:source 5:originmodule
  51. define INITPO_template
  52. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  53. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  54. ALL_POFILES += $(podir)/$(3).$(2).po
  55. LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  56. $(4)_POMODULES := $(filter-out $(3),$$($(4)_POMODULES))
  57. $(4)_POLOCALES := $(filter-out $(2),$$($(4)_POLOCALES))
  58. $(podir)/$(3).$(2).po: $(3) $(5)
  59. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(3)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" masterdir="$$(CURDIR)/$(1)" pofile="$(CURDIR)/$$@" mkpo
  60. # TODO: Implement the below for automated tests, after unfuzzing the above like this:
  61. # grep -v '^#, fuzzy$' | sed 's/^#, fuzzy,/#,/'
  62. #
  63. #$$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  64. # mkdir -p $(1)
  65. # $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(1)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" masterdir="$$(CURDIR)/$(3)" pofile="$(CURDIR)/$(podir)/$(3).$(locale).po" threshold=0 "$(CURDIR)/$$@"
  66. endef
  67. $(foreach source,$(SOURCES),$(foreach module,$(po-init-modules),$(foreach locale,$(po-init-locales),$(eval $(call INITPO_template,$(l10ndir),$(locale),$(module),$(source),$(if $(po-init-fromlocale),$(module)_l10n/$(po-init-fromlocale),$(module)))))))
  68. # 1:moduledir 2:locale 3:mastermodule 4:source
  69. define PO_template
  70. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  71. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  72. ALL_POFILES += $(podir)/$(3).$(2).po
  73. LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  74. $(podir)/$(3).$(2).po: $(3)
  75. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(3)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" pofile="$(CURDIR)/$$@" updatepo
  76. $$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  77. mkdir -p $(1)
  78. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(1)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" masterdir="$$(CURDIR)/$(3)" pofile="$(CURDIR)/$(podir)/$(3).$(locale).po" "$$(patsubst $(1)/%,%,$$@)"
  79. endef
  80. # Only update if not initializing - can't do both at once
  81. ifeq ($(po-init-modules),)
  82. $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(foreach locale,$($(source)_POLOCALES),$(eval $(call PO_template,$(l10ndir),$(locale),$(module),$(source))))))
  83. endif
  84. # 1:dummydir
  85. define DUMMYMODULE_template
  86. $(1):
  87. mkdir -p $$@
  88. # WARNING: this may wipe unrelated files too!
  89. ultraclean::
  90. rm -rf "$(1)"
  91. endef
  92. $(foreach module,$(dummy_MODULES),$(eval $(call DUMMYMODULE_template,$(masterdir))))
  93. # 1:configfile
  94. define CONFIG_template
  95. $(1):
  96. mkdir -p $$@
  97. # WARNING: this may wipe unrelated files too!
  98. install::
  99. ikiwiki --setup $(1) --rebuild
  100. endef
  101. $(foreach config,$(CONFIGS),$(eval $(call CONFIG_template,$(config))))