+# ----- metaprogramming (translators, pleaee ignore all this) -----
+#
+# We present translators with a single file po/messages.pot containing
+# all the messages for the translated programs in dgit.deb and
+# git-debrebase.deb. This also includes the messages from the shared
+# perl modules.
+#
+# But when we make the .debs, we want to ship in each .deb the
+# messages for that .deb, only (but including the common parts).
+#
+# So we generate three intermediate .pots,
+# .{dgit,git-debrebase,common}.pot
+# and merge them to make messages.pot.
+#
+# From the translations we generate two .mo files for each output
+# language: {dgit,git-debrebase}.mo -- including the common messages.
+#
+# To avoid dirtying the tree whenever we do `make install',
+# we honour SUPPRESS_PO_UPDATE, to be used like this
+# make install prefix=$(prefix) SUPPRESS_PO_UPDATE=1
+
+all: messages.pot mofiles
+
+e=set -e; exec >$@.tmp
+f=mv -f $@.tmp $@
+o= >$@.tmp && $f
+
+S=@
+# Set S='' to see commands being run
+
+.%.potfiles:
+ $S $e; echo ../$*; $f
+
+.common.potfiles:
+ $S $e; find ../Debian -name \*.pm; $f
+
+.%.make: .%.potfiles Makefile part.make
+ $S $e; \
+ sed 's/~/$*/g' part.make; \
+ sed "s#^#.$*.pot: #" $<; \
+ $f
+
+# echo 'MOS_$$(addsuffix'
+# find -name $*.mo |sed ; $f
+
+-include .dgit.make
+-include .git-debrebase.make
+-include .common.make
+
+POFILES := $(wildcard *.po)
+LANGS := $(basename $(POFILES))
+
+MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
+ $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
+
+messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
+ $S msgcat --to-code=UTF-8 $^ >.messages.0.tmp
+ $S ( ./remove-potcdate <$@ ||: ) >.messages.1.tmp
+ $S ./remove-potcdate <.messages.0.tmp >.messages.2.tmp
+ $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
+ @echo 'Updated $@.'
+
+%.mo: %.po
+ $S msgfmt -o $@ $<
+
+XGETTEXT_OPTS += -Lperl -k__ -k___
+XGETTEXT_OPTS += --from-code=UTF-8
+XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
+# The --package-* avoids this error from make check's `msgfmt -c'
+# warning: header field 'Project-Id-Version' still has the initial default value
+
+%.pot:
+ $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
+
+mofiles: $(MOFILES)
+ @echo 'Generated mo/*.mo (binary translated messages) OK.'