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