Bump to 4.15.0
[platform/upstream/iso-codes.git] / common.mk
1 xmldir = $(datadir)/xml/iso-codes
2 nodist_xml_DATA = $(DOMAIN).xml
3
4 pofiles = $(wildcard $(srcdir)/*.po)
5 mofiles = $(patsubst $(srcdir)/%.po,%.mo, $(pofiles))
6 noinst_DATA = $(mofiles) $(xml_DATA:.xml=.pot)
7
8 localedir = $(datadir)/locale
9
10 EXTRA_DIST = \
11         $(pofiles)      \
12         $(DOMAIN).pot
13
14 MOSTLYCLEANFILES = \
15         $(mofiles) \
16         $(DOMAIN).xml
17
18 # Generic target to create binary .mo files from .po files
19 %.mo: %.po
20         $(MSGFMT) $(MSGFMT_FLAGS) -o $@ $<
21
22 # Generic target to create .pot files from JSON data files
23 $(DOMAIN).pot: $(top_srcdir)/bin/pot_from_json.py $(top_srcdir)/data/$(DOMAIN).json $(top_srcdir)/bin/remove-potcdate.sin
24         cp $@ backup.pot
25         python3 $(top_srcdir)/bin/pot_from_json.py $(DOMAIN) $(top_srcdir)/data
26         sed -f $(top_srcdir)/bin/remove-potcdate.sin < $@ > $(DOMAIN).1po
27         sed -f $(top_srcdir)/bin/remove-potcdate.sin < backup.pot > $(DOMAIN).2po
28         if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
29                 rm -f $(DOMAIN).1po $(DOMAIN).2po $@ && \
30                 mv backup.pot $@; \
31         else \
32                 rm -f $(DOMAIN).1po $(DOMAIN).2po backup.pot; \
33         fi
34
35 # Generic target to create deprecated .xml files from JSON data files
36 $(DOMAIN).xml: $(top_srcdir)/bin/xml_from_json.py $(top_srcdir)/data/$(DOMAIN).json
37         python3 $(top_srcdir)/bin/xml_from_json.py $(DOMAIN) $(top_srcdir)/data $@
38
39 # Used in the domain subdirectories for checking that
40 # all .po files contain UTF-8 data
41 check-local:
42         python3 $(top_srcdir)/bin/check_valid_utf8.py $(pofiles)
43
44 # This target merges all po files with the current pot file,
45 # removes obsolete msgids and substitutes the Project-Id-Version
46 # header with the PROJECT only, removing the VERSION part.
47 # This is done to keep the diff between releases small.
48 #
49 # NOTE:
50 # Removing obsolete msgids is not the recommended way to go.
51 # However, we've decided that in the specific case of iso-codes
52 # the benefit outweights the loss of information. Having only msgids
53 # with one (sometimes two or three) words, the fuzzy matching performed
54 # with obsolete msgids will not ease the translator's work, but
55 # will lead to confusing entries.
56 #
57 # However, if there is only a small change, we include the fuzzy
58 # entry with the previous msgid to hopefully save some work.
59 .PHONY: update-po
60 update-po:
61         for pofile in $(pofiles); do \
62                 $(MSGMERGE) --previous $$pofile $(DOMAIN).pot > tmpfile; \
63                 $(MSGATTRIB) --no-obsolete tmpfile > $$pofile; \
64                 sed -i -e 's/^\"Project-Id-Version: iso.*/\"Project-Id-Version: $(DOMAIN)\\n\"/' $$pofile; \
65         done
66         rm -f tmpfile
67         if [ -f sr.po ]; then \
68                 $(RECODE_SR_LATIN) < sr.po > sr@latin.po; \
69                 sed -i -e 's/^\"Language: sr\\n\"/\"Language: sr@latin\\n\"/' sr@latin.po; \
70         fi
71         if [ -f tt@iqtelif.po ]; then \
72                 $(MSGFILTER) --keep-header sed -f $(top_srcdir)/bin/recode-tt-cyrillic.sed < tt@iqtelif.po > tt.po; \
73                 sed -i -e 's/^\"Language: tt@iqtelif\\n\"/\"Language: tt\\n\"/' tt.po; \
74         fi
75
76 install-data-hook: $(mofiles)
77         $(mkinstalldirs) $(DESTDIR)$(localedir)
78         catalogs='$(mofiles)'; \
79         for cat in $$catalogs; do \
80                 cat=`basename $$cat`; \
81                 lang=`echo $$cat | sed 's/\.mo$$//'`; \
82                 dir=$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES; \
83                 $(mkinstalldirs) $$dir; \
84                 $(INSTALL_DATA) $$cat $$dir/$(DOMAIN).mo; \
85                 if [ "$(DOMAIN)" = "iso_639-2" ]; then (cd $$dir && $(LN_S) $(DOMAIN).mo iso_639.mo); fi; \
86                 if [ "$(DOMAIN)" = "iso_639-3" ]; then (cd $$dir && $(LN_S) $(DOMAIN).mo iso_639_3.mo); fi; \
87                 if [ "$(DOMAIN)" = "iso_639-5" ]; then (cd $$dir && $(LN_S) $(DOMAIN).mo iso_639_5.mo); fi; \
88                 if [ "$(DOMAIN)" = "iso_3166-1" ]; then (cd $$dir && $(LN_S) $(DOMAIN).mo iso_3166.mo); fi; \
89                 if [ "$(DOMAIN)" = "iso_3166-2" ]; then (cd $$dir && $(LN_S) $(DOMAIN).mo iso_3166_2.mo); fi; \
90         done
91         if [ "$(DOMAIN)" = "iso_639-2" ]; then (cd $(DESTDIR)$(xmldir) && $(LN_S) $(DOMAIN).xml iso_639.xml); fi
92         if [ "$(DOMAIN)" = "iso_639-3" ]; then (cd $(DESTDIR)$(xmldir) && $(LN_S) $(DOMAIN).xml iso_639_3.xml); fi
93         if [ "$(DOMAIN)" = "iso_639-5" ]; then (cd $(DESTDIR)$(xmldir) && $(LN_S) $(DOMAIN).xml iso_639_5.xml); fi
94         if [ "$(DOMAIN)" = "iso_3166-1" ]; then (cd $(DESTDIR)$(xmldir) && $(LN_S) $(DOMAIN).xml iso_3166.xml); fi
95         if [ "$(DOMAIN)" = "iso_3166-2" ]; then (cd $(DESTDIR)$(xmldir) && $(LN_S) $(DOMAIN).xml iso_3166_2.xml); fi
96
97 uninstall-hook:
98         catalogs='$(mofiles)'; \
99         for cat in $$catalogs; do \
100                 cat=`basename $$cat`; \
101                 lang=`echo $$cat | sed 's/\.mo$$//'`; \
102                 rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo; \
103                 if [ "$(DOMAIN)" = "iso_639-2" ]; then rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/iso_639.mo; fi; \
104                 if [ "$(DOMAIN)" = "iso_639-3" ]; then rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/iso_639_3.mo; fi; \
105                 if [ "$(DOMAIN)" = "iso_639-5" ]; then rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/iso_639_5.mo; fi; \
106                 if [ "$(DOMAIN)" = "iso_3166-1" ]; then rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/iso_3166.mo; fi; \
107                 if [ "$(DOMAIN)" = "iso_3166-1" ]; then rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/iso_3166_2.mo; fi; \
108         done
109         if [ "$(DOMAIN)" = "iso_639-2" ]; then rm -f $(DESTDIR)$(xmldir)/iso_639.xml; fi
110         if [ "$(DOMAIN)" = "iso_639-3" ]; then rm -f $(DESTDIR)$(xmldir)/iso_639_3.xml; fi
111         if [ "$(DOMAIN)" = "iso_639-5" ]; then rm -f $(DESTDIR)$(xmldir)/iso_639_5.xml; fi
112         if [ "$(DOMAIN)" = "iso_3166-1" ]; then rm -f $(DESTDIR)$(xmldir)/iso_3166.xml; fi
113         if [ "$(DOMAIN)" = "iso_3166-2" ]; then rm -f $(DESTDIR)$(xmldir)/iso_3166_2.xml; fi