nls-global.mk 5.7 KB
Newer Older
1
# src/nls-global.mk
P
Peter Eisentraut 已提交
2 3 4 5 6 7 8

# Common rules for Native Language Support (NLS)
#
# If some subdirectory of the source tree wants to provide NLS, it
# needs to contain a file 'nls.mk' with the following make variable
# assignments:
#
9 10 11 12 13
# CATALOG_NAME          -- name of the message catalog (xxx.po); probably
#                          name of the program
# AVAIL_LANGUAGES       -- list of languages that are provided/supported
# GETTEXT_FILES         -- list of source files that contain message strings
# GETTEXT_TRIGGERS      -- (optional) list of functions that contain
P
Peter Eisentraut 已提交
14
#                          translatable strings
15 16 17
# GETTEXT_FLAGS         -- (optional) list of gettext --flag arguments to mark
#                          function arguments that contain C format strings
#                          (functions must be listed in TRIGGERS and FLAGS)
P
Peter Eisentraut 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#
# That's all, the rest is done here, if --enable-nls was specified.
#
# The only user-visible targets here are 'init-po', to make an initial
# "blank" catalog from program sources, and 'update-po', which is to
# be called if the messages in the program source have changed, in
# order to merge the changes into the existing .po files.


# existence checked by Makefile.global; otherwise we won't get here
include $(srcdir)/nls.mk

# If user specified the languages he wants in --enable-nls=LANGUAGES,
# filter out the rest.  Else use all available ones.
ifdef WANTED_LANGUAGES
LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
else
LANGUAGES = $(AVAIL_LANGUAGES)
endif

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)))
P
Peter Eisentraut 已提交
41

42
ifdef XGETTEXT
43
XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org --no-wrap --sort-by-file --package-name='$(CATALOG_NAME) (PostgreSQL)' --package-version='$(MAJORVERSION)'
44 45 46
endif

ifdef MSGMERGE
47
MSGMERGE += --no-wrap --previous --sort-by-file
48
endif
P
Peter Eisentraut 已提交
49

50 51
# _ is defined in c.h, so it's global
GETTEXT_TRIGGERS += _
52
GETTEXT_FLAGS    += _:1:pass-c-format
53

P
Peter Eisentraut 已提交
54

55 56 57 58 59 60
# common settings that apply to backend and all backend modules
BACKEND_COMMON_GETTEXT_TRIGGERS = \
    errmsg errmsg_plural:1,2 \
    errdetail errdetail_log errdetail_plural:1,2 \
    errhint \
    errcontext
61 62 63 64 65
BACKEND_COMMON_GETTEXT_FLAGS = \
    errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
    errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
    errhint:1:c-format \
    errcontext:1:c-format
66 67


P
Peter Eisentraut 已提交
68 69 70
all-po: $(MO_FILES)

%.mo: %.po
71
	$(MSGFMT) $(MSGFMT_FLAGS) -o $@ $<
P
Peter Eisentraut 已提交
72 73

ifeq ($(word 1,$(GETTEXT_FILES)),+)
74
po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
75
ifdef XGETTEXT
76
	$(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) -f $<
P
Peter Eisentraut 已提交
77
else
78 79 80
	@echo "You don't have 'xgettext'."; exit 1
endif
else # GETTEXT_FILES
81
po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
82 83
# Change to srcdir explicitly, don't rely on $^.  That way we get
# consistent #: file references in the po files.
84
ifdef XGETTEXT
85
	$(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) $(GETTEXT_FILES)
86 87
else
	@echo "You don't have 'xgettext'."; exit 1
P
Peter Eisentraut 已提交
88
endif
89
endif # GETTEXT_FILES
90
	@$(MKDIR_P) $(dir $@)
91 92
	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 >$@
	rm messages.po
P
Peter Eisentraut 已提交
93 94


R
Robert Haas 已提交
95
# catalog name extensions must match behavior of PG_TEXTDOMAIN() in c.h
P
Peter Eisentraut 已提交
96
install-po: all-po installdirs-po
97
ifneq (,$(LANGUAGES))
P
Peter Eisentraut 已提交
98
	for lang in $(LANGUAGES); do \
99
	  $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
P
Peter Eisentraut 已提交
100
	done
101
endif
P
Peter Eisentraut 已提交
102 103

installdirs-po:
104
	$(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
P
Peter Eisentraut 已提交
105 106

uninstall-po:
107
	$(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
P
Peter Eisentraut 已提交
108 109 110


clean-po:
111
	$(if $(MO_FILES),rm -f $(MO_FILES))
112
	@$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
113
	rm -f po/$(CATALOG_NAME).pot
P
Peter Eisentraut 已提交
114 115


116
init-po: po/$(CATALOG_NAME).pot
P
Peter Eisentraut 已提交
117 118


119 120 121
# For performance reasons, only calculate these when the user actually
# requested update-po or a specific file.
ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
122 123
ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | LC_ALL=C sort -u)
all_compendia := $(shell find $(top_srcdir) -name '*.po' -print | LC_ALL=C sort)
P
Peter Eisentraut 已提交
124
else
125 126 127 128 129 130 131
ALL_LANGUAGES = $(AVAIL_LANGUAGES)
all_compendia = FORCE
FORCE:
endif

ifdef WANTED_LANGUAGES
ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
P
Peter Eisentraut 已提交
132 133
endif

134 135 136
update-po: $(ALL_LANGUAGES:%=po/%.po.new)

$(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
137
	$(MSGMERGE) --lang=$* $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
138

139 140 141 142
# For languages not yet available, merge against oneself, to pick
# up translations from the compendia.  (Merging against /dev/null
# doesn't work so well; it inserts the headers from the first-named
# compendium.)
143
po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
144
	$(MSGMERGE) --lang=$* $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
145

P
Peter Eisentraut 已提交
146 147 148 149 150

all: all-po
install: install-po
installdirs: installdirs-po
uninstall: uninstall-po
151
clean distclean maintainer-clean: clean-po
P
Peter Eisentraut 已提交
152 153

.PHONY: all-po install-po installdirs-po uninstall-po clean-po \
154
        init-po update-po