Join me on Facebook!
— Written by Triangles on July 26, 2015 • updated on July 26, 2015 • ID 8 —
Automake can recurse into subdirectories and compile source files from there.
Lately I had the need to split the source code of a C++ project into smaller directories, in order to mantain a certain level of organization (and mental sanity as well). Automake supports the so-called make recursion: the ability to recursively parse a list of subdirectories and parse/execute other Makefiles from there. (Un)Fortunately that feature is highly discouraged:
Makefile.amfile per sub-directory (no thanks);
A great alternative is the so-called non-recursive make, simpler and easy to mantain. The game starts from the top-level directory, where lies the one and only
Makefile.am. This is the top-level file which contains the options for Automake. Here you have to put references to source files with a relative path, for example:
... myapp_SOURCES = \ src/folder/core.cpp \ src/folder/utils.cpp \ src/another-folder/core.cpp \ src/another-folder/something.cpp ...
This will compile all the source files in object files directly inside the top build directory. Is that what you want? Not in my case and in the example above, because both objects generated from
src/folder/core.cpp and from
src/another-folder/core.cpp would clash.
That's not a problem: you just have to tell Automake to leave objects in sub-directories, instead of putting them all in one place. To do so, change the
AM_INIT_AUTOMAKE call in
configure.ac and add the option
... AM_INIT_AUTOMAKE([subdir-objects]) ...
And you're done.