Browse Source

Generalize source architecture handling by abstracting it through the new
Debian triplet.

Guillem Jover 17 years ago
parent
commit
5d31013c78
9 changed files with 156 additions and 74 deletions
  1. 25 0
      ChangeLog
  2. 1 1
      Makefile.am
  3. 4 3
      cputable
  4. 2 1
      debian/archtable
  5. 2 0
      debian/changelog
  6. 12 11
      ostable
  7. 82 45
      scripts/controllib.pl
  8. 14 13
      scripts/dpkg-architecture.pl
  9. 14 0
      triplettable

+ 25 - 0
ChangeLog

@@ -1,3 +1,28 @@
+2007-05-07  Guillem Jover  <guillem@debian.org>
+
+	* scripts/controllib.pl (%debtriplet_to_debarch): New variable.
+	(%debarch_to_debtriplet): Likewise.
+	(split_gnu, split_debian): Remove functions.
+	(debian_arch_fix, debian_arch_split): Likewise.
+	(debian_to_gnu, gnu_to_debian): Likewise.
+	(read_triplettable): New function.
+	(gnutriplet_to_debtriplet, debtriplet_to_gnutriplet): Likewise.
+	(debtriplet_to_debarch, debarch_to_debtriplet): Likewise.
+	(get_valid_arches): Call read_cputable and read_ostable if @cpu or @os
+	are empty. Use debtriplet_to_debarch instead of debian_arch_fix.
+	(debian_arch_eq): Use debarch_to_debtriplet instead of
+	debian_arch_split. Compare the whole Debian triplet.
+	(debian_arch_is): Likewise.
+	* scripts/dpkg-architecture.pl: Do not call the now internal functions
+	read_cputable and read_ostable. Use debtriplet_to_gnutriplet,
+	gnutriplet_to_debtriplet, debarch_to_debtriplet and
+	debtriplet_to_debarch instead of debian_to_gnu, gnu_to_debian.
+	* debian/archtable: Update comment to reflect the new Debian triplet.
+	* cputable: Likewise.
+	* ostable: Likewise. Include the ABI information in the Debian name.
+	* triplettable: New file.
+	* Makefile.am (dist_pkgdata_DATA): Add triplettable.
+
 2007-05-04  Guillem Jover  <guillem@debian.org>
 
 	* scripts/dpkg-architecture.pl: Use get_valid_arches instead of

+ 1 - 1
Makefile.am

@@ -21,7 +21,7 @@ SUBDIRS = \
 ACLOCAL_AMFLAGS = -I m4
 
 
-dist_pkgdata_DATA = cputable ostable
+dist_pkgdata_DATA = cputable ostable triplettable
 
 EXTRA_DIST = \
 	debian/archtable \

+ 4 - 3
cputable

@@ -1,12 +1,13 @@
 # This file contains the table of known CPU names.
 #
 # Architecture names are formed as a combination of the system name
-# (from ostable) and CPU name (from this table).  A list of architecture
+# (from ostable) and CPU name (from this table) after mapping from
+# the Debian triplet (from triplettable). A list of architecture
 # names in the Debian ‘sid’ distribution can be found in the archtable
 # file.
 #
-# Column 1 is the Debian name for the CPU, used to form the architecture
-# name.
+# Column 1 is the Debian name for the CPU, used to form the cpu part in
+# the Debian triplet.
 # Column 2 is the GNU name for the CPU, used to output build and host
 # targets in ‘dpkg-architecture’.
 # Column 3 is an extended regular expression used to match against the

+ 2 - 1
debian/archtable

@@ -2,7 +2,8 @@
 # distribution.
 #
 # Architecture names are formed as a combination of the system name
-# (from ostable) and CPU name (from cputable).  Support for new
+# (from ostable) and CPU name (from cputable) after mapping from
+# the Debian triplet (from triplettable). Support for new
 # architectures in dpkg is added in those files, architecture names
 # are only added to this file when added to the distribution.
 #

+ 2 - 0
debian/changelog

@@ -64,6 +64,8 @@ dpkg (1.14.0) UNRELEASED; urgency=low
   * Reorder a bit fields in output files.
   * Speed up dpkg-shlibdeps by avoiding doing a dpkg-query for duped
     libraries. Thanks to Aaron M. Ucko. Closes: #421290
+  * Generalize source architecture handling by abstracting it through the new
+    Debian triplet.
 
   [ Updated dpkg translations ]
   * Romanian (Eddy Petri?or).

+ 12 - 11
ostable

@@ -1,23 +1,24 @@
 # This file contains the table of known operating system names.
 #
 # Architecture names are formed as a combination of the system name
-# (from this table) and CPU name (from cputable).  A list of architecture
+# (from this table) and CPU name (from cputable) after mapping from
+# the Debian triplet (from triplettable). A list of architecture
 # names in the Debian ‘sid’ distribution can be found in the archtable
 # file.
 #
-# Column 1 is the Debian name for the system, used to form the
-# architecture name.
+# Column 1 is the Debian name for the system, used to form the system part
+# in the Debian triplet.
 # Column 2 is the GNU name for the system, used to output build and host
 # targets in ‘dpkg-architecture’.
 # Column 3 is an extended regular expression used to match against the
 # system part of the output of the GNU config.guess script.
 #
 # <Debian name>	<GNU name>	<config.guess regex>
-linux		linux-gnu	linux[^-]*(-gnu.*)?
-darwin		darwin		darwin[^-]*
-freebsd		freebsd		freebsd[^-]*
-kfreebsd	kfreebsd-gnu	kfreebsd[^-]*(-gnu.*)?
-knetbsd		knetbsd-gnu	knetbsd[^-]*(-gnu.*)?
-netbsd		netbsd		netbsd[^-]*
-openbsd		openbsd		openbsd[^-]*
-hurd		gnu		gnu[^-]*
+gnu-linux	linux-gnu	linux[^-]*(-gnu.*)?
+gnu-kfreebsd	kfreebsd-gnu	kfreebsd[^-]*(-gnu.*)?
+gnu-knetbsd	knetbsd-gnu	knetbsd[^-]*(-gnu.*)?
+gnu-hurd	gnu		gnu[^-]*
+bsd-darwin	darwin		darwin[^-]*
+bsd-freebsd	freebsd		freebsd[^-]*
+bsd-netbsd	netbsd		netbsd[^-]*
+bsd-openbsd	openbsd		openbsd[^-]*

+ 82 - 45
scripts/controllib.pl

@@ -101,6 +101,9 @@ my (@cpu, @os);
 my (%cputable, %ostable);
 my (%cputable_re, %ostable_re);
 
+my %debtriplet_to_debarch;
+my %debarch_to_debtriplet;
+
 {
     my $host_arch;
 
@@ -117,9 +120,13 @@ my (%cputable_re, %ostable_re);
 
 sub get_valid_arches()
 {
+    read_cputable() if (!@cpu);
+    read_ostable() if (!@os);
+
     foreach my $os (@os) {
 	foreach my $cpu (@cpu) {
-	    print debian_arch_fix($os, $cpu)."\n";
+	    my $arch = debtriplet_to_debarch(split(/-/, $os, 2), $cpu);
+	    print $arch."\n" if defined($arch);
 	}
     }
 }
@@ -152,40 +159,58 @@ sub read_ostable
     close OSTABLE;
 }
 
-sub split_debian
+sub read_triplettable()
 {
-    local ($_) = @_;
-
-    if (/^([^-]*)-(.*)/) {
-	return ($1, $2);
-    } else {
-	return ("linux", $_);
+    read_cputable() if (!@cpu);
+
+    open TRIPLETTABLE, "$pkgdatadir/triplettable"
+	or syserr(_g("unable to open triplettable"));
+    while (<TRIPLETTABLE>) {
+	if (m/^(?!\#)(\S+)\s+(\S+)/) {
+	    my $debtriplet = $1;
+	    my $debarch = $2;
+
+	    if ($debtriplet =~ /<cpu>/) {
+		foreach my $_cpu (@cpu) {
+		    (my $dt = $debtriplet) =~ s/<cpu>/$_cpu/;
+		    (my $da = $debarch) =~ s/<cpu>/$_cpu/;
+
+		    $debarch_to_debtriplet{$da} = $dt;
+		    $debtriplet_to_debarch{$dt} = $da;
+		}
+	    } else {
+		$debarch_to_debtriplet{$2} = $1;
+		$debtriplet_to_debarch{$1} = $2;
+	    }
+	}
     }
+    close TRIPLETTABLE;
 }
 
-sub debian_to_gnu
+sub debtriplet_to_gnutriplet(@)
 {
-    my ($arch) = @_;
-    my ($os, $cpu) = split_debian($arch);
-
-    return undef unless exists($cputable{$cpu}) && exists($ostable{$os});
-    return join("-", $cputable{$cpu}, $ostable{$os});
-}
+    read_cputable() if (!@cpu);
+    read_ostable() if (!@os);
 
-sub split_gnu
-{
-    local ($_) = @_;
+    my ($abi, $os, $cpu) = @_;
 
-    /^([^-]*)-(.*)/;
-    return ($1, $2);
+    return undef unless defined($abi) && defined($os) && defined($cpu) &&
+        exists($cputable{$cpu}) && exists($ostable{"$abi-$os"});
+    return join("-", $cputable{$cpu}, $ostable{"$abi-$os"});
 }
 
-sub gnu_to_debian
+sub gnutriplet_to_debtriplet($)
 {
     my ($gnu) = @_;
-    my ($cpu, $os);
+    return undef unless defined($gnu);
+    my ($gnu_cpu, $gnu_os) = split(/-/, $gnu, 2);
+    return undef unless defined($gnu_cpu) && defined($gnu_os);
+
+    read_cputable() if (!@cpu);
+    read_ostable() if (!@os);
+
+    my ($os, $cpu);
 
-    my ($gnu_cpu, $gnu_os) = split_gnu($gnu);
     foreach my $_cpu (@cpu) {
 	if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
 	    $cpu = $_cpu;
@@ -201,53 +226,65 @@ sub gnu_to_debian
     }
 
     return undef if !defined($cpu) || !defined($os);
-    return debian_arch_fix($os, $cpu);
+    return (split(/-/, $os, 2), $cpu);
 }
 
-
-sub debian_arch_fix
+sub debtriplet_to_debarch(@)
 {
-    my ($os, $cpu) = @_;
+    read_triplettable() if (!%debtriplet_to_debarch);
 
-    if ($os eq "linux") {
-	return $cpu;
+    my ($abi, $os, $cpu) = @_;
+
+    if (!defined($abi) || !defined($os) || !defined($cpu)) {
+	return undef;
+    } elsif (exists $debtriplet_to_debarch{"$abi-$os-$cpu"}) {
+	return $debtriplet_to_debarch{"$abi-$os-$cpu"};
     } else {
-	return "$os-$cpu";
+	return undef;
     }
 }
 
-sub debian_arch_split {
+sub debarch_to_debtriplet($)
+{
+    read_triplettable() if (!%debarch_to_debtriplet);
+
     local ($_) = @_;
 
-    if (/^([^-]*)-(.*)/) {
-	return ($1, $2);
-    } elsif (/any/ || /all/) {
-	return ($_, $_);
+    if (/any/ || /all/) {
+	return ($_, $_, $_);
+    } elsif (/^([^-]*)-([^-]*)-(.*)/) {
+	return ($1, $2, $3);
     } else {
-	return ("linux", $_);
+	my $triplet = $debarch_to_debtriplet{$_};
+
+	if (defined($triplet)) {
+	    return split('-', $triplet, 3);
+	} else {
+	    return undef;
+	}
     }
 }
 
 sub debian_arch_eq {
     my ($a, $b) = @_;
-    my ($a_os, $a_cpu) = debian_arch_split($a);
-    my ($b_os, $b_cpu) = debian_arch_split($b);
+    my ($a_abi, $a_os, $a_cpu) = debarch_to_debtriplet($a);
+    my ($b_abi, $b_os, $b_cpu) = debarch_to_debtriplet($b);
 
-    return ("$a_os-$a_cpu" eq "$b_os-$b_cpu");
+    return ("$a_abi-$a_os-$a_cpu" eq "$b_abi-$b_os-$b_cpu");
 }
 
 sub debian_arch_is {
     my ($real, $alias) = @_;
-    my ($real_os, $real_cpu) = debian_arch_split($real);
-    my ($alias_os, $alias_cpu) = debian_arch_split($alias);
+    my ($real_abi, $real_os, $real_cpu) = debarch_to_debtriplet($real);
+    my ($alias_abi, $alias_os, $alias_cpu) = debarch_to_debtriplet($alias);
 
-    if ("$real_os-$real_cpu" eq "$alias_os-$alias_cpu") {
+    if ("$real_abi-$real_os-$real_cpu" eq "$alias_abi-$alias_os-$alias_cpu") {
 	return 1;
-    } elsif ("$alias_os-$alias_cpu" eq "any-any") {
+    } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "any-any-any") {
 	return 1;
-    } elsif ("$alias_os-$alias_cpu" eq "any-$real_cpu") {
+    } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "$real_abi-any-$real_cpu") {
 	return 1;
-    } elsif ("$alias_os-$alias_cpu" eq "$real_os-any") {
+    } elsif ("$alias_abi-$alias_os-$alias_cpu" eq "$real_abi-$real_os-any") {
 	return 1;
     }
 

+ 14 - 13
scripts/dpkg-architecture.pl

@@ -69,9 +69,6 @@ Actions:
 "), $progname;
 }
 
-&read_cputable;
-&read_ostable;
-
 # Check for -L
 if (grep { m/^-L$/ } @ARGV) {
     foreach my $arch (get_valid_arches()) {
@@ -84,7 +81,7 @@ if (grep { m/^-L$/ } @ARGV) {
 
 chomp (my $deb_build_arch = `dpkg --print-architecture`);
 &syserr("dpkg --print-architecture failed") if $?>>8;
-my $deb_build_gnu_type = debian_to_gnu($deb_build_arch);
+my $deb_build_gnu_type = debtriplet_to_gnutriplet(debarch_to_debtriplet($deb_build_arch));
 
 # Default host: Current gcc.
 my $gcc = `\${CC:-gcc} -dumpmachine`;
@@ -99,12 +96,13 @@ my $deb_host_arch = undef;
 my $deb_host_gnu_type;
 
 if ($gcc ne '') {
-    $deb_host_arch = &gnu_to_debian($gcc);
+    my (@deb_host_archtriplet) = gnutriplet_to_debtriplet($gcc);
+    $deb_host_arch = debtriplet_to_debarch(@deb_host_archtriplet);
     unless (defined $deb_host_arch) {
 	warning(sprintf(_g("Unknown gcc system type %s, falling back to default (native compilation)"), $gcc));
 	$gcc = '';
     } else {
-	$gcc = $deb_host_gnu_type = &debian_to_gnu($deb_host_arch);
+	$gcc = $deb_host_gnu_type = debtriplet_to_gnutriplet(@deb_host_archtriplet);
     }
 }
 if (!defined($deb_host_arch)) {
@@ -160,17 +158,20 @@ while (@ARGV) {
 }
 
 if ($req_host_arch ne '' && $req_host_gnu_type eq '') {
-    $req_host_gnu_type = &debian_to_gnu ($req_host_arch);
+    $req_host_gnu_type = debtriplet_to_gnutriplet(debarch_to_debtriplet($req_host_arch));
     die (sprintf(_g("unknown Debian architecture %s, you must specify GNU system type, too"), $req_host_arch)) unless defined $req_host_gnu_type;
 }
 
 if ($req_host_gnu_type ne '' && $req_host_arch eq '') {
-    $req_host_arch = &gnu_to_debian ($req_host_gnu_type);
+    $req_host_arch = debtriplet_to_debarch(gnutriplet_to_debtriplet($req_host_gnu_type));
     die (sprintf(_g("unknown GNU system type %s, you must specify Debian architecture, too"), $req_host_gnu_type)) unless defined $req_host_arch;
 }
 
 if ($req_host_gnu_type ne '' && $req_host_arch ne '') {
-    my $dfl_host_gnu_type = debian_to_gnu($req_host_arch);
+    my $dfl_host_gnu_type = debtriplet_to_gnutriplet(debarch_to_debtriplet($req_host_arch));
+    die (sprintf(_g("unknown default GNU system type for Debian architecture %s"),
+                 $req_host_arch))
+	unless defined $dfl_host_gnu_type;
     warning(sprintf(_g("Default GNU system type %s for Debian arch %s does not match specified GNU system type %s"), $dfl_host_gnu_type, $req_host_arch, $req_host_gnu_type)) if $dfl_host_gnu_type ne $req_host_gnu_type;
 }
 
@@ -182,10 +183,10 @@ $deb_host_gnu_type = $req_host_gnu_type if $req_host_gnu_type ne '';
 warning(sprintf(_g("Specified GNU system type %s does not match gcc system type %s."), $deb_host_gnu_type, $gcc)) if !($req_is_arch or $req_eq_arch) && ($gcc ne '') && ($gcc ne $deb_host_gnu_type);
 
 # Split the Debian and GNU names
-my ($deb_host_arch_os, $deb_host_arch_cpu) = split_debian($deb_host_arch);
-my ($deb_build_arch_os, $deb_build_arch_cpu) = split_debian($deb_build_arch);
-my ($deb_host_gnu_cpu, $deb_host_gnu_system) = split_gnu($deb_host_gnu_type);
-my ($deb_build_gnu_cpu, $deb_build_gnu_system) = split_gnu($deb_build_gnu_type);
+my ($deb_host_arch_abi, $deb_host_arch_os, $deb_host_arch_cpu) = debarch_to_debtriplet($deb_host_arch);
+my ($deb_build_arch_abi, $deb_build_arch_os, $deb_build_arch_cpu) = debarch_to_debtriplet($deb_build_arch);
+my ($deb_host_gnu_cpu, $deb_host_gnu_system) = split(/-/, $deb_host_gnu_type, 2);
+my ($deb_build_gnu_cpu, $deb_build_gnu_system) = split(/-/, $deb_build_gnu_type, 2);
 
 my %env = ();
 if (!$force) {

+ 14 - 0
triplettable

@@ -0,0 +1,14 @@
+# Bidirectional mapping between a Debian triplet and a Debian arch.
+#
+# Supported variables: <cpu>
+#
+# <Debian triplet>	<Debian arch>
+gnu-linux-<cpu>		<cpu>
+gnu-kfreebsd-<cpu>	kfreebsd-<cpu>
+gnu-knetbsd-<cpu>	knetbsd-<cpu>
+gnu-hurd-<cpu>		hurd-<cpu>
+bsd-freebsd-<cpu>	freebsd-<cpu>
+bsd-openbsd-<cpu>	openbsd-<cpu>
+bsd-netbsd-<cpu>	netbsd-<cpu>
+bsd-darwin-<cpu>	darwin-<cpu>
+