summaryrefslogtreecommitdiff
path: root/make/rules.mk
blob: 38fdbff5b85a1cb8609c4e4768fda5885e6fc83b (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 5:flavor
  13. define MODULE_template
  14. $(3)_BRANCHES += $$(subst -FLAVOR,$(5:%=-$(5)),$$(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)$(5),$(3),$$(subst MODULE,$(3),$$($(4)_ORIGIN)))
  20. $(1): master = $$(subst -FLAVOR,$(5:%=-$(5)),$$(subst -LOCALE,$(2:%=-$(2)),$$($(4)_BRANCH)))
  21. $(1): branches = $$(if $(2)$(5),,$$(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. #$(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(foreach flavor,$(patsubst $(module)-%,%,$($(source)_MODULEFLAVORS)),$(eval $(call MODULE_template,$(flavordir),,$(module),$(source),$(flavor))))))
  37. #$(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(foreach flavor,$(patsubst $(module)-%,%,$($(source)_MODULEFLAVORS)),$(foreach locale,$($(source)_LOCALES),$(eval $(call MODULE_template,$(flavorl10ndir),$(locale),$(module),$(source),$(flavor)))))))
  38. $(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(foreach flavor,$($(source)_$(module)_FLAVORS),$(eval $(call MODULE_template,$(flavordir),,$(module),$(source),$(flavor))))))
  39. $(foreach source,$(SOURCES),$(foreach module,$($(source)_MODULES),$(foreach flavor,$($(source)_$(module)_FLAVORS),$(foreach locale,$($(source)_LOCALES),$(eval $(call MODULE_template,$(flavorl10ndir),$(locale),$(module),$(source),$(flavor)))))))
  40. # Override po4a with local Markdown-supportive text module
  41. export PERL5LIB = $(CURDIR)/perl
  42. # 1:moduledir 2:locale 3:mastermodule 4:source
  43. define POT_template
  44. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  45. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  46. ALL_POTFILES += $(podir)/$(3).pot
  47. $(3)_L10NFILES = $$(patsubst $(1)/%,%,$$(shell find $(1) -type f -name '*.$$(filetype)' | LANG=C sort))
  48. MASTER_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  49. $(podir)/$(3).pot: $(1)
  50. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(1)" package="$(4)" module="$(3)" version="$(5)" locale="LOCALE" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" potfile="$(CURDIR)/$$@" mkpot; \
  51. .PHONY: $(1)
  52. endef
  53. $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(eval $(call POT_template,$(masterdir),,$(module),$(source),$($(source)_VERSION)))))
  54. # 1:moduledir 2:locale 3:mastermodule 4:source 5:originmodule
  55. define INITPO_template
  56. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  57. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  58. ALL_POFILES += $(podir)/$(3).$(2).po
  59. LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  60. $(4)_POMODULES := $(filter-out $(3),$$($(4)_POMODULES))
  61. $(4)_POLOCALES := $(filter-out $(2),$$($(4)_POLOCALES))
  62. $(podir)/$(3).$(2).po: $(3) $(5)
  63. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(3)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" masterdir="$$(CURDIR)/$(1)" pofile="$(CURDIR)/$$@" mkpo
  64. # TODO: Implement the below for automated tests, after unfuzzing the above like this:
  65. # grep -v '^#, fuzzy$' | sed 's/^#, fuzzy,/#,/'
  66. #
  67. #$$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  68. # mkdir -p $(1)
  69. # $(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)/$$@"
  70. endef
  71. $(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)))))))
  72. # 1:moduledir 2:locale 3:mastermodule 4:source
  73. define PO_template
  74. fileformat = $(if $(filter templates,$(3)),$(HTMLTEMPLATE),text)
  75. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  76. ALL_POFILES += $(podir)/$(3).$(2).po
  77. LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  78. $(podir)/$(3).$(2).po: $(3)
  79. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(3)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" pofile="$(CURDIR)/$$@" updatepo
  80. $$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  81. mkdir -p $(1)
  82. $(MAKE) -f "$$(CURDIR)/make/po4a.mk" -C "$(1)" fileformat="$$(fileformat)" l10nfiles="$$($(3)_L10NFILES)" masterdir="$$(CURDIR)/$(3)" pofile="$(CURDIR)/$(podir)/$(3).$(locale).po" "$$(patsubst $(1)/%,%,$$@)"
  83. endef
  84. # Only update if not initializing - can't do both at once
  85. ifeq ($(po-init-modules),)
  86. $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(foreach locale,$($(source)_POLOCALES),$(eval $(call PO_template,$(l10ndir),$(locale),$(module),$(source))))))
  87. endif
  88. # 1:dummydir
  89. define DUMMYMODULE_template
  90. $(1):
  91. mkdir -p $$@
  92. # WARNING: this may wipe unrelated files too!
  93. ultraclean::
  94. rm -rf "$(1)"
  95. endef
  96. $(foreach module,$(dummy_MODULES),$(eval $(call DUMMYMODULE_template,$(masterdir))))
  97. # 1:configfile
  98. define CONFIG_template
  99. $(1):
  100. mkdir -p $$@
  101. # WARNING: this may wipe unrelated files too!
  102. install::
  103. ikiwiki --setup $(1) --rebuild
  104. endef
  105. $(foreach config,$(CONFIGS),$(eval $(call CONFIG_template,$(config))))