[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: preprocessor output target

From: Jason Roscoe
Subject: Re: preprocessor output target
Date: Thu, 05 Jun 2008 15:00:16 -0400
User-agent: Thunderbird (X11/20080421)

Brian Dessent wrote:
If you are using gcc then you can add -save-temps to CFLAGS, e.g.

rm init.o && make CFLAGS="-save-temps -g -O2"

Assuming that everything else in the build dir was up-to-date at that
point, this will rebuild just init.o but it will leave init.i and init.s
as a side effect.  The .s assembler output is handy if you want to
inspect the code generated by the compiler -- however if that's your
intent it's usually easier to read if you omit -g (and add

I find that this method is also handy when debugging.  Say that there's
a static function in foo.c that the compiler has inlined (or some other
condition that generally makes life in the debugger more difficult.) You can simply rebuild foo.o without optimization, leaving everything
else the same from the previous build.

Note however that if you wish to override a variable on the make command
in order to add an option, you have to specify the full contents of the
current value (which for CFLAGS is typically -g -O2 if using gcc and you
didn't explicitly specify a CFLAGS when configuring.)  If you just do
"make CFLAGS=-save-temps" then you lose all the settings that the build
system might have added, which could be significant.  In those cases
where CFLAGS is nontrivial I first look at the generated Makefile to see
what the substituted value is, and then to that I add or remove whatever
flags I'm interested in.  I wish there was a way to invoke make with a
+= override instead of a = override but this does not exist AFAIK.


This is excellent. I was not aware of the '-save-temps' gcc option. And thanks for reminding me about overriding the configured CFLAGS. Normally, if I am interested in the preprocessor output it is only temporary while I am trying to debug the compile. Anyway, your suggestion about removing the .o brings me to another question which might be better suited for the libtool list but I'm sure someone on here can answer it. I am using libtool in my example and so I do not have an init.o object. What is the equivalent to:

rm init.o && make init.o

when using libtool?

Thanks for the help.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]