1 #!/bin/sh
  2 #
  3 # Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
  4 # Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
  5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6 #
  7 # This code is free software; you can redistribute it and/or modify it
  8 # under the terms of the GNU General Public License version 2 only, as
  9 # published by the Free Software Foundation.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 # This is a wrapper for the config.guess from autoconf. The latter does not
 27 # properly detect 64 bit systems on all platforms. Instead of patching the
 28 # autoconf system (which might easily get lost in a future update), we wrap it
 29 # and fix the broken property, if needed.
 30 
 31 DIR=`dirname $0`
 32 OUT=`. $DIR/autoconf-config.guess`
 33 
 34 # Detect C library.
 35 # Use '-gnu'  suffix on systems that use glibc.
 36 # Use '-musl' suffix on systems that use the musl libc.
 37 echo $OUT | grep -- -linux- > /dev/null 2> /dev/null
 38 if test $? = 0; then
 39   libc_vendor=`ldd --version 2>&1 | sed -n '1s/.*\(musl\).*/\1/p'`
 40   if [ x"${libc_vendor}" = x"musl" ]; then
 41     OUT=`echo $OUT | sed 's/-gnu/-musl/'`
 42   fi
 43 fi
 44 
 45 # Test and fix cygwin on x86_64
 46 echo $OUT | grep 86-pc-cygwin > /dev/null 2> /dev/null
 47 if test $? != 0; then
 48   echo $OUT | grep 86-pc-mingw > /dev/null 2> /dev/null
 49 fi
 50 if test $? = 0; then
 51   case `echo $PROCESSOR_IDENTIFIER | cut -f1 -d' '` in
 52     intel64|Intel64|INTEL64|em64t|EM64T|amd64|AMD64|8664|x86_64)
 53       REAL_CPU=x86_64
 54       OUT=$REAL_CPU`echo $OUT | sed -e 's/[^-]*//'`
 55       ;;
 56   esac
 57 fi
 58 
 59 # Test and fix wsl
 60 echo $OUT | grep unknown-linux-gnu > /dev/null 2> /dev/null
 61 if test $? = 0; then
 62   uname -r | grep -i microsoft > /dev/null 2> /dev/null
 63   if test $? = 0; then
 64     OUT=`echo $OUT | sed -e 's/unknown-linux-gnu/pc-wsl/'`
 65   fi
 66 fi
 67 
 68 # Test and fix architecture string on AIX
 69 # On AIX 'config.guess' returns 'powerpc' as architecture but 'powerpc' is
 70 # implicitely handled as 32-bit architecture in 'platform.m4' so we check
 71 # for the kernel mode rewrite it to 'powerpc64' if we'Re running in 64-bit mode.
 72 # The check could also be done with `/usr/sbin/prtconf | grep "Kernel Type" | grep "64-bit"`
 73 echo $OUT | grep powerpc-ibm-aix > /dev/null 2> /dev/null
 74 if test $? = 0; then
 75   if [ -x /bin/getconf ] ; then
 76     KERNEL_BITMODE=`getconf KERNEL_BITMODE`
 77     if  [ "$KERNEL_BITMODE" = "32" ]; then
 78       KERNEL_BITMODE=""
 79     fi
 80   fi
 81   OUT=powerpc$KERNEL_BITMODE`echo $OUT | sed -e 's/[^-]*//'`
 82 fi
 83 
 84 # Test and fix little endian PowerPC64.
 85 # TODO: should be handled by autoconf-config.guess.
 86 if [ "x$OUT" = x ]; then
 87   if [ `uname -m` = ppc64le ]; then
 88     if [ `uname -s` = Linux ]; then
 89       OUT=powerpc64le-unknown-linux-gnu
 90     fi
 91   fi
 92 fi
 93 
 94 # Test and fix little endian MIPS.
 95 if [ "x$OUT" = x ]; then
 96   if [ `uname -s` = Linux ]; then
 97     if [ `uname -m` = mipsel ]; then
 98       OUT=mipsel-unknown-linux-gnu
 99     elif [ `uname -m` = mips64el ]; then
100       OUT=mips64el-unknown-linux-gnu
101     fi
102   fi
103 fi
104 
105 # Test and fix LoongArch64.
106 if [ "x$OUT" = x ]; then
107   if [ `uname -s` = Linux ]; then
108     if [ `uname -m` = loongarch64 ]; then
109       OUT=loongarch64-unknown-linux-gnu
110     fi
111   fi
112 fi
113 
114 # Test and fix cpu on macos-aarch64, uname -p reports arm, buildsys expects aarch64
115 echo $OUT | grep arm-apple-darwin > /dev/null 2> /dev/null
116 if test $? != 0; then
117   # The GNU version of uname may be on the PATH which reports arm64 instead
118   echo $OUT | grep arm64-apple-darwin > /dev/null 2> /dev/null
119 fi
120 if test $? = 0; then
121   if [ `uname -m` = arm64 ]; then
122     OUT=aarch64`echo $OUT | sed -e 's/[^-]*//'`
123   fi
124 fi
125 
126 # Test and fix cpu on Macosx when C preprocessor is not on the path
127 echo $OUT | grep i386-apple-darwin > /dev/null 2> /dev/null
128 if test $? = 0; then
129   REAL_CPU=`uname -m`
130   OUT=$REAL_CPU`echo $OUT | sed -e 's/[^-]*//'`
131 fi
132 
133 echo $OUT