0
  A   ˆl–Ü4ý(TÐ;â�À·q ©‹Fÿ�þYŒ.¬ãDp¢�‘¶�üÿÅ„a¿Ä_ˆI|¥�+V[(ÄÃ ;    # Copyright Â© 2006-2015 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/>.

package Dpkg::Arch;

=encoding utf8

=head1 NAME

Dpkg::Arch - handle architectures

=head1 DESCRIPTION

The Dpkg::Arch module provides functions to handle Debian architectures,
wildcards, and mapping from and to GNU triplets.

No symbols are exported by default. The :all tag can be used to import all
symbols. The :getters, :parsers, :mappers and :operators tags can be used
to import specific symbol subsets.

=cut

use strict;
use warnings;
use feature qw(state);

our $VERSION = '1.03';
our @EXPORT_OK = qw(
    get_raw_build_arch
    get_raw_host_arch
    get_build_arch
    get_host_arch
    get_host_gnu_type
    get_valid_arches
    debarch_eq
    debarch_is
    debarch_is_wildcard
    debarch_is_illegal
    debarch_is_concerned
    debarch_to_abiattrs
    debarch_to_cpubits
    debarch_to_gnutriplet
    debarch_to_debtuple
    debarch_to_multiarch
    debarch_list_parse
    debtuple_to_debarch
    debtuple_to_gnutriplet
    gnutriplet_to_debarch
    gnutriplet_to_debtuple
    gnutriplet_to_multiarch
);
our %EXPORT_TAGS = (
    all => [ @EXPORT_OK ],
    getters => [ qw(
        get_raw_build_arch
        get_raw_host_arch
        get_build_arch
        get_host_arch
        get_host_gnu_type
        get_valid_arches
    ) ],
    parsers => [ qw(
        debarch_list_parse
    ) ],
    mappers => [ qw(
        debarch_to_abiattrs
        debarch_to_gnutriplet
        debarch_to_debtuple
        debarch_to_multiarch
        debtuple_to_debarch
        debtuple_to_gnutriplet
        gnutriplet_to_debarch
        gnutriplet_to_debtuple
        gnutriplet_to_multiarch
    ) ],
    operators => [ qw(
        debarch_eq
        debarch_is
        debarch_is_wildcard
        debarch_is_illegal
        debarch_is_concerned
    ) ],
);


use Exporter qw(import);
use List::Util qw(any);

use Dpkg ();
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::BuildEnv;

my (@cpu, @os);
my (%cputable, %ostable);
my (%cputable_re, %ostable_re);
my (%cpubits, %cpuendian);
my %abibits;

my %debtuple_to_debarch;
my %debarch_to_debtuple;

=head1 FUNCTIONS

=over 4

=item $arch = get_raw_build_arch()

Get the raw build Debian architecture, without taking into account variables
from the environment.

=cut

sub get_raw_build_arch()
{
    state $build_arch;

    return $build_arch if defined $build_arch;

    # Note: We *always* require an installed dpkg when inferring the
    # build architecture. The bootstrapping case is handled by
    # dpkg-architecture itself, by avoiding computing the DEB_BUILD_
    # variables when they are not requested.

    ## no critic (TestingAndDebugging::ProhibitNoWarnings)
    no warnings qw(exec);
    $build_arch = qx(dpkg --print-architecture);
    syserr('dpkg --print-architecture failed') if $? >> 8;

    chomp $build_arch;
    return $build_arch;
}

=item $arch = get_build_arch()

Get the build Debian architecture, using DEB_BUILD_ARCH from the environment
if available.

=cut

sub get_build_arch()
{
    return Dpkg::BuildEnv::get('DEB_BUILD_ARCH') || get_raw_build_arch();
}

{
    my %cc_host_gnu_type;

    sub get_host_gnu_type()
    {
        my $CC = $ENV{CC} || 'gcc';

        return $cc_host_gnu_type{$CC} if defined $cc_host_gnu_type{$CC};

        ## no critic (TestingAndDebugging::ProhibitNoWarnings)
        no warnings qw(exec);
   