Working around Autotools missing dependencies errors

Executive Summary

Resolving machine-specific dependencies for a minimal Autotools project created from scratch is typically a trivial task. But trying to do the same for a code base ported from another machine or repository can result in an unwelcome challenge. We present a work-around for cases where Autotools fails to resolve machine-specific dependencies for ported projects.

IMPORTANT! A "work-around" is simply that. It is not a long-term solution. If the need is to bypass a bug in configuration management so one can quickly move on to working in the code base, this work-around may be for you. But the long-term solution is to resolve the problem with the configuration. One might start by looking for the problem in configure.ac or Makefile.am.

Basic

The minimal GNU Autotools project should require only three files:

  • configure.in - input to autoconf
  • Makefile.am - input to automake
  • mysource.c - source code (of course, you can name this file whatever you wish)

configure.ac may also be used to generate configure.in.

The Autotools documentation has an example of such a minimal project. Unfortunately, the Autotools documentation is not always clear or consistent on how to resolve machine-specific dependencies. The linked example above provides a pretty simple fix for resolving missing dependencies prior to building:

[user@server ~]$ autoreconf --install

Were it only so simple! On the machine I'm writing this post from, the command above will write some macros in a subdirectory named autom4te.cache and generate the files configure and config.h.in in the local directory.

But the first step of the build process (./configure) stops on an error:

config.status: error: cannot find input file: `Makefile.in'

The Autotools documentation will tell you to issue the following to resolve missing dependencies:

[user@server ~]$ automake --add-missing

But you may see a bunch of unresolved errors such as:

Makefile.am: error: required file './NEWS' not found
Makefile.am: error: required file './README' not found
Makefile.am: error: required file './AUTHORS' not found
Makefile.am: error: required file './ChangeLog' not found

Many of these can be eliminated simply by having your Makefile ignore strict GNU requirements such as including an AUTHORS file and so on. Automake can be initialized to ignore GNU standards with the foreign option. It is also a good idea during the early developmental stages of a package to turn on all Automake warnings and have them reported as errors. The -Wall -Werror options will accomplish this.

AM_INIT_AUTOMAKE([-Wall -Werror foreign])

This is about the point in setting up an Autotools project from scratch where following the documentation can send things off the rails if your machine does not cooperate (more soecifically, if your machine does not respond to the commands in the documentation in much the same way the machine(s) in the documentation does.

Although it's impossible to anticipate every scenario, there are a few which appear to be more common than others. Among these is the problem of the missing install-sh script. The requirement for a suitable install program is written up in the Autoconf manual in the section on Particular Program Checks. Put simply, if Autoconf cannot find a suitable install program, the maintainer is instructed to distribute the script install-sh which comes with Autoconf. But for reasons no one seems able to explain, this is a dependency which is not resolved by any of the commands above.

The work-around is copy these files from your Automake installation into a build-aux directory off your project root. I prefer use symbolic links for this but the effect is the same. Every installation may have slight differences but the following should help the user find their Automake files on their own specific X-ish machine (and also create a symbolic link to the offending missing file install-sh:

[user@server ~]$ which automake
/usr/bin/automake
[user@server ~]$ automake --version
automake (GNU automake) 1.16.1
...
[user@server ~]$ ls -al /usr/share/automake-1.16 ...
-rwxr-xr-x. 1 root root 15368 Mar 11 2018 install-sh ...
[user@server ~]$ ln -s /usr/share/automake-1.16/install-sh build-aux/install-sh