I have an autotools-managed project (sscce tar.gz package here) with this structure:
My configure.ac
is:
AC_INIT([foo], [1.0], [foo@bar.ba])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
My Makefile.am
were:
bin_PROGRAMS = main
main_SOURCES = main.c foo.c foo.h
It compiled and ran perfectly... but then I note my Makefile.am
was not correct. It stated that my main code depended upon foo.h
, but the real file was foo/foo.h
. I changed it, and the compilation was working as expected, as it was before:
bin_PROGRAMS = main
main_SOURCES = main.c foo.c foo/foo.h
However, it made me wonder: how did it work when the dependencies were wrong? It worked so well that I could even edit foo/foo.h
and make
would recompile the dependent files. Actually, I could even remove the header file from the dependencies...
bin_PROGRAMS = main
main_SOURCES = main.c foo.c
...and it would be still scanned an would trigger the recompilation of dependent files.
So, my questions are:
- How does the autotools-generated
Makefile
know thatfoo/foo.h
is a dependency to be analyzed during themake
invocation? - Should I add the header files to the
main_SOURCES
variable? - Shouldn't
make
fail in the first case, since I am declaring that a non-existent file is a dependency?