summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUwe Kleine-König <uwe@kleine-koenig.org>2019-02-15 11:14:27 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-02-25 23:01:04 +0100
commit5b6d9e9cdd559268a64ecf8d071cfb678855fa06 (patch)
treeaeface925545208799fcd5ea07487d19df0ff25e
parent9e7712272fea017c6e3dcf29dc321990028159c8 (diff)
downloadsparse-5b6d9e9cdd559268a64ecf8d071cfb678855fa06.tar.gz
cgcc: favor using 'gcc -dumpmachine' to determine specifics
`uname -m` returns information about the host machine but this information is useless when cgcc is used with a non-native compiler since it's information about the target machine that is needed. So, first try to determine the target machine via `gcc -dumpmachine` and default to `uname -m`. Note: this should fix problems with Debian build when armhf builder is run on a arm64 environment. Originally-by: Uwe Kleine-König <uwe@kleine-koenig.org> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rwxr-xr-xcgcc33
1 files changed, 28 insertions, 5 deletions
diff --git a/cgcc b/cgcc
index 88681983..389cedb2 100755
--- a/cgcc
+++ b/cgcc
@@ -338,7 +338,34 @@ sub add_specs {
chomp $os;
return &add_specs (lc $os);
} elsif ($spec eq 'host_arch_specs') {
- my $arch = `uname -m`;
+ my $gccmachine;
+ my $arch;
+
+ $gccmachine = `$ccom -dumpmachine`;
+ chomp $gccmachine;
+
+ if ($gccmachine =~ '^aarch64-') {
+ return &add_specs ('aarch64');
+ } elsif ($gccmachine =~ '^arm-.*eabihf$') {
+ return &add_specs ('arm+hf');
+ } elsif ($gccmachine =~ '^arm-') {
+ return &add_specs ('arm');
+ } elsif ($gccmachine =~ '^i[23456]86-') {
+ return &add_specs ('i386');
+ } elsif ($gccmachine =~ '^(powerpc|ppc)64le-') {
+ return &add_specs ('ppc64+le');
+ } elsif ($gccmachine =~ '^s390x-') {
+ return &add_specs ('s390x');
+ } elsif ($gccmachine eq 'x86_64-linux-gnu') {
+ return &add_specs ('x86_64');
+ }
+
+ # fall back to uname -m to determine the specifics.
+ # Note: this is only meaningful when using natively
+ # since information about the host is used to
+ # guess characteristics of the target.
+
+ $arch = `uname -m`;
chomp $arch;
if ($arch =~ /^(i.?86|athlon)$/i) {
return &add_specs ('i386');
@@ -357,10 +384,6 @@ sub add_specs {
} elsif ($arch =~ /^(sparc64)$/i) {
return &add_specs ('sparc64');
} elsif ($arch =~ /^arm(?:v[78]l)?$/i) {
- chomp (my $gccmachine = `$ccom -dumpmachine`);
- if ($gccmachine eq 'arm-linux-gnueabihf') {
- return &add_specs ('arm+hf');
- }
return &add_specs ('arm');
} elsif ($arch =~ /^(aarch64)$/i) {
return &add_specs ('aarch64');