]> sipb.mit.edu Git - ikiwiki.git/blob - po/Makefile
releasing version 3.20120629
[ikiwiki.git] / po / Makefile
1 # List here all source files with translatable strings.
2 POTFILES=$(sort $(shell find ../IkiWiki -type f -name \*.pm)) \
3         ../ikiwiki.in ../IkiWiki.pm ../auto.setup
4
5 POFILES=$(wildcard *.po)
6 MOFILES=$(POFILES:.po=.mo)
7
8 # Translated underlays can only be generated if po4a is available.
9 TRANSLATED_UNDERLAYS=$(shell if perl -e 'use Locale::Po4a::Common' 2>/dev/null; then echo ../underlays/locale; fi)
10
11 all: ikiwiki.pot mo $(TRANSLATED_UNDERLAYS)
12
13 mo: $(MOFILES)
14
15 install: all
16         # Normal mo files for program translation.
17         for file in $(MOFILES); do \
18                 lang=`echo $$file | sed 's/\.mo//'`; \
19                 install -d $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/; \
20                 install -m 0644 $$file $(DESTDIR)$(PREFIX)/share/locale/$$lang/LC_MESSAGES/ikiwiki.mo; \
21         done
22         
23         # Underlay translation via po files that go in special per-language
24         # underlays.
25         for file in `cd underlays && find . -type f -name \*.po`; do \
26                 lang=`echo $$file | sed -e 's/.po$$//' -e 's/.*\\.//'`; \
27                 dir=`dirname "$(DESTDIR)$(PREFIX)/share/ikiwiki/po/$$lang/$$file"`; \
28                 install -d $$dir; \
29                 install -m 0644 underlays/$$file $$dir; \
30         done
31
32 ikiwiki.pot: $(POTFILES)
33         @if perl -e '($$ver)=`xgettext -V | head -n 1`=~/.*\s+([0-9]+\.[0-9]+)/; die "gettext $$ver too old, not updating the pot file\n" if $$ver < 0.16'; then \
34                 echo "Rebuilding the pot file"; \
35                 xgettext --from-code=UTF-8 $(POTFILES) -o ikiwiki.pot -Lperl --add-comments=translators; \
36         fi
37
38 clean:
39         rm -f $(MOFILES) messages messages.mo *_stamp
40         rm -rf html underlays/.ikiwiki $(TRANSLATED_UNDERLAYS)
41         find underlays -name \*.mdwn -or -name \*.pot | xargs rm -f
42
43 %.mo: %.po
44         @if ! msgfmt -o $@ $<; then echo "unable to run msgfmt"; fi
45
46 %.po: ikiwiki.pot
47         @echo -n "Merging ikiwiki.pot and $@"
48 # Typically all that changes is a date or line number. I'd prefer not to
49 # commit such changes, so detect and ignore them.
50         @if ! msgmerge $@ ikiwiki.pot -o $@.new 2>&1; then \
51                 echo "unable to run msgmerge"; \
52         else \
53                 if [ "`diff $@ $@.new | grep '[<>]' | grep -v '[<>] #:' | wc -l`" -ne 2 ]; then \
54                         mv -f $@.new $@; \
55                 else \
56                         rm -f $@.new; \
57                 fi; \
58                 msgfmt --statistics $@ 2>&1; \
59         fi
60
61 check:
62         @for file in $(POFILES); do \
63                 lang=`echo $$file | sed 's/\.po//'`; \
64                 printf "$$lang: "; \
65                 msgfmt -o /dev/null -c -v --statistics $$lang.po;\
66         done
67
68 underlays_copy_stamp:
69         # copy all the files we want to translate into a srcdir
70         for file in `cd ..; find underlays -follow -name \*.mdwn`; do \
71                 install -d $$(dirname $$file); \
72                 cp -aL ../$$file $$file 2>/dev/null || \
73                 install -m 644 ../$$file $$file; \
74         done
75         install -d underlays/directives/ikiwiki/directive
76         for file in `cd ..; find doc/ikiwiki/directive/ -maxdepth 1 -type f`; do \
77                 cp -a ../$$file underlays/directives/ikiwiki/directive ||  \
78                 install -m 644 ../$$file underlays/directives/ikiwiki/directive; \
79         done
80         install -d underlays/empty
81         touch $@
82
83 underlays: ../ikiwiki.out underlays_copy_stamp
84         ../ikiwiki.out -libdir .. -setup underlay.setup -refresh
85
86 ../ikiwiki.out: ../Makefile
87         make -C .. ikiwiki.out
88
89 ../Makefile: ../Makefile.PL
90         cd .. && ./Makefile.PL
91
92 $(TRANSLATED_UNDERLAYS): po2wiki_stamp
93 po2wiki_stamp: po2wiki underlays_copy_stamp
94         PERL5LIB=.. ./po2wiki underlay.setup
95         touch $@
96
97 .PHONY: underlays