0
votes

I'm trying to add some shell commands to automatically search for Makefile.am in my project autoconf (so that I don't have to worry about forgetting to add an entry next time when there's a new Makefile.am). But it does not seem to work. I've tried to create a minimum project setup to illustrate the problem. The project directory contains:

├── AUTHORS
├── ChangeLog
├── common.mk.in
├── configure.ac
├── COPYING
├── INSTALL
├── install-sh
├── Makefile.am
├── missing
├── NEWS
├── proj1
│   ├── Makefile.am
│   ├── module1
│   │   └── Makfile.am
│   └── module2
│       └── Makfile.am
├── proj2
│   ├── Makefile.am
│   ├── module1
│   │   └── Makfile.am
│   └── module2
│       └── Makfile.am
└── README

Most files here are empty, except:

---------configure.ac---------

AC_INIT([TEST], [1.0])
found_makefile_am=`find . -name 'Makefile.am' | sed -e 's/\.am$//g' -e 's/^\.\///g' | sed ':a;N;$!ba;s/\n/ /g'`
found_mk=`find . -name '*.mk.in' | sed -e 's/\.am$//g' -e 's/^\.\///g' | sed ':a;N;$!ba;s/\n/ /g'`
AM_INIT_AUTOMAKE
#AC_CONFIG_FILES([proj2/Makefile proj1/Makefile Makefile])
AC_CONFIG_FILES([${found_makefile_am}])
AC_CONFIG_FILES([${found_mk}])
AC_OUTPUT

---------proj*/Makefile.am---------

SUBDIRS = module1 module2

Note that the line:

AC_CONFIG_FILES([${found_mk}])

works perfectly but this one:

AC_CONFIG_FILES([${found_makefile_am}])

Failed with:

$autoreconf -i
automake-1.12: error: no 'Makefile.am' found for any configure output
automake-1.12: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?
autoreconf-2.69: automake failed with exit status: 1

And I had to replace it with:

AC_CONFIG_FILES([proj2/Makefile proj1/Makefile Makefile])

It just seems to me that the shell variable is not properly expanded right before autoconfig invokes automake. So is there any solution to this problem?

2

2 Answers

2
votes

Populating configure.ac needs to happen before autoconf is run, so any shell commands should be invoked by m4_esyscmd. Note that I'm giving you advice about the best way to pound your thumb with a hammer, which is to say that you really ought not do this, but if you want to automatically populate the content of AC_CONFIG_FILES, you can do:

AC_CONFIG_FILES(m4_esyscmd([find ...]))

where ... is the remainder of your find command. This will invoke the find command when m4 is running during autoconf rather than waiting until the configure script is executed by the user. This is necessary because you need to find the Makefile.am files before automake is run, and automake is invoked long before the configure script.

1
votes

I guess this probably CANNOT be done as shown in automake manual:

http://www.gnu.org/software/automake/manual/automake.html#Requirements

Note that you should not use shell variables to declare Makefile files for which automake must create Makefile.in. Even AC_SUBST does not help here, because automake needs to know the file name when it runs in order to check whether Makefile.am exists.