|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 1999-2020 Gentoo Authors |
| 3 | +# Distributed under the terms of the GNU General Public License v2 |
| 4 | +# |
| 5 | +# Openssl doesn't play along nicely with cross-compiling |
| 6 | +# like autotools based projects, so let's teach it new tricks. |
| 7 | +# |
| 8 | +# Review the bundled 'config' script to see why kind of targets |
| 9 | +# we can pass to the 'Configure' script. |
| 10 | + |
| 11 | + |
| 12 | +# Testing routines |
| 13 | +if [[ $1 == "test" ]] ; then |
| 14 | + for c in \ |
| 15 | + "arm-gentoo-linux-uclibc |linux-generic32 -DL_ENDIAN" \ |
| 16 | + "armv5b-linux-gnu |linux-armv4 -DB_ENDIAN" \ |
| 17 | + "x86_64-pc-linux-gnu |linux-x86_64" \ |
| 18 | + "alpha-linux-gnu |linux-alpha-gcc" \ |
| 19 | + "alphaev56-unknown-linux-gnu |linux-alpha+bwx-gcc" \ |
| 20 | + "i686-pc-linux-gnu |linux-elf" \ |
| 21 | + "whatever-gentoo-freebsdX.Y |BSD-generic32" \ |
| 22 | + "i686-gentoo-freebsdX.Y |BSD-x86-elf" \ |
| 23 | + "sparc64-alpha-freebsdX.Y |BSD-sparc64" \ |
| 24 | + "ia64-gentoo-freebsd5.99234 |BSD-ia64" \ |
| 25 | + "x86_64-gentoo-freebsdX.Y |BSD-x86_64" \ |
| 26 | + "hppa64-aldsF-linux-gnu5.3 |linux-generic32 -DB_ENDIAN" \ |
| 27 | + "powerpc-gentOO-linux-uclibc |linux-ppc" \ |
| 28 | + "powerpc64-unk-linux-gnu |linux-ppc64" \ |
| 29 | + "powerpc64le-linux-gnu |linux-ppc64le" \ |
| 30 | + "x86_64-apple-darwinX |darwin64-x86_64-cc" \ |
| 31 | + "powerpc64-apple-darwinX |darwin64-ppc-cc" \ |
| 32 | + "i686-apple-darwinX |darwin-i386-cc" \ |
| 33 | + "i386-apple-darwinX |darwin-i386-cc" \ |
| 34 | + "powerpc-apple-darwinX |darwin-ppc-cc" \ |
| 35 | + "i586-pc-winnt |winnt-parity" \ |
| 36 | + "s390-ibm-linux-gnu |linux-generic32 -DB_ENDIAN" \ |
| 37 | + "s390x-linux-gnu |linux64-s390x" \ |
| 38 | + ;do |
| 39 | + CHOST=${c/|*} |
| 40 | + ret_want=${c/*|} |
| 41 | + ret_got=$(CHOST=${CHOST} "$0") |
| 42 | + |
| 43 | + if [[ ${ret_want} == "${ret_got}" ]] ; then |
| 44 | + echo "PASS: ${CHOST}" |
| 45 | + else |
| 46 | + echo "FAIL: ${CHOST}" |
| 47 | + echo -e "\twanted: ${ret_want}" |
| 48 | + echo -e "\twe got: ${ret_got}" |
| 49 | + fi |
| 50 | + done |
| 51 | + exit 0 |
| 52 | +fi |
| 53 | +[[ -z ${CHOST} && -n $1 ]] && CHOST=$1 |
| 54 | + |
| 55 | + |
| 56 | +# Detect the operating system |
| 57 | +case ${CHOST} in |
| 58 | + *-aix*) system="aix";; |
| 59 | + *-darwin*) system="darwin";; |
| 60 | + *-freebsd*) system="BSD";; |
| 61 | + *-hpux*) system="hpux";; |
| 62 | + *-linux*) system="linux";; |
| 63 | + *-solaris*) system="solaris";; |
| 64 | + *-winnt*) system="winnt";; |
| 65 | + x86_64-*-mingw*) system="mingw64";; |
| 66 | + *mingw*) system="mingw";; |
| 67 | + *) exit 0;; |
| 68 | +esac |
| 69 | + |
| 70 | + |
| 71 | +# Compiler munging |
| 72 | +compiler="gcc" |
| 73 | +if [[ ${CC} == "ccc" ]] ; then |
| 74 | + compiler=${CC} |
| 75 | +fi |
| 76 | + |
| 77 | + |
| 78 | +# Detect target arch |
| 79 | +machine="" |
| 80 | +chost_machine=${CHOST%%-*} |
| 81 | +case ${system} in |
| 82 | +linux) |
| 83 | + case ${chost_machine}:${ABI} in |
| 84 | + aarch64*be*) machine="aarch64 -DB_ENDIAN";; |
| 85 | + aarch64*) machine="aarch64 -DL_ENDIAN";; |
| 86 | + alphaev56*|\ |
| 87 | + alphaev[678]*)machine=alpha+bwx-${compiler};; |
| 88 | + alpha*) machine=alpha-${compiler};; |
| 89 | + armv[4-9]*b*) machine="armv4 -DB_ENDIAN";; |
| 90 | + armv[4-9]*) machine="armv4 -DL_ENDIAN";; |
| 91 | + arm*b*) machine="generic32 -DB_ENDIAN";; |
| 92 | + arm*) machine="generic32 -DL_ENDIAN";; |
| 93 | + avr*) machine="generic32 -DL_ENDIAN";; |
| 94 | + bfin*) machine="generic32 -DL_ENDIAN";; |
| 95 | + # hppa64*) machine=parisc64;; |
| 96 | + hppa*) machine="generic32 -DB_ENDIAN";; |
| 97 | + i[0-9]86*|\ |
| 98 | + x86_64*:x86) machine=elf;; |
| 99 | + ia64*) machine=ia64;; |
| 100 | + loongarch64*) machine="generic64 -DL_ENDIAN";; |
| 101 | + m68*) machine="generic32 -DB_ENDIAN";; |
| 102 | + mips*el*) machine="generic32 -DL_ENDIAN";; |
| 103 | + mips*) machine="generic32 -DB_ENDIAN";; |
| 104 | + powerpc64*le*)machine=ppc64le;; |
| 105 | + powerpc64*) machine=ppc64;; |
| 106 | + powerpc*le*) machine="generic32 -DL_ENDIAN";; |
| 107 | + powerpc*) machine=ppc;; |
| 108 | + riscv32*) machine="generic32 -DL_ENDIAN";; |
| 109 | + riscv64*) machine="generic64 -DL_ENDIAN";; |
| 110 | + # sh64*) machine=elf;; |
| 111 | + sh*b*) machine="generic32 -DB_ENDIAN";; |
| 112 | + sh*) machine="generic32 -DL_ENDIAN";; |
| 113 | + # TODO: Might want to do -mcpu probing like glibc to determine a |
| 114 | + # better default for sparc-linux-gnu targets. This logic will |
| 115 | + # break v7 and older systems when they use it. |
| 116 | + sparc*v7*) machine="generic32 -DB_ENDIAN";; |
| 117 | + sparc64*) machine=sparcv9 system=linux64;; |
| 118 | + sparc*v9*) machine=sparcv9;; |
| 119 | + sparc*v8*) machine=sparcv8;; |
| 120 | + sparc*) machine=sparcv8;; |
| 121 | + s390x*) machine=s390x system=linux64;; |
| 122 | + s390*) machine="generic32 -DB_ENDIAN";; |
| 123 | + x86_64*:x32) machine=x32;; |
| 124 | + x86_64*) machine=x86_64;; |
| 125 | + esac |
| 126 | + ;; |
| 127 | +BSD) |
| 128 | + case ${chost_machine} in |
| 129 | + alpha*) machine=generic64;; |
| 130 | + i[6-9]86*) machine=x86-elf;; |
| 131 | + ia64*) machine=ia64;; |
| 132 | + sparc64*) machine=sparc64;; |
| 133 | + x86_64*) machine=x86_64;; |
| 134 | + *) machine=generic32;; |
| 135 | + esac |
| 136 | + ;; |
| 137 | +aix) |
| 138 | + machine=${compiler} |
| 139 | + ;; |
| 140 | +darwin) |
| 141 | + case ${chost_machine} in |
| 142 | + powerpc64) machine=ppc-cc; system=${system}64;; |
| 143 | + powerpc) machine=ppc-cc;; |
| 144 | + i?86*) machine=i386-cc;; |
| 145 | + x86_64) machine=x86_64-cc; system=${system}64;; |
| 146 | + esac |
| 147 | + ;; |
| 148 | +hpux) |
| 149 | + case ${chost_machine} in |
| 150 | + ia64) machine=ia64-${compiler} ;; |
| 151 | + esac |
| 152 | + ;; |
| 153 | +solaris) |
| 154 | + case ${chost_machine} in |
| 155 | + i386) machine=x86-${compiler} ;; |
| 156 | + x86_64*) machine=x86_64-${compiler}; system=${system}64;; |
| 157 | + sparcv9*) machine=sparcv9-${compiler}; system=${system}64;; |
| 158 | + sparc*) machine=sparcv8-${compiler};; |
| 159 | + esac |
| 160 | + ;; |
| 161 | +winnt) |
| 162 | + machine=parity |
| 163 | + ;; |
| 164 | +mingw*) |
| 165 | + # special case ... no xxx-yyy style name |
| 166 | + echo ${system} |
| 167 | + ;; |
| 168 | +esac |
| 169 | + |
| 170 | + |
| 171 | +# If we have something, show it |
| 172 | +[[ -n ${machine} ]] && echo ${system}-${machine} |
0 commit comments