]> granicus.if.org Git - postgresql/blob - src/nls-global.mk
Run maintainer-check on all PO files, not only configured ones
[postgresql] / src / nls-global.mk
1 # src/nls-global.mk
2
3 # Common rules for Native Language Support (NLS)
4 #
5 # If some subdirectory of the source tree wants to provide NLS, it
6 # needs to contain a file 'nls.mk' with the following make variable
7 # assignments:
8 #
9 # CATALOG_NAME          -- name of the message catalog (xxx.po); probably
10 #                          name of the program
11 # AVAIL_LANGUAGES       -- list of languages that are provided/supported
12 # GETTEXT_FILES         -- list of source files that contain message strings
13 # GETTEXT_TRIGGERS      -- (optional) list of functions that contain
14 #                          translatable strings
15 # GETTEXT_FLAGS         -- (optional) list of gettext --flag arguments to mark
16 #                          function arguments that contain C format strings
17 #                          (functions must be listed in TRIGGERS and FLAGS)
18 #
19 # That's all, the rest is done here, if --enable-nls was specified.
20 #
21 # The only user-visible targets here are 'init-po', to make an initial
22 # "blank" catalog from program sources, and 'update-po', which is to
23 # be called if the messages in the program source have changed, in
24 # order to merge the changes into the existing .po files.
25
26
27 # existence checked by Makefile.global; otherwise we won't get here
28 include $(srcdir)/nls.mk
29
30 # If user specified the languages he wants in --enable-nls=LANGUAGES,
31 # filter out the rest.  Else use all available ones.
32 ifdef WANTED_LANGUAGES
33 LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
34 else
35 LANGUAGES = $(AVAIL_LANGUAGES)
36 endif
37
38 PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
39 ALL_PO_FILES = $(addprefix po/, $(addsuffix .po, $(AVAIL_LANGUAGES)))
40 MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
41
42 ifdef XGETTEXT
43 XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org
44 endif
45
46 # _ is defined in c.h, so it's global
47 GETTEXT_TRIGGERS += _
48 GETTEXT_FLAGS    += _:1:pass-c-format
49
50
51 # common settings that apply to backend and all backend modules
52 BACKEND_COMMON_GETTEXT_TRIGGERS = \
53     errmsg errmsg_plural:1,2 \
54     errdetail errdetail_log errdetail_plural:1,2 \
55     errhint \
56     errcontext
57 BACKEND_COMMON_GETTEXT_FLAGS = \
58     errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
59     errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
60     errhint:1:c-format \
61     errcontext:1:c-format
62
63
64 all-po: $(MO_FILES)
65
66 %.mo: %.po
67         $(MSGFMT) -o $@ $<
68
69 ifeq ($(word 1,$(GETTEXT_FILES)),+)
70 po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
71 ifdef XGETTEXT
72         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) -f $<
73 else
74         @echo "You don't have 'xgettext'."; exit 1
75 endif
76 else # GETTEXT_FILES
77 po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
78 # Change to srcdir explicitly, don't rely on $^.  That way we get
79 # consistent #: file references in the po files.
80 ifdef XGETTEXT
81         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) $(GETTEXT_FILES)
82 else
83         @echo "You don't have 'xgettext'."; exit 1
84 endif
85 endif # GETTEXT_FILES
86         @$(MKDIR_P) $(dir $@)
87         sed -e '1,18 { s/SOME DESCRIPTIVE TITLE./LANGUAGE message translation file for $(CATALOG_NAME)/;s/PACKAGE/PostgreSQL/g;s/VERSION/$(MAJORVERSION)/g;s/YEAR/'`date +%Y`'/g; }' messages.po >$@
88         rm messages.po
89
90
91 # catalog name extentions must match behavior of PG_TEXTDOMAIN() in c.h
92 install-po: all-po installdirs-po
93 ifneq (,$(LANGUAGES))
94         for lang in $(LANGUAGES); do \
95           $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
96         done
97 endif
98
99 installdirs-po:
100         $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
101
102 uninstall-po:
103         $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
104
105
106 clean-po:
107         $(if $(MO_FILES),rm -f $(MO_FILES))
108         @$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
109         rm -f po/$(CATALOG_NAME).pot
110
111
112 maintainer-check-po: $(ALL_PO_FILES)
113         for file in $^; do \
114           $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
115         done
116
117
118 init-po: po/$(CATALOG_NAME).pot
119
120
121 # For performance reasons, only calculate these when the user actually
122 # requested update-po or a specific file.
123 ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
124 ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | LC_ALL=C sort -u)
125 all_compendia := $(shell find $(top_srcdir) -name '*.po' -print | LC_ALL=C sort)
126 else
127 ALL_LANGUAGES = $(AVAIL_LANGUAGES)
128 all_compendia = FORCE
129 FORCE:
130 endif
131
132 ifdef WANTED_LANGUAGES
133 ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
134 endif
135
136 update-po: $(ALL_LANGUAGES:%=po/%.po.new)
137
138 $(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
139         $(MSGMERGE) $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
140
141 # For languages not yet available, merge against oneself, to pick
142 # up translations from the compendia.  (Merging against /dev/null
143 # doesn't work so well; it inserts the headers from the first-named
144 # compendium.)
145 po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
146         $(MSGMERGE) $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
147
148
149 all: all-po
150 install: install-po
151 installdirs: installdirs-po
152 uninstall: uninstall-po
153 clean distclean maintainer-clean: clean-po
154 maintainer-check: maintainer-check-po
155
156 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
157         maintainer-check-po init-po update-po