chiark / gitweb /
NOTES.podchecker: Document why I'm not using podchecker
[dgit.git] / po / Makefile
1 # dgit message translation machinery
2 #
3 # Translators: there is no need to look at this file.  It contains
4 # complicated machinery which you do not need to understand :-).
5 # See po/README instead.
6
7 # Copyright (C)2018 Ian Jackson
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 # ----- metaprogramming (translators, pleaee ignore all this) -----
23 #
24 # We present translators with a single file po/messages.pot containing
25 # all the messages for the translated programs in dgit.deb and
26 # git-debrebase.deb.  This also includes the messages from the shared
27 # perl modules.
28 #
29 # But when we make the .debs, we want to ship in each .deb the
30 # messages for that .deb, only (but including the common parts).
31 #
32 # So we generate three intermediate .pots,
33 #   .{dgit,git-debrebase,common}.pot
34 # and merge them to make messages.pot.
35 #
36 # From the translations we generate two .mo files for each output
37 # language: {dgit,git-debrebase}.mo -- including the common messages.
38 #
39 # To avoid dirtying the tree whenever we do `make install',
40 # we honour SUPPRESS_PO_UPDATE, to be used like this
41 #   make install prefix=$(prefix) SUPPRESS_PO_UPDATE=1
42
43 all: messages.pot mofiles
44
45 include ../i18n-common.make
46
47 .%.potfiles:
48         $S $e; echo ../$*; $f
49
50 .common.potfiles:
51         $S $e; find ../Debian -name \*.pm; $f
52
53 .%.make: .%.potfiles Makefile part.make
54         $S $e; \
55          sed 's/~/$*/g' part.make; \
56          sed "s#^#.$*.pot: #" $<; \
57         $f
58
59 -include .dgit.make
60 -include .git-debrebase.make
61 -include .common.make
62
63 POFILES := $(wildcard *.po)
64 LANGS := $(basename $(POFILES))
65
66 MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
67         $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
68
69 messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
70         $S msgcat --to-code=UTF-8 $^            >.messages.0.tmp
71         $S ( ./remove-potcdate <$@ ||: )        >.messages.1.tmp
72         $S ./remove-potcdate <.messages.0.tmp   >.messages.2.tmp
73         $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
74         @echo 'Updated $@.'
75
76 %.mo: %.po
77         $S msgfmt -o $@ $<
78
79 XGETTEXT_OPTS += -Lperl -k__ -kf_ -ki_
80 XGETTEXT_OPTS += --from-code=UTF-8
81 XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
82 # The --package-* avoids this error from make check's `msgfmt -c'
83 #  warning: header field 'Project-Id-Version' still has the initial default value
84
85 %.pot:
86         $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
87
88 mofiles: $(MOFILES)
89         @echo 'Generated mo/*.mo (binary translated messages) OK.'
90
91 install: all
92         set -e; for file in $(MOFILES); do \
93                 lang=$${file#*_}; lang=$${lang%.mo}; \
94                 part=$${file#mo/}; part=$${part%%_*}; \
95                 d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
96                 install -d $$d; \
97                 install -m 0644 $$file $$d/$$part.mo; \
98         done
99
100 clean:
101         rm -f .*.make .*.potfiles .*.pot .*.tmp
102         rm -rf mo
103
104 %.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
105         @echo -n "Merging messages.pot and $@ "
106         $S if test -f $@; then \
107                 msgmerge --previous $@ messages.pot -o $@.new; \
108         else \
109                 msgcat --lang=$* messages.pot >$@.new; \
110         fi
111         $S mv -f $@.new $@
112         $S msgfmt -o /dev/null --statistics $@
113
114 .PRECIOUS: .%.potfiles
115
116 pofiles: $(POFILES)
117
118 update: pofiles check
119
120 check: $(if $(SUPPRESS_PO_UPDATE),,pofiles)
121         $S set -e; for file in $(POFILES); do \
122                 lang=`echo $$file | sed 's/\.po//'`; \
123                 printf "$$lang: "; \
124                 msgfmt -o /dev/null -c -v --statistics $$lang.po;\
125         done