[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: adding specific C flags for a SINGLE source file
From: |
Sander Niemeijer |
Subject: |
Re: adding specific C flags for a SINGLE source file |
Date: |
Fri, 10 Dec 2004 11:12:50 +0100 |
this comes *really* close to working. Problem is that in the Makefile
one
ends up with:
$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
$(libboincbenchmark_a_CPPFLAGS) $(CPPFLAGS)
$(libboincbenchmark_a_CXXFLAGS) $(CXXFLAGS)
Notice (grrrr!!) that user's $(CXXFLAGS) is *last*. So I can't
over-ride
it with libboincbenchmark_a_CXXFLAGS.
In other words:
libboincbenchmark_a_CXXFLAGS=-O3
CXXFLAGS=-g -O2
and I end up with
-O3 -g -O2.
Any idea how to get around this?
I had exactly the same problem. We had a single (very large) source
file in a libtool library that we wanted to compile without compiler
optimization turned on (i.e. we wanted to use -O0) in order to bring
down the compilation time (from 20 minutes to within a minute for this
specific file).
This was the cleanest solution I could come up with:
---
FOO_O = foo.o
$(FOO_O): foo.c
$(MAKE) foo.o CFLAGS="$(CFLAGS) $(DISOPT_FLAG)" FOO_O=dummy-foo.o
FOO_LO = foo.lo
$(FOO_LO): foo.c
$(MAKE) foo.lo CFLAGS="$(CFLAGS) $(DISOPT_FLAG)" FOO_LO=dummy-foo.lo
---
What this does is create a special rule for foo.o and foo.lo (yes, even
though it goes against the advice that was given, unfortunately we
_need_ a special rule for "foo.o: foo.c" to get this to work).
Fortunately the rules that are executed are very clean. What happens is
that once the foo.o target gets build the rule disables itself again by
redefining FOO_O to something else and then it calls make again with a
modified CFLAGS setting. In this way you still use the default .c.o
build rules from automake (including all the nice dependency
information generation), but now with a modified CFLAGS setting.
There are some pitfalls however:
- we didn't use a libname_la_CFLAGS setting, but if you do you would
have to setup rules for libname-foo.o and libname-foo.lo
- If the source file foo.c is not in the same directory as your
Makefile(.in), make won't be able to find foo.c. To solve this problem
we added the following (ugly) 'copy' rule:
---
foo.c: $(foo_dir)/foo.c
cp `test -f '$(foo_dir)/foo.c' || echo '$(srcdir)/'`$(foo_dir)/foo.c
foo.c
---
I still don't like this approach very much, but it was the best
approach that I could come up with.
As a general remark, automake is not that clear in the precedence that
compiler flags take (will FOOFLAGS come before or after
AM_FOOFLAGS/target_FOOFLAGS) and if/how one would be able to overrule
these flags. Important is also to notice that CXXFLAGS/CFLAGS or
overruled by adding a new option at the end (e.g. '-O2 -O3' would end
up meaning '-O3'), but with include/library search paths in
CPPFLAGS/LDFLAGS it is exactly the other way around (e.g. '-Ifoo -Ibar'
ends up meaning '-Ifoo' when you have a foo/foo.h and bar/foo.h). I
think some notes about this in the documentation or FAQ would also be
very helpful.
Best regards,
Sander Niemeijer
- adding specific C flags for a SINGLE source file, Bruce Allen, 2004/12/08
- Re: adding specific C flags for a SINGLE source file, Stepan Kasal, 2004/12/09
- Re: adding specific C flags for a SINGLE source file, Alexandre Duret-Lutz, 2004/12/09
- Re: adding specific C flags for a SINGLE source file, Bruce Allen, 2004/12/09
- Re: adding specific C flags for a SINGLE source file, Bruce Allen, 2004/12/09
- Re: adding specific C flags for a SINGLE source file,
Sander Niemeijer <=
- Re: adding specific C flags for a SINGLE source file, Kevin P. Fleming, 2004/12/10
- Re: adding specific C flags for a SINGLE source file, Jacob Meuser, 2004/12/10
- Re: adding specific C flags for a SINGLE source file, Alexandre Duret-Lutz, 2004/12/10
- Re: adding specific C flags for a SINGLE source file, Sander Niemeijer, 2004/12/13
- Re: adding specific C flags for a SINGLE source file, Sander Niemeijer, 2004/12/10
- Re: adding specific C flags for a SINGLE source file, Alexandre Duret-Lutz, 2004/12/10
- Re: adding specific C flags for a SINGLE source file, Sander Niemeijer, 2004/12/13
- Re: adding specific C flags for a SINGLE source file, Stepan Kasal, 2004/12/13
- Re: adding specific C flags for a SINGLE source file, Sander Niemeijer, 2004/12/13