makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- make -*-
  2. # This will compile the gettext message catalogues.
  3. # The other make files drop file lists in build/po/domains/DOMAIN/* which
  4. # is then picked up by this make file to define all the domains and all the
  5. # source files that compose each domain. It then produces the POT files
  6. # and then filters the PO files through the per-domain POT file to create
  7. # the input to msgformat, which is then dumped into a locale directory.
  8. BASE=..
  9. SUBDIR=po
  10. # Bring in the default rules
  11. include ../buildlib/defaults.mak
  12. CATALOGS := $(addsuffix .gmo, $(shell sed -e '/^\#/ d' -e '/^$$/ d' LINGUAS | tr '\n' ' '))
  13. DOMAINS := $(sort $(notdir $(wildcard $(PO_DOMAINS)/*)))
  14. POTFILES := $(addsuffix .pot,$(addprefix $(PO)/,$(DOMAINS)))
  15. # Construct a list of all mo files for all domains under $(PO_DOMAINS)
  16. MOFILES := $(patsubst %.gmo,%.mo,$(CATALOGS))
  17. MOFILES := $(foreach D,$(DOMAINS),$(addprefix $(PO_DOMAINS)/$(D)/,$(MOFILES)))
  18. LANG_POFILES := $(patsubst %.mo,%.po,$(MOFILES))
  19. LINGUAS := $(patsubst %.gmo,%,$(CATALOGS))
  20. GETDOMAIN = $(word 1,$(subst /, ,$(1)))
  21. # Generate the list of files from the bits the other make files dropped
  22. # and produce the .pot file.
  23. $(POTFILES) : $(PO)/%.pot :
  24. echo "Generating POT file $@"
  25. echo $@ : $(wildcard $(PO)/domains/$*/*.*list) $(addprefix $(BASE)/,$(shell cat $(wildcard $(PO)/domains/$*/*.srclist))) > $@.d.tmp
  26. cmp --silent $@.d.tmp $@.d || mv $@.d.tmp $@.d
  27. # From sh source
  28. cat $(PO)/domains/$*/*.shlist 2> /dev/null | (cd $(BASE) && xargs -n1 bash --dump-po-strings) > $(PO)/domains/$*/sh.pot.tmp
  29. cmp --silent $(PO)/domains/$*/sh.pot.tmp $(PO)/domains/$*/sh.pot || \
  30. mv $(PO)/domains/$*/sh.pot.tmp $(PO)/domains/$*/sh.pot
  31. # From C/C++ source
  32. cat $(PO)/domains/$*/*.srclist | sort > $(PO)/POTFILES_$*.in
  33. $(XGETTEXT) --default-domain=$* --directory=$(BASE) \
  34. --add-comments --foreign --keyword=_ --keyword=N_ \
  35. --add-location=file \
  36. --keyword=P_:1,2 \
  37. --files-from=$(PO)/POTFILES_$*.in -o $(PO)/domains/$*/c.pot.tmp
  38. cmp --silent $(PO)/domains/$*/c.pot.tmp $(PO)/domains/$*/c.pot || \
  39. mv $(PO)/domains/$*/c.pot.tmp $(PO)/domains/$*/c.pot
  40. rm -f $(PO)/POTFILES_$*.in
  41. $(MSGCOMM) --omit-header --more-than=0 $(PO)/domains/$*/c.pot $(PO)/domains/$*/sh.pot --output=$@.tmp
  42. cmp --silent $@ $@.tmp || mv $@.tmp $@
  43. # copy into the domain dirs to make rosetta happy
  44. rm -f $(PO)/domains/$*/*.pot
  45. cp $@ $(PO)/domains/$*
  46. # Filter the complete translation with the domain specific file to produce
  47. # only the subtext needed for this domain
  48. # We cannot express the dependencies required for this directly with a pattern
  49. # rule, so we use the .d hack.
  50. $(LANG_POFILES) : $(PO_DOMAINS)/%.po : $(POTFILES)
  51. printf "%s " "Generating $@"
  52. echo $@ : $(notdir $@) $(PO)/$(call GETDOMAIN,$*).pot > $(PO)/$(call GETDOMAIN,$*)_$(notdir $@).d
  53. $(MSGMERGE) --add-location=file $(notdir $@) $(PO)/$(call GETDOMAIN,$*).pot -o $@
  54. $(MOFILES) : $(PO_DOMAINS)/%.mo : $(PO_DOMAINS)/%.po
  55. printf "%s: " "Generating $(LOCALE)/$(notdir $*)/LC_MESSAGES/$(call GETDOMAIN,$*).mo"
  56. $(GMSGFMT) --statistics -o $@ $<
  57. mkdir -p $(LOCALE)/$(notdir $*)/LC_MESSAGES/
  58. cp $@ $(LOCALE)/$(notdir $*)/LC_MESSAGES/$(call GETDOMAIN,$*).mo
  59. stats: all-linguas-enabled
  60. for i in *.pot *.po; do echo -n "$$i: "; msgfmt --output-file=/dev/null --statistics $$i; done
  61. binary: $(POTFILES) $(MOFILES) all-linguas-enabled
  62. $(PACKAGE)-all.pot: $(POTFILES)
  63. # we create our partial pot files without a header to avoid changing dates in *.mo files,
  64. # but we want a header for our master-pot file, so we use a dummy pot with nothing but the header
  65. $(XGETTEXT) --default-domain=$(PO)/$(PACKAGE)-dummy.pot --foreign --language=c \
  66. -o $(PO)/$(PACKAGE)-dummy.pot --force-po --package-name='$(PACKAGE)' \
  67. --package-version='$(PACKAGE_VERSION)' --msgid-bugs-address='$(PACKAGE_MAIL)' /dev/null
  68. $(MSGCOMM) --more-than=0 $(PO)/$(PACKAGE)-dummy.pot $(POTFILES) --output=$(PACKAGE)-all.pot
  69. rm -f $(PO)/$(PACKAGE)-dummy.pot
  70. .PHONY: update-po all-linguas-enabled
  71. update-po: $(PACKAGE)-all.pot all-linguas-enabled
  72. for lang in ${LINGUAS}; do \
  73. echo "Updating $$lang.po"; \
  74. $(MSGMERGE) $$lang.po $(PACKAGE)-all.pot -o $$lang.new.po; \
  75. cmp $$lang.new.po $$lang.po || cp $$lang.new.po $$lang.po; \
  76. rm -f $$lang.new.po; \
  77. done
  78. all-linguas-enabled: LINGUAS
  79. ifdef NOISY
  80. echo "Available Translations: $(shell ls *.po | cut -d'.' -f 1 | sort | tr '\n' ' ')"
  81. echo "Mentioned Translations: $(shell sed -e '/^\#\#/ d' -e '/^$$/ d' -e 's/# //' LINGUAS | tr ' ' '\n' | sort | tr '\n' ' ')"
  82. echo "Build Translations: $(shell echo "$(LINGUAS)" | tr ' ' '\n' | sort | tr '\n' ' ')"
  83. endif
  84. test "$(shell ls *.po | cut -d'.' -f 1 | sort | tr '\n' ' ')" = \
  85. "$(shell sed -e '/^\#\#/ d' -e '/^$$/ d' -e 's/# //' LINGUAS | tr ' ' '\n' | sort | tr '\n' ' ')" || \
  86. ( echo "ERROR: Not all available translations are mentioned in po/LINGUAS!"; exit 100)
  87. clean: clean/local
  88. clean/local:
  89. rm -f $(MOFILES) $(LANG_POFILES) $(PO)/*.d
  90. # Include the dependencies that are available
  91. The_DFiles = $(wildcard $(PO)/*.d)
  92. ifneq ($(words $(The_DFiles)),0)
  93. include $(The_DFiles)
  94. endif
  95. # otherwise the output is completely screwed
  96. .NOTPARALLEL: