* doc/autoconf.texi (Particular Programs): AC_PROG_MKDIR_P now
[autoconf.git] / tests / local.at
blobc49e1f3692cfcdf9b85f1617c3ce80ccbc4a0263
1 # M4 macros used in building Autoconf test suites.        -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4 # 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 2, or (at your option)
9 # 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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # We need a very up to date version of Autotest.
22 m4_version_prereq([2.57])
24 # Used in many tests.
25 m4_pattern_allow([^AS_EXIT$])
26 m4_pattern_allow([^m4_(define|shift)$])
28 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
31 ## ---------------- ##
32 ## Utility macros.  ##
33 ## ---------------- ##
35 # AT_CMP(FILE-1, FILE-2)
36 # ----------------------
37 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
38 m4_define([AT_CMP],
39 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
40 AT_CHECK([$at_diff "$1" "$2"])
41 ])# AT_CMP
44 ## ---------------- ##
45 ## Testing syntax.  ##
46 ## ---------------- ##
48 # AT_CHECK_SHELL_SYNTAX(PROGRAM)
49 # ------------------------------
50 # If the shell handles `-n' well, use it to check the syntax of PROGRAM;
51 # otherwise, do nothing.
52 m4_define([AT_CHECK_SHELL_SYNTAX],
53 [AS_IF([test "$ac_cv_sh_n_works" = yes],
54   [AT_CHECK([/bin/sh -n $1])])])
56 m4_define([AT_CHECK_PERL_SYNTAX],
57 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c $abs_top_builddir/bin/$1],
58           0, [], [ignore])])
60 ## ------------------ ##
61 ## Testing autom4te.  ##
62 ## ------------------ ##
65 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
66 # -----------------------------------------------------------
67 # If stderr is specified, normalize the observed stderr.  E.g. (GNU M4 1.5):
69 #  /usr/local/bin/m4: script.4s: 1: Cannot open foo: No such file or directory
70 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
72 # or (using gm4 as GNU M4 1.4):
74 #  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
75 #  autom4te: /usr/local/bin/gm4 failed with exit status: 1
77 # becomes
79 #  m4: script.4s: 1: Cannot open foo: No such file or directory
80 #  autom4te: m4 failed with exit status: 1
82 # We use the following sed patterns:
84 #     (file): (line): (m4):
85 # or  (m4): (file): (line):
86 # to  m4: (file): (line):
88 # and
89 #     autom4te: [^ ]m4
90 # to  autom4te: m4
91 m4_define([AT_CHECK_AUTOM4TE],
92 [AT_CHECK([autom4te $1], [$2], [$3], m4_ifval([$4], [stderr]))
93 m4_ifval([$4],
94 [AT_CHECK([[sed -e 's/^\([^:]*\): *\([0-9][0-9]*\): *[^:]*m4: /m4: \1: \2: /' \
95                 -e 's/^[^:]*m4: *\([^:]*\): *\([0-9][0-9]*\): /m4: \1: \2: /' \
96                 -e 's/^autom4te: [^ ]*m4 /autom4te: m4 /' \
97                 -e 's/^autom4te: [^ ]*m4.exe /autom4te: m4 /' \
98                 -e 's/ (E[A-Z]*)$//' \
99            stderr]], [0],[$4])])
104 ## ----------------- ##
105 ## Testing M4sugar.  ##
106 ## ----------------- ##
109 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
110 # ------------------------------------
111 # Escape the invalid tokens with @&t@.
112 m4_define([AT_DATA_M4SUGAR],
113 [AT_DATA([$1],
114 [m4_bpatsubsts([$2],
115                [@&t@],    [@&@&t@t@],
116                [\(m4\)_], [\1@&t@_],
117                [dnl],     [d@&t@nl])])])
120 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
121 # ----------------------------------------------------------
122 m4_define([AT_CHECK_M4SUGAR],
123 [AT_KEYWORDS([m4sugar])
124 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
125                    [$2], [$3], [$4])])
129 ## -------------- ##
130 ## Testing M4sh.  ##
131 ## -------------- ##
134 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
135 # ---------------------------------
136 # Escape the invalid tokens with @&t@.
137 m4_define([AT_DATA_M4SH],
138 [AT_DATA([$1],
139 [m4_bpatsubsts([$2],
140                [@&t@],        [@&@&t@t@],
141                [\(m4\|AS\)_], [\1@&t@_],
142                [dnl],         [d@&t@nl])])])
145 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
146 # -------------------------------------------------------
147 m4_define([AT_CHECK_M4SH],
148 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
149                    [$2], [$3], [$4])])
153 ## ------------------ ##
154 ## Testing Autoconf.  ##
155 ## ------------------ ##
158 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
159 # -------------------------------------
160 # Escape the invalid tokens with @&t@.
161 m4_define([AT_DATA_AUTOCONF],
162 [AT_DATA([$1],
163 [m4_bpatsubsts([$2],
164                [@&t@],            [@&@&t@t@],
165                [\(m4\|AS\|AC\)_], [\1@&t@_],
166                [dnl],             [d@&t@nl])])])
170 # AT_CONFIGURE_AC(BODY)
171 # ---------------------
172 # Create a full configure.ac running BODY, with a config header set up,
173 # AC_OUTPUT, and environment checking hooks.
174 m4_define([AT_CONFIGURE_AC],
175 [AT_DATA_AUTOCONF([aclocal.m4],
177 # AC_STATE_SAVE(FILE)
178 # -------------------
179 # Save the shell variables and directory listing.  AT_CHECK_ENV uses these to
180 # confirm that no test modifies variables outside the Autoconf namespace or
181 # leaves temporary files.  AT_CONFIG_CMP uses the variable dumps to confirm that
182 # tests have the same side effects regardless of caching.
183 m4_defun([AC_STATE_SAVE],
184 [(set) 2>&1 | sort >state-env.$][1
185 ls -1 | sed '/^at-/d;/^state-/d;/^config\./d' | sort >state-ls.$][1
186 ])# AC_STATE_SAVE
189 AT_DATA([configure.ac],
190 [[AC_INIT
191 AC_CONFIG_AUX_DIR($top_srcdir/config)
192 AC_CONFIG_HEADER(config.h:config.hin)
193 AC_STATE_SAVE(before)]
195 [AC_OUTPUT
196 AC_STATE_SAVE(after)
198 ])# AT_CONFIGURE_AC
201 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
202 # ----------------------------------------------------------
203 # We always use "--force", to prevent problems with timestamps if the testsuite
204 # were running too fast.
205 m4_define([AT_CHECK_AUTOCONF],
206 [AT_CHECK([autoconf --force $1], [$2], [$3], [$4])
207 if test -s configure; then
208   AT_CHECK_SHELL_SYNTAX(configure)
213 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
214 # ------------------------------------------------------------
215 m4_define([AT_CHECK_AUTOHEADER],
216 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
220 # AT_CHECK_CONFIGURE(END-COMMAND,
221 #                    [EXIT-STATUS = 0],
222 #                    [STDOUT = IGNORE], STDERR)
223 # --------------------------------------------
224 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
225 # Using --srcdir is more expensive.
226 m4_define([AT_CHECK_CONFIGURE],
227 [AT_CAPTURE_FILE([config.log])[]dnl
228  AT_CHECK([top_srcdir=$abs_top_srcdir ./configure $1],
229           [$2],
230           m4_default([$3], [ignore]), [$4])])
233 # AT_CHECK_ENV
234 # ------------
235 # Check that the full configure run remained in its variable name space,
236 # and cleaned up tmp files.
238 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
239 # In this case just don't pay attention to the env.  It would be great
240 # to keep the error message but we can't: that would break AT_CHECK.
242 # Some tests might exit prematurely when they find a problem, in
243 # which case `env-after' is probably missing.  Don't check it then.
245 # Here are the variables `configure' may modify during execution:
246 # - ^as_
247 #   M4sh's shell name space.
248 # - ^ac_
249 #   Autoconf's shell name space.
250 # - prefix and exec_prefix
251 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
252 #   `/usr/local' and `${prefix}' for make.
253 # - (host|build|target)(_(alias|cpu|vendor|os))?
254 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
255 # - cross_compiling
256 #   Set by AC_INIT.
257 # - interpval
258 #   Set by AC_SYS_INTERPRETER.
259 # - CONFIG_STATUS and DEFS
260 #   Set by AC_OUTPUT.
261 # - AC_SUBST'ed variables
262 #   (FIXME: Generate a list of these automatically.)
263 # - _|@|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
264 #   Some variables some shells use and change.
265 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
266 #      | '!'=18186
267 #      | '#'=0
268 #      | '$'=6908
270 m4_define([AT_CHECK_ENV],
271 [# Compare directory listings.
272 test -f state-ls.before ||
273   AS_ERROR([state-ls.before not present])
274 test -f state-ls.after && { AT_CMP([state-ls.before], [state-ls.after]) }
275 # Compare variable space dumps.
276 if test -f state-env.before && test -f state-env.after; then
277   for act_file in state-env.before state-env.after
278   do
279     $EGREP -v '^(m4_join([|],
280       [a[cs]_.*],
281       [(exec_)?prefix|DEFS|CONFIG_STATUS],
282       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
283       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
284       [ERLANG_INSTALL_LIB_DIR|OBJC|OBJCPP|OBJCFLAGS],
285       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
286       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
287       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
288       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
289       [(host|build|target)(_(alias|cpu|vendor|os))?],
290       [cross_compiling],
291       [interpval|PATH_SEPARATOR],
292       [F77_DUMMY_MAIN|f77_(case|underscore)],
293       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
294       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
295       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
296       [GREP|[EF]GREP|SED],
297       [[_@]|.[*#?$].|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
298      $act_file 2>/dev/null |
299       # There may be variables spread on several lines; remove latter lines.
300       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
301   done
302   AT_CMP([clean-state-env.before], [clean-state-env.after])
307 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
308 # -------------------------------------
309 # Check the outcomes of two configure runs for equality by comparing dumps of
310 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
311 # variable space dumps.
313 # We permit variance between runs in the following shell variables:
314 # - ^as_
315 #   M4sh's shell name space.
316 # - ^ac_, excluding ^ac_cv_
317 #   Autoconf's private shell name space.
318 # - PPID [bash, zsh]
319 # - RANDOM [zsh]
320 # - SECONDS [zsh]
321 # - '$' [zsh]
323 # Furthermore, it is okay for a non-cache variable initialized to empty in one
324 # run to be unset in another run.  This happens when, for example, cache update
325 # code tries a number of values in LIBS and eventually restores LIBS to its
326 # original value. If LIBS was previously unset, it will have become set and
327 # empty.  (OTOH, cache variables indicate the result of the test even if they
328 # are empty, so we have to be strict about them.)
330 # Lines that do not look like `foo=bar' are probably latter lines of
331 # multiline values; trim them.
333 m4_define([AT_CONFIG_CMP],
334 [for act_file in $1 $2
336   $SED '/^ac_cv_/ b
337         /^m4_defn([m4_re_word])=./ !d
338         /^[[^=]]*='\'''\''$/ d
339         /^a[[cs]]_/ d
340         /^PPID=/ d
341         /^RANDOM=/ d
342         /^SECONDS=/ d
343         /'\'\\\$\''=/ d
344         ' $act_file >at_config_vars-$act_file
345 done
346 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
347 ])# AT_CONFIG_CMP
350 # AT_CHECK_DEFINES(CONTENT)
351 # -------------------------
352 # Verify that config.h, once stripped, is CONTENT.
353 # Stripping consists of keeping CPP lines (i.e. containing a hash),
354 # but those of automatically checked features (STDC_HEADERS etc.)
355 # and symbols (PACKAGE_...).
356 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
357 m4_define([AT_CHECK_DEFINES],
358 [AT_CHECK([[sed '/#/!d
359 /INTTYPES/d
360 /MEMORY/d
361 /PACKAGE_/d
362 /STDC_HEADERS/d
363 /STDINT/d
364 /STDLIB/d
365 /STRING/d
366 /SYS_STAT/d
367 /SYS_TYPES/d
368 /UNISTD/d' config.h]],,
369           [$1])])
372 # AT_CHECK_AUTOUPDATE
373 # -------------------
374 m4_define([AT_CHECK_AUTOUPDATE],
375 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
379 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
380 # --------------------------------------
381 # Create a minimalist configure.ac running the macro named
382 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
383 # and that the shell runs correctly the configure.
384 m4_define([_AT_CHECK_AC_MACRO],
385 [AT_CONFIGURE_AC([$1])
387 AT_CHECK_AUTOCONF
388 AT_CHECK_AUTOHEADER
389 AT_CHECK_CONFIGURE
390 AT_CHECK_ENV
391 ])# _AT_CHECK_AC_MACRO
394 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
395 #                [AUTOCONF-FLAGS = -W obsolete])
396 # -----------------------------------------------------
397 # Create a minimalist configure.ac running the macro named
398 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
399 # and that the shell runs correctly the configure.
401 # We run `configure' twice, both times with a cache, and compare
402 # the environment after each run to detect inconsistencies.
404 # New macros are not expected to depend upon obsolete macros.
405 m4_define([AT_CHECK_MACRO],
406 [AT_SETUP([$1])
408 AT_CONFIGURE_AC([m4_default([$2], [$1])])
410 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
411 AT_CHECK_AUTOHEADER
413 for at_run in r1 r2
415     AT_CHECK_CONFIGURE([-C])
416     cp -f state-env.after state-env.$at_run
417     cp -f config.h config-h.$at_run
418     AT_CHECK_ENV
419 done
421 AT_CMP([config-h.r1], [config-h.r2])
422 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
426 AT_CLEANUP()dnl
427 ])# AT_CHECK_MACRO
430 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
431 #                      [AUTOCONF-FLAGS = -W obsolete])
432 # -----------------------------------------------------------
433 # Like the previous one, but creates two checks: for native
434 # compile and for cross-compile.
435 m4_define([AT_CHECK_MACRO_CROSS],
436 [AT_CHECK_MACRO($@)
437 AT_CHECK_MACRO([$1 (cross compile)],
438   [AT_KEYWORDS([cross])
439   # Exercise the code used when cross-compiling.
440   cross_compiling=yes
441   ac_tool_warned=yes
442   m4_default([$2], [$1])],
443   [$3], [$4])
447 # AT_CHECK_AU_MACRO(MACRO)
448 # ------------------------
449 # Create a minimalist configure.ac running the macro named
450 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
451 # on that script, and that the shell runs correctly the configure.
453 # Updated configure.ac shall not depend upon obsolete macros, which votes
454 # in favor of `-W obsolete', but since many of these macros leave a message
455 # to be removed by the user once her code is adjusted, let's not check.
457 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
458 m4_define([AT_CHECK_AU_MACRO],
459 [AT_SETUP([$1])
460 AT_KEYWORDS([autoupdate])
462 AT_CONFIGURE_AC([$1])
464 AT_CHECK_AUTOCONF
465 AT_CHECK_AUTOHEADER
466 AT_CHECK_CONFIGURE
467 AT_CHECK_ENV
469 rm config.hin
470 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
471 AT_CHECK([grep '^$1$' configure.ac], 1)
473 AT_CHECK_AUTOCONF
474 AT_CHECK_AUTOHEADER
475 AT_CHECK_CONFIGURE
476 AT_CHECK_ENV
478 AT_CLEANUP()dnl
479 ])# AT_CHECK_AU_MACRO
483 ## ----------------------- ##
484 ## Launch the test suite.  ##
485 ## ----------------------- ##
487 AT_INIT
488 AT_COPYRIGHT(
489 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
490 Foundation, Inc.
491 This is free software; see the source for copying conditions.  There is NO
492 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.])