xref: /netbsd-src/external/gpl3/autoconf/dist/tests/local.at (revision d874e91932377fc40d53f102e48fc3ee6f4fe9de)
1# M4 macros used in building Autoconf test suites.        -*- Autotest -*-
2
3# Copyright (C) 2000-2012 Free Software Foundation, Inc.
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18m4_version_prereq([2.57])
19
20# Used in many tests.
21m4_pattern_allow([^AS_EXIT$])
22m4_pattern_allow([^m4_(define|shift)$])
23
24# Programs this package provides
25AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
26
27# Enable colored test output.
28AT_COLOR_TESTS
29
30## ---------------- ##
31## Utility macros.  ##
32## ---------------- ##
33
34# AT_CMP(FILE-1, FILE-2)
35# ----------------------
36# Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
37m4_define([AT_CMP],
38[m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
39AT_CHECK([$at_diff "$1" "$2"])
40])# AT_CMP
41
42
43## ---------------- ##
44## Testing syntax.  ##
45## ---------------- ##
46
47# AT_CHECK_SHELL_SYNTAX(PROGRAM)
48# ------------------------------
49# If the shell handles `-n' well, use it to check the syntax of PROGRAM;
50# otherwise, do nothing.  ksh93 -n also spits outs loads of warnings
51# about older constructs, but we don't care about the warnings.
52m4_define([AT_CHECK_SHELL_SYNTAX],
53[AT_SKIP_IF([test "$ac_cv_sh_n_works" != yes])
54AT_CHECK([/bin/sh -n $1], [], [], [ignore])])
55
56m4_define([AT_CHECK_PERL_SYNTAX],
57[AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c "$abs_top_builddir"/bin/$1],
58          0, [], [ignore])])
59
60## ------------------ ##
61## Testing autom4te.  ##
62## ------------------ ##
63
64
65# AT_CHECK_M4(COMMAND, [EXIT-STATUS = 0], STDOUT, STDERR)
66# -------------------------------------------------------
67# If stderr is specified, normalize the observed stderr.
68# This (using GNU M4 1.4.6)
69#
70#  /usr/local/bin/m4:script.4s:1: cannot open `foo': No such file or directory
71#  autom4te: /usr/local/bin/m4 failed with exit status: 1
72#
73# or this (GNU M4 1.4.11)
74#
75#  /usr/local/bin/m4:script.4s:1: include: cannot open `foo': No such file or directory
76#  autom4te: /usr/local/bin/m4 failed with exit status: 1
77#
78# or this (GNU M4 1.4 installed as gm4)
79#
80#  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
81#  autom4te: /usr/local/bin/gm4 failed with exit status: 1
82#
83# or this (GNU M4 1.4.13 installed as m4-1.4.13):
84#
85#  /usr/bin/m4-1.4.13:script.4s:1: include: cannot open `foo': No such file or directory
86#  autom4te: /usr/bin/m4-1.4.13 failed with exit status: 1
87#
88# becomes
89#
90#  m4:script.4s:1: cannot open `foo': No such file or directory
91#  autom4te: m4 failed with exit status: 1
92#
93# We use the following sed patterns:
94#
95#     (m4): ?(file): ?(line):
96# or  (file): ?(line): ?(m4):
97# to  m4:(file):(line):
98#
99# and
100#     m4:(file):(line): Cannot open foo:
101# or  m4:(file):(line): include: cannot open `foo':
102# to  m4:(file):(line): cannot open `foo':
103#
104# and
105#     autom4te: [^ ]m4
106# or  autom4te: [^ ]m4.exe
107# to  autom4te: m4
108#
109# Moreover, DJGPP error messages include the error code in brackets;
110# remove the error code during normalization.
111#
112m4_define([AT_CHECK_M4],
113[AT_CHECK([$1], [$2], [$3],
114          m4_case([$4], [], [], [ignore], [ignore], [stderr]))
115m4_case([$4], [], [], [ignore], [],
116[AT_CHECK([[sed 's/^[^:]*m4[-.ex0-9]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
117	s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4[-.ex0-9]*: /m4:\1\2 /
118	s/: C\(annot open \)\([^`:]*\):/: c\1`\2'\'':/
119	s/: include:\( cannot open\)/:\1/
120	s/^autom4te: [^ ]*m4[.ex]* /autom4te: m4 /
121	s/ (E[A-Z]*)$//
122    ' stderr >&2]], [0], [], [$4])])
123])
124
125# AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
126# -----------------------------------------------------------
127m4_define([AT_CHECK_AUTOM4TE],
128[AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
129
130
131
132## ----------------- ##
133## Testing M4sugar.  ##
134## ----------------- ##
135
136
137# AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
138# ------------------------------------
139# Escape the invalid tokens with @&t@.
140m4_define([AT_DATA_M4SUGAR],
141[AT_DATA([$1],
142[m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\)\(_\)\|\(d\)\(nl\)],
143              [\1\3\5@&t@\2\4\6])])])
144
145
146# AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
147# ----------------------------------------------------------
148m4_define([AT_CHECK_M4SUGAR],
149[AT_KEYWORDS([m4sugar])
150AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
151	           [$2], [$3], [$4])])
152
153
154
155## -------------- ##
156## Testing M4sh.  ##
157## -------------- ##
158
159
160# AT_DATA_M4SH(FILE-NAME, CONTENTS)
161# ---------------------------------
162# Escape the invalid tokens with @&t@.
163m4_define([AT_DATA_M4SH],
164[AT_DATA([$1],
165[m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\)\(_\)\|\(d\)\(nl\)],
166              [\1\3\5@&t@\2\4\6])])])
167
168
169# AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
170# -------------------------------------------------------
171m4_define([AT_CHECK_M4SH],
172[AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
173	           [$2], [$3], [$4])])
174
175
176
177## ------------------ ##
178## Testing Autoconf.  ##
179## ------------------ ##
180
181
182# AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
183# -------------------------------------
184# Escape the invalid tokens with @&t@.
185m4_define([AT_DATA_AUTOCONF],
186[AT_DATA([$1],
187[m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AC\)\(_\)\|\(d\)\(nl\)],
188              [\1\3\5@&t@\2\4\6])])])
189
190
191
192# AT_CONFIGURE_AC(BODY)
193# ---------------------
194# Create a full configure.ac running BODY, with a config header set up,
195# AC_OUTPUT, and environment checking hooks.
196m4_define([AT_CONFIGURE_AC],
197[AT_DATA([configure.ac],
198[[AC_INIT
199AC_CONFIG_HEADERS(config.h:config.hin)
200AC_STATE_SAVE(before)]
201$1
202[AC_OUTPUT
203AC_STATE_SAVE(after)
204]])
205cp "$abs_top_srcdir/build-aux/install-sh" \
206   "$abs_top_srcdir/build-aux/config.guess" \
207   "$abs_top_srcdir/build-aux/config.sub" .
208cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
209])# AT_CONFIGURE_AC
210
211
212# AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
213# ----------------------------------------------------------
214# We always use "--force", to prevent problems with timestamps if the testsuite
215# were running too fast.
216m4_define([AT_CHECK_AUTOCONF],
217[AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
218if test -s configure && test "$ac_cv_sh_n_works" = yes; then
219  AT_CHECK_SHELL_SYNTAX([configure])
220fi
221])
222
223
224# AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
225# ------------------------------------------------------------
226m4_define([AT_CHECK_AUTOHEADER],
227[AT_CHECK([autoheader $1], [$2], [$3], [$4])
228])
229
230
231# AT_CHECK_CONFIGURE(END-COMMAND,
232#                    [EXIT-STATUS = 0],
233#                    [STDOUT = IGNORE], STDERR)
234# ---------------------------------------------
235# `abs_top_srcdir' is needed so that `./configure' finds install-sh.
236# Using --srcdir is more expensive.
237m4_define([AT_CHECK_CONFIGURE],
238[AT_CAPTURE_FILE([config.log])[]dnl
239 AT_CHECK([./configure $configure_options $1],
240	  [$2],
241	  m4_default([$3], [ignore]), [$4])])
242
243
244# AT_CHECK_ENV
245# ------------
246# Check that the full configure run remained in its variable name space,
247# and cleaned up tmp files.
248#
249# Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
250# In this case just don't pay attention to the env.  It would be great
251# to keep the error message but we can't: that would break AT_CHECK.
252#
253# FreeBSD sh may intermingle the trace output from the egrep and grep
254# commands in the pipe, so turn off tracing for these.
255#
256# Some tests might exit prematurely when they find a problem, in
257# which case `env-after' is probably missing.  Don't check it then.
258#
259# Here are the variables `configure' may modify during execution:
260# - ^as_
261#   M4sh's shell name space.
262# - ^ac_
263#   Autoconf's shell name space.
264# - prefix and exec_prefix
265#   are kept undefined (NONE) until AC_OUTPUT which then sets them to
266#   `/usr/local' and `${prefix}' for make.
267# - (host|build|target)(_(alias|cpu|vendor|os))?
268#   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
269# - cross_compiling
270#   Set by AC_INIT.
271# - interpval
272#   Set by AC_SYS_INTERPRETER.
273# - CONFIG_STATUS and DEFS
274#   Set by AC_OUTPUT.
275# - AC_SUBST'ed variables
276#   (FIXME: Generate a list of these automatically.)
277# - _|@|.[*#?$].|argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
278#   Some variables some shells use and change.
279#   `.[*#?$].' catches `$#' etc. which are displayed like this:
280#      | '!'=18186
281#      | '#'=0
282#      | '$'=6908
283#
284m4_define([AT_CHECK_ENV],
285[m4_divert_once([PREPARE_TESTS], [_AT_CHECK_ENV])dnl
286AT_CHECK([at_check_env])])
287m4_define([_AT_CHECK_ENV],
288[AS_FUNCTION_DESCRIBE([at_check_env], [],
289[Compare the directory and environment state both before and after a run,
290and return non-zero status if they differ inappropriately.])
291at_check_env ()
292{
293# Compare directory listings.
294test -f state-ls.before ||
295  AS_ERROR([state-ls.before not present])
296test -f state-ls.after \
297  && { $at_diff state-ls.before state-ls.after || return 1; }
298# Compare variable space dumps.
299if test -f state-env.before && test -f state-env.after; then
300  set +x
301  grep_failed=false
302  for act_file in state-env.before state-env.after
303  do
304    ($EGREP -v '^(m4_join([|],
305      [a[cs]_.*],
306      [(exec_)?prefix|DEFS|CONFIG_STATUS],
307      [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
308      [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
309      [ERLANG_LIB_DIR_.*|ERLANG_LIB_VER_.*|ERLANG_INSTALL_LIB_DIR],
310      [ERLANG_INSTALL_LIB_DIR_.*|ERLANG_ERTS_VER|OBJC|OBJCPP|OBJCFLAGS],
311      [OBJCXX|OBJCXXCPP|OBJCXXFLAGS],
312      [GOC|GOFLAGS],
313      [OPENMP_CFLAGS],
314      [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
315      [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
316      [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
317      [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
318      [(host|build|target)(_(alias|cpu|vendor|os))?],
319      [cross_compiling|U],
320      [interpval|PATH_SEPARATOR],
321      [GFC|F77_DUMMY_MAIN|f77_(case|underscore)],
322      [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_[fF]|_MODEXT|_MODINC|_MODOUT|_DEFINE)?],
323      [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
324      [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
325      [GREP|[EF]GREP|SED],
326      [[_@]|.[*#?$].],
327      [argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
328     $act_file ||
329       test $? -eq 1 || echo failed >&2
330    ) 2>stderr-$act_file |
331      # There may be variables spread on several lines; remove latter lines.
332      $GREP '^m4_defn([m4_re_word])=' >clean-$act_file ||
333        test $? -eq 1 || grep_failed=:
334    test -s stderr-$act_file && grep_failed=:
335  done
336  $at_traceon
337  $grep_failed || $at_diff clean-state-env.before clean-state-env.after
338fi
339} [#]at_check_env])
340
341
342# AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
343# -------------------------------------
344# Check the outcomes of two configure runs for equality by comparing dumps of
345# their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
346# variable space dumps.
347#
348# We permit variance between runs in the following shell variables:
349# - ^as_
350#   M4sh's shell name space.
351# - ^ac_, excluding ^ac_cv_
352#   Autoconf's private shell name space.
353# - PPID [bash, zsh]
354# - RANDOM [zsh]
355# - SECONDS [zsh]
356# - '$' [zsh]
357# - argv [zsh]
358# - ARGC [zsh]
359#
360# Furthermore, it is okay for a non-cache variable initialized to empty in one
361# run to be unset in another run.  This happens when, for example, cache update
362# code tries a number of values in LIBS and eventually restores LIBS to its
363# original value. If LIBS was previously unset, it will have become set and
364# empty.  (OTOH, cache variables indicate the result of the test even if they
365# are empty, so we have to be strict about them.)
366#
367# Lines that do not look like `foo=bar' are probably latter lines of
368# multiline values; trim them.
369#
370m4_define([AT_CONFIG_CMP],
371[for act_file in $1 $2
372do
373  $SED '/^ac_cv_/ b
374	/^m4_defn([m4_re_word])=./ !d
375	/^[[^=]]*='\'''\''$/ d
376	/^a[[cs]]_/ d
377	/^OLDPWD=/ d
378	/^PPID=/ d
379	/^RANDOM=/ d
380	/^SECONDS=/ d
381	/'\'\\\$\''=/ d
382	/^argv=/ d
383	/^ARGC=/ d
384	' $act_file >at_config_vars-$act_file
385done
386AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
387])# AT_CONFIG_CMP
388
389
390# AT_CHECK_DEFINES(CONTENT)
391# -------------------------
392# Verify that config.h, once stripped, is CONTENT.
393# Stripping consists of keeping CPP lines (i.e. containing a hash),
394# but those of automatically checked features (STDC_HEADERS etc.)
395# and symbols (PACKAGE_...).
396# AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
397m4_define([AT_CHECK_DEFINES],
398[AT_CHECK([[sed '/#/!d
399/INTTYPES/d
400/MEMORY/d
401/PACKAGE_/d
402/STDC_HEADERS/d
403/STDINT/d
404/STDLIB/d
405/STRING/d
406/SYS_STAT/d
407/SYS_TYPES/d
408/UNISTD/d' config.h]],,
409	  [$1])])
410
411
412# AT_CHECK_AUTOUPDATE
413# -------------------
414m4_define([AT_CHECK_AUTOUPDATE],
415[AT_CHECK([autoupdate $1], [$2], [$3], [$4])
416])
417
418
419# _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
420# --------------------------------------
421# Create a minimalist configure.ac running the macro named
422# NAME-OF-THE-MACRO, check that autoconf runs on that script,
423# and that the shell runs correctly the configure.
424m4_define([_AT_CHECK_AC_MACRO],
425[AT_CONFIGURE_AC([$1])
426$2
427AT_CHECK_AUTOCONF
428AT_CHECK_AUTOHEADER
429AT_CHECK_CONFIGURE
430AT_CHECK_ENV
431])# _AT_CHECK_AC_MACRO
432
433
434# AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
435#                [AUTOCONF-FLAGS = -W obsolete])
436# -----------------------------------------------------
437# Create a minimalist configure.ac running the macro named
438# NAME-OF-THE-MACRO, check that autoconf runs on that script,
439# and that the shell runs correctly the configure.
440#
441# We run `configure' twice, both times with a cache, and compare
442# the environment after each run to detect inconsistencies.
443#
444# New macros are not expected to depend upon obsolete macros.
445m4_define([AT_CHECK_MACRO],
446[AT_SETUP([$1])
447
448AT_CONFIGURE_AC([m4_default([$2], [$1])])
449
450AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
451AT_CHECK_AUTOHEADER
452
453for at_run in r1 r2
454do
455    AT_CHECK_CONFIGURE([-C])
456    cp -f state-env.after state-env.$at_run
457    cp -f config.h config-h.$at_run
458    AT_CHECK_ENV
459done
460
461AT_CMP([config-h.r1], [config-h.r2])
462AT_CONFIG_CMP([state-env.r1], [state-env.r2])
463
464$3
465
466AT_CLEANUP[]dnl
467])# AT_CHECK_MACRO
468
469
470# AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
471#                      [AUTOCONF-FLAGS = -W obsolete])
472# -----------------------------------------------------------
473# Like the previous one, but creates two checks: for native
474# compile and for cross-compile.
475m4_define([AT_CHECK_MACRO_CROSS],
476[AT_CHECK_MACRO($@)
477AT_CHECK_MACRO([$1 (cross compile)],
478  [AT_KEYWORDS([cross])
479  # Exercise the code used when cross-compiling.
480  cross_compiling=yes
481  ac_tool_warned=yes
482  m4_default([$2], [$1])],
483  [$3], [$4])
484])
485
486
487# AT_CHECK_AU_MACRO(MACRO)
488# ------------------------
489# Create a minimalist configure.ac running the macro named
490# NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
491# on that script, and that the shell runs correctly the configure.
492#
493# Updated configure.ac shall not depend upon obsolete macros, which votes
494# in favor of `-W obsolete', but since many of these macros leave a message
495# to be removed by the user once her code is adjusted, let's not check.
496#
497# Remove config.hin to avoid `autoheader: config.hin is unchanged'.
498m4_define([AT_CHECK_AU_MACRO],
499[AT_SETUP([$1])
500AT_KEYWORDS([autoupdate])
501
502AT_CONFIGURE_AC([$1])
503
504AT_CHECK_AUTOCONF
505AT_CHECK_AUTOHEADER
506AT_CHECK_CONFIGURE
507AT_CHECK_ENV
508
509rm config.hin
510AT_CHECK_AUTOUPDATE([], 0, [], ignore)
511AT_CHECK([grep '^$1$' configure.ac], 1)
512
513AT_CHECK_AUTOCONF
514AT_CHECK_AUTOHEADER
515AT_CHECK_CONFIGURE
516AT_CHECK_ENV
517
518AT_CLEANUP[]dnl
519])# AT_CHECK_AU_MACRO
520
521
522
523## ----------------------- ##
524## Launch the test suite.  ##
525## ----------------------- ##
526
527AT_INIT
528