TExcelTAD
Home › Meson, Autotools & xmake › make dist & make distcheck

make dist & make distcheck

For an Autotools project the release tarball is the product. It contains the generated configure, Makefile.in files and helper scripts, so users can build with nothing but a shell, make and a compiler. Automake generates two targets for making it:

Target Does
make dist packs every distributed file into NAME-VERSION.tar.gz (dist-xz, dist-zip… for other formats, or AM_INIT_AUTOMAKE([dist-xz no-dist-gzip]))
make distcheck make dist, then unpacks the tarball and, in a read-only source tree with an out-of-tree build directory, runs configure, make, make check, make install into a temporary prefix, make uninstall (checking nothing is left behind), make distclean (checking nothing is left behind), and make dist again from the unpacked copy

make distcheck is the strictest test any build system in this course has. Release managers run it before every release, and so should your CI.

What goes into the tarball

Automake distributes automatically: everything in _SOURCES (including headers listed there), configure.ac, Makefile.am, the generated configure and Makefile.ins, the helper scripts, TESTS scripts, dist_* data, and common files such as README and COPYING if present. Everything else must be listed in EXTRA_DIST. Forgetting a file is the most common release bug, and distcheck catches it because it builds from the tarball, not from your checkout.

bash · try it yourself
mkdir -p calc/src && cd calc
cat > configure.ac <<'AC'
AC_INIT([calc], [1.0.0])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects])
AM_SILENT_RULES([yes])
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
AC
cat > Makefile.am <<'AM'
bin_PROGRAMS = calc
calc_SOURCES = src/main.c        # oops: src/ops.h is not listed anywhere
AM
echo 'static inline int add(int a, int b) { return a + b; }' > src/ops.h
echo '#include <stdio.h>
#include "ops.h"
int main(void) { printf("%d\n", add(2, 2)); return 0; }' > src/main.c
autoreconf -i 2> /dev/null
./configure --quiet
make -j1 -s && ./calc
echo "--- distcheck"
make -j1 distcheck 2>&1 | grep -E 'error|Error' | head -3
echo "--- fixed: list the header"
sed -i 's|^calc_SOURCES = .*|calc_SOURCES = src/main.c src/ops.h|' Makefile.am
make -j1 distcheck 2>&1 | tail -4
tar -tzf calc-1.0.0.tar.gz | sort
  CC       src/main.o
  CCLD     calc
4
--- distcheck
../../src/main.c:2:10: fatal error: ops.h: No such file or directory
make[1]: *** [Makefile:383: src/main.o] Error 1
make: *** [Makefile:550: distcheck] Error 1
--- fixed: list the header
============================================
calc-1.0.0 archives ready for distribution:
calc-1.0.0.tar.gz
============================================
calc-1.0.0/
calc-1.0.0/Makefile.am
calc-1.0.0/Makefile.in
calc-1.0.0/aclocal.m4
calc-1.0.0/build-aux/
calc-1.0.0/build-aux/compile
calc-1.0.0/build-aux/depcomp
calc-1.0.0/build-aux/install-sh
calc-1.0.0/build-aux/missing
calc-1.0.0/configure
calc-1.0.0/configure.ac
calc-1.0.0/src/
calc-1.0.0/src/main.c
calc-1.0.0/src/ops.h

The build in the checkout worked, because src/ops.h was sitting right there. The tarball didn't contain it, so the distcheck build failed with ops.h: No such file or directory, which is exactly what a user would have seen. (Notice also that changing Makefile.am didn't need a manual autoreconf: the generated Makefile noticed and re-ran automake itself.)

Notice what the tarball contains: configure, Makefile.in, aclocal.m4 and build-aux/. Those generated files are what makes ./configure && make work for users, and why the Field Notes say to keep them out of git but in the tarball.

What distcheck also enforces

Because the unpacked source tree is made read-only and the build happens in a separate _build/sub directory, distcheck also catches:

  • rules that write into the source tree (generated files must go to the build directory, $(builddir), not $(srcdir));
  • VPATH bugs: rules using foo.txt where $(srcdir)/foo.txt is needed;
  • install/uninstall asymmetry: a custom install-data-local without a matching uninstall-local;
  • files left behind by make distclean (a generated file missing from DISTCLEANFILES);
  • tests that only pass in the developer's tree.

AM_DISTCHECK_CONFIGURE_FLAGS = --enable-foo in Makefile.am passes extra configure options to the distcheck build, for example to test the full feature set.

Reproducible tarballs

Two make dist runs normally produce different tarballs, because file times and owners go into the archive. If you publish checksums or want reproducible releases (see Reproducible Builds), set the tar options: AM_INIT_AUTOMAKE([tar-ustar]) plus TAR_OPTIONS="--mtime=@$SOURCE_DATE_EPOCH --sort=name --owner=0 --group=0 --numeric-owner" in the environment, and GZIP=-n so gzip doesn't store a time stamp.

Test yourself

A header used by your program is not listed in any Makefile.am. make works in your checkout. What does make distcheck do?

  1. Passes
  2. Fails: the header is not in the tarball, so building from the tarball breaks
  3. Adds the header automatically
  4. Warns but passes

Why does make distcheck make the unpacked source tree read-only?

  1. To save disk space
  2. To catch rules that write generated files into the source directory instead of the build directory
  3. Because tar requires it
  4. To speed up the build

Which of these files is in an Autotools release tarball but should not be committed to git?

  1. configure.ac
  2. Makefile.am
  3. configure
  4. src/main.c