chiark / gitweb /
4e043eb320c8079b26c2a892a9d94559b8a74193
[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 e=set -e; exec >$@.tmp
46 f=mv -f $@.tmp $@
47 o= >$@.tmp && $f
48
49 S=@
50 # Set S='' to see commands being run
51
52 .%.potfiles:
53         $S $e; echo ../$*; $f
54
55 .common.potfiles:
56         $S $e; find ../Debian -name \*.pm; $f
57
58 .%.make: .%.potfiles Makefile part.make
59         $S $e; \
60          sed 's/~/$*/g' part.make; \
61          sed "s#^#.$*.pot: #" $<; \
62         $f
63
64 #        echo 'MOS_$$(addsuffix'
65 #        find -name $*.mo |sed ; $f
66
67 -include .dgit.make
68 -include .git-debrebase.make
69 -include .common.make
70
71 POFILES := $(wildcard *.po)
72 LANGS := $(basename $(POFILES))
73
74 MOFILES = $(foreach part,$(filter-out common,$(PARTS)), \
75         $(addprefix mo/$(part)_, $(POFILES:.po=.mo)))
76
77 messages.pot: $(if $(SUPPRESS_PO_UPDATE),,$(POTS))
78         $S msgcat --to-code=UTF-8 $^            >.messages.0.tmp
79         $S ( ./remove-potcdate <$@ ||: )        >.messages.1.tmp
80         $S ./remove-potcdate <.messages.0.tmp   >.messages.2.tmp
81         $S cmp -s .messages.[12].tmp || mv -v .messages.0.tmp $@
82         @echo 'Updated $@.'
83
84 %.mo: %.po
85         $S msgfmt -o $@ $<
86
87 XGETTEXT_OPTS += -Lperl -k__ -k___
88 XGETTEXT_OPTS += --from-code=UTF-8
89 XGETTEXT_OPTS += --package-name=dgit --package-version=ongoing
90 # The --package-* avoids this error from make check's `msgfmt -c'
91 #  warning: header field 'Project-Id-Version' still has the initial default value
92
93 %.pot:
94         $S TZ=UTC xgettext $(XGETTEXT_OPTS) $^ -o $@.tmp && $f
95
96 mofiles: $(MOFILES)
97         @echo 'Generated mo/*.mo (binary translated messages) OK.'
98
99 install: all
100         set -e; for file in $(MOFILES); do \
101                 lang=$${file#*_}; lang=$${lang%.mo}; \
102                 part=$${file#mo/}; part=$${part%%_*}; \
103                 d=$(DESTDIR)$(prefix)/share/locale/$$lang/LC_MESSAGES; \
104                 install -d $$d; \
105                 install -m 0644 $$file $$d/$$part.mo; \
106         done
107
108 clean:
109         rm -f .*.make .*.potfiles .*.pot .*.tmp
110         rm -rf mo
111
112 %.po: $(if $(SUPPRESS_PO_UPDATE),,messages.pot)
113         @echo -n "Merging messages.pot and $@ "
114         $S if test -f $@; then \
115                 msgmerge --previous $@ messages.pot -o $@.new; \
116         else \
117                 msgcat --lang=$* messages.pot >$@.new; \
118         fi
119         $S mv -f $@.new $@
120         $S msgfmt -o /dev/null --statistics $@
121
122 .PRECIOUS: .%.potfiles
123
124 all-po: $(POFILES)
125
126 check: $(if $(SUPPRESS_PO_UPDATE),,all-po)
127         $S set -e; for file in $(POFILES); do \
128                 lang=`echo $$file | sed 's/\.po//'`; \
129                 printf "$$lang: "; \
130                 msgfmt -o /dev/null -c -v --statistics $$lang.po;\
131         done