tests: expose automake bug#14560
[platform/upstream/automake.git] / t / primary-prefix-invalid-couples.tap
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 # Not all primaries/directories combinations are valid.
18 # Automake should flag them as errors.
19 # Originated from PR/294, extended later (following bug #7647) to
20 # cover more cases.
21 # See also test 'primary-prefix-valid-couples.test'.
22
23 . test-init.sh
24
25 plan_ "later"
26
27 oIFS=$IFS # Saved for later.
28
29 : > ar-lib
30 : > ltmain.sh
31 : > texinfo.tex
32 : > py-compile
33 : > config.guess
34 : > config.sub
35
36 cat >> configure.ac <<'END'
37 AC_PROG_CC
38 AM_PROG_AR
39 AC_PROG_RANLIB
40 AC_SUBST([LIBTOOL], [:]) dnl So that we don't have to require Libtool.
41 AM_PROG_GCJ
42 AM_PATH_PYTHON
43 AM_PATH_LISPDIR
44 END
45
46 $ACLOCAL || fatal_ "aclocal failure"
47
48 # Please keep this list in sync with the list of "Directory Variables"
49 # in the GNU Coding Standards and with the list additional directory
50 # variables provided by autoconf and/or automake (pkgdatadir, pkglibdir,
51 # ...).   See also the hash '%standard_prefix' in the automake script.
52 prefixes='bin data dataroot doc dvi exec html include info lib libexec
53           lisp locale localstate man man1 man2 man3 man4 man5 man6 man7
54           man8 man9 oldinclude pdf pkgdata pkginclude pkglib pkglibexec
55           ps sbin sharedstate sysconf'
56 # Please keep this list in sync with the list of primaries documented in
57 # the Automake manual (see the "The Uniform Naming Scheme" section).
58 primaries='PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA
59            HEADERS MANS TEXINFOS'
60
61 # Use files, not variables, to hold the list of all the possible
62 # prefix_PRIMARY couples and the list of those couples valid for
63 # automake, to avoid having unreadable very verbose traces.
64
65 set +x # Don't be overly verbose.
66
67 for prefix in $prefixes; do
68   for primary in $primaries; do
69     echo ${prefix} ${primary}
70   done
71 done >all.list
72
73 for primary in $primaries; do
74   prefixes_ok=''
75   case $primary in
76     LIBRARIES|LTLIBRARIES)
77       prefixes_ok='lib pkglib'
78       ;;
79     PROGRAMS)
80       prefixes_ok='bin sbin libexec pkglibexec'
81       ;;
82     SCRIPTS)
83       prefixes_ok='bin sbin libexec pkglibexec pkgdata'
84       ;;
85     DATA)
86       prefixes_ok='data dataroot pkgdata doc html dvi pdf ps
87                    sysconf sharedstate localstate lisp'
88       ;;
89     HEADERS)
90       prefixes_ok='include oldinclude pkginclude'
91       ;;
92     LISP)
93       prefixes_ok='lisp'
94       ;;
95     PYTHON)
96       prefixes_ok='python'
97       ;;
98     JAVA)
99       prefixes_ok='java'
100       ;;
101     MANS)
102       # FIXME: Here we'd like to have:
103       #   prefixes_ok='man man1 man2 man3 man4 man5 man6 man7 man8 man9'
104       # but Automake currently fails on that, as it allows the MANS
105       # primary to be coupled to any prefix.
106       # See also Automake bug#7656.
107       # We should dig out how automake had come to behave this way, and
108       # if such a behaviour can be safely changed.
109       prefixes_ok=$prefixes
110       ;;
111     TEXINFOS)
112       # FIXME: Here we'd like to have:
113       #   prefixes_ok='info'
114       # but Automake currently fails on that, as it allows the use of
115       # 'foo_TEXINFOS' to declare extra Texinfo sources for the 'foo'
116       # Texinfo manual, as in e.g.:
117       #   info_TEXINFOS = foo.texi
118       #   foo_TEXINFOS = gpl.texi
119       # See also Automake bug#7657.
120       prefixes_ok=$prefixes
121       ;;
122     *)
123       fatal_ "unrecognized primary '$primary'"
124       ;;
125   esac
126   for prefix in $prefixes_ok; do
127     echo ${prefix}_${primary}
128   done
129 done >allow.list
130
131 # 'html_TEXINFOS' is not yet supported, and might never be.
132 grep -v '^html TEXINFOS$' all.list | awk '{print NR, $0}' > t
133 mv -f t all.list
134
135 # For debugging.
136 echo '=== all.list ==='
137 cat all.list
138 echo '=== allow.list ==='
139 cat allow.list
140
141 # Create the Makefile.am.
142 while read lineno prefix primary; do
143   test -n "$prefix" && test -n "$primary" && test 0 -lt $lineno \
144     || fatal_ "internal error in 'all.list'"
145   pfx='' ext=''
146   case $primary in
147     LTLIBRARIES) pfx=lib ext=la;;
148     LIBRARIES) pfx=lib ext=a;;
149     MANS) ext=man;;
150     HEADERS) ext=h;;
151     JAVA) ext=java;;
152     PYTHON) ext=py;;
153     LISP) ext=el;;
154     TEXINFOS) ext=texi;;
155   esac
156   test -z "$ext" || ext=.$ext
157   if test $primary = TEXINFOS; then
158     echo @setfilename foo$lineno.info > foo$lineno.texi
159   fi
160   echo ${prefix}_${primary} = ${pfx}foo${lineno}${ext}
161 done <all.list >Makefile.am
162
163 # For debugging.
164 echo '=== Makefile.am ==='
165 cat Makefile.am
166
167 set -x # Restore shell xtraces from now on.
168
169 AUTOMAKE_fails \
170   -d "'automake -a' error out on mismatched prefix/primary couples" \
171   -- --add-missing
172
173 while read lineno prefix primary; do
174   test -n "$prefix" && test -n "$primary" && test 0 -lt $lineno \
175     || fatal_ "internal error in 'all.list'"
176   grep "^${prefix}_${primary}$" allow.list >/dev/null && continue
177   errmsg_rx=".*${prefix}dir.* not a legitimate directory .*$primary"
178   command_ok_ \
179     "mismatched prefix/primary in ${prefix}_${primary}" \
180     grep "^Makefile\\.am:$lineno: $errmsg_rx" stderr
181 done <all.list
182
183 # Check that automake really failed only for the expected reason(s).
184 grep -v 'dir.* not a legitimate directory' stderr && exit 1
185
186 # Check that the same failures are present without the '--add-missing'
187 # option.
188 mv stderr stderr.old
189 AUTOMAKE_fails -d "automake error out on mismatched prefix/primary couples"
190 command_ok_ "... and with the same diagnostic of 'automake -a'" \
191             diff stderr.old stderr
192
193 :