]> sipb.mit.edu Git - ikiwiki.git/blob - po/Makefile
thoughts
[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         msgfmt -o $@ $<
45
46 %.po: ikiwiki.pot
47         @echo -n "Merging ikiwiki.pot and $@"
48         @msgmerge $@ ikiwiki.pot -o $@.new 2>&1
49 # Typically all that changes was a date or line number. I'd prefer not to
50 # commit such changes, so detect and ignore them.
51         @if [ "`diff $@ $@.new | grep '[<>]' | grep -v '[<>] #:' | wc -l`" -ne 2 ]; then \
52                 mv -f $@.new $@; \
53         else \
54                 rm -f $@.new; \
55         fi
56         @msgfmt --statistics $@ 2>&1
57
58 check:
59         @for file in $(POFILES); do \
60                 lang=`echo $$file | sed 's/\.po//'`; \
61                 printf "$$lang: "; \
62                 msgfmt -o /dev/null -c -v --statistics $$lang.po;\
63         done
64
65 underlays_copy_stamp:
66         # copy all the files we want to translate into a srcdir
67         for file in `cd ..; find underlays -follow -name \*.mdwn`; do \
68                 install -d $$(dirname $$file); \
69                 cp -aL ../$$file $$file 2>/dev/null || \
70                 install -m 644 ../$$file $$file; \
71         done
72         install -d underlays/directives/ikiwiki/directive
73         for file in `cd ..; find doc/ikiwiki/directive/ -maxdepth 1 -type f`; do \
74                 cp -a ../$$file underlays/directives/ikiwiki/directive ||  \
75                 install -m 644 ../$$file underlays/directives/ikiwiki/directive; \
76         done
77         install -d underlays/empty
78         touch $@
79
80 underlays: ../ikiwiki.out underlays_copy_stamp
81         ../ikiwiki.out -libdir .. -setup underlay.setup -refresh
82
83 ../ikiwiki.out: ../Makefile
84         make -C .. ikiwiki.out
85
86 ../Makefile: ../Makefile.PL
87         cd .. && ./Makefile.PL
88
89 $(TRANSLATED_UNDERLAYS): po2wiki_stamp
90 po2wiki_stamp: po2wiki underlays_copy_stamp
91         PERL5LIB=.. ./po2wiki underlay.setup
92         touch $@
93
94 .PHONY: underlays