/usr/bin/dpkg-architecture is in dpkg-dev 1.18.25.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | #!/usr/bin/perl
#
# dpkg-architecture
#
# Copyright © 1999-2001 Marcus Brinkmann <brinkmd@debian.org>
# Copyright © 2004-2005 Scott James Remnant <scott@netsplit.com>,
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use warnings;
use Dpkg ();
use Dpkg::Gettext;
use Dpkg::Getopt;
use Dpkg::ErrorHandling;
use Dpkg::Arch qw(:getters :mappers debarch_eq debarch_is);
textdomain('dpkg-dev');
sub version {
printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
printf g_('
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
');
}
sub usage {
printf g_(
'Usage: %s [<option>...] [<command>]')
. "\n\n" . g_(
'Commands:
-l, --list list variables (default).
-L, --list-known list valid architectures (matching some criteria).
-e, --equal <arch> compare with host Debian architecture.
-i, --is <arch-wildcard> match against host Debian architecture.
-q, --query <variable> prints only the value of <variable>.
-s, --print-set print command to set environment variables.
-u, --print-unset print command to unset environment variables.
-c, --command <command> set environment and run the command in it.
-?, --help show this help message.
--version show the version.')
. "\n\n" . g_(
'Options:
-a, --host-arch <arch> set host Debian architecture.
-t, --host-type <type> set host GNU system type.
-A, --target-arch <arch> set target Debian architecture.
-T, --target-type <type> set target GNU system type.
-W, --match-wildcard <arch-wildcard>
restrict architecture list matching <arch-wildcard>.
-B, --match-bits <arch-bits>
restrict architecture list matching <arch-bits>.
-E, --match-endian <arch-endian>
restrict architecture list matching <arch-endian>.
-f, --force force flag (override variables set in environment).')
. "\n", $Dpkg::PROGNAME;
}
sub check_arch_coherency
{
my ($arch, $gnu_type) = @_;
if ($arch ne '' && $gnu_type eq '') {
$gnu_type = debarch_to_gnutriplet($arch);
error(g_('unknown Debian architecture %s, you must specify ' .
'GNU system type, too'), $arch)
unless defined $gnu_type;
}
if ($gnu_type ne '' && $arch eq '') {
$arch = gnutriplet_to_debarch($gnu_type);
error(g_('unknown GNU system type %s, you must specify ' .
'Debian architecture, too'), $gnu_type)
unless defined $arch;
}
if ($gnu_type ne '' && $arch ne '') {
my $dfl_gnu_type = debarch_to_gnutriplet($arch);
error(g_('unknown default GNU system type for Debian architecture %s'),
$arch)
unless defined $dfl_gnu_type;
warning(g_('default GNU system type %s for Debian arch %s does not ' .
'match specified GNU system type %s'), $dfl_gnu_type,
$arch, $gnu_type)
if $dfl_gnu_type ne $gnu_type;
}
return ($arch, $gnu_type);
}
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_TARGET |
DEB_ARCH_INFO | DEB_ARCH_ATTR |
DEB_MULTIARCH | DEB_GNU_INFO;
my %arch_vars = (
DEB_BUILD_ARCH => DEB_BUILD,
DEB_BUILD_ARCH_ABI => DEB_BUILD | DEB_ARCH_INFO,
DEB_BUILD_ARCH_LIBC => DEB_BUILD | DEB_ARCH_INFO,
DEB_BUILD_ARCH_OS => DEB_BUILD | DEB_ARCH_INFO,
DEB_BUILD_ARCH_CPU => DEB_BUILD | DEB_ARCH_INFO,
DEB_BUILD_ARCH_BITS => DEB_BUILD | DEB_ARCH_ATTR,
DEB_BUILD_ARCH_ENDIAN => DEB_BUILD | DEB_ARCH_ATTR,
DEB_BUILD_MULTIARCH => DEB_BUILD | DEB_MULTIARCH,
DEB_BUILD_GNU_CPU => DEB_BUILD | DEB_GNU_INFO,
DEB_BUILD_GNU_SYSTEM => DEB_BUILD | DEB_GNU_INFO,
DEB_BUILD_GNU_TYPE => DEB_BUILD | DEB_GNU_INFO,
DEB_HOST_ARCH => DEB_HOST,
DEB_HOST_ARCH_ABI => DEB_HOST | DEB_ARCH_INFO,
DEB_HOST_ARCH_LIBC => DEB_HOST | DEB_ARCH_INFO,
DEB_HOST_ARCH_OS => DEB_HOST | DEB_ARCH_INFO,
DEB_HOST_ARCH_CPU => DEB_HOST | DEB_ARCH_INFO,
DEB_HOST_ARCH_BITS => DEB_HOST | DEB_ARCH_ATTR,
DEB_HOST_ARCH_ENDIAN => DEB_HOST | DEB_ARCH_ATTR,
DEB_HOST_MULTIARCH => DEB_HOST | DEB_MULTIARCH,
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_ABI => DEB_TARGET | DEB_ARCH_INFO,
DEB_TARGET_ARCH_LIBC => DEB_TARGET | DEB_ARCH_INFO,
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_match_wildcard = '';
my $req_match_bits = '';
my $req_match_endian = '';
my $req_variable_to_print;
my $action = 'list';
my $force = 0;
sub action_needs($) {
my $bits = shift;
return (($req_vars & $bits) == $bits);
}
@ARGV = normalize_options(args => \@ARGV, delim => '-c');
while (@ARGV) {
my $arg = shift;
if ($arg eq '-a' or $arg eq '--host-arch') {
$req_host_arch = shift;
} elsif ($arg eq '-t' or $arg eq '--host-type') {
$req_host_gnu_type = shift;
} elsif ($arg eq '-A' or $arg eq '--target-arch') {
$req_target_arch = shift;
} elsif ($arg eq '-T' or $arg eq '--target-type') {
$req_target_gnu_type = shift;
} elsif ($arg eq '-W' or $arg eq '--match-wildcard') {
$req_match_wildcard = shift;
} elsif ($arg eq '-B' or $arg eq '--match-bits') {
$req_match_bits = shift;
} elsif ($arg eq '-E' or $arg eq '--match-endian') {
$req_match_endian = shift;
} elsif ($arg eq '-e' or $arg eq '--equal') {
$req_eq_arch = shift;
$req_vars = $arch_vars{DEB_HOST_ARCH};
$action = 'equal';
} elsif ($arg eq '-i' or $arg eq '--is') {
$req_is_arch = shift;
$req_vars = $arch_vars{DEB_HOST_ARCH};
$action = 'is';
} elsif ($arg eq '-u' or $arg eq '--print-unset') {
$req_vars = DEB_NONE;
$action = 'print-unset';
} elsif ($arg eq '-l' or $arg eq '--list') {
$action = 'list';
} elsif ($arg eq '-s' or $arg eq '--print-set') {
$req_vars = DEB_ALL;
$action = 'print-set';
} elsif ($arg eq '-f' or $arg eq '--force') {
$force=1;
} elsif ($arg eq '-q' or $arg eq '--query') {
my $varname = shift;
error(g_('%s is not a supported variable name'), $varname)
unless (exists $arch_vars{$varname});
$req_variable_to_print = "$varname";
$req_vars = $arch_vars{$varname};
$action = 'query';
} elsif ($arg eq '-c' or $arg eq '--command') {
$action = 'command';
last;
} elsif ($arg eq '-L' or $arg eq '--list-known') {
$req_vars = 0;
$action = 'list-known';
} elsif ($arg eq '-?' or $arg eq '--help') {
usage();
exit 0;
} elsif ($arg eq '--version') {
version();
exit 0;
} else {
usageerr(g_("unknown option '%s'"), $arg);
}
}
my %v;
#
# Set build variables
#
$v{DEB_BUILD_ARCH} = get_raw_build_arch()
if (action_needs(DEB_BUILD));
($v{DEB_BUILD_ARCH_ABI}, $v{DEB_BUILD_ARCH_LIBC},
$v{DEB_BUILD_ARCH_OS}, $v{DEB_BUILD_ARCH_CPU}) = debarch_to_debtuple($v{DEB_BUILD_ARCH})
if (action_needs(DEB_BUILD | DEB_ARCH_INFO));
($v{DEB_BUILD_ARCH_BITS}, $v{DEB_BUILD_ARCH_ENDIAN}) = debarch_to_cpuattrs($v{DEB_BUILD_ARCH})
if (action_needs(DEB_BUILD | DEB_ARCH_ATTR));
$v{DEB_BUILD_MULTIARCH} = debarch_to_multiarch($v{DEB_BUILD_ARCH})
if (action_needs(DEB_BUILD | DEB_MULTIARCH));
if (action_needs(DEB_BUILD | DEB_GNU_INFO)) {
$v{DEB_BUILD_GNU_TYPE} = debarch_to_gnutriplet($v{DEB_BUILD_ARCH});
($v{DEB_BUILD_GNU_CPU}, $v{DEB_BUILD_GNU_SYSTEM}) = split(/-/, $v{DEB_BUILD_GNU_TYPE}, 2);
}
#
# Set host variables
#
# First perform some sanity checks on the host arguments passed.
($req_host_arch, $req_host_gnu_type) = check_arch_coherency($req_host_arch, $req_host_gnu_type);
# Proceed to compute the host variables if needed.
$v{DEB_HOST_ARCH} = $req_host_arch || get_raw_host_arch()
if (action_needs(DEB_HOST));
($v{DEB_HOST_ARCH_ABI}, $v{DEB_HOST_ARCH_LIBC},
$v{DEB_HOST_ARCH_OS}, $v{DEB_HOST_ARCH_CPU}) = debarch_to_debtuple($v{DEB_HOST_ARCH})
if (action_needs(DEB_HOST | DEB_ARCH_INFO));
($v{DEB_HOST_ARCH_BITS}, $v{DEB_HOST_ARCH_ENDIAN}) = debarch_to_cpuattrs($v{DEB_HOST_ARCH})
if (action_needs(DEB_HOST | DEB_ARCH_ATTR));
$v{DEB_HOST_MULTIARCH} = debarch_to_multiarch($v{DEB_HOST_ARCH})
if (action_needs(DEB_HOST | DEB_MULTIARCH));
if (action_needs(DEB_HOST | DEB_GNU_INFO)) {
if ($req_host_gnu_type eq '') {
$v{DEB_HOST_GNU_TYPE} = debarch_to_gnutriplet($v{DEB_HOST_ARCH});
} else {
$v{DEB_HOST_GNU_TYPE} = $req_host_gnu_type;
}
($v{DEB_HOST_GNU_CPU}, $v{DEB_HOST_GNU_SYSTEM}) = split(/-/, $v{DEB_HOST_GNU_TYPE}, 2);
my $host_gnu_type = get_host_gnu_type();
warning(g_('specified GNU system type %s does not match CC system ' .
'type %s, try setting a correct CC environment variable'),
$v{DEB_HOST_GNU_TYPE}, $host_gnu_type)
if ($host_gnu_type ne '') && ($host_gnu_type 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.
$v{DEB_TARGET_ARCH} = $req_target_arch || $req_host_arch || get_raw_host_arch()
if (action_needs(DEB_TARGET));
($v{DEB_TARGET_ARCH_ABI}, $v{DEB_TARGET_ARCH_LIBC},
$v{DEB_TARGET_ARCH_OS}, $v{DEB_TARGET_ARCH_CPU}) = debarch_to_debtuple($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);
}
if ($action eq 'list') {
foreach my $k (sort keys %arch_vars) {
print "$k=$v{$k}\n";
}
} elsif ($action eq 'print-set') {
foreach my $k (sort keys %arch_vars) {
print "$k=$v{$k}; ";
}
print 'export ' . join(' ', sort keys %arch_vars) . "\n";
} elsif ($action eq 'print-unset') {
print 'unset ' . join(' ', sort keys %arch_vars) . "\n";
} elsif ($action eq 'equal') {
exit !debarch_eq($v{DEB_HOST_ARCH}, $req_eq_arch);
} elsif ($action eq 'is') {
exit !debarch_is($v{DEB_HOST_ARCH}, $req_is_arch);
} elsif ($action eq 'command') {
@ENV{keys %v} = values %v;
exec @ARGV;
} elsif ($action eq 'query') {
print "$v{$req_variable_to_print}\n";
} elsif ($action eq 'list-known') {
foreach my $arch (get_valid_arches()) {
my ($bits, $endian) = debarch_to_cpuattrs($arch);
next if $req_match_endian and $endian ne $req_match_endian;
next if $req_match_bits and $bits ne $req_match_bits;
next if $req_match_wildcard and not debarch_is($arch, $req_match_wildcard);
print "$arch\n";
}
}
|