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_DIR with 18# aclocal. See also related test 'aclocal-macrodir.tap'. 19 20am_create_testdir=empty 21. test-init.sh 22 23plan_ 7 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_DIR is honored" 75 76cat > configure.ac <<'END' 77AC_INIT([md], [10.0]) 78AC_CONFIG_MACRO_DIR([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 96test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install" 97 98cat > configure.ac << 'END' 99AC_INIT([inst], [1.0]) 100AC_CONFIG_MACRO_DIR([the-dir]) 101THE_MACRO 102END 103 104mkdir sys-dir the-dir 105echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4 106 107test ! -r the-dir/my.m4 \ 108 && $ACLOCAL --install --system-acdir ./sys-dir \ 109 && diff sys-dir/my.m4 the-dir/my.m4 \ 110 || r='not ok' 111 112test_end 113 114#--------------------------------------------------------------------------- 115 116test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR" 117 118cat > configure.ac <<'END' 119AC_INIT([md], [4.6]) 120AC_CONFIG_MACRO_DIR([dir1]) 121MY_FOO 122END 123 124mkdir dir1 dir2 125echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4 126echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4 127 128$ACLOCAL -I dir2 \ 129 && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \ 130 && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \ 131 && $AUTOCONF \ 132 && not $FGREP '::ko::ko::' configure \ 133 && $FGREP '::ok::ok::' configure \ 134 || r='not ok' 135 136test_end 137 138#--------------------------------------------------------------------------- 139 140test_begin "AC_CONFIG_MACRO_DIR([foo]) can create directory 'foo'" 141 142cat > configure.ac << 'END' 143AC_INIT([x], [1.0]) 144AC_CONFIG_MACRO_DIR([foo]) 145MY_MACRO 146END 147 148mkdir acdir 149echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4 150 151test ! -d foo \ 152 && $ACLOCAL --install --system-acdir ./acdir \ 153 && diff acdir/bar.m4 foo/bar.m4 \ 154 || r='not ok' 155 156test_end 157 158#--------------------------------------------------------------------------- 159 160test_begin "AC_CONFIG_MACRO_DIR([non-existent]) warns with -Wunsupported" 161 162cat > configure.ac << 'END' 163AC_INIT([oops], [1.0]) 164AC_CONFIG_MACRO_DIR([non-existent]) 165AM_INIT_AUTOMAKE 166END 167 168$ACLOCAL -Wno-error 2>stderr \ 169 && cat stderr >&2 \ 170 && grep "couldn't open directory 'non-existent'" stderr \ 171 && test -f aclocal.m4 \ 172 || r='not ok' 173 174rm -rf aclocal.m4 autom4te*.cache 175 176$ACLOCAL -Werror -Wno-unsupported \ 177 && test -f aclocal.m4 \ 178 || r='not ok' 179 180test_end 181 182#--------------------------------------------------------------------------- 183 184test_begin "AC_CONFIG_MACRO_DIR([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist" 185 186cat > configure.ac << 'END' 187AC_INIT([oops], [1.0]) 188AC_CONFIG_MACRO_DIR([not-exist]) 189END 190 191cat > Makefile.am << 'END' 192ACLOCAL_AMFLAGS = -I not-exist 193END 194 195$ACLOCAL -Wno-error 2>stderr \ 196 && cat stderr >&2 \ 197 && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \ 198 || r='not ok' 199 200test_end 201 202#--------------------------------------------------------------------------- 203 204# Avoid spurious failures with pre-2.70 autoconf. 205# FIXME: remove this in automake 2.0, once we require Autoconf 2.70. 206if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then 207 208 test_begin "AC_CONFIG_MACRO_DIR interaction with AC_REQUIRE" 209 210 unindent > configure.ac <<'END' 211 AC_INIT([req], [1.0]) 212 AC_CONFIG_MACRO_DIR([macro-dir]) 213 AC_DEFUN([MY_FOO], [AC_REQUIRE([MY_BAR])]) 214 MY_FOO 215END 216 217 mkdir macro-dir 218 echo 'AC_DEFUN([MY_BAR], [//my//bar//])' > macro-dir/x.m4 219 220 st=0; $ACLOCAL 2>stderr || st=$? 221 cat stderr >&2 222 223 test $st -eq 0 \ 224 && test ! -s stderr \ 225 && $FGREP 'm4_include([macro-dir/x.m4])' aclocal.m4 \ 226 && $AUTOCONF \ 227 && not $EGREP 'MY_(FOO|BAR)' configure \ 228 && $FGREP '//my//bar//' configure \ 229 || r='not ok' 230 231 test_end 232 233else 234 235 skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)" 236 237fi 238 239: 240