M. Berk
M. Berk

Reputation: 199

Why aren't changes to header files accounted for in the Makefiles of mature C projects?

I have been reading up on make and looking at the Makefiles for popular C projects on GitHub to cement my understanding.

One thing I am struggling to understand is why none of the examples I've looked at (e.g. lz4, linux and FFmpeg) seem to account for header file dependencies.

For my own project, I have header files that contain:

  1. Numeric and string constants
  2. Macros
  3. Short, inline functions

It would seem essential, therefore, to take any changes to these into account when determining whether to recompile.

I have discovered that gcc can automatically generate Makefile fragments from dependencies as in this SO answer but I haven't seen this used in any of the projects I've looked at.

Can you help me understand why these projects apparently ignore header file dependencies?

Upvotes: 5

Views: 231

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140168

I'll attempt to answer.

The source distros of some projects include a configure script which creates a makefile from a template/whatever.

So the end user which needs to recompile the package for his/her target just has to do:

$ configure --try-options-until-it-works
$ make

Things can go wrong during the configure phase, but this has nothing to do with the makefile itself. User has to download stuff, adjust paths or configure switches and run again until makefile is successfully generated.

But once the makefile is generated, things should go pretty smooth from there for the user which only needs to build the product once to be able to use it.

A few portion of users will need to change some source code. In that case, they'll have to clean everything, because the makefile provided isn't the way the actual developpers manage their builds. They may use other systems (code::blocks, Ant, gprbuild...) , and just provide the makefile to automate production from scratch and avoid to depend on a complex production system. make is fairly standard even on Windows/MinGW.

Note that there are some filesystems which provide build audit (Clearcase) where the dependencies are automatically managed (clearmake).

If you see the makefile as a batch script to build all the sources, you don't need to bother adding a dependency system using

  • a template makefile
  • a gcc -MM command to append dependencies to it (which takes time)

Note that you can build it yourself with some extra work (adding a depend target to your makefile)

Upvotes: 3

Related Questions