views:

57

answers:

1

Greetings,

I need to disable optimization flag for a individual file using autotools. What is the best way to do it?

+5  A: 

Do you mean an individual source file or an individual executable?

To disable optimization for an executable is simple:

bin_PROGRAMS = myprog
myprog_SOURCES = foo.c bar.c
myprog_CFLAGS = -O0

If you mean that you want to disable the optimization for a single source file temporarily, say for debugging purposes, you can just remake that file at the prompt: (example from the automake manual)

rm bar.o
make CFLAGS=-O0 bar.o
make

To do it for an individual source file permanently is not so simple, and probably best done by creating a convenience library:

noinst_LIBRARIES = libnoopt.a
libnoopt_a_SOURCES = bar.c
libnoopt_a_CFLAGS = -O0

bin_PROGRAMS = myprog
myprog_SOURCES = foo.c
myprog_CFLAGS = -O2
myprog_LDADD = libnoopt.a
ptomato