Parcourir la source

dpkg-architecture: Add support for target information

This adds support for the DEB_TARGET_ family of variables, which denote
the machine the compiler should be building for.

If the user did not specify them on the command line they will default
to the host architecture.
Guillem Jover il y a 12 ans
Parent
commit
f29ed62d0c
3 fichiers modifiés avec 89 ajouts et 3 suppressions
  1. 4 0
      debian/changelog
  2. 30 1
      man/dpkg-architecture.1
  3. 55 2
      scripts/dpkg-architecture.pl

+ 4 - 0
debian/changelog

@@ -10,6 +10,10 @@ dpkg (1.17.14) UNRELEASED; urgency=low
   * Fix compiler flag detection with non-GCC compilers in the build system.
   * Fix perl warning on dpkg-source when typing Ctrl-D on patch name prompt.
   * Add new dpkg-deb --ctrl-tarfile command.
+  * dpkg-architecture:
+    - Add support for target system information via the new DEB_TARGET_ family
+      of variables, and new -A and -T options to override defaulting to the
+      host system.
 
   [ Raphaël Hertzog ]
   * Explain better in deb-triggers(5) why interest/activate-noawait should be

+ 30 - 1
man/dpkg-architecture.1

@@ -2,7 +2,7 @@
 .\"
 .\" Copyright © 2005 Marcus Brinkmann <brinkmd@debian.org>
 .\" Copyright © 2005 Scott James Remnant <scott@netsplit.com>
-.\" Copyright © 2006-2013 Guillem Jover <guillem@debian.org>
+.\" Copyright © 2006-2014 Guillem Jover <guillem@debian.org>
 .\" Copyright © 2009-2012 Raphaël Hertzog <hertzog@debian.org>
 .\"
 .\" This is free software; you can redistribute it and/or modify
@@ -94,6 +94,14 @@ Set the Debian architecture.
 .BI \-t gnu-system-type
 Set the GNU system type.
 .TP
+.BI \-A debian-architecture
+Set the target Debian architecture. This is only needed when building a
+cross-toolchain, one that will be built on the build architecture, to be
+run on the host architecture, and to build code for the target architecture.
+.TP
+.BI \-T gnu-system-type
+Set the target GNU system type.
+.TP
 .B \-f
 Values set by existing environment variables with the same name as used by
 the scripts are honored (i.e. used by \fBdpkg\-architecture\fP), except if
@@ -106,6 +114,8 @@ in some other script (for example \fBdpkg\-buildpackage\fP(1)).
 The machine the package is built on.
 .IP "host machine" 4
 The machine the package is built for.
+.IP "target machine" 4
+The machine the compiler is building for.
 .IP "Debian architecture" 4
 The Debian architecture string, which specifies the binary tree in the
 FTP archive. Examples: i386, sparc, hurd\-i386.
@@ -158,6 +168,25 @@ The GNU system type of the host machine.
 .IP "\fBDEB_HOST_MULTIARCH\fP" 4
 The clarified GNU system type of the host machine, used for filesystem
 paths (since dpkg 1.16.0).
+.IP "\fBDEB_TARGET_ARCH\fP" 4
+The Debian architecture of the target machine (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_ARCH_OS\fP" 4
+The Debian system name of the target machine (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_ARCH_CPU\fP" 4
+The Debian cpu name of the target machine (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_ARCH_BITS\fP" 4
+The pointer size of the target machine (in bits; since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_ARCH_ENDIAN\fP" 4
+The endianness of the target machine (little / big; since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_GNU_CPU\fP" 4
+The CPU part of \fBDEB_TARGET_GNU_TYPE\fP (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_GNU_SYSTEM\fP" 4
+The System part of \fBDEB_TARGET_GNU_TYPE\fP (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_GNU_TYPE\fP" 4
+The GNU system type of the target machine (since dpkg 1.17.14).
+.IP "\fBDEB_TARGET_MULTIARCH\fP" 4
+The clarified GNU system type of the target machine, used for filesystem
+paths (since dpkg 1.17.14).
 .
 .SH FILES
 .SS Architecture tables

+ 55 - 2
scripts/dpkg-architecture.pl

@@ -4,7 +4,7 @@
 #
 # Copyright © 1999-2001 Marcus Brinkmann <brinkmd@debian.org>
 # Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>,
-# Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
+# Copyright © 2006-2014 Guillem Jover <guillem@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -49,6 +49,8 @@ sub usage {
 'Options:
   -a<debian-arch>    set current Debian architecture.
   -t<gnu-system>     set current GNU system type.
+  -A<debian-arch>    set target Debian architecture.
+  -T<gnu-system>     set target GNU system type.
   -f                 force flag (override variables set in environment).')
     . "\n\n" . _g(
 'Commands:
@@ -108,13 +110,15 @@ use constant {
     DEB_NONE => 0,
     DEB_BUILD => 1,
     DEB_HOST => 2,
+    DEB_TARGET => 64,
     DEB_ARCH_INFO => 4,
     DEB_ARCH_ATTR => 8,
     DEB_MULTIARCH => 16,
     DEB_GNU_INFO => 32,
 };
 
-use constant DEB_ALL => DEB_BUILD | DEB_HOST | DEB_ARCH_INFO | DEB_ARCH_ATTR |
+use constant DEB_ALL => DEB_BUILD | DEB_HOST | DEB_TARGET |
+                        DEB_ARCH_INFO | DEB_ARCH_ATTR |
                         DEB_MULTIARCH | DEB_GNU_INFO;
 
 my %arch_vars = (
@@ -136,11 +140,22 @@ my %arch_vars = (
     DEB_HOST_GNU_CPU => DEB_HOST | DEB_GNU_INFO,
     DEB_HOST_GNU_SYSTEM => DEB_HOST | DEB_GNU_INFO,
     DEB_HOST_GNU_TYPE => DEB_HOST | DEB_GNU_INFO,
+    DEB_TARGET_ARCH => DEB_TARGET,
+    DEB_TARGET_ARCH_OS => DEB_TARGET | DEB_ARCH_INFO,
+    DEB_TARGET_ARCH_CPU => DEB_TARGET | DEB_ARCH_INFO,
+    DEB_TARGET_ARCH_BITS => DEB_TARGET | DEB_ARCH_ATTR,
+    DEB_TARGET_ARCH_ENDIAN => DEB_TARGET | DEB_ARCH_ATTR,
+    DEB_TARGET_MULTIARCH => DEB_TARGET | DEB_MULTIARCH,
+    DEB_TARGET_GNU_CPU => DEB_TARGET | DEB_GNU_INFO,
+    DEB_TARGET_GNU_SYSTEM => DEB_TARGET | DEB_GNU_INFO,
+    DEB_TARGET_GNU_TYPE => DEB_TARGET | DEB_GNU_INFO,
 );
 
 my $req_vars = DEB_ALL;
 my $req_host_arch = '';
 my $req_host_gnu_type = '';
+my $req_target_arch = '';
+my $req_target_gnu_type = '';
 my $req_eq_arch = '';
 my $req_is_arch = '';
 my $req_variable_to_print;
@@ -158,6 +173,10 @@ while (@ARGV) {
 	$req_host_arch = ${^POSTMATCH};
     } elsif (m/^-t/p) {
 	$req_host_gnu_type = ${^POSTMATCH};
+    } elsif (m/^-A/p) {
+	$req_target_arch = ${^POSTMATCH};
+    } elsif (m/^-T/p) {
+	$req_target_gnu_type = ${^POSTMATCH};
     } elsif (m/^-e/p) {
 	$req_eq_arch = ${^POSTMATCH};
 	$req_vars = $arch_vars{DEB_HOST_ARCH};
@@ -261,6 +280,40 @@ if (action_needs(DEB_HOST | DEB_GNU_INFO)) {
         if ($gcc ne '') && ($gcc ne $v{DEB_HOST_GNU_TYPE});
 }
 
+#
+# Set target variables
+#
+
+# First perform some sanity checks on the target arguments passed.
+
+($req_target_arch, $req_target_gnu_type) = check_arch_coherency($req_target_arch, $req_target_gnu_type);
+
+# Proceed to compute the target variables if needed.
+
+if (action_needs(DEB_TARGET)) {
+    if ($req_target_arch eq '') {
+        $v{DEB_TARGET_ARCH} = $v{DEB_HOST_ARCH};
+    } else {
+        $v{DEB_TARGET_ARCH} = $req_target_arch;
+    }
+}
+($abi, $v{DEB_TARGET_ARCH_OS}, $v{DEB_TARGET_ARCH_CPU}) = debarch_to_debtriplet($v{DEB_TARGET_ARCH})
+    if (action_needs(DEB_TARGET | DEB_ARCH_INFO));
+($v{DEB_TARGET_ARCH_BITS}, $v{DEB_TARGET_ARCH_ENDIAN}) = debarch_to_cpuattrs($v{DEB_TARGET_ARCH})
+    if (action_needs(DEB_TARGET | DEB_ARCH_ATTR));
+
+$v{DEB_TARGET_MULTIARCH} = debarch_to_multiarch($v{DEB_TARGET_ARCH})
+    if (action_needs(DEB_TARGET | DEB_MULTIARCH));
+
+if (action_needs(DEB_TARGET | DEB_GNU_INFO)) {
+    if ($req_target_gnu_type eq '') {
+        $v{DEB_TARGET_GNU_TYPE} = debarch_to_gnutriplet($v{DEB_TARGET_ARCH});
+    } else {
+        $v{DEB_TARGET_GNU_TYPE} = $req_target_gnu_type;
+    }
+    ($v{DEB_TARGET_GNU_CPU}, $v{DEB_TARGET_GNU_SYSTEM}) = split(/-/, $v{DEB_TARGET_GNU_TYPE}, 2);
+}
+
 
 for my $k (keys %arch_vars) {
     $v{$k} = $ENV{$k} if (length $ENV{$k} && !$force);