views:

773

answers:

4

I have a very large C project with many separate C files and headers and many dozens of contributors. Many contributors do not have a strong knowledge of makefiles and dependencies, resulting in the not uncommon problem where you almost always have to "make clean" before you can trust "make" to have produced correct output.

If make took minutes, this wouldn't be an issue, but it's nearly 2 hours on a fast machine now, and people are starting to check in code that works when they make, but they don't clean first and their code ultimately breaks the build. Don't ask why these aren't caught by the build manager before a new baseline is cut...

Yes, we shouldn't have let it go this far.

Yes, we're educating our developers.

As usual, we don't have time to stop everything and fix it by hand.

I'm thinking there are tools along these lines:

  • Are there automated tools to help build correct dependency information for an existing project from the C and H files?
  • Are there automated tools to describe dependency information according to the makefiles?
  • Is there a holy grail of a tool to describe the differences between the above two dependency trees?

But what else can/should be done to resolve this issue?

Thanks in advance...

+4  A: 

It might be easiest to switch from Make to a tool which automatically detects dependencies. For example, SCons doesn't make you list dependencies but instead automatically parses the files being compiled and looks for includes. You simply specify which files should be compiled and which files go into which executables. Switching build systems will be easier for the fact that your developers aren't really Make experts.

Another alternative if you stick with Make is to use the gcc -M option to automatically detect dependencies. The answer to the Automatically discovering C dependencies question has an example of how to have your makefiles automatically discover dependencies so that you don't need to specify them by hand.

Eli Courtwright
Add a 'make depend' rule to the makefiles that rebuilds the dependencies, as in the cross-referenced SO question/answers.
Jonathan Leffler
+1  A: 

Hi Adam,

We have the same problem at my workplace. The Trunk was always broken after merges or check-ins.

We set up a continuous integation build machine that does a make clean in about 45 minutes compared to about 2 hours on a dev machine.The integration server polls the SVN repository every 2 hours for new check-ins and starts a make clean.

That way, we can monitor exactly when the build was broken and fix it right away. We use Hudson as our continuous integration server, its free and open source, its a work of art and very easy to set up. Plus the User Interface is very intuitive, all the other developers love it.

Cheers,

Julien Nephtali
your link to hudson is broken.
Ilya
Thx, I just corrected it
Julien Nephtali
+1  A: 

The canonical way of solving this is to let the compiler automatically generate dependency info for you. Something like this (assuming gcc, you'll want to check your compiler for similar options)

SOURCES=foo.c bar.c

%.d: %.c
    $(CC) $(CFLAGS) -MM $< >$@ 

include $(SOURCES:.c=.d)

The GNU Make manual has a chapter on automatically generating prerequisites.

EDIT: I usually recommend people to start using CMake when they have this kind of issue.

JesperE