Work around bug in xgettext 0.19.8.1
[pspp] / po / automake.mk
1 # PSPP - a program for statistical analysis.
2 # Copyright (C) 2017, 2020 Free Software Foundation, Inc.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 include $(top_srcdir)/po/Makevars
18
19 XGETTEXT=xgettext
20 MSGMERGE=msgmerge
21 MSGFMT=msgfmt
22
23 POFILES = \
24         po/ca.po \
25         po/de.po \
26         po/el.po \
27         po/es.po \
28         po/fr.po \
29         po/gl.po \
30         po/hu.po \
31         po/ja.po \
32         po/lt.po \
33         po/nl.po \
34         po/pl.po \
35         po/pt_BR.po \
36         po/ru.po \
37         po/sl.po \
38         po/tr.po \
39         po/uk.po \
40         po/zh_CN.po
41
42 LOCALPOFILES = po/cs.po
43
44 POTFILE=po/$(DOMAIN).pot
45
46 TRANSLATABLE_FILES = $(DIST_SOURCES) $(all_q_sources)
47
48 XGETTEXT_OPTIONS = \
49         --copyright-holder="$(COPYRIGHT_HOLDER)" \
50         --package-name=$(PACKAGE) \
51         --package-version=$(VERSION) \
52         --msgid-bugs-address=$(MSGID_BUGS_ADDRESS) \
53         --from-code=UTF-8 \
54         --add-comments='TRANSLATORS:' \
55         --directory=$(top_srcdir)
56
57 ALL_TRANSLATABLE_FILES = \
58         $(TRANSLATABLE_FILES) \
59         $(UI_FILES) \
60         src/ui/gui/org.fsf.pspp.metainfo.xml.in \
61         src/ui/gui/org.fsf.pspp.desktop.in
62
63 $(POTFILE): $(ALL_TRANSLATABLE_FILES) Makefile
64         @$(MKDIR_P) po
65         $(AM_V_GEN)$(XGETTEXT) $(XGETTEXT_OPTIONS) $(TRANSLATABLE_FILES) --language=C --keyword=_ --keyword=N_ -o $@,tmp
66         $(AM_V_at)$(XGETTEXT) $(XGETTEXT_OPTIONS) -j $(UI_FILES) --language=Glade -o $@,tmp
67         ## xgettext 0.19.8.1 is known to crash on exit on the following command.
68         ## See https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=a0cab233
69         ## Therefore we ignore the exit status
70         $(AM_V_at)$(XGETTEXT) $(XGETTEXT_OPTIONS) --its=$(top_srcdir)/po/metainfo.its -j src/ui/gui/org.fsf.pspp.metainfo.xml.in -o $@,tmp || true
71         $(AM_V_at)$(XGETTEXT) $(XGETTEXT_OPTIONS) -j src/ui/gui/org.fsf.pspp.desktop.in -o $@,tmp
72         $(AM_V_at)$(SED) -e '/^"POT-Creation-Date: .*/d' $@,tmp > $@
73
74 $(LOCALPOFILES) $(POFILES): $(POTFILE)
75         $(AM_V_GEN)$(MSGMERGE) --previous --quiet $(top_srcdir)/$@ $? -o $@,tmp
76         $(AM_V_at)if test -e $(top_srcdir)/$@,aux ; then \
77                 touch $@,tmp ; \
78                 msgcat --use-first $(top_srcdir)/$@,aux $@,tmp -o $@,tmp; \
79         fi ;
80         $(AM_V_at)$(SED) -e '/^"POT-Creation-Date: /d' $@,tmp > $@,tmp2
81         $(RM) $@,tmp
82         $(MSGFMT) -c $@,tmp2
83         mv $@,tmp2 $@
84
85 SUFFIXES += .po .gmo
86 .po.gmo:
87         @$(MKDIR_P) `dirname $@`
88         $(AM_V_GEN)$(MSGFMT) $< -o $@
89
90
91 GMOFILES = $(LOCALPOFILES:.po=.gmo) $(POFILES:.po=.gmo)
92
93 ALL_LOCAL += $(GMOFILES)
94
95 install-data-hook: $(GMOFILES)
96         for f in $(GMOFILES); do \
97           lang=`echo $$f | $(SED) -e 's%po/\(.*\)\.gmo%\1%' ` ; \
98           $(MKDIR_P) $(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
99           $(INSTALL_DATA) $$f $(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES/$(DOMAIN).mo ; \
100         done
101
102 uninstall-hook:
103         for f in $(GMOFILES); do \
104           lang=`echo $$f | $(SED) -e 's%po/\(.*\)\.gmo%\1%' ` ; \
105           rm -f $(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES/$(DOMAIN).mo ; \
106         done
107
108
109 EXTRA_DIST += \
110         $(LOCALPOFILES) \
111         $(POFILES) \
112         $(POTFILE) \
113         po/metainfo.its \
114         po/LINGUAS \
115         po/ChangeLog \
116         po/cs.po,aux
117
118 CLEANFILES += $(GMOFILES) $(POTFILE)
119
120 # Clean $(POFILES) from build directory but not if that's the same as
121 # the source directory.
122 po_CLEAN:
123         @if test "$(srcdir)" != .; then \
124                 echo rm -f $(LOCALPOFILES) $(POFILES); \
125                 rm -f $(LOCALPOFILES) $(POFILES); \
126         fi
127 CLEAN_LOCAL += po_CLEAN
128
129 # Download the po files from http://translationproject.org
130 # The final action to this rule is to remove the .pot file.  This
131 # is because the po files must be re-merged against an updated version of it.
132 .PHONY: po-update
133 po-update: $(POFILES)
134         for p in $^; do \
135                 wget --recursive --level=1 --accept=po --no-directories --no-use-server-timestamps \
136                 --directory-prefix=po -O ${top_srcdir}/$$p,tmp \
137                 https://translationproject.org/latest/pspp/`basename $$p` ; \
138                 mv ${top_srcdir}/$$p,tmp ${top_srcdir}/$$p; \
139         done
140         $(RM) $(POTFILE)