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