WIP: Vibra support
[neverball] / po / Makefile
1 #-------------------------------------------------------------------------------
2
3 # Basic LINGUAS environment variable support
4
5 ALL_LINGUAS := $(basename $(wildcard *.po))
6
7 ifneq ($(LINGUAS),)
8     LINGUAS := $(filter $(ALL_LINGUAS), $(LINGUAS))
9 else
10     LINGUAS := $(ALL_LINGUAS)
11 endif
12
13 #-------------------------------------------------------------------------------
14
15 ROOT := ..
16
17 DOMAIN    := neverball
18 MODIR     := $(ROOT)/locale
19 POFILES   := $(LINGUAS:%=%.po)
20 MOFILES   := $(LINGUAS:%=$(MODIR)/%/LC_MESSAGES/$(DOMAIN).mo)
21 SOURCES   := \
22     $(wildcard $(ROOT)/ball/*.[ch])  \
23     $(wildcard $(ROOT)/share/*.[ch]) \
24     $(wildcard $(ROOT)/putt/*.[ch])
25
26 COPYRIGHT := Robert Kooima
27 BUGADDR   := robert.kooima@gmail.com
28
29 XGETTEXT := xgettext
30 XGETTEXT_FLAGS := \
31     --add-comments=Translators --from-code=UTF-8 \
32     --keyword=_ --keyword=N_ --keyword=L_        \
33     --keyword=sgettext                           \
34     --default-domain="$(DOMAIN)"                 \
35     --copyright-holder="$(COPYRIGHT)"            \
36     --msgid-bugs-address="$(BUGADDR)"
37
38 #------------------------------------------------------------------------------
39
40 all: $(MOFILES)
41
42 clean:
43         rm -rf $(MODIR)
44
45 #------------------------------------------------------------------------------
46
47 # Here it gets somewhat convoluted.  Basic idea is:  we want the
48 # update-po target which is widely supported in autotools-based
49 # internationalised packages.  update-po unconditionally updates the POT
50 # file, and thus forces PO and MO files to be updated as well.  The
51 # logic is loosely based on Makefile.in.in distributed with GNU gettext.
52
53 update-po: $(DOMAIN).pot-update $(POFILES) $(MOFILES)
54
55 $(MODIR)/%/LC_MESSAGES/$(DOMAIN).mo: %.po
56         mkdir -p $(dir $@)
57         msgfmt -c --statistics -o $@ $<
58
59 %.po: $(DOMAIN).pot
60         msgmerge -U --previous $@ $<
61         touch $@
62
63 $(DOMAIN).pot $(DOMAIN).pot-update:
64         $(XGETTEXT) $(XGETTEXT_FLAGS) -o $(DOMAIN).pot \
65             --directory="$(ROOT)" $(SOURCES:$(ROOT)/%=%)
66
67         # Force encoding to UTF-8
68         sed "1,/^$$/ s/CHARSET/UTF-8/" < $(DOMAIN).pot > $(DOMAIN).pot.utf8
69         mv -f $(DOMAIN).pot.utf8 $(DOMAIN).pot
70
71         sh $(ROOT)/scripts/extractpo.sh $(ROOT) >> $(DOMAIN).pot
72         grep -v '^# ' < mtrl.pot >> $(DOMAIN).pot
73         msguniq -o $(DOMAIN).pot.uniq $(DOMAIN).pot
74         mv -f $(DOMAIN).pot.uniq $(DOMAIN).pot
75
76 #------------------------------------------------------------------------------
77
78 stats:
79         @find -name '*.po' | sort | xargs -n1 -I{} \
80             sh -c 'printf "{}: "; msgfmt -o /dev/null --statistics {}'
81
82 #------------------------------------------------------------------------------
83