2
votes

I'm trying to create a very simple build script using the autoconf/automake tool chain (mostly as a learning exercise.)

Most examples seem to indicate that you need a separate Makefile.am in every source directory, and that the Makefile.am file in the project root should include a SUBDIRS directive which tells autoconf where to look for additional Makefiles.

I thought it might be possible, for a very simple project, to have a single Makefile.am in the project root directory. However, when I try to do this, and run the generated configure script - it creates a single Makefile in the project root which is empty (0 bytes.)

I'm not really sure what I'm doing wrong here.

So, my directory structure is extremely simple:

MyProject
---src
------myproject.cpp
---Makefile.am
---configure.ac

The configure.ac file is minimal:

AC_INIT(myproject, 1.0)
AC_MSG_NOTICE([My Project])
AC_PROG_CXX
AC_LANG(C++)
AC_CHECK_HEADERS(iostream)
AC_CONFIG_SRCDIR(src/myproject.cpp)
AM_INIT_AUTOMAKE(MyProject, 1.0)
AC_OUTPUT(Makefile)

And the Makefile.am is also very simple:

bin_PROGRAMS = myproject
myproject_SOURCES = src/myproject.cpp
myproject_CPPFLAGS = --std=c++11

I run:

autoconf configure.ac > configure

When I run the configure script, there are no errors.

Then I see it generated a Makefile in the project root directory:

 # ls -lh | grep Make
-rw-r--r-- 1 root root    0 Nov  8 16:13 Makefile
-rw-r--r-- 1 root root   98 Nov  8 15:53 Makefile.am
-rw-r--r-- 1 root root    0 Nov  8 15:00 Makefile.in

And you can see, the Makefile it generated is completely empty.

So I'm obviously misunderstanding something fundamental about how autoconf/automake is supposed to work. What am I doing incorrectly here?

2
Did you run automake? - reinierpost

2 Answers

0
votes

I had the same problem - where automake would generate empty Makefiles. I don't know why it happened, but I fixed it by deleting all the files generated by autoconf, e.g. Makefile.in (the zero-byte Makefile.in is definitely bad).

You can also try autoreconf -if

0
votes

That's interesting, I have tried to reproduce your case and I got different, albeit expected results.

  • The AM_INIT_AUTOMAKE invocation is obsolete, you should write AM_INIT_AUTOMAKE([foreign]). The foreign tells automake not to complain about missing README, ChangeLog, etc.
  • You have your Makefile.am in a different folder than source files. Although it is OK, the new automake should complain that it is a forward-incompatibility, I got this on the output (automake 1.15):

    Makefile.am:2: warning: source file 'src/myproject.cpp' is in a subdirectory,
    Makefile.am:2: but option 'subdir-objects' is disabled
    automake: warning: possible forward-incompatibility.
    automake: At least a source file is in a subdirectory, but the 'subdir-objects'
    automake: automake option hasn't been enabled.  For now, the corresponding output
    ...
    

    Those are just warnings though.

  • Anyway, instead of running just autoconf, I have ran autoreconf -i (or -i -f to be sure --- the -f option overwrites all files those tool generate). Autoreconf runs autoconf, automake and other tools in the right order for you.

  • After autoreconf finished, I got a configure script that worked as expected and after running it, I got a correct Makefile, too.