user108088
user108088

Reputation: 1168

Debugging a Makefile

Let me prefice this question with the comment that I know very little about Makefiles or make.

There is a very large project that is automatically built nightly. It is built in both Debug and Release mode, Debug being used for utilities like Valgrind to provide code analysis. Somehow, some of the built libraries are losing the debug flag during the make process, which makes some analysis output unhelpful. I was tasked with finding the bug and I need some suggestions on how to go about locating/repairing the issue.

Thanks in advance

Upvotes: 3

Views: 1663

Answers (3)

user262802
user262802

Reputation: 61

use remake, its really good

Upvotes: 0

reinierpost
reinierpost

Reputation: 8611

make itself also supports a debug flag, -d; depending on how your Makefiles call each other, it may be possible to pass it through (and if not, you can rewrite them to do so with a script); then if you feed the resulting output to a file you can start looking for clues.

Upvotes: 5

bstpierre
bstpierre

Reputation: 31226

Given the sparse information, I can only sketch a very general strategy based on what I've seen in terms of Makefile usage for a handful of large projects.

If you don't already know where the flags originate, search through the Makefiles to find out.

Something like:

find . -name Makefile -exec grep -nH -- -g {} \;

(Adjusting the -name pattern if your project uses included Makefiles like foo.mk or bar.mak or something. And adjusting the "-g" if your debug flag is something else.)

You'll probably find it assigned to a variable like CFLAGS. Look around the spot where this variable is assigned, it is probably set conditionally (e.g. ifeq($(RELEASE),1)).

Now look at the Makefile(s) in the library that isn't getting those flags. Find the spot where the compile command lives. Is it using the right variable? Are these Makefiles overriding the variable?

It may also be helpful to capture the output of a build to a file and search around for any other places that might not have the debug flags set.

Upvotes: 4

Related Questions