@@ -200,6 +200,7 @@
*.[aos]
*.o.json
*.py[co]
+.build/
.depend/
*.gcda
*.gcno
@@ -569,6 +569,7 @@ INSTALL = install
TCL_PATH = tclsh
TCLTK_PATH = wish
XGETTEXT = xgettext
+MSGCAT = msgcat
MSGFMT = msgfmt
CURL_CONFIG = curl-config
GCOV = gcov
@@ -855,6 +856,7 @@ SOURCES_CMD = ( \
-o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
-o \( -name contrib -type d -prune \) \
-o \( -name build -type d -prune \) \
+ -o \( -name .build -type d -prune \) \
-o \( -name 'trash*' -type d -prune \) \
-o \( -name '*.[hcS]' -type f -print \) \
-o \( -name '*.sh' -type f -print \) \
@@ -2706,6 +2708,7 @@ XGETTEXT_FLAGS = \
--force-po \
--add-comments=TRANSLATORS: \
--msgid-bugs-address="Git Mailing List <git@vger.kernel.org>" \
+ --package-name=Git \
--from-code=UTF-8
XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
--keyword=_ --keyword=N_ --keyword="Q_:1,2"
@@ -2724,34 +2727,68 @@ LOCALIZED_SH += t/t0200/test.sh
LOCALIZED_PERL += t/t0200/test.perl
endif
-## Note that this is meant to be run only by the localization coordinator
-## under a very controlled condition, i.e. (1) it is to be run in a
-## Git repository (not a tarball extract), (2) any local modifications
-## will be lost.
+## We generate intermediate .build/pot/po/%.po files containing a
+## extract of the translations we find in each file in the source
+## tree. We will assemble them using msgcat to create the final
+## "po/git.pot" file.
+LOCALIZED_ALL_GEN_PO =
+
+LOCALIZED_C_GEN_PO = $(LOCALIZED_C:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_C_GEN_PO)
+
+LOCALIZED_SH_GEN_PO = $(LOCALIZED_SH:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_SH_GEN_PO)
+
+LOCALIZED_PERL_GEN_PO = $(LOCALIZED_PERL:%=.build/pot/po/%.po)
+LOCALIZED_ALL_GEN_PO += $(LOCALIZED_PERL_GEN_PO)
+
## Gettext tools cannot work with our own custom PRItime type, so
## we replace PRItime with PRIuMAX. We need to update this to
## PRIdMAX if we switch to a signed type later.
+$(LOCALIZED_C_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT) \
+ if grep -q PRItime $<; then \
+ (\
+ sed -e 's|PRItime|PRIuMAX|g' <$< \
+ >.build/pot/po/$< && \
+ cd .build/pot/po && \
+ $(XGETTEXT) --omit-header \
+ -o $(@:.build/pot/po/%=%) \
+ $(XGETTEXT_FLAGS_C) $< && \
+ rm $<; \
+ ); \
+ else \
+ $(XGETTEXT) --omit-header \
+ -o $@ $(XGETTEXT_FLAGS_C) $<; \
+ fi
-po/git.pot: $(GENERATED_H) FORCE
- # All modifications will be reverted at the end, so we do not
- # want to have any local change.
- git diff --quiet HEAD && git diff --quiet --cached
+$(LOCALIZED_SH_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
+ -o$@ $(XGETTEXT_FLAGS_SH) $<
- @for s in $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL); \
- do \
- sed -e 's|PRItime|PRIuMAX|g' <"$$s" >"$$s+" && \
- cat "$$s+" >"$$s" && rm "$$s+"; \
- done
+$(LOCALIZED_PERL_GEN_PO): .build/pot/po/%.po: %
+ $(call mkdir_p_parent_template)
+ $(QUIET_XGETTEXT)$(XGETTEXT) --omit-header \
+ -o$@ $(XGETTEXT_FLAGS_PERL) $<
+
+define gen_pot_header
+$(XGETTEXT) $(XGETTEXT_FLAGS_C) \
+ -o - /dev/null | \
+sed -e 's|charset=CHARSET|charset=UTF-8|' \
+ -e 's|\(Last-Translator: \)FULL NAME <.*>|\1make by the Makefile|' \
+ -e 's|\(Language-Team: \)LANGUAGE <.*>|\1Git Mailing List <git@vger.kernel.org>|' \
+ >$@ && \
+echo '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"' >>$@
+endef
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
- $(LOCALIZED_SH)
- $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
- $(LOCALIZED_PERL)
+.build/pot/git.header: $(LOCALIZED_ALL_GEN_PO)
+ $(call mkdir_p_parent_template)
+ $(QUIET_GEN)$(gen_pot_header)
- # Reverting the munged source, leaving only the updated $@
- git reset --hard
- mv $@+ $@
+po/git.pot: .build/pot/git.header $(LOCALIZED_ALL_GEN_PO) FORCE
+ $(QUIET_GEN)$(MSGCAT) $(filter-out FORCE,$^) >$@
.PHONY: pot
pot: po/git.pot
@@ -3290,6 +3327,7 @@ cocciclean:
$(RM) contrib/coccinelle/*.cocci.patch*
clean: profile-clean coverage-clean cocciclean
+ $(RM) -r .build
$(RM) *.res
$(RM) $(OBJECTS)
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)