]> granicus.if.org Git - postgresql/blob - src/nls-global.mk
Make .pot files depend on the makefiles, so that they are updated when the
[postgresql] / src / nls-global.mk
1 # $PostgreSQL: pgsql/src/nls-global.mk,v 1.19 2009/01/15 09:01:24 petere Exp $
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 #
16 # That's all, the rest is done here, if --enable-nls was specified.
17 #
18 # The only user-visible targets here are 'init-po', to make an initial
19 # "blank" catalog from program sources, and 'update-po', which is to
20 # be called if the messages in the program source have changed, in
21 # order to merge the changes into the existing .po files.
22
23
24 # existence checked by Makefile.global; otherwise we won't get here
25 include $(srcdir)/nls.mk
26
27 # If user specified the languages he wants in --enable-nls=LANGUAGES,
28 # filter out the rest.  Else use all available ones.
29 ifdef WANTED_LANGUAGES
30 LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
31 else
32 LANGUAGES = $(AVAIL_LANGUAGES)
33 endif
34
35 PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
36 MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
37
38 ifdef XGETTEXT
39 XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org
40 endif
41
42
43 all-po: $(MO_FILES)
44
45 %.mo: %.po
46         $(MSGFMT) -o $@ $<
47
48 ifdef XGETTEXT
49 ifeq ($(word 1,$(GETTEXT_FILES)),+)
50 po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
51         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) -f $<
52 else
53 po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
54 # Change to srcdir explicitly, don't rely on $^.  That way we get
55 # consistent #: file references in the po files.
56         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(GETTEXT_FILES)
57 endif
58         @$(mkinstalldirs) $(dir $@)
59         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 >$@
60         rm messages.po
61 else # not XGETTEXT
62         @echo "You don't have 'xgettext'."; exit 1
63 endif # not XGETTEXT
64
65
66 # catalog name extentions must match behavior of PG_TEXTDOMAIN() in c.h
67 install-po: all-po installdirs-po
68 ifneq (,$(LANGUAGES))
69         for lang in $(LANGUAGES); do \
70           $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
71         done
72 endif
73
74 installdirs-po:
75         $(mkinstalldirs) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES)
76
77 uninstall-po:
78         rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo)
79
80
81 clean-po:
82         $(if $(MO_FILES),rm -f $(MO_FILES))
83         @$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
84         rm -f po/$(CATALOG_NAME).pot
85
86
87 maintainer-check-po: $(PO_FILES)
88         for file in $^; do \
89           $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
90         done
91
92
93 init-po: po/$(CATALOG_NAME).pot
94
95
96 # For performance reasons, only calculate these when the user actually
97 # requested update-po or a specific file.
98 ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
99 ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | sort -u)
100 all_compendia := $(shell find $(top_srcdir) -name '*.po' -print)
101 else
102 ALL_LANGUAGES = $(AVAIL_LANGUAGES)
103 all_compendia = FORCE
104 FORCE:
105 endif
106
107 ifdef WANTED_LANGUAGES
108 ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
109 endif
110
111 update-po: $(ALL_LANGUAGES:%=po/%.po.new)
112
113 $(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
114         $(MSGMERGE) $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
115
116 # For languages not yet available, merge against empty file, to pick
117 # up translations from the compendia.
118 po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
119         $(MSGMERGE) /dev/null $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
120
121
122 all: all-po
123 install: install-po
124 installdirs: installdirs-po
125 uninstall: uninstall-po
126 clean distclean maintainer-clean: clean-po
127 maintainer-check: maintainer-check-po
128
129 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
130         maintainer-check-po init-po update-po
131 .SILENT: installdirs-po