1# Example for use of GNU gettext.
2# This file is in the public domain.
3#
4# Makefile configuration - processed by automake.
5
6# List of files which contain translatable strings.
7POTFILES = \
8  Hello.java
9
10# Usually the message domain is the same as the package name.
11DOMAIN = $(PACKAGE)
12
13# These options get passed to xgettext.
14XGETTEXT_OPTIONS =
15
16# This is the copyright holder that gets inserted into the header of the
17# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
18# package.  (Note that the msgstr strings, extracted from the package's
19# sources, belong to the copyright holder of the package.)  Translators are
20# expected to transfer the copyright for their translations to this person
21# or entity, or to disclaim their copyright.  The empty string stands for
22# the public domain; in this case the translators are expected to disclaim
23# their copyright.
24COPYRIGHT_HOLDER = Yoyodyne, Inc.
25
26# This tells whether or not to prepend "GNU " prefix to the package
27# name that gets inserted into the header of the $(DOMAIN).pot file.
28# Possible values are "yes", "no", or empty.  If it is empty, try to
29# detect it automatically by scanning the files in $(top_srcdir) for
30# "GNU packagename" string.
31PACKAGE_GNU = no
32
33# This is the email address or URL to which the translators shall report
34# bugs in the untranslated strings:
35# - Strings which are not entire sentences, see the maintainer guidelines
36#   in the GNU gettext documentation, section 'Preparing Strings'.
37# - Strings which use unclear terms or require additional context to be
38#   understood.
39# - Strings which make invalid assumptions about notation of date, time or
40#   money.
41# - Pluralisation problems.
42# - Incorrect English spelling.
43# - Incorrect formatting.
44# It can be your email address, or a mailing list address where translators
45# can write to without being subscribed, or the URL of a web page through
46# which the translators can contact you.
47MSGID_BUGS_ADDRESS = bug-gettext@gnu.org
48
49# These options get passed to msgmerge.
50# Useful options are in particular:
51#   --previous            to keep previous msgids of translated messages,
52#   --quiet               to reduce the verbosity.
53MSGMERGE_OPTIONS = --quiet
54
55# These options get passed to msginit.
56# If you want to disable line wrapping when writing PO files, add
57# --no-wrap to MSGMERGE_OPTIONS, XGETTEXT_OPTIONS, and
58# MSGINIT_OPTIONS.
59MSGINIT_OPTIONS =
60
61MSGMERGE = @MSGMERGE@
62MSGMERGE_UPDATE = @MSGMERGE@ --update
63MSGMERGE_FOR_MSGFMT_OPTION = @MSGMERGE_FOR_MSGFMT_OPTION@
64MSGCAT = msgcat
65MSGINIT = msginit
66MSGCONV = msgconv
67MSGFILTER = msgfilter
68
69# This is computed as $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
70POTFILES_DEPS = @POTFILES_DEPS@
71
72# This is computed as $(foreach lang, $(LINGUAS), $(srcdir)/$(lang).po)
73POFILES = @POFILES@
74# This is computed as $(foreach lang, $(LINGUAS), $(lang).po-update)
75UPDATEPOFILES = @UPDATEPOFILES@
76# This is computed as $(foreach lang, $(LINGUAS), $(lang).nop)
77DUMMYPOFILES = @DUMMYPOFILES@
78# This is computed as $(foreach lang, $(LINGUAS), $(srcdir)/$(DOMAIN)_$(lang).properties)
79PROPERTIESFILES = @PROPERTIESFILES@
80# This is computed as $(foreach lang, $(LINGUAS), $(srcdir)/$(DOMAIN)_$(lang).class)
81CLASSFILES = @CLASSFILES@
82
83# This is computed as
84# $(foreach lang, user-specified subset of $(LINGUAS), $(DOMAIN)_$(lang).properties)
85CATALOGS = @JAVACATALOGS@
86
87SUFFIXES = .po .sed .sin .nop .po-create .po-update
88
89# The .pot file, stamp-po, .po files, and .properties or .class files appear
90# in release tarballs. The GNU Coding Standards say in
91# <https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html>:
92#   "GNU distributions usually contain some files which are not source files
93#    ... . Since these files normally appear in the source directory, they
94#    should always appear in the source directory, not in the build directory.
95#    So Makefile rules to update them should put the updated files in the
96#    source directory."
97# Therefore we put these files in the source directory, not the build directory.
98
99.sin.sed:
100	sed -e '/^#/d' $< > t-$@
101	mv t-$@ $@
102
103
104all-local: $(srcdir)/stamp-po
105
106# $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no
107# internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because
108# we don't want to bother translators with empty POT files). We assume that
109# LINGUAS is empty in this case, i.e. $(POFILES) and $(PROPERTIESFILES) are
110# empty. In this case, $(srcdir)/stamp-po is a nop (i.e. a phony target).
111
112# $(srcdir)/stamp-po is a timestamp denoting the last time at which the CATALOGS
113# have been loosely updated. Its purpose is that when a developer or translator
114# checks out the package from a version control system, and the $(DOMAIN).pot
115# file is not under version control, "make" will update the $(DOMAIN).pot and
116# the $(CATALOGS), but subsequent invocations of "make" will do nothing. This
117# timestamp would not be necessary if updating the $(CATALOGS) would always
118# touch them; however, the rule for $(POFILES) has been designed to not touch
119# files that don't need to be changed.
120$(srcdir)/stamp-po: $(srcdir)/$(DOMAIN).pot
121	test ! -f $(srcdir)/$(DOMAIN).pot || \
122	  $(MAKE) update-properties
123	@test ! -f $(srcdir)/$(DOMAIN).pot || { \
124	  echo "touch $(srcdir)/stamp-po" && \
125	  echo timestamp > $(srcdir)/stamp-poT && \
126	  mv $(srcdir)/stamp-poT $(srcdir)/stamp-po; \
127	}
128
129# Note: Target 'all' must not depend on target '$(DOMAIN).pot-update',
130# otherwise packages like GCC can not be built if only parts of the source
131# have been downloaded.
132
133# This target rebuilds $(DOMAIN).pot; it is an expensive operation.
134# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed.
135# The determination of whether the package xyz is a GNU one is based on the
136# heuristic whether some file in the top level directory mentions "GNU xyz".
137# If GNU 'find' is available, we avoid grepping through monster files.
138$(DOMAIN).pot-update: $(POTFILES_DEPS) remove-potcdate.sed
139	package_gnu="$(PACKAGE_GNU)"; \
140	test -n "$$package_gnu" || { \
141	  if { if (LC_ALL=C find --version) 2>/dev/null | grep GNU >/dev/null; then \
142	         LC_ALL=C find -L $(top_srcdir) -maxdepth 1 -type f -size -10000000c -exec grep -i 'GNU $(PACKAGE)' /dev/null '{}' ';' 2>/dev/null; \
143	       else \
144	         LC_ALL=C grep -i 'GNU $(PACKAGE)' $(top_srcdir)/* 2>/dev/null; \
145	       fi; \
146	     } | grep -v 'libtool:' >/dev/null; then \
147	     package_gnu=yes; \
148	   else \
149	     package_gnu=no; \
150	   fi; \
151	}; \
152	if test "$$package_gnu" = "yes"; then \
153	  package_prefix='GNU '; \
154	else \
155	  package_prefix=''; \
156	fi; \
157	if test -n '$(MSGID_BUGS_ADDRESS)'; then \
158	  msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \
159	else \
160	  msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \
161	fi; \
162	case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
163	  '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \
164	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
165	      --add-comments=TRANSLATORS: \
166	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
167	      --msgid-bugs-address="$$msgid_bugs_address" \
168	      $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \
169	      $(POTFILES) \
170	    ;; \
171	  *) \
172	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
173	      --add-comments=TRANSLATORS: \
174	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
175	      --package-name="$${package_prefix}$(PACKAGE)" \
176	      --package-version='$(VERSION)' \
177	      --msgid-bugs-address="$$msgid_bugs_address" \
178	      $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \
179	      $(POTFILES) \
180	    ;; \
181	esac
182	test ! -f $(DOMAIN).po || { \
183	  if test -f $(srcdir)/$(DOMAIN).pot-header; then \
184	    sed -e '1,/^#$$/d' < $(DOMAIN).po > $(DOMAIN).1po && \
185	    cat $(srcdir)/$(DOMAIN).pot-header $(DOMAIN).1po > $(DOMAIN).po && \
186	    rm -f $(DOMAIN).1po \
187	    || exit 1; \
188	  fi; \
189	  if test -f $(srcdir)/$(DOMAIN).pot; then \
190	    sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \
191	    sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \
192	    if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
193	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \
194	    else \
195	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(srcdir)/$(DOMAIN).pot && \
196	      mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
197	    fi; \
198	  else \
199	    mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
200	  fi; \
201	}
202
203# This rule has no dependencies: we don't need to update $(DOMAIN).pot at
204# every "make" invocation, only create it when it is missing.
205# Only "make $(DOMAIN).pot-update" or "make dist" will force an update.
206$(srcdir)/$(DOMAIN).pot:
207	$(MAKE) $(DOMAIN).pot-update
208
209# This target rebuilds a PO file if $(DOMAIN).pot has changed.
210# Note that a PO file is not touched if it doesn't need to be changed.
211$(POFILES): $(srcdir)/$(DOMAIN).pot
212	@lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \
213	if test -f "$(srcdir)/$${lang}.po"; then \
214	  test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
215	  echo "$${cdcmd}$(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot"; \
216	  cd $(srcdir) \
217	    && { case `$(MSGMERGE_UPDATE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
218	           '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].*) \
219	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) $${lang}.po $(DOMAIN).pot;; \
220	           0.1[6-7] | 0.1[6-7].*) \
221	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --previous $${lang}.po $(DOMAIN).pot;; \
222	           *) \
223	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot;; \
224	         esac; \
225	       }; \
226	else \
227	  $(MAKE) $${lang}.po-create; \
228	fi
229
230
231html ID:
232
233MOSTLYCLEANFILES =
234MOSTLYCLEANFILES += remove-potcdate.sed
235MOSTLYCLEANFILES += stamp-poT
236MOSTLYCLEANFILES += core core.* *.stackdump $(DOMAIN).po $(DOMAIN).1po $(DOMAIN).2po *.new.po
237
238MAINTAINERCLEANFILES = \
239  $(DOMAIN).pot stamp-po \
240  $(DOMAIN).properties $(PROPERTIESFILES) $(CLASSFILES)
241
242EXTRA_DIST = remove-potcdate.sin LINGUAS $(POFILES) $(DOMAIN).properties $(PROPERTIESFILES)
243
244# Hidden from automake, but really activated. Works around an automake-1.5 bug.
245#distdir: distdir1
246distdir1:
247	$(MAKE) update-po
248	$(MAKE) $(srcdir)/stamp-po
249	@if test -f $(srcdir)/$(DOMAIN).pot; then \
250	  for file in $(DOMAIN).pot stamp-po; do \
251	    if test -f $$file; then d=.; else d=$(srcdir); fi; \
252	    cp -p $$d/$$file $(distdir)/$$file || exit 1; \
253	  done; \
254	else \
255	  case $(XGETTEXT) in \
256	    :) echo "Warning: Creating a tarball without '$(DOMAIN).pot', because a suitable 'xgettext' program was not found in PATH." 1>&2;; \
257	    *) echo "Warning: Creating a tarball without '$(DOMAIN).pot', because 'xgettext' found no strings to extract. Check the POTFILES and the XGETTEXT_OPTIONS in the Makefile.am file." 1>&2;; \
258	  esac; \
259	fi
260
261update-po: Makefile
262	$(MAKE) $(DOMAIN).pot-update
263	test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES)
264	$(MAKE) update-properties
265
266# General rule for creating PO files.
267
268.nop.po-create:
269	@lang=`echo $@ | sed -e 's/\.po-create$$//'`; \
270	echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \
271	exit 1
272
273# General rule for updating PO files.
274
275.nop.po-update:
276	@lang=`echo $@ | sed -e 's/\.po-update$$//'`; \
277	tmpdir=`pwd`; \
278	echo "$$lang:"; \
279	test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
280	echo "$${cdcmd}$(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang --previous $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \
281	cd $(srcdir); \
282	if { case `$(MSGMERGE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
283	       '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].*) \
284	         $(MSGMERGE) $(MSGMERGE_OPTIONS) -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
285	       0.1[6-7] | 0.1[6-7].*) \
286	         $(MSGMERGE) $(MSGMERGE_OPTIONS) --previous -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
287	       *) \
288	         $(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang --previous -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
289	     esac; \
290	   }; then \
291	  if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \
292	    rm -f $$tmpdir/$$lang.new.po; \
293	  else \
294	    if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \
295	      :; \
296	    else \
297	      echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \
298	      exit 1; \
299	    fi; \
300	  fi; \
301	else \
302	  echo "msgmerge for $$lang.po failed!" 1>&2; \
303	  rm -f $$tmpdir/$$lang.new.po; \
304	fi
305
306$(DUMMYPOFILES):
307
308# During .po -> .properties or .class conversion, take into account the most
309# recent changes to the .pot file. This eliminates the need to update the .po
310# files when the .pot file has changed, which would be troublesome if the .po
311# files are put under version control.
312
313update-properties: Makefile $(srcdir)/$(DOMAIN).pot $(POFILES)
314	@echo "$(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en --properties-output -o $(srcdir)/$(DOMAIN).properties"; \
315	$(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en --properties-output -o $(DOMAIN).properties || { rm -f $(DOMAIN).properties; exit 1; }
316# Move $(DOMAIN).properties into $(srcdir). But don't provoke a gratuitous error
317# in a VPATH build with read-only $(srcdir).
318	@if test '$(srcdir)' != .; then \
319	  if test -f $(srcdir)/$(DOMAIN).properties && cmp $(DOMAIN).properties $(srcdir)/$(DOMAIN).properties >/dev/null; then \
320	    rm -f $(DOMAIN).properties; \
321	  else \
322	    mv -f $(DOMAIN).properties $(srcdir)/$(DOMAIN).properties; \
323	  fi; \
324	fi
325	@for f in $(POFILES); do \
326	  lang=`echo $$f | sed -e 's,.*/,,' -e 's,\.po$$,,'`; \
327	  echo "$(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $(srcdir)/$${lang}.po $(srcdir)/$(DOMAIN).pot"; \
328	  $(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $(srcdir)/$${lang}.po $(srcdir)/$(DOMAIN).pot || exit 1; \
329	  echo "$(GMSGFMT) -c --statistics --verbose -o /dev/null $${lang}.1po"; \
330	  $(GMSGFMT) -c --statistics --verbose -o /dev/null $${lang}.1po || exit 1; \
331	  echo "$(MSGCAT) --properties-output -o $(srcdir)/$(DOMAIN)_$$lang.properties $${lang}.1po"; \
332	  $(MSGCAT) --properties-output -o $(DOMAIN)_$$lang.properties.tmp $${lang}.1po || exit 1; \
333	  if test '$(srcdir)' = .; then \
334	    mv -f $(DOMAIN)_$$lang.properties.tmp $(DOMAIN)_$$lang.properties || exit 1; \
335	  else \
336	    if test -f $(srcdir)/$(DOMAIN)_$$lang.properties && cmp $(DOMAIN)_$$lang.properties.tmp $(srcdir)/$(DOMAIN)_$$lang.properties >/dev/null; then \
337	      rm -f $(DOMAIN)_$$lang.properties.tmp; \
338	    else \
339	      mv -f $(DOMAIN)_$$lang.properties.tmp $(srcdir)/$(DOMAIN)_$$lang.properties || exit 1; \
340	    fi; \
341	  fi; \
342	  rm -f $${lang}.1po; \
343	done
344
345# Alternatively, we could create classes instead of properties files.
346update-classes: Makefile $(srcdir)/$(DOMAIN).pot $(POFILES)
347	@echo "$(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en --properties-output -o $(srcdir)/$(DOMAIN).properties"; \
348	$(MSGINIT) -i $(srcdir)/$(DOMAIN).pot --no-translator -l en --properties-output -o $(DOMAIN).properties || { rm -f $(DOMAIN).properties; exit 1; }
349# Move $(DOMAIN).properties into $(srcdir). But don't provoke a gratuitous error
350# in a VPATH build with read-only $(srcdir).
351	@if test '$(srcdir)' != .; then \
352	  if test -f $(srcdir)/$(DOMAIN).properties && cmp $(DOMAIN).properties $(srcdir)/$(DOMAIN).properties >/dev/null; then \
353	    rm -f $(DOMAIN).properties; \
354	  else \
355	    mv -f $(DOMAIN).properties $(srcdir)/$(DOMAIN).properties; \
356	  fi; \
357	fi
358	@for f in $(POFILES); do \
359	  lang=`echo $$f | sed -e 's,.*/,,' -e 's,\.po$$,,'`; \
360	  echo "$(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $(srcdir)/$${lang}.po $(srcdir)/$(DOMAIN).pot"; \
361	  $(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $(srcdir)/$${lang}.po $(srcdir)/$(DOMAIN).pot || exit 1; \
362	  echo "$(GMSGFMT) -c --statistics --verbose -j -d $(srcdir) -r $(DOMAIN) -l $${lang} $${lang}.1po"; \
363	  $(GMSGFMT) -c --statistics --verbose -j -d . -r $(DOMAIN) -l $${lang} $${lang}.1po || exit 1; \
364	  if test '$(srcdir)' != .; then \
365	    if test -f $(srcdir)/$(DOMAIN)_$$lang.class && cmp $(DOMAIN)_$$lang.class $(srcdir)/$(DOMAIN)_$$lang.class >/dev/null; then \
366	      rm -f $(DOMAIN)_$$lang.class; \
367	    else \
368	      mv -f $(DOMAIN)_$$lang.class $(srcdir)/$(DOMAIN)_$$lang.class || exit 1; \
369	    fi; \
370	  fi; \
371	  rm -f $${lang}.1po; \
372	done
373
374echo-catalogs:
375# When packaging the catalogs for installation, include the fallback catalog always.
376	@echo $(DOMAIN).properties $(CATALOGS)
377