Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:59:15+00:00 2026-06-08T08:59:15+00:00

I have an autotools-managed project ( sscce tar.gz package here ) with this structure:

  • 0

I have an autotools-managed project (sscce tar.gz package here) with this structure:

./main.c
./foo.c
./foo/foo.h

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 that foo/foo.h is a dependency to be analyzed during the make 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?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:59:16+00:00Added an answer on June 8, 2026 at 8:59 am

    Have a look at the automake manual. Dependency computation is done at build time, as a side-effect of compilation. The history of dependency tracking might also be interesting to you. Note that there’s an error in the manual here: it makes it sound like depcomp is unconditionally invoked, which is not the case (a test at configure time checks if your compiler can do without it: see the @am__fastdepCC_TRUE@ lines in Makefile.in.

    So what happens is that files listing the dependencies of each object are stored in a hidden subdirectory called .deps. These files are initally empty and get overwritten as their corresponding source file is compiled. (For gcc, this is done via -MD and related flags.)

    You should absolutely list your headers in the main_SOURCES variable, so that your Makefile will package them up when you run make dist (or better yet, make distcheck).

    make won’t fail if you list a non-existent header, because you’re not actually listing the dependencies in your main_SOURCES line. automake will process that assignment and then write out the rules for building main (which will depend on object files only) and the various object files (via a suffix rule). The headers aren’t the direct input file to anything in the build process, so you skate by. Running make dist on your sample project gives the error:

    make: *** No rule to make target `foo.h', needed by `distdir'.  Stop.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C project that has the following structure Main/ Makefile.am bin/ src/
I have a project that uses autotools. A nice feature of autotools is 'out-of-source'
Summary : I have a project using GNU Autotools. I have a pot file.
We have an autotools project that has a mixture of unit and integration tests,
In a project built with GNU Autotools, I have a script that needs to
I am new to autotools and have managed to create a, for the moment,
I have a project with autotools: automake, autoconf. I want to prohibit make from
Problem: I have a project which I'm porting from Solaris/Lex/Yacc to Linux/Flex/Bison + Autotools.
I have an autotools project. The same tarball on one machine compiles the files
I have a library managed by autotools. I have the following line in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.