Skip to content

Autotools: read configure.ac and Makefile.am for C and C++ flags and make check tests - #522

Merged
lefticus merged 9 commits into
cpp-best-practices:mainfrom
leftibot:autotools-make
Dec 2, 2026
Merged

lefticus merged 9 commits into
cpp-best-practices:mainfrom
leftibot:autotools-make

Conversation

@leftibot

@leftibot leftibot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #470

What

Autotools projects had no C build system. Every make command CI ran in them was unknown ("the makefile: none is found where make runs"), because configure writes the makefile and it is not in the checkout. So jq and tmux were ERROR on most checks, and their warning flags and make check tests were missed.

The core this PR covers:

  • configure.ac, evaluated without running m4 or the shell (build_systems/autotools/configure_syntax.py, configure.py):
    • It reads macro calls (one quote level stripped, arguments re-read as m4 rescans them) and the shell statements between them.
    • Shell: if/elif/else/fi, case patterns, test ... && X=.... Macros: AS_IF, AS_CASE, AC_ARG_ENABLE/AC_ARG_WITH (one action when the option is given, the other when not), and macros the file defines (AC_DEFUN).
    • Flag macros add their flag where the compiler accepts it: AX_CHECK_COMPILE_FLAG, AX_APPEND_COMPILE_FLAGS, AX_APPEND_FLAG, gl_WARN_ADD. The requirement is worded as CMake's flag checks are.
    • It also reads AC_SUBST and AM_CONDITIONAL. Other macros' arguments are read behind a requirement of their own.
    • test "x$GCC" = xyes (and GXX, ac_cv_c_compiler_gnu) is the GCC-like compilers; any other test is a requirement as written.
    • tmux's configure.ac:1207 -Werror, which the issue cites, is an LTO probe: it sets CFLAGS for one link check and restores it. It correctly leaves no -Werror.
  • Makefile.am, read with the configure.ac above it (automake.py): AM_CFLAGS, AM_CXXFLAGS, AM_CPPFLAGS and each built target's own <target>_CFLAGS. They are read through Automake's if/else/endif conditionals, which hold where AM_CONDITIONAL's test holds (tmux's IS_GCC is GCC-like compilers ∧ IS_GCC). Configure's substitutions ($(WARN_CFLAGS), @VAR@) are expanded from configure.ac.
  • Autotools is a C and C++ build system, recognised by Makefile.am. configure.ac alone does not count: opam's configure.ac configures an OCaml build.
  • make check runs the tests (MAKE_CHECK test runner): make check, distcheck or recheck where a Makefile.am is, or in a build tree outside the checkout (cd build && ../configure && make check), runs the tests TESTS and check_PROGRAMS name. tests-run is judged per unit, as for CTest.
  • make where only a Makefile.am is (make.py): the Makefile.am's rules are read, with its conditionals as tests of configure's @NAME_TRUE@ substitutions and its silent-rule prefixes ($(AM_V_GEN)) empty. Automake's own targets (all, check, install, distcheck, …, in policy/automake.toml) are the project's build and tests, not unknown. Any other target is unknown, as before.

What the readers cannot follow is noted, never dropped: a configure.ac or Makefile.am read only in part gets a PartlyRead note (a macro call or quote never closed, a conditional never closed, defined macros nested past limits.toml's most_defined_calls). The #469 condition bound applies here too.

Left of #470

  • Plain Make as a C/C++ build system. Stockfish's src/Makefile, antirez/kilo, libbpf, and redis's src/Makefile: their CFLAGS/CXXFLAGS and test/check goals.
  • Macros a project defines in m4/ (aclocal's directory) are not followed. curl's warnings come from CURL_CC_DEBUG_OPTS in m4/curl-compilers.m4, so curl's results don't change.
  • configure's command-line options (./configure --disable-debug) do not settle AC_ARG_ENABLE yet. tmux's -W... flags behind IS_DEBUG count as an option, though tmux CI passes --disable-debug.
  • case "$CC" per compiler, and AX_CFLAGS_WARN_ALL-style macros.
  • A target's own _CFLAGS replacing AM_CFLAGS for that target.
  • check-local hooks, and the commands of the TESTS scripts themselves.
  • -W, GCC's old spelling of -Wextra, is not recognised as -Wextra (tmux).

Tests

tests/test_autotools.py uses jq's configure.ac/Makefile.am (flags, if WIN32, if ENABLE_ASAN, TESTS, the jq.1.prebuilt rule) and tmux's LTO probe and IS_GCC/IS_DEBUG conditionals. It covers:

  • the syntax reader;
  • AS_IF/AS_CASE/case, AC_ARG_*, AC_LANG_PUSH, AC_DEFUN;
  • substitutions, nested Makefile.am files, and unclosed conditionals and calls;
  • compiler-warnings, warnings-as-errors and tests-run on jq;
  • make check in-tree, in a build tree, and elsewhere;
  • make in an Automake directory: the rules are read and only a target nothing defines is unknown.

tests/test_policy.py covers the new automake.toml and limits.toml entries. I wrote most of these tests after a first draft of the reader, not before it.

Corpus (before → after, score)

project score changes
jqlang/jq 40.0 → 52.2 16 ERRORs resolved (the make unknowns are gone); compiler-warnings WARN (found -Wall -Wextra); sanitizers PASS; tests-run FAIL → WARN (C passes: make check runs TESTS)
tmux/tmux 33.8 → 40.2 16 ERRORs resolved; compiler-warnings FAIL (found -Wall -Wshadow, behind IS_DEBUG); warnings-as-errors FAIL (the -Werror was a probe); tests-run FAIL (CI runs regress/, not make check)
zeromq/libzmq 53.5 → 55.4 sanitizers ERROR → PASS
curl, opam, stumpwm, datetime-fortran unchanged

Existing tests and snapshots that changed

  • tests/checks/test_tests_run.py: the expected messages now list Automake's tests and make check among the known runners ("no tests found (tests Automake's make check runs (...), tests defined by Bazel ...)", "no CI configuration runs make check, bazel test, ctest or meson test"). The issue asks for exactly this: the hint used to name only Bazel, CTest and Meson. The tests' intent is unchanged.
  • Snapshots regenerated: bare_c.json, bare_cpp.json, buildable.json, well_configured_c.json, well_configured_cpp.json (the same tests-run wording, and make check among the C/C++ test tools in the answers) and registry.json (the new make check tool). No result status changed.

For the maintainer

  • The warnings-as-errors wording still says "the build files (CMake files, presets, meson.build)". Adding configure.ac and Makefile.am to it would change every fixture snapshot that prints it, so I left it.
  • In jq the tests-run message says "run by make check and pg_regress": the PostgreSQL pg_regress runner (ecosystems/sql.py) claims any make check for C. This is older behaviour that only shows now; it is outside this stack.
  • configure.py and automake.py reuse CMake's Scope/Item (build_systems/cmake/evaluation.py, values.py), rather than copying them. Moving them to a shared module is a small refactor I left out to keep the diff away from other stacks.

Gates

gates2.sh all passed: ruff, ruff format, mypy, lizard, 3506 tests, coverage 99%, jscpd, markdownlint, strict self-check.

Coverage

codecov/patch was 98.76%. tests/test_autotools.py adds ConfigureFormsTests plus one Makefile.am test, each a configure.ac or Makefile.am form taken from real projects:

  • a shell test in brackets (an m4 quote, which m4 strips)
  • several assignments on one line, and a case pattern on a line of its own
  • AS_IF with no else, and AS_CASE with no default
  • AC_SUBST with a value
  • unquoted arguments that hold $(uname -s)
  • a body-less AC_DEFUN, and a stray else/fi
  • an assignment no build reaches (not-GCC inside GCC)
  • a configure.ac past the conditions bound (the bound is lowered for the test)
  • a Makefile.am variable set only if DEBUG and used only if !DEBUG

Patch coverage locally: 602/602 lines and branches for this PR's own diff, 740/740 for the stack against main.

Since review

  • Automake's reference depth is now policy/limits.toml's automake.most_references, following CMake: bound the growth of conditions in loops over conditional items #517's change.
  • As the maintainer asked, the C-family and Fortran warnings-as-errors messages no longer name build systems. They now read "warnings are not treated as errors in CI configuration or the build files". The hints, and CMake's own presets finding, are unchanged.
  • Existing test and snapshots changed: tests/checks/test_warnings_as_errors.py's SEARCHED constant, and one line each in the bare_c, bare_cpp, bare_fortran and buildable snapshots.

Test fix (later commit): test_a_configure_too_complex_to_follow_is_noted now gives each reading fresh variable names and reads twice. Conditions are kept for the whole process, so a second reading of the same text built nothing new and never reached the lowered bound. mutmut runs the suite more than once in a process, so the test failed in its clean run on #532 and #533.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.45%. Comparing base (e4b03c0) to head (ad0dabc).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #522      +/-   ##
==========================================
+ Coverage   99.44%   99.45%   +0.01%     
==========================================
  Files         374      378       +4     
  Lines       27250    27932     +682     
  Branches     3429     3550     +121     
==========================================
+ Hits        27099    27781     +682     
  Misses        151      151              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

leftibot and others added 8 commits December 1, 2026 14:39
… a line says so

data-wellformed failed files that are not data until they are rendered:
redis/docker-library-redis's Dockerfile.template (a jq template) and
trailofbits/algo's files/cloud-init/base.yml (a Jinja2 template Ansible's
lookup('template', ...) renders). A file that does not parse is now noted as
a template, not failed, when a word of its name after the first says so
(`Dockerfile.template`, `values.tpl.yaml`, `*.j2`) or when a template block
opens one of its lines (`{%` or `{{` after its indentation). A file that
parses is data whatever its name (CloudFormation's `*.template.json`). The
words and openers are a new policy table, `policy/templates.toml`.

Part of cpp-best-practices#473

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
On curl, evaluating CMakeLists.txt exhausted memory: the loop that writes
libcurl.pc sets `_explicit_libs` again for each of CURL_LIBS' conditional
items, so the variable gained an item per pass, each with a "last writer"
condition over every pass after it, and with the requirements named in a bad
order (each `TARGET CURL::x` after every option) the diagrams grew
exponentially.

- A variable set again to the same value where it was set before is one item,
  in the builds of both sides: each build holds one side's items alone, so
  merging changes nothing a build sees, and the condition no longer grows
  with every pass.
- A build file's evaluation is bounded: one command's operations on conditions
  add at most `policy/limits.toml`'s `most_nodes` (10000) nodes. Past it a
  condition is a requirement of its own, "the builds at CMakeLists.txt:2197
  (too complex to follow)", the value is kept, and the file is noted as read
  in part (a PartlyRead fact), never dropped.

curl's whole run now takes about two minutes and 600 MB under `ulimit -v 6000000`.

Fixes cpp-best-practices#469

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
The maintainer asked that no limit be hard-coded. Beside the CMake
conditions' most_nodes, limits.toml now holds, with unchanged values:
the conditions' most_disjuncts and most_choices; every nesting depth of
limits.py (CMake calls, GitLab includes/extends/references, .bazelrc
imports, Azure templates, make includes, reusable workflows, composite
actions, tsconfig extends, GitHub expressions, shell substitutions,
compounds and quoting, JSON); the CMake evaluation's most_iterations,
most_commands, most_calls and most_values; Meson's most_iterations and
most_statements; the file sizes read (--max-file-size's default, data
files parsed, archives decompressed, a license file's head); and the YAML
places recorded. test_policy checks the table against each reader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…make check tests

Autotools projects (jq, tmux, curl, libzmq) had no C build system, so their
warning flags and `make check` tests were missed, and every make command CI
ran was unknown ("the makefile: none is found where make runs"): configure
writes the makefile, so it is not in the checkout.

- configure.ac is evaluated without running m4 or the shell
  (build_systems/autotools/configure_syntax.py, configure.py): macro calls
  and shell statements, `if`/`case` branches, AS_IF, AS_CASE, AC_ARG_ENABLE,
  AC_ARG_WITH, the flag macros (AX_CHECK_COMPILE_FLAG, AX_APPEND_COMPILE_FLAGS,
  AX_APPEND_FLAG, gl_WARN_ADD) where the compiler accepts the flag, macros
  the file defines, AC_SUBST and AM_CONDITIONAL. `test "x$GCC" = xyes` is
  the GCC-like compilers; any other test is a requirement as written.
  tmux's LTO probe, which sets -Werror for one compile check and restores
  CFLAGS, leaves no -Werror.
- Each Makefile.am is read with the configure.ac above it (automake.py):
  AM_CFLAGS, AM_CXXFLAGS, AM_CPPFLAGS and each built target's own flags,
  through Automake conditionals, with configure's substitutions expanded.
- Autotools (Makefile.am) is a build system of C and C++; `make check`,
  `distcheck` or `recheck` where a Makefile.am is (or in a build tree
  outside the checkout) runs the tests TESTS and check_PROGRAMS name.
- Where no makefile is in the checkout but a Makefile.am is, make reads the
  Makefile.am's rules, and Automake's own targets (policy/automake.toml) are
  known, not unknown.

Part of cpp-best-practices#470

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…ctices#470)

Brackets around a shell test (an m4 quote, stripped), several assignments
on a line, a case pattern on a line of its own, AS_IF and AS_CASE without
their last branch, AC_SUBST with a value, unquoted arguments holding
parentheses, a body-less AC_DEFUN, a stray else or fi, an assignment no
build reaches, a configure.ac past the bound on conditions, and a
Makefile.am variable set only where it is not used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
)

Like configure.ac's most_defined_calls, how deep a Makefile.am reference
is followed is a limit, not a constant in the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…ystem (cpp-best-practices#470)

The maintainer asked that the message read the same for every build
system: "warnings are not treated as errors in CI configuration or the
build files", rather than listing CMake files, presets and meson.build
(leaving out configure.ac), or fpm's flags for Fortran. The hints, which
say how in each build system, are unchanged, as is CMake's own presets
finding. test_warnings_as_errors' SEARCHED and the bare_c, bare_cpp,
bare_fortran and buildable snapshots change to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…pp-best-practices#470)

Conditions are kept for the whole process, so a second reading of the
same configure.ac builds no new nodes and never reaches the lowered
bound. mutmut runs the suite more than once in one process, so the test
failed in its clean run on cpp-best-practices#532 and cpp-best-practices#533. Each reading now gets names of
its own, and the test reads twice to hold that in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@lefticus
lefticus merged commit 3ad6ffe into cpp-best-practices:main Dec 2, 2026
35 checks passed
@lefticus
lefticus deleted the autotools-make branch December 2, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants