summaryrefslogtreecommitdiff
path: root/make/rules.mk
blob: 753aa3af94c49780ed25bdddf7008d1ec828f3ad (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. # 1:moduledir 2:locale 3:mastermodule 4:source
  8. define MODULE_template
  9. $(4): $(1)
  10. $(1): origin = $$(subst MODULE,$(3),$$($(4)_ORIGIN))
  11. $(1): master = $$(subst -LOCALE,$(2:%=-$(2)),$$($(4)_BRANCH))
  12. $(1):
  13. mkdir -p $$@
  14. @if [ -d "$$@/.git" ]; then \
  15. cd $$@ && \
  16. git pull; \
  17. else \
  18. cd $$@ && \
  19. git init && \
  20. git remote add -f -t $$(master) -m $$(master) origin $$(origin) && \
  21. git merge origin && \
  22. git branch -m $$(master) && \
  23. git config remote.origin.push +refs/heads/$$(master):refs/heads/$$(master); \
  24. fi
  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. # 1:moduledir 2:locale 3:mastermodule 4:source
  36. define POT_template
  37. fileformat = $(if $(filter templates,$(3)),htmltemplate,text)
  38. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  39. ALL_POTFILES += $(podir)/$(3).pot
  40. $(3)_L10NFILES = $$(patsubst $(1)/%,%,$$(shell find $(1) -type f -name '*.$$(filetype)'))
  41. MASTER_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  42. $(podir)/$(3).pot: $(1)
  43. cd "$(1)" && PERL5LIB="$(CURDIR)/perl" po4a-gettextize -M UTF-8 -L UTF-8 -f $$(fileformat) -o markdown $$(patsubst %,-m %,$$($(3)_L10NFILES)) -p $(CURDIR)/$$@
  44. .PHONY: $(1)
  45. endef
  46. $(foreach source,$(SOURCES),$(foreach module,$($(source)_POMODULES),$(eval $(call POT_template,$(masterdir),,$(module),$(source)))))
  47. # 1:moduledir 2:locale 3:mastermodule 4:source 5:originmodule
  48. define INITPO_template
  49. fileformat = $(if $(filter templates,$(3)),htmltemplate,text)
  50. filetype = $(if $(filter templates,$(3)),tmpl,mdwn)
  51. ALL_POFILES += $(podir)/$(3).$(2).po
  52. LOCALE_L10NFILES += $$(patsubst %,$(1)/%,$$($(3)_L10NFILES))
  53. $(4)_POMODULES := $(filter-out $(3),$$($(4)_POMODULES))
  54. $(4)_POLOCALES := $(filter-out $(2),$$($(4)_POLOCALES))
  55. $(podir)/$(3).$(2).po: $(3) $(5)
  56. cd "$(3)" && PERL5LIB="$(CURDIR)/perl" po4a-gettextize -M UTF-8 -L UTF-8 -f $$(fileformat) -o markdown $$(patsubst %,-m %,$$($(3)_L10NFILES)) $$(patsubst %,-l $$(CURDIR)/$(1)/%,$($(3)_L10NFILES)) -p $(CURDIR)/$$@
  57. # TODO: Implement the below for automated tests, after unfuzzing the above like this:
  58. # grep -v '^#, fuzzy$' | sed 's/^#, fuzzy,/#,/'
  59. #
  60. # FIXME: needs to depend also on its masterfile
  61. #$$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  62. # mkdir -p $(1)
  63. # cd "$(1)" && PERL5LIB="$(CURDIR)/perl" po4a-translate -M UTF-8 -L UTF-8 -k 0 -f $(fileformat) -o markdown $$(patsubst $(1)/%,-m $(CURDIR)/$(3)/%,$$@) -p $(CURDIR)/$(podir)/$(3).$(locale).po -l $(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. cd "$(3)" && PERL5LIB="$(CURDIR)/perl" po4a-updatepo -M UTF-8 -f $(fileformat) -o markdown $$(patsubst %,-m %,$$($(3)_L10NFILES)) -p $(CURDIR)/$$@
  74. $$(patsubst %,$(1)/%,$$($(3)_L10NFILES)): $(podir)/$(3).$(2).po
  75. mkdir -p $(1)
  76. cd "$(1)" && PERL5LIB="$(CURDIR)/perl" po4a-translate -M UTF-8 -L UTF-8 -k 100 -f $(fileformat) -o markdown $$(patsubst $(1)/%,-m $$(CURDIR)/$(3)/%,$$@) -p $(CURDIR)/$(podir)/$(3).$(locale).po -l $(CURDIR)/$$@
  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))))