C How to Compile without optimizations using bsd makefiles?

When debugging it is bad to optimize the compiled product.

The <programname>.full output file contains the symbols, but it seems optimized :(
This means not all variables are accessible to the debugger... "value optimized out" :(

What is the correct way to set cflag -O0 in the makefile for just that program?
(I do not want to modify make.conf if possible)
 
Typically, just set the make variable that contains the debug flags by hand from the command line as an environment variable: "CFLAGS=-O0 make foo.o". For simple make files, this might help.
Another option is to find the make rule that creates the desired target, and edit the makefile to explicitly add "-O0" right there. Although editing makefiles is less than fun (still better than make.conf).
Also turn on make debugging (with the various -d flags) to see what command lines are being executed.
As a last ditch option (works surprisingly well): Delete the program or object file you want, then just say "make". Most likely, make will display the commands used to create it, like "cc -O3 -I../myincludes/ foo.C -o foo.o" and then "cc -O3 -L../mylib/ foo.o -lmy -o foo". Take those command lines, and with a mouse cut and paste them, and edit any offending "-O..." out and add "-O0". This only works if you have make debug turned on enough to see the actual compile lines. And it gets to be insane if the command lines are too long and can't be cut and pasted without losing your mind.
 
Back
Top