views:

65

answers:

4

I want to backtrace the makefile for firefox so that I can get the final gcc command that is used to compile the c++ files. How can I do that?

A: 

Can you redirect the output of make to a file, then use a text editor to search for the line of interest?

Greg Hewgill
+1  A: 

The usual stunt for this is to replace gcc with a program that reads the gcc command line, store it in some log file so it can be inspected, and then launches gcc with the command line. You can do this by replacing "gcc.exe" in your development directories by this stepping stone program.

Ira Baxter
How exactly would I do that?
Jaelebi
You need to write a custom program named "gcc.exe" (using the C compiler, say) that reads the command line, etc.This isn't a tiny program, but it isn't huge either. Replacing the original gcc.exe is a matter of moving the original to, say, "gcc_original.exe" and parking your version where gcc used to be; obviously, yours has to pass control to gcc_original.exe along with the original command line. See the various process forking commands to find the right one to do this (I did this some 10 years ago and forget the precise calls you need). Don't expect this to be a 20 minute job.
Ira Baxter
While this is a useful technique, it seems like overkill for this situation because `make` prints to the console each command line that it runs.
Greg Hewgill
Can I just create a bash script to analyze the arguments and pass them onto gcc?
Jaelebi
Depends on what he wants to do. If he only wants to look at the line, piping make may work. If he wants to reuse that line to drive a static analysis tool (that simulates what gcc does), then he probably wants to automate it the way I described.
Ira Baxter
Don't know if you can do this with bash. You might try it.
Ira Baxter
Yes, you can do it with bash.
Michael Aaron Safyan
+2  A: 

If you find a line in there that begins with "@ $(CXX)" or "@ g++", then change the line to "$(CXX)" or "g++" -- in other words, delete the "@" symbol from the line. When an "@" symbol appears at the beginning of a command in a Makefile, it causes Make to not echo the command before executing it. Deleting the "@" symbol will cause the expanded form of the line to be echoed before the command is invoked.

I haven't looked at Firefox's makefile, so it is more than possible that they are using predefined pattern rules for building the code, in which case you won't see any lines beginning with "$(CXX)" . If that is the case, you will need to override the rules, so that the default build rules echo the commands before executing them.

For more information on overriding Makefile pattern build rules, see this link:

http://www.gnu.org/software/make/manual/make.html#Pattern-Rules

Michael Aaron Safyan
+1, good point about the use of @.
Greg Hewgill
There are no "$(cxx)" kind of tags or lines in the makefile.
Jaelebi
In that case, you will have to override the pattern rules, as in (just a word of caution, the following isn't going to space properly, due to the limitations of Stack Overflow comments):%.o : %.cpp $(CXX) $< -o $@
Michael Aaron Safyan
+1  A: 

Here's the make rule that compiles C++ files: http://hg.mozilla.org/mozilla-central/annotate/c1ab8650e0ce/config/rules.mk#l1391

If all you want to do is replace the compiler, you can (in your mozconfig, or on the configure commandline) set CXX="whatever".

Ted Mielczarek
I dont want to replace the compiler, just want to see what gcc... commands the makefiles execute. Since firefox makefiles call other makefiles and are quite complex.
Jaelebi
Then you want to look at rules.mk, that's where all the actual make rules live.
Ted Mielczarek