Subject: bug#74387: Cannot nest Make conditionals inside Automake conditionals

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 17 Nov 2024 13:07:52 +0900

Hello,

Consider the following:

--8<---------------cut here---------------start------------->8---
$ guix shell --pure automake autoconf coreutils grep \
  --with-latest=automake --with-latest=autoconf --without-tests=automake

[...]

[env]$ autoconf --version
autoconf (GNU Autoconf) 2.72
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

[env]$ automake --version
automake (GNU automake) 1.17
Features: subsecond-mtime

Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later
  <https://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <[email-masked]>
       and Alexandre Duret-Lutz <[email-masked]>.

[env]$ cat configure.ac
AC_INIT([if-without-endif-bug], [0.0.0])

AM_INIT_AUTOMAKE([foreign])

AM_CONDITIONAL([CAN_RUN_TESTS], [true])

AC_CONFIG_FILES([Makefile])

AC_OUTPUT

[env]$ cat Makefile.am
if CAN_RUN_TESTS

SH_TESTS = dummy/test1.sh dummy/test2.sh
SH_TESTS_SLOW = dummy/slow-test.sh

TESTS = $(SH_TESTS)

# By default, filter out slow tests.  The slow tests can be requested
# by setting the WITH_SLOW_TESTS Make variable.
ifdef WITH_SLOW_TESTS
TESTS += $(SH_TESTS_SLOW)
else
$(info Skipping slow tests; set WITH_SLOW_TESTS=1 to run them)
endif

endif

$ autoreconf -vif
autoreconf: export WARNINGS=
autoreconf: Entering directory '.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: /gnu/store/6vdjwn5yjnwir2279h0mfc5ws9wnz8d7-autoconf-2.72/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
Makefile.am:16: error: endif without if
autoreconf: error: automake failed with exit status: 1
--8<---------------cut here---------------end--------------->8---

In other words, Automake doesn't handle nesting pure Make conditionals
(ifeq, ifneq, ifdef, offended) inside an Automake conditional block (if).

My attaching the configure.ac and Makefile.am files for convenience.

Thanks for maintaining Automake!

-- 
Maxim