automake
[Top][All Lists]
Advanced

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

Re: preprocessor output target


From: Brian Dessent
Subject: Re: preprocessor output target
Date: Thu, 05 Jun 2008 09:19:31 -0700

Jason Roscoe wrote:

> I apologize if this is not the correct list but maybe someone here can
> answer ...  I have a project that uses autoconf/automake and libtool.  I
> was wondering if there is already a macro that will create Makefile
> targets for getting the preprocessor output.  For example, if I have a
> source file called init.c, I would like to be able to type something
> like 'make init.i' and get the output of the preprocessor only (e.g.,
> gcc -E).  The main reason is that I want to be able to see the headers
> that are being included and where they are getting pulled from.  Is this
> already built in to the tools I am using?  Thanks.

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
-fverbose-asm.)

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.

Brian




reply via email to

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