tests: expose automake bug#14560
[platform/upstream/automake.git] / t / gettext-macros.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Try to find the gettext '.m4' files and make them easily accessed
18 # to the test cases requiring them.
19 # See also automake bug#9807.
20
21 . test-init.sh
22
23 extract_program_version ()
24 {
25   "$1" --version | sed 1q | $PERL -ne '/(\d(?:\.\d+)+)/ and print "$1\n"'
26 }
27
28 echo "# Automatically generated by $me." > get.sh
29 echo : >> get.sh
30
31 # The 'gettextize' and 'autopoint' scripts will look into Makefile.am.
32 echo ACLOCAL_AMFLAGS = -I m4 > Makefile.am
33
34 # Prefer autopoint to gettextize, since the more modern versions of the
35 # latter might unconditionally require user interaction to complete;
36 # yes, this means confirmation from /dev/tty (!) -- see:
37 #  <http://lists.gnu.org/archive/html/bug-gettext/2011-12/msg00000.html>
38 # Since this "forced interaction" behaviour of gettextize wasn't present
39 # before the introduction of autopoint, we should be able to safely
40 # fall back to calling gettextize non-interactively if autopoint is not
41 # present.
42 if autopoint --version; then
43   am_gettextize_command=autopoint
44 else
45   am_gettextize_command=gettextize
46 fi
47
48 # We will need to specify the correct autopoint (or gettextize) version
49 # in the AM_GNU_GETTEXT_VERSION call in configure.ac if we want autopoint
50 # (or gettextize) to setup the correct infrastructure -- in particular,
51 # for what concerns us, to bring in all the required .m4 files.
52 autopoint_version=$(extract_program_version $am_gettextize_command) \
53   && test -n "$autopoint_version" \
54   || autopoint_version=0.10.35
55
56 cat > configure.ac <<END
57 AC_INIT([foo], [1.0])
58 AC_PROG_CC
59 # Both required by autopoint.
60 AM_GNU_GETTEXT
61 AM_GNU_GETTEXT_VERSION([$autopoint_version])
62 END
63
64 if $am_gettextize_command --force && test -f m4/gettext.m4; then
65   echo "ACLOCAL_PATH='$(pwd)/m4':\$ACLOCAL_PATH" >> get.sh
66   echo "export ACLOCAL_PATH" >> get.sh
67 else
68   # Older versions of gettext might not have a gettextize program
69   # available, but this doesn't mean the user hasn't made the gettext
70   # macros available, e.g., by properly setting ACLOCAL_PATH.
71   rm -rf m4
72   mkdir m4
73   # See below for an explanation about the use the of '-Wno-syntax'.
74   if $ACLOCAL -Wno-syntax -I m4 --install && test -f m4/gettext.m4; then
75     : # Gettext macros already accessible by default.
76   else
77     echo "skip_all_ \"couldn't find or get gettext macros\"" >> get.sh
78   fi
79 fi
80
81 cat >> get.sh <<'END'
82 # Even recent versions of gettext used the now-obsolete 'AM_PROG_MKDIR_P'
83 # m4 macro.  So we need the following to avoid spurious errors.
84 ACLOCAL="$ACLOCAL -Wno-obsolete"
85 AUTOMAKE="$AUTOMAKE -Wno-obsolete"
86 END
87
88 . ./get.sh
89
90 $ACLOCAL --force -I m4 || cat >> get.sh <<'END'
91 # We need to use '-Wno-syntax', since we do not want our test suite
92 # to fail merely because some third-party '.m4' file is underquoted.
93 ACLOCAL="$ACLOCAL -Wno-syntax"
94 END
95
96 # Remove any Makefile.in possibly created by gettextize/autopoint, to
97 # avoid spurious maintainer-check failures.
98 rm -f $(find . -name Makefile.in)
99
100 # The file gettextize or autopoint might have copied in the 'm4'
101 # subdirectory of the test directory are going to be needed by
102 # other tests, so we must not remove the test directory.
103 keep_testdirs=yes
104
105 :