[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Force -O0 flags, inhibit the default -O2 flags
From: |
Brian |
Subject: |
Force -O0 flags, inhibit the default -O2 flags |
Date: |
Sat, 24 Sep 2005 12:05:33 -0600 |
I have a need to force three files to not be optimized. I've followed the
instructions in the manual for setting them up in their own library, and
then using LIBADD to combine it with the original library.
If I use AM_CXXFLAGS, the -O0 is superceded by a -O2. The same occurs if I
use libx_la_CXXFLAGS. I am not allowed to override CXXFLAGS (and don't want
to).
Makefile.am <http://Makefile.am> sample (one or the other):
- libx_la_CXXFLAGS = -O0
- AM_CXXFLAGS = -O0
Resultant commands:
- g++ [...] -O0 -g -O2
- /bin/sh ../../libtool --tag=CXX --mode=link g++ -O0 -g -O2 -o [...]
Here's the relevant libtool rules in the generated makefile:
-
CXXFLAGS = -g -O2
- LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CXXFLAGS) $(CXXFLAGS)
- .cpp.lo:
if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<;
\
then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f
"$(DEPDIR)/$*.Tpo"; exit 1; fi
As you can see, CXXFLAGS comes dead last in line in the variables, and I am
never allowed to override that. I have copied the relevant section of the
manual below for reference. Thanks for your comments.
Brian Mingus
26.7 Per-Object Flags Emulation
One of my source files needs to be compiled with different flags. How
do I do?
Automake supports per-program and per-library compilation flags (see Program
and Library
Variables<http://sources.redhat.com/automake/automake.html#Program-and-Library-Variables>and
Flag
Variables
Ordering<http://sources.redhat.com/automake/automake.html#Flag-Variables-Ordering>).
With this you can define compilation flags that apply to all files compiled
for a target. For instance, in
bin_PROGRAMS = foo
foo_SOURCES = foo.c foo.h bar.c bar.h main.c
foo_CFLAGS = -some -flags
foo-foo.o, foo-bar.o, and foo-main.o will all be compiled with -some -flags.
(If you wonder about the names of these object files, see renamed
objects<http://sources.redhat.com/automake/automake.html#renamed-objects>.)
Note that foo_CFLAGS gives the flags to use when compiling all the C sources
of the *program* foo, it has nothing to do with foo.c or foo-foo.ospecifically.
What if foo.c needs to be compiled into foo.o using some specific flags,
that none of the other files require? Obviously per-program flags are not
directly applicable here. Something like per-object flags are expected, i.e.,
flags that would be used only when creating foo-foo.o. Automake does not
support that, however this is easy to simulate using a library that contains
only that object, and compiling this library with per-library flags.
bin_PROGRAMS = foo
foo_SOURCES = bar.c bar.h main.c
foo_CFLAGS = -some -flags
foo_LDADD = libfoo.a
noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = foo.c foo.h
libfoo_a_CFLAGS = -some -other -flags
Here foo-bar.o and foo-main.o will all be compiled with -some -flags, while
libfoo_a-foo.o will be compiled using -some -other -flags. Eventually, all
three objects will be linked to form foo.
This trick can also be achieved using Libtool convenience libraries, for
instance noinst_LTLIBRARIES = libfoo.la <http://libfoo.la> (see Libtool
Convenience
Libraries<http://sources.redhat.com/automake/automake.html#Libtool-Convenience-Libraries>).
Another tempting idea to implement per-object flags is to override the
compile rules automake would output for these files. Automake will not
define a rule for a target you have defined, so you could think about
defining the foo-foo.o: foo.c rule yourself. We recommend against this,
because this is error prone. For instance, if you add such a rule to the
first example, it will break the day you decide to remove foo_CFLAGS(because
foo.c will then be compiled as foo.o instead of foo-foo.o, see renamed
objects <http://sources.redhat.com/automake/automake.html#renamed-objects>).
Also in order to support dependency tracking, the two .o/.obj extensions,
and all the other flags variables involved in a compilation, you will end up
modifying a copy of the rule previously output by automake for this file. If
a new release of Automake generates a different rule, your copy will need to
be updated by hand.
- Force -O0 flags, inhibit the default -O2 flags,
Brian <=
- Re: Force -O0 flags, inhibit the default -O2 flags, Harald Dunkel, 2005/09/25
- Re: Force -O0 flags, inhibit the default -O2 flags, Ralf Corsepius, 2005/09/26
- Re: Force -O0 flags, inhibit the default -O2 flags, Harald Dunkel, 2005/09/27
- Re: Force -O0 flags, inhibit the default -O2 flags, Bob Friesenhahn, 2005/09/27
- Re: Force -O0 flags, inhibit the default -O2 flags, Brian, 2005/09/27
- Re: Force -O0 flags, inhibit the default -O2 flags, Bob Friesenhahn, 2005/09/27
- Re: Force -O0 flags, inhibit the default -O2 flags, Ralf Corsepius, 2005/09/28
- Re: Force -O0 flags, inhibit the default -O2 flags, Sander Niemeijer, 2005/09/28
- Re: Force -O0 flags, inhibit the default -O2 flags, Ralf Corsepius, 2005/09/28
- Re: Force -O0 flags, inhibit the default -O2 flags, Harald Dunkel, 2005/09/28