Bug#31946: Patch files and dpkg-architecture
Here are the promised files I forgot to attach. Sorry.
Marcus
--
"Rhubarb is no Egyptian god." Debian GNU/Linux finger brinkmd@
Marcus Brinkmann http://www.debian.org master.debian.org
Marcus.Brinkmann@ruhr-uni-bochum.de for public PGP Key
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/ PGP Key ID 36E7CD09
#! /usr/bin/perl
#
# History
# 0.0.1 Initial release.
# 0.0.2 Don't use dpkg to get default gnu system, so the default is
# correct even on non-linux system.
# Warn if the host gnu system does not match the gcc system.
# Determine default from gcc if possible, else fall back to native
# compilation.
# Do not set environment variables which are already defined unless
# force flag is given.
# 1.0.0 Changed target to host, because this complies with GNU
# nomenclature.
# Added command facility.
$version="1.0.0";
$0 = `basename $0`; chomp $0;
$dpkglibdir="/usr/lib/dpkg";
push(@INC,$dpkglibdir);
require 'controllib.pl';
%archtable=('i386', 'i486-linux',
'sparc', 'sparc-linux',
'alpha', 'alpha-linux',
'm68k', 'm68k-linux',
'arm', 'arm-linux',
'powerpc', 'powerpc-linux',
'hurd-i386', 'i386-gnu');
sub usageversion {
print STDERR
"Debian GNU/Linux $0 $version. Copyright (C) 1999 Marcus Brinkmann.
This is free software; see the GNU General Public Licence version 2
or later for copying conditions. There is NO warranty.
Usage:
$0 [<option> ...] [<action>]
Options:
-a<debian-arch> set Debian architecture
-t<gnu-system> set GNU system type
-f force flag (set even variables which are set)
Actions:
-l list environment variables (default)
-s print command to set environment variables
-u print command to unset environment variables
-c <command> set environment and run the command in it.
Known Debian Architectures are ".join(", ",keys %archtable)."
Known GNU System Types are ".join(", ",map ($archtable{$_},keys %archtable))."
";
}
sub rewrite_gnu_cpu {
local ($_) = @_;
s/(?:i386|i586|i686|pentium)(.*linux)/i486$1/;
s/ppc/powerpc/;
return $_;
}
sub gnu_to_debian {
local ($gnu) = @_;
local (@list);
local ($a);
$gnu = &rewrite_gnu_cpu($gnu);
foreach $a (keys %archtable) {
push @list, $a if $archtable{$a} eq $gnu;
}
return @list;
}
# Set default values:
$deb_build_arch = `dpkg --print-installation-architecture`;
chomp $deb_build_arch;
$deb_build_gnu_system = $archtable{$deb_build_arch};
$deb_build_gnu_arch = $deb_build_gnu_system;
$deb_build_gnu_os = $deb_build_gnu_system;
$deb_build_gnu_arch =~ s/-.*$//;
$deb_build_gnu_os =~ s/^.*-//;
# Default host: Current gcc.
$gcc = `\${CC:-gcc} --print-libgcc-file-name`;
$gcc =~ s!^.*gcc-lib/(.*)/\d+(?:.\d+)*/libgcc.*$!$1!s;
if ($gcc eq '') {
&warn ("Couldn't determine gcc system type, falling back to default (native compilation)");
} else {
@list = &gnu_to_debian($gcc);
if (!defined(@list)) {
&warn ("Unknown gcc system type $gcc, falling back to default (native compilation)"),
} elsif ($#list > 0) {
&warn ("Ambiguous gcc system type $gcc, you must specify Debian architecture, too (one of ".join(", ",@list).")");
} else {
$deb_host_arch = $list[0];
$deb_host_gnu_system = $gcc;
$deb_host_gnu_arch = $gcc;
$deb_host_gnu_os = $gcc;
$deb_host_gnu_arch =~ s/-.*$//;
$deb_host_gnu_os =~ s/^.*-//;
}
}
if (!defined($deb_host_arch)) {
# Default host: Native compilation.
$deb_host_arch = $deb_build_arch;
$deb_host_gnu_arch = $deb_build_gnu_arch;
$deb_host_gnu_os = $deb_build_gnu_os;
$deb_host_gnu_system = $deb_build_gnu_system;
}
$req_host_arch = '';
$req_host_gnu_system = '';
$action='l';
$force=0;
while (@ARGV) {
$_=shift(@ARGV);
if (m/^-a/) {
$req_host_arch = $';
} elsif (m/^-t/) {
$req_host_gnu_system = &rewrite_gnu_cpu($');
} elsif (m/^-[lsu]$/) {
$action = $_;
$action =~ s/^-//;
} elsif (m/^-f$/) {
$force=1;
} elsif (m/^-c$/) {
$action = 'c';
last;
} else {
usageerr("unknown option \`$_'");
}
}
if ($req_host_arch ne '' && $req_host_gnu_system eq '') {
die ("unknown Debian architecture $req_host_arch, you must specify GNU system type, too") if !exists $archtable{$req_host_arch};
$req_host_gnu_system = $archtable{$req_host_arch}
}
if ($req_host_gnu_system ne '' && $req_host_arch eq '') {
@list = &gnu_to_debian ($req_host_gnu_system);
die ("unknown GNU system type $req_host_gnu_system, you must specify Debian architecture, too") if !defined(@list);
die ("ambiguous GNU system type $req_host_gnu_system, you must specify Debian architecture, too (one of ".join(", ",@list).")") if $#list > 0;
$req_host_arch = $list[0];
}
if (exists $archtable{$req_host_arch}) {
&warn("Default GNU system type $archtable{$req_host_arch} for Debian arch $req_host_arch does not match specified GNU system type $req_host_gnu_system\n") if $archtable{$req_host_arch} ne $req_host_gnu_system;
}
die "couldn't parse GNU system type $req_host_gnu_system, must be arch-os or arch-vendor-os" if $req_host_gnu_system !~ m/^([\w\d]+(-[\w\d]+){1,2})?$/;
$deb_host_arch = $req_host_arch if $req_host_arch ne '';
if ($req_host_gnu_system ne '') {
$deb_host_gnu_arch = $deb_host_gnu_os = $deb_host_gnu_system = $req_host_gnu_system;
$deb_host_gnu_arch =~ s/-.*$//;
$deb_host_gnu_os =~ s/^.*-//;
}
#$gcc = `\${CC:-gcc} --print-libgcc-file-name`;
#$gcc =~ s!^.*gcc-lib/(.*)/\d+(?:.\d+)*/libgcc.*$!$1!s;
&warn("Specified GNU system type $deb_host_gnu_system does not match gcc system type $gcc.") if ($gcc ne '') && ($gcc ne $deb_host_gnu_system);
undef @env;
push @env, "DEB_BUILD_ARCH=$deb_build_arch" if $force || (! exists $ENV{DEB_BUILD_ARCH});
push @env, "DEB_BUILD_GNU_ARCH=$deb_build_gnu_arch" if $force || (! exists $ENV{DEB_BUILD_GNU_ARCH});
push @env, "DEB_BUILD_GNU_OS=$deb_build_gnu_os" if $force || (! exists $ENV{DEB_BUILD_GNU_OS});
push @env, "DEB_BUILD_GNU_SYSTEM=$deb_build_gnu_system" if $force || (! exists $ENV{DEB_BUILD_GNU_SYSTEM});
push @env, "DEB_HOST_ARCH=$deb_host_arch" if $force || (! exists $ENV{DEB_HOST_ARCH});
push @env, "DEB_HOST_GNU_ARCH=$deb_host_gnu_arch" if $force || (! exists $ENV{DEB_HOST_GNU_ARCH});
push @env, "DEB_HOST_GNU_OS=$deb_host_gnu_os" if $force || (! exists $ENV{DEB_HOST_GNU_OS});
push @env, "DEB_HOST_GNU_SYSTEM=$deb_host_gnu_system" if $force || (! exists $ENV{DEB_HOST_GNU_SYSTEM});
if ($action eq 'l') {
print join("\n",@env)."\n";
} elsif ($action eq 's') {
print "export ".join("\n",@env)."\n";
} elsif ($action eq 'u') {
print "unset DEB_BUILD_ARCH DEB_BUILD_GNU_ARCH DEB_BUILD_GNU_OS DEB_BUILD_GNU_SYSTEM DEB_HOST_ARCH DEB_HOST_GNU_ARCH DEB_HOST_GNU_OS DEB_HOST_GNU_SYSTEM\n";
} elsif ($action eq 'c') {
foreach $_ (@env) {
m/^(.*)=(.*)$/;
$ENV{$1}=$2;
}
exec @ARGV;
}
__END__
=head1 NAME
dpkg-architecture - set and determine the architecture for package building
=head1 SYNOPSIS
dpkg-architecture [options] [action]
Valid options:
B<-a> Debian-Architecture
B<-t> Gnu-System-Type
B<-f>
Valid actions:
B<-l>, B<-s>, B<-u>, B<-c> Command
=head1 DESCRIPTION
dpkg-architecture does provide a facility to determine and set the build and
host architecture for package building.
=head1 OVERVIEW
The build architecture is always determined by an external call to dpkg, and
can not be set at the command line.
You can specify the host architecture by providing one or both of the options B<-a>
and B<-t>. The default is determined by an external call to gcc, or the same as
the build architecture if CC or gcc are both not available. One out of B<-a> and B<-t>
is sufficient, the value of the other will be set to a usable default.
Indeed, it is often better to only specify one, because dpkg-architecture
will warn you if your choice doesn't match the default.
The default action is B<-l>, which prints the environment variales, one each line,
in the format VARIABLE=value. If you specify B<-s>, it will output an export
command. This can be used to set the environment variables using eval. B<-u>
does return a similar command to unset all variables. B<-c> does execute a
command in an environment which has all variables set to the determined
value.
Existing environment variables with the same name as used by the scripts are
not overwritten, except the B<-f> force flag is present. This allows the user
to override a value even when the call to dpkg-architecture is buried in
some other script (for example dpkg-buildpackage).
=head1 TERMS
=over 4
=item build machine
The machine the package is build on.
=item host machine
The machine the package is build for.
=item Debian Architecture
The Debian archietcture string, which specifies the binary tree in the FTP
archive. Examples: i386, sparc, hurd-i386.
=item GNU System Type
An architecture specification string consisting of two or three parts,
cpu-os or cpu-vendor-os. Examples: i386-linux, sparc-linux, i386-gnu.
=back
=head1 EXAMPLES
dpkg-buildpackage accepts the B<-a> option and passes it to dpkg-architecture.
Other examples:
CC=i386-gnu-gcc dpkg-architecture C<-c> debian/rules build
eval `dpkg-architecture C<-u>`
=head1 VARIABLES
The following variables are set by dpkg-architecture:
=over 4
=item DEB_BUILD_ARCH
The Debian architecture of the build machine.
=item DEB_BUILD_GNU_SYSTEM
The GNU system type of the build machine.
=item DEB_BUILD_GNU_ARCH
The CPU part of DEB_BUILD_GNU_SYSTEM
=item DEB_BUILD_GNU_OS
The OS part of DEB_BUILD_GNU_SYSTEM
=item DEB_HOST_ARCH
The Debian architecture of the host machine.
=item DEB_HOST_GNU_SYSTEM
The GNU system type of the host machine.
=item DEB_HOST_GNU_ARCH
The CPU part of DEB_HOST_GNU_SYSTEM
=item DEB_HOST_GNU_OS
The OS part of DEB_HOST_GNU_SYSTEM
=back
=head1 DEBIAN/RULES
The environment variables set by dpkg-architecture are passed to
debian/rules as make variables (see make documentation). You can and should
use them in the build process as needed. Here are some examples, which also
show how you can improve the cross compilation support in your package:
Instead:
ARCH=`dpkg --print-architecture`
configure $(ARCH)-linux
please use the following:
B_ARCH=$(DEB_BUILD_GNU_SYSTEM)
H_ARCH=$(DEB_HOST_GNU_SYSTEM)
configure --build=$(B_ARCH) --host=$(H_ARCH)
Instead:
ARCH=`dpkg --print-architecture`
if [ $(ARCH) = 'alpha' ] ...
please use:
ARCH=$(DEB_HOST_ARCH)
if [ $(ARCH) = 'alpha' ] ...
In general, calling dpkg in the rules file to get architecture information
is deprecated (until you want to provide backward compatibility, see below).
Especially the --print-architecture option is unreliable since we have
Debian architectures which don't equal a processor name.
=head1 BACKWARD COMPATIBILITY
When providing a new facility, it is always a good idea to stay compatible with old
versions of the programs. Note that dpkg-architecture does not affect old
debian/rules files, so the only thing to consider is using old building
scripts with new debian/rules files. The following does the job:
DEB_BUILD_ARCH=`dpkg --print-installation-architecture`
DEB_BUILD_GNU_ARCH=`dpkg --print-gnu-build-architecture`
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=$(DEB_BUILD_GNU_ARCH)-$(DEB_BUILD_GNU_OS)
DEB_HOST_ARCH=$(DEB_BUILD_ARCH)
DEB_HOST_GNU_ARCH=$(DEB_BUILD_GNU_ARCH)
DEB_HOST_GNU_OS=$(DEB_BUILD_GNU_OS)
DEB_HOST_GNU_SYSTEM=$(DEB_BUILD_GNU_SYSTEM)
Put a subset of these lines at the top of your debian/rules file; these
default values will be overwritten if dpkg-architecture is used.
You don't need the full set. Choose a consistent set which contain the
values you use in the rukes file. For example, if you only need the host
Debian architecture, `DEB_HOST_ARCH=`dpkg --print-installation-architecture`
is sufficient.
=head1 SEE ALSO
dpkg-buildpackage
=head1 CONTACT
If you have questions about the usage of the make variables in your rules
files, or about cross compilation support in your packages, please email me.
The addresse is Marcus Brinkmann <brinkmd@debian.org>
--- ../cross/dpkg/dpkg-1.4.1/scripts/controllib.pl Sun Nov 1 17:36:14 1998
+++ controllib.pl Mon Jan 11 19:32:08 1999
@@ -62,9 +62,13 @@
}
sub findarch {
- $arch=`dpkg --print-architecture`;
- $? && &subprocerr("dpkg --print-architecture");
- $arch =~ s/\n$//;
+ if (exists $ENV{DEB_HOST_ARCH}) {
+ $arch=$ENV{DEB_HOST_ARCH};
+ } else {
+ $arch=`dpkg --print-architecture`;
+ $? && &subprocerr("dpkg --print-architecture");
+ chomp $arch;
+ }
$substvar{'Arch'}= $arch;
}
--- ../cross/dpkg/dpkg-1.4.1/scripts/dpkg-buildpackage.sh Sun Nov 1 17:36:16 1998
+++ dpkg-buildpackage Fri Jan 15 18:53:32 1999
@@ -18,7 +18,7 @@
-spgp the sign-command is called like PGP
-us unsigned source
-uc unsigned changes
- -a<arch> architecture field of the changes _file_name_
+ -a<arch> Debian architecture we build for
-b binary-only, do not build source } also passed to
-B binary-only, no arch-indep files } dpkg-genchanges
-v<version> changes since version <version> }
@@ -109,7 +109,9 @@
mustsetvar version "`dpkg-parsechangelog | sed -n 's/^Version: //p'`" "source version"
if [ -n "$maint" ]; then maintainer="$maint";
else mustsetvar maintainer "`dpkg-parsechangelog | sed -n 's/^Maintainer: //p'`" "source maintainer"; fi
+command -v dpkg-architecture > /dev/null 2>&1 && eval `dpkg-architecture -a${arch} -s`
test "${opt_a}" \
+ || arch=${DEB_HOST_ARCH} && test "${arch}" \
|| mustsetvar arch "`dpkg --print-architecture`" "build architecture"
sversion=`echo "$version" | perl -pe 's/^\d+://'`
--- ../cross/dpkg/dpkg-1.4.1/scripts/dpkg-gencontrol.pl Sun Nov 1 17:07:41 1998
+++ dpkg-gencontrol Mon Jan 11 19:16:42 1999
@@ -88,10 +88,14 @@
}
$arch = $override{Architecture} or do {
+ if (exists $ENV{DEB_HOST_ARCH}) {
+ $arch=$ENV{DEB_HOST_ARCH};
+ } else {
$arch=`dpkg --print-architecture`;
$? && &subprocerr("dpkg --print-architecture");
+ }
};
-$arch =~ s/\n$//;
+chomp $arch;
&parsechangelog;
&parsecontrolfile;
--- ../cross/dpkg/dpkg-1.4.1/scripts/dpkg-source.1 Sun Nov 1 17:36:19 1998
+++ dpkg-source.1 Fri Jan 15 18:51:49 1999
@@ -552,6 +552,11 @@
.TP
.BR -us ", " -uc
Do not sign the source package or the changelog, respectively.
+.TP
+.BI -a architecture
+Specify the Debian architecture we build for. The architecture of the
+machine we build on is determined automatically, and is also the default for
+the host machine.
.SH DPKG-DISTADDFILE ARGUMENTS
.B dpkg-distaddfile
does not take any non-common options. It takes three non-option
Reply to: