Re: debian/rules and environment variables

2007-09-05 Thread Neil Williams
On Wed, 5 Sep 2007 19:31:48 +0200
Peter Eisentraut [EMAIL PROTECTED] wrote:

 It has been suggested in bug #411520 that cdbs should be set up so that 
 it preserves CFLAGS set in the environment.  But I haven't found any 
 clear specification about how debian/rules, being a makefile, should 
 deal with environment variables.

http://lists.debian.org/debian-embedded/2007/08/msg00033.html

Where MAKEFLAGS are concerned, packages and build tools should not be
overriding environment variables and there is an issue in CDBS
regarding this which I need to get around to filing.

 CDBS is a culprit but also very easy to fix:
 DEB_CONFIGURE_SCRIPT_ENV=
 
 The reason is that CDBS presets 
 DEB_CONFIGURE_SCRIPT_ENV = CC=$(CC) CXX=$(CXX) CFLAGS=$(CFLAGS) 
 CXXFLAGS=$(CXXFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS)
 
 but passes those values TO ./configure instead of reading them
 AFTER ./configure has had a chance to process --build= and --host=.

This used to work because dpkg-cross explicitly overrode MAKEFLAGS but
this caused build failures with packages that need to compile tools
during the build - wrong architecture when executing. (#425445)

Now the CDBS behaviour actually re-implements the broken dpkg-cross
behaviour that is being fixed during the rewrite for #439979 so that
although the dpkg-cross changes fix builds like libx11-6 (which
compiles and then runs a tool {see #425445}, grep now fails to
cross-build without the above patch to debian/rules because
the ./configure setting (safely managed via dpkg-architecture) is
thrown out.

I would like to see that debian/rules and any other build tool NEVER
changes MAKEFLAGS or any related environment variable to make
cross-building easier.

 The best I could find is Policy 10.1 which states that the following 
 compilation parameters should be used:
 
 CC = gcc
 CFLAGS = -O2 -g -Wall
 
 (It doesn't say, these variables should be set this way.)  It appears, 
 however, that hardly any package (containing C language code) 
 explicitly sets CC, and I think it is certainly useful to be able to 
 set a different CC in the environment. 

Only with care. Just changing $CC is insufficient because you also need
to change the include path for libraries and the LD_LIBRARY path,
otherwise you'll end up compiling with arm-linux-gnu-gcc but linking
against libraries from /usr/lib instead of /usr/arm-linux-gnu/lib.

This is currently handled by remapping the paths for each command
during the build using symlinks and a perl parser script in dpkg-cross.
Guillem is working on a replacement dpkg method for ensuring that the
cross-compiler finds the correct libraries.

http://lists.debian.org/debian-devel/2007/08/msg01152.html

 Yet at the same time most 
 packages set CFLAGS explicitly, overriding anything that's there 
 before. 

CFLAGS is less of a problem for cross-building (so far) - it is CC that
has been the most problematic.

 The language in the policy and various rules templates appear 
 to encourage that.  But as the submitter of #411520 stated, it could 
 also be useful to be able to build a package with different compiler 
 flags.

Not just the flags.

On a related note, I'm thinking that *all* packages using ./configure
should be using:
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
...
./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
 ...

This then allows cross-builders to simply call dpkg-architecture to set
the correct environment and ./configure will do the right thing.

Once the dpkg-cross rewrite makes it into unstable (hopefully in the
next dpkg upload after the one today - i.e. in dpkg 1.14.7) I'll go for
a rebuild of the Emdebian packages and start filing bugs against those
packages that don't bother with these simple checks, tagged with the
usertag 'cross-build'.

-- 


Neil Williams
=
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/



pgpCVgjXcTYdM.pgp
Description: PGP signature


Re: debian/rules and environment variables

2007-09-05 Thread Bernd Zeimetz
Hi,

 On a related note, I'm thinking that *all* packages using ./configure
 should be using:
 DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
 DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
 ...
 ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
  ...
 
 This then allows cross-builders to simply call dpkg-architecture to set
 the correct environment and ./configure will do the right thing.

What about packages which do not use configure?
Are there any rules to follow, especially if you need to pass CC and
other options to upstream's build system, which is just a bunch of
Makefiles in this case. Although I doubt that anybody would
cross-compile this package, I'd appreciate some general hints.


Thanks,

Bernd

-- 
Bernd Zeimetz
[EMAIL PROTECTED] http://bzed.de/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: debian/rules and environment variables

2007-09-05 Thread Neil Williams
On Wed, 05 Sep 2007 22:51:30 +0200
Bernd Zeimetz [EMAIL PROTECTED] wrote:

 Hi,
 
  On a related note, I'm thinking that *all* packages using ./configure
  should be using:
  DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
  DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
  ...
  ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
   ...
  
  This then allows cross-builders to simply call dpkg-architecture to set
  the correct environment and ./configure will do the right thing.
 
 What about packages which do not use configure?

Then it is up to the cross-building scripts to set the correct
environment and up to the package NOT to override those environment
settings. Right now, the way to do this is being rewritten and previous
behaviour is known to be causing build failures so just try to leave
the environment variables alone.

If you need to change the upstream behaviour, use a patch. Get your
package to build cleanly on a native system (i.e. without overwriting
environment variables) and it should cross-build cleanly.

 Are there any rules to follow, especially if you need to pass CC and
 other options to upstream's build system, 

Don't do that. There should be no reason to change CC. If you want
optimisations, that's CFLAGS or CPPFLAGS.

 which is just a bunch of
 Makefiles in this case. Although I doubt that anybody would
 cross-compile this package, I'd appreciate some general hints.

Every package is likely to need to be cross-compiled by someone at some
point - except Architecture: all. That's why I was working on a patch
for gcc during Debconf - to cross-build gcc using a gcc cross-compiler
to package libraries built from the gcc source on amd64 (or powerpc) to
link against packages cross built for arm.

-- 


Neil Williams
=
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/



pgpOHeZBJXD6X.pgp
Description: PGP signature