zoli2k
zoli2k

Reputation: 3468

What is the best way to set compilation flags for individual source files using GCC and autotools?

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

Upvotes: 4

Views: 878

Answers (1)

ptomato
ptomato

Reputation: 57920

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

Upvotes: 7

Related Questions