1# po.m4 serial 3 (gettext-0.14)
2dnl Copyright (C) 1995-2003 Free Software Foundation, Inc.
3dnl This file is free software, distributed under the terms of the GNU
4dnl General Public License.  As a special exception to the GNU General
5dnl Public License, this file may be distributed as part of a program
6dnl that contains a configuration script generated by Autoconf, under
7dnl the same distribution terms as the rest of that program.
8dnl
9dnl This file can can be used in projects which are not available under
10dnl the GNU General Public License or the GNU Library General Public
11dnl License but which still want to provide support for the GNU gettext
12dnl functionality.
13dnl Please note that the actual code of the GNU gettext library is covered
14dnl by the GNU Library General Public License, and the rest of the GNU
15dnl gettext package package is covered by the GNU General Public License.
16dnl They are *not* in the public domain.
17
18dnl Authors:
19dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
20dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2003.
21
22dnl Checks for all prerequisites of the po subdirectory.
23AC_DEFUN([AM_PO_SUBDIRS],
24[
25  AC_REQUIRE([AC_PROG_MAKE_SET])dnl
26  AC_REQUIRE([AC_PROG_INSTALL])dnl
27  AC_REQUIRE([AM_MKINSTALLDIRS])dnl
28  AC_REQUIRE([AM_NLS])dnl
29
30  dnl Perform the following tests also if --disable-nls has been given,
31  dnl because they are needed for "make dist" to work.
32
33  dnl Search for GNU msgfmt in the PATH.
34  dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions.
35  dnl The second test excludes FreeBSD msgfmt.
36  AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
37    [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1 &&
38     (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
39    :)
40  AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
41
42  dnl Search for GNU xgettext 0.12 or newer in the PATH.
43  dnl The first test excludes Solaris xgettext and early GNU xgettext versions.
44  dnl The second test excludes FreeBSD xgettext.
45  AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
46    [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
47     (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)],
48    :)
49  dnl Remove leftover from FreeBSD xgettext call.
50  rm -f messages.po
51
52  dnl Search for GNU msgmerge 0.11 or newer in the PATH.
53  AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
54    [$ac_dir/$ac_word --update -q /dev/null /dev/null >/dev/null 2>&1], :)
55
56  dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
57  dnl Test whether we really found GNU msgfmt.
58  if test "$GMSGFMT" != ":"; then
59    dnl If it is no GNU msgfmt we define it as : so that the
60    dnl Makefiles still can work.
61    if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 &&
62       (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
63      : ;
64    else
65      GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'`
66      AC_MSG_RESULT(
67        [found $GMSGFMT program is not GNU msgfmt; ignore it])
68      GMSGFMT=":"
69    fi
70  fi
71
72  dnl This could go away some day; the PATH_PROG_WITH_TEST already does it.
73  dnl Test whether we really found GNU xgettext.
74  if test "$XGETTEXT" != ":"; then
75    dnl If it is no GNU xgettext we define it as : so that the
76    dnl Makefiles still can work.
77    if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 &&
78       (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then
79      : ;
80    else
81      AC_MSG_RESULT(
82        [found xgettext program is not GNU xgettext; ignore it])
83      XGETTEXT=":"
84    fi
85    dnl Remove leftover from FreeBSD xgettext call.
86    rm -f messages.po
87  fi
88
89  AC_OUTPUT_COMMANDS([
90    for ac_file in $CONFIG_FILES; do
91      # Support "outfile[:infile[:infile...]]"
92      case "$ac_file" in
93        *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
94      esac
95      # PO directories have a Makefile.in generated from Makefile.in.in.
96      case "$ac_file" in */Makefile.in)
97        # Adjust a relative srcdir.
98        ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
99        ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
100        ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
101        # In autoconf-2.13 it is called $ac_given_srcdir.
102        # In autoconf-2.50 it is called $srcdir.
103        test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
104        case "$ac_given_srcdir" in
105          .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
106          /*) top_srcdir="$ac_given_srcdir" ;;
107          *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
108        esac
109        if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then
110          rm -f "$ac_dir/POTFILES"
111          test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES"
112          cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ 	]*\$/d" -e "s,.*,     $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES"
113          POMAKEFILEDEPS="POTFILES.in"
114          # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend
115          # on $ac_dir but don't depend on user-specified configuration
116          # parameters.
117          if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
118            # The LINGUAS file contains the set of available languages.
119            if test -n "$OBSOLETE_ALL_LINGUAS"; then
120              test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
121            fi
122            ALL_LINGUAS_=`sed -e "/^#/d" "$ac_given_srcdir/$ac_dir/LINGUAS"`
123            # Hide the ALL_LINGUAS assigment from automake.
124            eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
125            POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
126          else
127            # The set of available languages was given in configure.in.
128            eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
129          fi
130          # Compute POFILES
131          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
132          # Compute UPDATEPOFILES
133          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
134          # Compute DUMMYPOFILES
135          # as      $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
136          # Compute GMOFILES
137          # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
138          case "$ac_given_srcdir" in
139            .) srcdirpre= ;;
140            *) srcdirpre='$(srcdir)/' ;;
141          esac
142          POFILES=
143          UPDATEPOFILES=
144          DUMMYPOFILES=
145          GMOFILES=
146          for lang in $ALL_LINGUAS; do
147            POFILES="$POFILES $srcdirpre$lang.po"
148            UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
149            DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
150            GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
151          done
152          # CATALOGS depends on both $ac_dir and the user's LINGUAS
153          # environment variable.
154          INST_LINGUAS=
155          if test -n "$ALL_LINGUAS"; then
156            for presentlang in $ALL_LINGUAS; do
157              useit=no
158              if test "%UNSET%" != "$LINGUAS"; then
159                desiredlanguages="$LINGUAS"
160              else
161                desiredlanguages="$ALL_LINGUAS"
162              fi
163              for desiredlang in $desiredlanguages; do
164                # Use the presentlang catalog if desiredlang is
165                #   a. equal to presentlang, or
166                #   b. a variant of presentlang (because in this case,
167                #      presentlang can be used as a fallback for messages
168                #      which are not translated in the desiredlang catalog).
169                case "$desiredlang" in
170                  "$presentlang"*) useit=yes;;
171                esac
172              done
173              if test $useit = yes; then
174                INST_LINGUAS="$INST_LINGUAS $presentlang"
175              fi
176            done
177          fi
178          CATALOGS=
179          if test -n "$INST_LINGUAS"; then
180            for lang in $INST_LINGUAS; do
181              CATALOGS="$CATALOGS $lang.gmo"
182            done
183          fi
184          test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile"
185          sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile"
186          for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do
187            if test -f "$f"; then
188              case "$f" in
189                *.orig | *.bak | *~) ;;
190                *) cat "$f" >> "$ac_dir/Makefile" ;;
191              esac
192            fi
193          done
194        fi
195        ;;
196      esac
197    done],
198   [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
199    # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it
200    # from automake.
201    eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
202    # Capture the value of LINGUAS because we need it to compute CATALOGS.
203    LINGUAS="${LINGUAS-%UNSET%}"
204   ])
205])
206
207dnl Postprocesses a Makefile in a directory containing PO files.
208AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE],
209[
210  # When this code is run, in config.status, two variables have already been
211  # set:
212  # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in,
213  # - LINGUAS is the value of the environment variable LINGUAS at configure
214  #   time.
215
216changequote(,)dnl
217  # Adjust a relative srcdir.
218  ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
219  ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
220  ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
221  # In autoconf-2.13 it is called $ac_given_srcdir.
222  # In autoconf-2.50 it is called $srcdir.
223  test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir"
224  case "$ac_given_srcdir" in
225    .)  top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;;
226    /*) top_srcdir="$ac_given_srcdir" ;;
227    *)  top_srcdir="$ac_dots$ac_given_srcdir" ;;
228  esac
229
230  # Find a way to echo strings without interpreting backslash.
231  if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then
232    gt_echo='echo'
233  else
234    if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then
235      gt_echo='printf %s\n'
236    else
237      echo_func () {
238        cat <<EOT
239$*
240EOT
241      }
242      gt_echo='echo_func'
243    fi
244  fi
245
246  # A sed script that extracts the value of VARIABLE from a Makefile.
247  sed_x_variable='
248# Test if the hold space is empty.
249x
250s/P/P/
251x
252ta
253# Yes it was empty. Look if we have the expected variable definition.
254/^[	 ]*VARIABLE[	 ]*=/{
255  # Seen the first line of the variable definition.
256  s/^[	 ]*VARIABLE[	 ]*=//
257  ba
258}
259bd
260:a
261# Here we are processing a line from the variable definition.
262# Remove comment, more precisely replace it with a space.
263s/#.*$/ /
264# See if the line ends in a backslash.
265tb
266:b
267s/\\$//
268# Print the line, without the trailing backslash.
269p
270tc
271# There was no trailing backslash. The end of the variable definition is
272# reached. Clear the hold space.
273s/^.*$//
274x
275bd
276:c
277# A trailing backslash means that the variable definition continues in the
278# next line. Put a nonempty string into the hold space to indicate this.
279s/^.*$/P/
280x
281:d
282'
283changequote([,])dnl
284
285  # Set POTFILES to the value of the Makefile variable POTFILES.
286  sed_x_POTFILES="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/POTFILES/g'`"
287  POTFILES=`sed -n -e "$sed_x_POTFILES" < "$ac_file"`
288  # Compute POTFILES_DEPS as
289  #   $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
290  POTFILES_DEPS=
291  for file in $POTFILES; do
292    POTFILES_DEPS="$POTFILES_DEPS "'$(top_srcdir)/'"$file"
293  done
294  POMAKEFILEDEPS=""
295
296  if test -n "$OBSOLETE_ALL_LINGUAS"; then
297    test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete"
298  fi
299  if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
300    # The LINGUAS file contains the set of available languages.
301    ALL_LINGUAS_=`sed -e "/^#/d" "$ac_given_srcdir/$ac_dir/LINGUAS"`
302    POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
303  else
304    # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS.
305    sed_x_LINGUAS="`$gt_echo \"$sed_x_variable\" | sed -e '/^ *#/d' -e 's/VARIABLE/LINGUAS/g'`"
306    ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
307  fi
308  # Hide the ALL_LINGUAS assigment from automake.
309  eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
310  # Compute POFILES
311  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
312  # Compute UPDATEPOFILES
313  # as      $(foreach lang, $(ALL_LINGUAS), $(lang).po-update)
314  # Compute DUMMYPOFILES
315  # as      $(foreach lang, $(ALL_LINGUAS), $(lang).nop)
316  # Compute GMOFILES
317  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
318  # Compute PROPERTIESFILES
319  # as      $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties)
320  # Compute CLASSFILES
321  # as      $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class)
322  # Compute QMFILES
323  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
324  # Compute MSGFILES
325  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang)).msg)
326  # Compute RESOURCESDLLFILES
327  # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(frob $(lang))/$(DOMAIN).resources.dll)
328  case "$ac_given_srcdir" in
329    .) srcdirpre= ;;
330    *) srcdirpre='$(srcdir)/' ;;
331  esac
332  POFILES=
333  UPDATEPOFILES=
334  DUMMYPOFILES=
335  GMOFILES=
336  PROPERTIESFILES=
337  CLASSFILES=
338  QMFILES=
339  MSGFILES=
340  RESOURCESDLLFILES=
341  for lang in $ALL_LINGUAS; do
342    POFILES="$POFILES $srcdirpre$lang.po"
343    UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
344    DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
345    GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
346    PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties"
347    CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class"
348    QMFILES="$QMFILES $srcdirpre$lang.qm"
349    frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
350    MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
351    frobbedlang=`echo $lang | sed -e 's/_/-/g'`
352    RESOURCESDLLFILES="$RESOURCESDLLFILES $srcdirpre$frobbedlang/\$(DOMAIN).resources.dll"
353  done
354  # CATALOGS depends on both $ac_dir and the user's LINGUAS
355  # environment variable.
356  INST_LINGUAS=
357  if test -n "$ALL_LINGUAS"; then
358    for presentlang in $ALL_LINGUAS; do
359      useit=no
360      if test "%UNSET%" != "$LINGUAS"; then
361        desiredlanguages="$LINGUAS"
362      else
363        desiredlanguages="$ALL_LINGUAS"
364      fi
365      for desiredlang in $desiredlanguages; do
366        # Use the presentlang catalog if desiredlang is
367        #   a. equal to presentlang, or
368        #   b. a variant of presentlang (because in this case,
369        #      presentlang can be used as a fallback for messages
370        #      which are not translated in the desiredlang catalog).
371        case "$desiredlang" in
372          "$presentlang"*) useit=yes;;
373        esac
374      done
375      if test $useit = yes; then
376        INST_LINGUAS="$INST_LINGUAS $presentlang"
377      fi
378    done
379  fi
380  CATALOGS=
381  JAVACATALOGS=
382  QTCATALOGS=
383  TCLCATALOGS=
384  CSHARPCATALOGS=
385  if test -n "$INST_LINGUAS"; then
386    for lang in $INST_LINGUAS; do
387      CATALOGS="$CATALOGS $lang.gmo"
388      JAVACATALOGS="$JAVACATALOGS \$(DOMAIN)_$lang.properties"
389      QTCATALOGS="$QTCATALOGS $lang.qm"
390      frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
391      TCLCATALOGS="$TCLCATALOGS $frobbedlang.msg"
392      frobbedlang=`echo $lang | sed -e 's/_/-/g'`
393      CSHARPCATALOGS="$CSHARPCATALOGS $frobbedlang/\$(DOMAIN).resources.dll"
394    done
395  fi
396
397  sed -e "s|@POTFILES_DEPS@|$POTFILES_DEPS|g" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@PROPERTIESFILES@|$PROPERTIESFILES|g" -e "s|@CLASSFILES@|$CLASSFILES|g" -e "s|@QMFILES@|$QMFILES|g" -e "s|@MSGFILES@|$MSGFILES|g" -e "s|@RESOURCESDLLFILES@|$RESOURCESDLLFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@JAVACATALOGS@|$JAVACATALOGS|g" -e "s|@QTCATALOGS@|$QTCATALOGS|g" -e "s|@TCLCATALOGS@|$TCLCATALOGS|g" -e "s|@CSHARPCATALOGS@|$CSHARPCATALOGS|g" -e 's,^#distdir:,distdir:,' < "$ac_file" > "$ac_file.tmp"
398  if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then
399    # Add dependencies that cannot be formulated as a simple suffix rule.
400    for lang in $ALL_LINGUAS; do
401      frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
402      cat >> "$ac_file.tmp" <<EOF
403$frobbedlang.msg: $lang.po
404	@echo "\$(MSGFMT) -c --tcl -d \$(srcdir) -l $lang $srcdirpre$lang.po"; \
405	\$(MSGFMT) -c --tcl -d "\$(srcdir)" -l $lang $srcdirpre$lang.po || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
406EOF
407    done
408  fi
409  if grep -l '@CSHARPCATALOGS@' "$ac_file" > /dev/null; then
410    # Add dependencies that cannot be formulated as a simple suffix rule.
411    for lang in $ALL_LINGUAS; do
412      frobbedlang=`echo $lang | sed -e 's/_/-/g'`
413      cat >> "$ac_file.tmp" <<EOF
414$frobbedlang/\$(DOMAIN).resources.dll: $lang.po
415	@echo "\$(MSGFMT) -c --csharp -d \$(srcdir) -l $lang $srcdirpre$lang.po -r \$(DOMAIN)"; \
416	\$(MSGFMT) -c --csharp -d "\$(srcdir)" -l $lang $srcdirpre$lang.po -r "\$(DOMAIN)" || { rm -f "\$(srcdir)/$frobbedlang.msg"; exit 1; }
417EOF
418    done
419  fi
420  if test -n "$POMAKEFILEDEPS"; then
421    cat >> "$ac_file.tmp" <<EOF
422Makefile: $POMAKEFILEDEPS
423EOF
424  fi
425  mv "$ac_file.tmp" "$ac_file"
426])
427