1#! /bin/sh 2# Copyright (C) 2012-2021 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 <https://www.gnu.org/licenses/>. 16 17# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with 18# aclocal. See also related test 'aclocal-macrodir.tap'. 19 20am_create_testdir=empty 21. test-init.sh 22 23plan_ 15 24 25ocwd=$(pwd) || fatal_ "getting current working directory" 26unset ACLOCAL_PATH 27 28# 29# General utility functions and variables. 30# 31# TODO: These should maybe be refactored, generalized and 32# moved into 't/ax/tap-functions.sh' ... 33# 34 35tcount=0 36r=invalid 37description='' 38directive='' 39 40test_begin () 41{ 42 if test -n "$description"; then 43 fatal_ "'test_begin' called, but another test seems active already" 44 else 45 r=ok 46 description=$1 47 directive=${2-} 48 echo "$description" > README.txt 49 shift 50 fi 51 tcount=$(($tcount + 1)) && test $tcount -gt 0 \ 52 || fatal_ "failed to bump the test count" 53 mkdir $tcount.d 54 cd $tcount.d 55} 56 57test_end () 58{ 59 if test -z "$description"; then 60 fatal_ "'test_end' called, but no test seems active" 61 else 62 cd "$ocwd" || fatal_ "cannot chdir back to top-level directory" 63 result_ "$r" -D "$directive" -- "$description" 64 # Don't leave directories for successful subtests hanging around. 65 if test -z "$directive" && test "$r" = ok; then 66 rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d" 67 fi 68 r=invalid directive= description= 69 fi 70} 71 72#--------------------------------------------------------------------------- 73 74test_begin "AC_CONFIG_MACRO_DIRS is honored" 75 76cat > configure.ac <<'END' 77AC_INIT([md], [10.0]) 78AC_CONFIG_MACRO_DIRS([macro-dir]) 79MY_FOO 80END 81 82mkdir macro-dir 83echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4 84 85$ACLOCAL \ 86 && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \ 87 && $AUTOCONF \ 88 && not $FGREP 'MY_FOO' configure \ 89 && $FGREP '::my::foo::' configure \ 90 || r='not ok' 91 92test_end 93 94#--------------------------------------------------------------------------- 95 96three_dirs_check () 97{ 98 mkdir dir1 dir2 dir3 99 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4 100 echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4 101 echo 'AC_DEFUN([MY_BAZ], [==my==baz==])' > dir3/0.m4 102 $ACLOCAL \ 103 && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \ 104 && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \ 105 && $FGREP 'm4_include([dir3/0.m4])' aclocal.m4 \ 106 && $AUTOCONF \ 107 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \ 108 && $FGREP '::my::foo::' configure \ 109 && $FGREP '!!my!!bar!!' configure \ 110 && $FGREP '==my==baz==' configure \ 111 || r='not ok' 112} 113 114#--------------------------------------------------------------------------- 115 116test_begin "AC_CONFIG_MACRO_DIRS several arguments" 117 118cat > configure.ac <<'END' 119AC_INIT([more-args], [0.2]) 120AC_CONFIG_MACRO_DIRS([dir1 dir2 dir3]) 121MY_FOO 122MY_BAR 123MY_BAZ 124END 125 126three_dirs_check 127 128test_end 129 130#--------------------------------------------------------------------------- 131 132test_begin "AC_CONFIG_MACRO_DIRS several calls" 133 134cat > configure.ac <<'END' 135AC_INIT([more-calls], [2.0]) 136AC_CONFIG_MACRO_DIRS([dir1]) 137AC_CONFIG_MACRO_DIRS([dir2 dir3]) 138MY_FOO 139MY_BAR 140MY_BAZ 141END 142 143three_dirs_check 144 145test_end 146 147#--------------------------------------------------------------------------- 148 149test_begin "AC_CONFIG_MACRO_DIRS extra whitespace" 150 151bslash=\\ 152 153cat > configure.ac <<END 154AC_INIT([more-args], [0.2]) 155AC_CONFIG_MACRO_DIRS([ dir1${bslash} 156${tab} dir2 ${tab}${tab}dir3 157${bslash} 158 159]) 160MY_FOO 161MY_BAR 162MY_BAZ 163END 164 165three_dirs_check 166 167test_end 168 169#--------------------------------------------------------------------------- 170 171test_begin "AC_CONFIG_MACRO_DIRS precedence" 172 173cat > configure.ac <<'END' 174AC_INIT([more-calls], [2.0]) 175AC_CONFIG_MACRO_DIRS([dir1]) 176AC_CONFIG_MACRO_DIRS([dir2 dir3]) 177MY_FOO 178MY_BAR 179MY_BAZ 180END 181 182mkdir dir1 dir2 dir3 183echo 'AC_DEFUN([MY_FOO], [OK-Foo])' > dir1/b.m4 184echo 'AC_DEFUN([MY_FOO], [KO-Foo])' > dir2/a.m4 185echo 'AC_DEFUN([MY_BAR], [OK-Bar])' > dir2/1.m4 186echo 'AC_DEFUN([MY_BAR], [KO-Bar])' > dir3/0.m4 187echo 'AC_DEFUN([MY_BAZ], [OK-Baz])' > dir3/x.m4 188 189$ACLOCAL \ 190 && $FGREP 'm4_include([dir1/b.m4])' aclocal.m4 \ 191 && $FGREP 'm4_include([dir2/1.m4])' aclocal.m4 \ 192 && $FGREP 'm4_include([dir3/x.m4])' aclocal.m4 \ 193 && test $($FGREP -c 'm4_include([dir1' aclocal.m4) -eq 1 \ 194 && test $($FGREP -c 'm4_include([dir2' aclocal.m4) -eq 1 \ 195 && test $($FGREP -c 'm4_include([dir3' aclocal.m4) -eq 1 \ 196 && $AUTOCONF \ 197 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \ 198 && $FGREP 'OK-Foo' configure \ 199 && $FGREP 'OK-Bar' configure \ 200 && $FGREP 'OK-Baz' configure \ 201 && not $FGREP 'KO-' configure \ 202 || r='not ok' 203 204test_end 205 206#--------------------------------------------------------------------------- 207 208test_begin "AC_CONFIG_MACRO_DIRS interaction with --install" 209 210cat > configure.ac << 'END' 211AC_INIT([inst], [1.0]) 212AC_CONFIG_MACRO_DIRS([the-dir]) 213THE_MACRO 214END 215 216mkdir sys-dir the-dir 217echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4 218 219test ! -r the-dir/my.m4 \ 220 && $ACLOCAL --install --system-acdir ./sys-dir \ 221 && diff sys-dir/my.m4 the-dir/my.m4 \ 222 || r='not ok' 223 224test_end 225 226#--------------------------------------------------------------------------- 227 228two_dirs_install_check () 229{ 230 mkdir sys-dir dir1 dir2 231 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4 232 echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4 233 test ! -r dir1/my.m4 \ 234 && $ACLOCAL --install --system-acdir ./sys-dir \ 235 && diff sys-dir/my.m4 dir1/my.m4 \ 236 && test ! -e dir2/my.m4 \ 237 && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \ 238 && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \ 239 || r='not ok' 240} 241 242#--------------------------------------------------------------------------- 243 244test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install" 245 246cat > configure.ac << 'END' 247AC_INIT([inst2a], [1.0]) 248AC_CONFIG_MACRO_DIRS([dir1 dir2]) 249THE_MACRO 250AX_FOO 251END 252 253two_dirs_install_check 254 255test_end 256 257#--------------------------------------------------------------------------- 258 259 260test_begin "several AC_CONFIG_MACRO_DIRS calls and --install" 261 262cat > configure.ac << 'END' 263AC_INIT([inst2b], [1.0]) 264AC_CONFIG_MACRO_DIRS([dir1]) 265AC_CONFIG_MACRO_DIRS([dir2]) 266THE_MACRO 267AX_FOO 268END 269 270two_dirs_install_check 271 272test_end 273 274#--------------------------------------------------------------------------- 275 276test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS" 277 278cat > configure.ac <<'END' 279AC_INIT([md], [4.6]) 280AC_CONFIG_MACRO_DIRS([dir1]) 281MY_FOO 282END 283 284mkdir dir1 dir2 285echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4 286echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4 287 288$ACLOCAL -I dir2 \ 289 && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \ 290 && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \ 291 && $AUTOCONF \ 292 && not $FGREP '::ko::ko::' configure \ 293 && $FGREP '::ok::ok::' configure \ 294 || r='not ok' 295 296test_end 297 298#--------------------------------------------------------------------------- 299 300test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'" 301 302cat > configure.ac << 'END' 303AC_INIT([x], [1.0]) 304AC_CONFIG_MACRO_DIRS([foo]) 305MY_MACRO 306END 307 308mkdir acdir 309echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4 310 311test ! -d foo \ 312 && $ACLOCAL --install --system-acdir ./acdir \ 313 && diff acdir/bar.m4 foo/bar.m4 \ 314 || r='not ok' 315 316test_end 317 318#--------------------------------------------------------------------------- 319 320test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (1)" 321 322cat > configure.ac << 'END' 323AC_INIT([oops], [1.0]) 324AC_CONFIG_MACRO_DIRS([non-existent]) 325AM_INIT_AUTOMAKE 326END 327 328$ACLOCAL -Wno-error 2>stderr \ 329 && cat stderr >&2 \ 330 && grep "couldn't open directory 'non-existent'" stderr \ 331 && test -f aclocal.m4 \ 332 || r='not ok' 333 334rm -rf aclocal.m4 autom4te*.cache 335 336$ACLOCAL -Werror -Wno-unsupported \ 337 && test -f aclocal.m4 \ 338 || r='not ok' 339 340test_end 341 342#--------------------------------------------------------------------------- 343 344test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (2)" 345 346cat > configure.ac << 'END' 347AC_INIT([oops], [1.0]) 348AC_CONFIG_MACRO_DIRS([dir-ok]) 349AC_CONFIG_MACRO_DIRS([dir-ko]) 350END 351 352mkdir dir-ok 353not $ACLOCAL 2>stderr \ 354 && cat stderr >&2 \ 355 && grep "couldn't open directory 'dir-ko'" stderr \ 356 && not grep "dir-ok" stderr \ 357 && test ! -e aclocal.m4 \ 358 || r='not ok' 359 360test_end 361 362#--------------------------------------------------------------------------- 363 364test_begin "AC_CONFIG_MACRO_DIRS([existent non-existent]) errors out" 365 366cat > configure.ac << 'END' 367AC_INIT([oops], [1.0]) 368AC_CONFIG_MACRO_DIRS([dir-ok]) 369AC_CONFIG_MACRO_DIRS([dir-ko]) 370END 371 372mkdir dir-ok 373 374not $ACLOCAL -Wnone --install 2>stderr \ 375 && cat stderr >&2 \ 376 && grep "couldn't open directory 'dir-ko'" stderr \ 377 && test ! -e dir-ko \ 378 || r='not ok' 379 380test_end 381 382#--------------------------------------------------------------------------- 383 384test_begin "AC_CONFIG_MACRO_DIRS([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist" 385 386cat > configure.ac << 'END' 387AC_INIT([oops], [1.0]) 388AC_CONFIG_MACRO_DIRS([not-exist]) 389END 390 391cat > Makefile.am << 'END' 392ACLOCAL_AMFLAGS = -I not-exist 393END 394 395$ACLOCAL -Wno-error 2>stderr \ 396 && cat stderr >&2 \ 397 && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \ 398 || r='not ok' 399 400test_end 401 402#--------------------------------------------------------------------------- 403 404# Avoid spurious failures with pre-2.70 autoconf. 405# FIXME: remove this in automake 2.0, once we require Autoconf 2.70. 406if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then 407 408 test_begin "AC_CONFIG_MACRO_DIRS interaction with AC_REQUIRE" 409 410 unindent > configure.ac <<'END' 411 AC_INIT([req], [1.0]) 412 AC_CONFIG_MACRO_DIRS([m1 m2]) 413 AC_DEFUN([MY_FOO], [ 414 AC_REQUIRE([MY_BAR]) 415 AC_REQUIRE([MY_BAZ]) 416 ]) 417 MY_FOO 418END 419 420 mkdir m1 m2 421 echo 'AC_DEFUN([MY_BAR], [^^my^^bar^^])' > m1/x.m4 422 echo 'AC_DEFUN([MY_BAZ], [~~my~~baz~~])' > m2/x.m4 423 424 st=0; $ACLOCAL 2>stderr || st=$? 425 cat stderr >&2 426 427 test $st -eq 0 \ 428 && test ! -s stderr \ 429 && $FGREP 'm4_include([m1/x.m4])' aclocal.m4 \ 430 && $FGREP 'm4_include([m2/x.m4])' aclocal.m4 \ 431 && $AUTOCONF \ 432 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \ 433 && $FGREP '^^my^^bar^^' configure \ 434 && $FGREP '~~my~~baz~~' configure \ 435 || r='not ok' 436 437 test_end 438 439else 440 441 skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)" 442 443fi 444 445: 446