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