I am trying to convert a project to use non-recursive automake. Based on a search on SO I could see that the topic has been covered to some extend. But there are not really any questions on how to convert a recursive automake project to a non recursive one. I have already read Karel Zak's blog and of course the autotools-mythbuster. There is a question with experiences regarding non-recursive automake but it does not explain how to convert a project. The only question that explains a bit seems to be regarding the subdir-objects option. But I could not get my project converted with these resources. Hence this question.
Lets start with a simple project setup:
project/
\-- configure.ac
|-- Makefile.am
\-- src/
\-- Makefile.am
|-- foo.c
|-- foo.h
\-- main.c
In configure.ac I just add the subdir-objects option:
AM_INIT_AUTOMAKE([subdir-objects])
In Makefile.am I removed the src directory from the root Makefiles.am's SUBDIRS variable. Then I removed the src/Makefile entry from the AC_CONFIG_FILES macro in `configure.ac.
Karel Zak's blog suggests to name the included Makefiles of the subdirectories Makemodule.am but Makefile.am seem to work too, if the sub folder is removed for the SUBDIRS variable and if the Makefile entry is removed from the AC_CONFIG_FILES config files macro.
Next I defined a global variable for the programs in the root Makefile.am and included the src/Makefile.am
bin_PROGRAMS=
include src/Makefile.am
In src/Makefile.am I changed:
bin_PROGRAMS=foo
to:
bin_PROGRAMS+=src/foo
and I also changed all occurences of foo_XXX to src_foo_XXX. And I added the prefix src/ to all .c and .h file names in src_foo_SOURCES.
But the program was not building and gave errors about include files not being found, for example:
fatal error: debug.h: No such file or directory
#include <debug.h>
Originally my src directories Makefile.am only hat the content variables src_foo_SOURCES, src_foo_CFLAGS, src_foo_LDFLAGS and src_foo_LDADD. My solution to this problem was to add src_foo_CPPFLAGS like this:
src_foo_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_builddir)/src \
-DDATADIR='"$(datadir)"' \
-DMODULEDIR='"$(moduledir)"' \
-DLIBEXECDIR='"$(libexecdir)"'
But I dont' really understand why this was necessary and why it built fine when I was using recursive automake?
I have another question regarding the answer of Brett Hale in this question. He writes:
You could use "$(srcdir)/sourceA.cpp", but this directory is implicit anyway. All you need is:
libadapter_la_SOURCES = sourceA.cpp sourceB.cpp
But I could not get it to work without prefixing the path, so that seems wrong to me, can someone confirm my experience?
Update: I am also having problems with the po/ subdir, how can I make that non-recursive? There is no Makefile.am in po/ just a Makevars file. There is a post on autotools-mythbuster, that indicates non-recursive make with gettext is not supported, but that post is from 2011. I'm not sure if anything might have changed in the mean time.