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