On Thu, Jun 05, 2008 at 09:19:31AM -0700, 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 > -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.
I use this technique as well, for a C++ app I'm working on. The way I get around this limitation is this: Our makefiles set up CXXFLAGS with some extensive modifications, but they don't touch CPPFLAGS. It seems as if the Makefiles are passing both CXXFLAGS and CPPFLAGS to g++, so I'm able to do: make CPPFLAGS=-save-temps ...and get exactly what I want. I don't think there's an analogue for CFLAGS, but this might help C++ guys. As an aside, the += capability would still be very nice to see. Mike