Stephen H. Gerstacker
Stephen H. Gerstacker

Reputation: 763

Disable optimizations for a specific file with autotools

I'm working on setting up autotools for a large code base that was once just a bash script compile and later just hand written Makefiles.

We have a set of files that require that compiler optimizations be turned off. These files are already in their own subdirectory, so they will have their own Makefile.am.

What's the proper way to drop any existing compiler optimizations and force a -O0 flag on the compiler for these specific files?

Upvotes: 1

Views: 972

Answers (2)

Stephen H. Gerstacker
Stephen H. Gerstacker

Reputation: 763

I went with Brett Hale's comment to use subpackages. I was able to insert

: ${CFLAGS="-O0"}

before AC_PROG_CC, which sets the appropriate optimization. The other solutions do not work, since the -g -O2 was getting added very last. You can never get another -O variable after it.

Upvotes: 3

MadScientist
MadScientist

Reputation: 100956

You don't have to remove existing optimizations: the last value of -O on the compiler invocation will be used, so it's good enough to just add -O0 at the end.

This is not directly supported by automake, but there's a trick you can use defined in the documentation.

Otherwise if you know you'll only ever invoke your makefile with GNU make you can play other tricks that are GNU make specific; you may have to disable automake warnings about non-portable content.

Upvotes: -1

Related Questions