OSDN Git Service

Don't call rm with empty file list.
[pg-rex/syncrep.git] / src / nls-global.mk
1 # $PostgreSQL: pgsql/src/nls-global.mk,v 1.13 2008/05/17 20:24:05 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 += --foreign-user -ctranslator
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))
51         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) -f $<
52 else
53 po/$(CATALOG_NAME).pot: $(GETTEXT_FILES)
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         mv messages.po $@
60 else # not XGETTEXT
61         @echo "You don't have 'xgettext'."; exit 1
62 endif # not XGETTEXT
63
64
65 install-po: all-po installdirs-po
66 ifneq (,$(LANGUAGES))
67         for lang in $(LANGUAGES); do \
68           $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME).mo || exit 1; \
69         done
70 endif
71
72 installdirs-po:
73         $(mkinstalldirs) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES)
74
75 uninstall-po:
76         rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME).mo)
77
78
79 clean-po:
80         $(if $(MO_FILES),rm -f $(MO_FILES))
81         @rm -f $(addsuffix .old, $(PO_FILES))
82         rm -f po/$(CATALOG_NAME).pot
83
84
85 maintainer-check-po: $(PO_FILES)
86         for file in $^; do \
87           $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
88         done
89
90
91 init-po: po/$(CATALOG_NAME).pot
92
93
94 define merge-lang
95 @printf 'merging $(1) '
96 @if $(MSGMERGE) $(srcdir)/po/$(1).po $< -o po/$(1).po.new $(addprefix --compendium=,$(shell find $(top_srcdir) -name $(1).po -printf '%p ')); \
97 then \
98     mv $(srcdir)/po/$(1).po po/$(1).po.old; \
99     mv po/$(1).po.new $(srcdir)/po/$(1).po; \
100 else \
101     echo "msgmerge for $(1) failed"; \
102     rm -f po/$(1).po.new; \
103 fi
104
105 endef
106
107 update-po: po/$(CATALOG_NAME).pot
108 ifdef MSGMERGE
109         $(foreach lang,$(LANGUAGES),$(call merge-lang,$(lang)))
110 else
111         @echo "You don't have 'msgmerge'." ; exit 1
112 endif
113
114
115 all: all-po
116 install: install-po
117 installdirs: installdirs-po
118 uninstall: uninstall-po
119 clean distclean maintainer-clean: clean-po
120 maintainer-check: maintainer-check-po
121
122 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
123         maintainer-check-po init-po update-po
124 .SILENT: installdirs-po