[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problem with implicit rule for .o files and overriding of CXXFLAGS.



В Wed, 25 Jun 2008 23:14:44 +0900, Charles Plessy написа:

>   When a Debian binary package is
>   built, variables such as {{{CFLAGS}}}, {{{CXXFLAGS}}},
>   {{{CPPFLAGS}}},... are set in the environnement and override the ones
>   in the {{{Makefile}}}.

That's not entirely true and not entirely false.  It's closer to being
false, though.  Environment variables do not override the ones explicitly 
set in the makefile (or on the command line), unless you do `make -e'.

If CFLAGS is set in the environment (f.i. by dpkg-buildpackage), and
you don't do any special handling in debian/rules, and it is defined
explicitly in upstream's makefile, the latter will be in effect.

If upstream's makefile does not define the variable, but instead has
rules with commands including $(CFLAGS), the value set by
dpkg-buildpackage will be used.

If you define 

CFLAGS = ...

in debian/rules, this is a make variable, not an environment variable, 
and it won't propagate to sub-make.

However, if you do

$(MAKE) CFLAGS="$(CFLAGS)"

that value will be used for the build and will override upstream's value, 
because variables defined on the command line override variables defined 
in the makefile.

This is why it's very wrong to define CFLAGS directly in Makefile.am,
because the user cannot do

./configure CFLAGS=... 

to override the value.  And the user is always right.

So the right thing to do depends on the package and/or the build system 
in question.  As these things vary wildly and it seems new "inventions" 
in this area is a vogue, I don't think that you can generalize and give a 
common recipe that will work for all cases.

> For Proda, if I pass -DVERSION="\"1.00\"" through CPPFLAGS, it
> indeeds solves my problem.

Good.

> But what can I propose upstream that fits the best practices that I
> just added to the wiki?

I just downloaded 1.0-4 and the Makefile looks OK to me (apart from using 
the variable for C++ compiler flags for preprocessor flags).  Of
course it's not portable, but that is another story.  With this define
in CPPFLAGS the behaviour is predictable and sane.

> If CPPFLAGS is set in the Makefile, it could be overriden, but if it
> is set to -DVERSION="\"1.00\"" from debian/rules, then this is one
> more think that one can forget to update when a new upstream version
> is released...

But this flag is upstream's and not a Debian modification, right?  If
so, you just have to modify your 02-fix_CXXFLAGS.patch until upstream
does the right thing in a new release.  Then you can just drop the
patch.

So If i were you I that patch would be only:

- OTHERFLAGS = -DVERSION="\"1.00\""
+ CPPFLAGS = -DVERSION="\"1.00\""

OTHERFLAGS will expand to the empty string, so it's harmless.


Reply to: