1570af302Sopenharmony_ci#!/bin/sh 2570af302Sopenharmony_ci 3570af302Sopenharmony_ciusage () { 4570af302Sopenharmony_cicat <<EOF 5570af302Sopenharmony_ciUsage: $0 [OPTION]... [VAR=VALUE]... [TARGET] 6570af302Sopenharmony_ci 7570af302Sopenharmony_ciTo assign environment variables (e.g., CC, CFLAGS...), specify them as 8570af302Sopenharmony_ciVAR=VALUE. See below for descriptions of some of the useful variables. 9570af302Sopenharmony_ci 10570af302Sopenharmony_ciDefaults for the options are specified in brackets. 11570af302Sopenharmony_ci 12570af302Sopenharmony_ciConfiguration: 13570af302Sopenharmony_ci --srcdir=DIR source directory [detected] 14570af302Sopenharmony_ci 15570af302Sopenharmony_ciInstallation directories: 16570af302Sopenharmony_ci --prefix=PREFIX main installation prefix [/usr/local/musl] 17570af302Sopenharmony_ci --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] 18570af302Sopenharmony_ci 19570af302Sopenharmony_ciFine tuning of the installation directories: 20570af302Sopenharmony_ci --bindir=DIR user executables [EPREFIX/bin] 21570af302Sopenharmony_ci --libdir=DIR library files for the linker [PREFIX/lib] 22570af302Sopenharmony_ci --includedir=DIR include files for the C compiler [PREFIX/include] 23570af302Sopenharmony_ci --syslibdir=DIR location for the dynamic linker [/lib] 24570af302Sopenharmony_ci 25570af302Sopenharmony_ciSystem types: 26570af302Sopenharmony_ci --target=TARGET configure to run on target TARGET [detected] 27570af302Sopenharmony_ci --host=HOST same as --target 28570af302Sopenharmony_ci --build=BUILD build system type; used only to infer cross-compiling 29570af302Sopenharmony_ci 30570af302Sopenharmony_ciOptional features: 31570af302Sopenharmony_ci --enable-optimize=... optimize listed components for speed over size [auto] 32570af302Sopenharmony_ci --enable-debug build with debugging information [disabled] 33570af302Sopenharmony_ci --disable-warnings build with recommended warnings flags [enabled] 34570af302Sopenharmony_ci --enable-wrapper=... build given musl toolchain wrapper [auto] 35570af302Sopenharmony_ci --disable-shared inhibit building shared library [enabled] 36570af302Sopenharmony_ci --disable-static inhibit building static library [enabled] 37570af302Sopenharmony_ci 38570af302Sopenharmony_ciOptional packages: 39570af302Sopenharmony_ci --with-malloc=... choose malloc implementation [mallocng] 40570af302Sopenharmony_ci 41570af302Sopenharmony_ciSome influential environment variables: 42570af302Sopenharmony_ci CC C compiler command [detected] 43570af302Sopenharmony_ci CFLAGS C compiler flags [-Os -pipe ...] 44570af302Sopenharmony_ci CROSS_COMPILE prefix for cross compiler and tools [none] 45570af302Sopenharmony_ci LIBCC compiler runtime library [detected] 46570af302Sopenharmony_ci 47570af302Sopenharmony_ciUse these variables to override the choices made by configure. 48570af302Sopenharmony_ci 49570af302Sopenharmony_ciEOF 50570af302Sopenharmony_ciexit 0 51570af302Sopenharmony_ci} 52570af302Sopenharmony_ci 53570af302Sopenharmony_ci# Helper functions 54570af302Sopenharmony_ci 55570af302Sopenharmony_ciquote () { 56570af302Sopenharmony_citr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } 57570af302Sopenharmony_ci$1 58570af302Sopenharmony_ciEOF 59570af302Sopenharmony_ciprintf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" 60570af302Sopenharmony_ci} 61570af302Sopenharmony_ciecho () { printf "%s\n" "$*" ; } 62570af302Sopenharmony_cifail () { echo "$*" ; exit 1 ; } 63570af302Sopenharmony_cifnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; } 64570af302Sopenharmony_cicmdexists () { type "$1" >/dev/null 2>&1 ; } 65570af302Sopenharmony_citrycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; } 66570af302Sopenharmony_ci 67570af302Sopenharmony_cistripdir () { 68570af302Sopenharmony_ciwhile eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done 69570af302Sopenharmony_ci} 70570af302Sopenharmony_ci 71570af302Sopenharmony_citrycppif () { 72570af302Sopenharmony_ciprintf "checking preprocessor condition %s... " "$1" 73570af302Sopenharmony_ciecho "typedef int x;" > "$tmpc" 74570af302Sopenharmony_ciecho "#if $1" >> "$tmpc" 75570af302Sopenharmony_ciecho "#error yes" >> "$tmpc" 76570af302Sopenharmony_ciecho "#endif" >> "$tmpc" 77570af302Sopenharmony_ciif $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 78570af302Sopenharmony_ciprintf "false\n" 79570af302Sopenharmony_cireturn 1 80570af302Sopenharmony_cielse 81570af302Sopenharmony_ciprintf "true\n" 82570af302Sopenharmony_cireturn 0 83570af302Sopenharmony_cifi 84570af302Sopenharmony_ci} 85570af302Sopenharmony_ci 86570af302Sopenharmony_citryflag () { 87570af302Sopenharmony_ciprintf "checking whether compiler accepts %s... " "$2" 88570af302Sopenharmony_ciecho "typedef int x;" > "$tmpc" 89570af302Sopenharmony_ciif $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 90570af302Sopenharmony_ciprintf "yes\n" 91570af302Sopenharmony_cieval "$1=\"\${$1} \$2\"" 92570af302Sopenharmony_cieval "$1=\${$1# }" 93570af302Sopenharmony_cireturn 0 94570af302Sopenharmony_cielse 95570af302Sopenharmony_ciprintf "no\n" 96570af302Sopenharmony_cireturn 1 97570af302Sopenharmony_cifi 98570af302Sopenharmony_ci} 99570af302Sopenharmony_ci 100570af302Sopenharmony_citryldflag () { 101570af302Sopenharmony_ciprintf "checking whether linker accepts %s... " "$2" 102570af302Sopenharmony_ciecho "typedef int x;" > "$tmpc" 103570af302Sopenharmony_ciif $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 104570af302Sopenharmony_ciprintf "yes\n" 105570af302Sopenharmony_cieval "$1=\"\${$1} \$2\"" 106570af302Sopenharmony_cieval "$1=\${$1# }" 107570af302Sopenharmony_cireturn 0 108570af302Sopenharmony_cielse 109570af302Sopenharmony_ciprintf "no\n" 110570af302Sopenharmony_cireturn 1 111570af302Sopenharmony_cifi 112570af302Sopenharmony_ci} 113570af302Sopenharmony_ci 114570af302Sopenharmony_ci 115570af302Sopenharmony_ci 116570af302Sopenharmony_ci# Beginning of actual script 117570af302Sopenharmony_ci 118570af302Sopenharmony_ciCFLAGS_C99FSE= 119570af302Sopenharmony_ciCFLAGS_AUTO= 120570af302Sopenharmony_ciCFLAGS_MEMOPS= 121570af302Sopenharmony_ciCFLAGS_NOSSP= 122570af302Sopenharmony_ciCFLAGS_TRY= 123570af302Sopenharmony_ciLDFLAGS_AUTO= 124570af302Sopenharmony_ciLDFLAGS_TRY= 125570af302Sopenharmony_ciOPTIMIZE_GLOBS= 126570af302Sopenharmony_cisrcdir= 127570af302Sopenharmony_ciprefix=/usr/local/musl 128570af302Sopenharmony_ciexec_prefix='$(prefix)' 129570af302Sopenharmony_cibindir='$(exec_prefix)/bin' 130570af302Sopenharmony_cilibdir='$(prefix)/lib' 131570af302Sopenharmony_ciincludedir='$(prefix)/include' 132570af302Sopenharmony_cisyslibdir='/lib' 133570af302Sopenharmony_citools= 134570af302Sopenharmony_citool_libs= 135570af302Sopenharmony_cibuild= 136570af302Sopenharmony_citarget= 137570af302Sopenharmony_cioptimize=auto 138570af302Sopenharmony_cidebug=no 139570af302Sopenharmony_ciwarnings=yes 140570af302Sopenharmony_cishared=auto 141570af302Sopenharmony_cistatic=yes 142570af302Sopenharmony_ciwrapper=auto 143570af302Sopenharmony_cigcc_wrapper=no 144570af302Sopenharmony_ciclang_wrapper=no 145570af302Sopenharmony_cimalloc_dir=mallocng 146570af302Sopenharmony_ci 147570af302Sopenharmony_cifor arg ; do 148570af302Sopenharmony_cicase "$arg" in 149570af302Sopenharmony_ci--help|-h) usage ;; 150570af302Sopenharmony_ci--srcdir=*) srcdir=${arg#*=} ;; 151570af302Sopenharmony_ci--prefix=*) prefix=${arg#*=} ;; 152570af302Sopenharmony_ci--exec-prefix=*) exec_prefix=${arg#*=} ;; 153570af302Sopenharmony_ci--bindir=*) bindir=${arg#*=} ;; 154570af302Sopenharmony_ci--libdir=*) libdir=${arg#*=} ;; 155570af302Sopenharmony_ci--includedir=*) includedir=${arg#*=} ;; 156570af302Sopenharmony_ci--syslibdir=*) syslibdir=${arg#*=} ;; 157570af302Sopenharmony_ci--enable-shared|--enable-shared=yes) shared=yes ;; 158570af302Sopenharmony_ci--disable-shared|--enable-shared=no) shared=no ;; 159570af302Sopenharmony_ci--enable-static|--enable-static=yes) static=yes ;; 160570af302Sopenharmony_ci--disable-static|--enable-static=no) static=no ;; 161570af302Sopenharmony_ci--enable-optimize) optimize=yes ;; 162570af302Sopenharmony_ci--enable-optimize=*) optimize=${arg#*=} ;; 163570af302Sopenharmony_ci--disable-optimize) optimize=no ;; 164570af302Sopenharmony_ci--enable-debug|--enable-debug=yes) debug=yes ;; 165570af302Sopenharmony_ci--disable-debug|--enable-debug=no) debug=no ;; 166570af302Sopenharmony_ci--enable-warnings|--enable-warnings=yes) warnings=yes ;; 167570af302Sopenharmony_ci--disable-warnings|--enable-warnings=no) warnings=no ;; 168570af302Sopenharmony_ci--enable-wrapper|--enable-wrapper=yes) wrapper=detect ;; 169570af302Sopenharmony_ci--enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ; clang_wrapper=yes ;; 170570af302Sopenharmony_ci--enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;; 171570af302Sopenharmony_ci--enable-wrapper=clang) wrapper=yes ; clang_wrapper=yes ;; 172570af302Sopenharmony_ci--disable-wrapper|--enable-wrapper=no) wrapper=no ;; 173570af302Sopenharmony_ci--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;; 174570af302Sopenharmony_ci--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;; 175570af302Sopenharmony_ci--with-malloc=*) malloc_dir=${arg#*=} ;; 176570af302Sopenharmony_ci--enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;; 177570af302Sopenharmony_ci--host=*|--target=*) target=${arg#*=} ;; 178570af302Sopenharmony_ci--build=*) build=${arg#*=} ;; 179570af302Sopenharmony_ci-* ) echo "$0: unknown option $arg" ;; 180570af302Sopenharmony_ciAR=*) AR=${arg#*=} ;; 181570af302Sopenharmony_ciRANLIB=*) RANLIB=${arg#*=} ;; 182570af302Sopenharmony_ciCC=*) CC=${arg#*=} ;; 183570af302Sopenharmony_ciCFLAGS=*) CFLAGS=${arg#*=} ;; 184570af302Sopenharmony_ciCPPFLAGS=*) CPPFLAGS=${arg#*=} ;; 185570af302Sopenharmony_ciLDFLAGS=*) LDFLAGS=${arg#*=} ;; 186570af302Sopenharmony_ciCROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;; 187570af302Sopenharmony_ciLIBCC=*) LIBCC=${arg#*=} ;; 188570af302Sopenharmony_ci*=*) ;; 189570af302Sopenharmony_ci*) build=$arg ; target=$arg ;; 190570af302Sopenharmony_ciesac 191570af302Sopenharmony_cidone 192570af302Sopenharmony_ci 193570af302Sopenharmony_cifor i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do 194570af302Sopenharmony_cistripdir $i 195570af302Sopenharmony_cidone 196570af302Sopenharmony_ci 197570af302Sopenharmony_ci# 198570af302Sopenharmony_ci# Get the source dir for out-of-tree builds 199570af302Sopenharmony_ci# 200570af302Sopenharmony_ciif test -z "$srcdir" ; then 201570af302Sopenharmony_cisrcdir="${0%/configure}" 202570af302Sopenharmony_cistripdir srcdir 203570af302Sopenharmony_cifi 204570af302Sopenharmony_ciabs_builddir="$(pwd)" || fail "$0: cannot determine working directory" 205570af302Sopenharmony_ciabs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir" 206570af302Sopenharmony_citest "$abs_srcdir" = "$abs_builddir" && srcdir=. 207570af302Sopenharmony_citest "$srcdir" != "." && test -f Makefile && test ! -h Makefile && fail "$0: Makefile already exists in the working directory" 208570af302Sopenharmony_ci 209570af302Sopenharmony_ci# 210570af302Sopenharmony_ci# Get a temp filename we can use 211570af302Sopenharmony_ci# 212570af302Sopenharmony_cii=0 213570af302Sopenharmony_ciset -C 214570af302Sopenharmony_ciwhile : ; do i=$(($i+1)) 215570af302Sopenharmony_citmpc="./conf$$-$PPID-$i.c" 216570af302Sopenharmony_ci2>|/dev/null > "$tmpc" && break 217570af302Sopenharmony_citest "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc" 218570af302Sopenharmony_cidone 219570af302Sopenharmony_ciset +C 220570af302Sopenharmony_citrap 'rm "$tmpc"' EXIT INT QUIT TERM HUP 221570af302Sopenharmony_ci 222570af302Sopenharmony_ci# 223570af302Sopenharmony_ci# Check that the requested malloc implementation exists 224570af302Sopenharmony_ci# 225570af302Sopenharmony_citest -d "$srcdir/src/malloc/$malloc_dir" \ 226570af302Sopenharmony_ci|| fail "$0: error: chosen malloc implementation '$malloc_dir' does not exist" 227570af302Sopenharmony_ci 228570af302Sopenharmony_ci# 229570af302Sopenharmony_ci# Check whether we are cross-compiling, and set a default 230570af302Sopenharmony_ci# CROSS_COMPILE prefix if none was provided. 231570af302Sopenharmony_ci# 232570af302Sopenharmony_citest "$target" && \ 233570af302Sopenharmony_citest "$target" != "$build" && \ 234570af302Sopenharmony_citest -z "$CROSS_COMPILE" && \ 235570af302Sopenharmony_ciCROSS_COMPILE="$target-" 236570af302Sopenharmony_ci 237570af302Sopenharmony_ci# 238570af302Sopenharmony_ci# Find a C compiler to use 239570af302Sopenharmony_ci# 240570af302Sopenharmony_ciprintf "checking for C compiler... " 241570af302Sopenharmony_citrycc ${CROSS_COMPILE}gcc 242570af302Sopenharmony_citrycc ${CROSS_COMPILE}c99 243570af302Sopenharmony_citrycc ${CROSS_COMPILE}cc 244570af302Sopenharmony_ciprintf "%s\n" "$CC" 245570af302Sopenharmony_citest -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } 246570af302Sopenharmony_ci 247570af302Sopenharmony_ciprintf "checking whether C compiler works... " 248570af302Sopenharmony_ciecho "typedef int x;" > "$tmpc" 249570af302Sopenharmony_ciif output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then 250570af302Sopenharmony_ciprintf "yes\n" 251570af302Sopenharmony_cielse 252570af302Sopenharmony_ciprintf "no; compiler output follows:\n%s\n" "$output" 253570af302Sopenharmony_ciexit 1 254570af302Sopenharmony_cifi 255570af302Sopenharmony_ci 256570af302Sopenharmony_ci# 257570af302Sopenharmony_ci# Figure out options to force errors on unknown flags. 258570af302Sopenharmony_ci# 259570af302Sopenharmony_citryflag CFLAGS_TRY -Werror=unknown-warning-option 260570af302Sopenharmony_citryflag CFLAGS_TRY -Werror=unused-command-line-argument 261570af302Sopenharmony_citryflag CFLAGS_TRY -Werror=ignored-optimization-argument 262570af302Sopenharmony_citryldflag LDFLAGS_TRY -Werror=unknown-warning-option 263570af302Sopenharmony_citryldflag LDFLAGS_TRY -Werror=unused-command-line-argument 264570af302Sopenharmony_ci 265570af302Sopenharmony_ci# 266570af302Sopenharmony_ci# Need to know if the compiler is gcc or clang to decide which toolchain 267570af302Sopenharmony_ci# wrappers to build. 268570af302Sopenharmony_ci# 269570af302Sopenharmony_ciprintf "checking for C compiler family... " 270570af302Sopenharmony_cicc_ver="$(LC_ALL=C $CC -v 2>&1)" 271570af302Sopenharmony_cicc_family=unknown 272570af302Sopenharmony_ciif fnmatch '*gcc\ version*' "$cc_ver" ; then 273570af302Sopenharmony_cicc_family=gcc 274570af302Sopenharmony_cielif fnmatch '*clang\ version*' "$cc_ver" ; then 275570af302Sopenharmony_cicc_family=clang 276570af302Sopenharmony_cifi 277570af302Sopenharmony_ciecho "$cc_family" 278570af302Sopenharmony_ci 279570af302Sopenharmony_ci# 280570af302Sopenharmony_ci# Figure out toolchain wrapper to build 281570af302Sopenharmony_ci# 282570af302Sopenharmony_ciif test "$wrapper" = auto || test "$wrapper" = detect ; then 283570af302Sopenharmony_ciecho "#include <stdlib.h>" > "$tmpc" 284570af302Sopenharmony_ciecho "#if ! __GLIBC__" >> "$tmpc" 285570af302Sopenharmony_ciecho "#error no" >> "$tmpc" 286570af302Sopenharmony_ciecho "#endif" >> "$tmpc" 287570af302Sopenharmony_ciprintf "checking for toolchain wrapper to build... " 288570af302Sopenharmony_ciif test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 289570af302Sopenharmony_ciecho "none" 290570af302Sopenharmony_cielif test "$cc_family" = gcc ; then 291570af302Sopenharmony_cigcc_wrapper=yes 292570af302Sopenharmony_ciecho "gcc" 293570af302Sopenharmony_cielif test "$cc_family" = clang ; then 294570af302Sopenharmony_ciclang_wrapper=yes 295570af302Sopenharmony_ciecho "clang" 296570af302Sopenharmony_cielse 297570af302Sopenharmony_ciecho "none" 298570af302Sopenharmony_ciif test "$wrapper" = detect ; then 299570af302Sopenharmony_cifail "$0: could not find an appropriate toolchain wrapper" 300570af302Sopenharmony_cifi 301570af302Sopenharmony_cifi 302570af302Sopenharmony_cifi 303570af302Sopenharmony_ci 304570af302Sopenharmony_ciif test "$gcc_wrapper" = yes ; then 305570af302Sopenharmony_citools="$tools obj/musl-gcc" 306570af302Sopenharmony_citool_libs="$tool_libs lib/musl-gcc.specs" 307570af302Sopenharmony_cifi 308570af302Sopenharmony_ciif test "$clang_wrapper" = yes ; then 309570af302Sopenharmony_citools="$tools obj/musl-clang obj/ld.musl-clang" 310570af302Sopenharmony_cifi 311570af302Sopenharmony_ci 312570af302Sopenharmony_ci# 313570af302Sopenharmony_ci# Find the target architecture 314570af302Sopenharmony_ci# 315570af302Sopenharmony_ciprintf "checking target system type... " 316570af302Sopenharmony_citest -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown 317570af302Sopenharmony_ciprintf "%s\n" "$target" 318570af302Sopenharmony_ci 319570af302Sopenharmony_ci# 320570af302Sopenharmony_ci# Convert to just ARCH 321570af302Sopenharmony_ci# 322570af302Sopenharmony_cicase "$target" in 323570af302Sopenharmony_ci# Catch these early to simplify matching for 32-bit archs 324570af302Sopenharmony_ciarm*) ARCH=arm ;; 325570af302Sopenharmony_ciaarch64*) ARCH=aarch64 ;; 326570af302Sopenharmony_cii?86-nt32*) ARCH=nt32 ;; 327570af302Sopenharmony_cii?86*) ARCH=i386 ;; 328570af302Sopenharmony_cix86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;; 329570af302Sopenharmony_cix86_64-nt64*) ARCH=nt64 ;; 330570af302Sopenharmony_cix86_64*) ARCH=x86_64 ;; 331570af302Sopenharmony_ciloongarch64*) ARCH=loongarch64 ;; 332570af302Sopenharmony_cim68k*) ARCH=m68k ;; 333570af302Sopenharmony_cimips64*|mipsisa64*) ARCH=mips64 ;; 334570af302Sopenharmony_cimips*) ARCH=mips ;; 335570af302Sopenharmony_cimicroblaze*) ARCH=microblaze ;; 336570af302Sopenharmony_cior1k*) ARCH=or1k ;; 337570af302Sopenharmony_cipowerpc64*|ppc64*) ARCH=powerpc64 ;; 338570af302Sopenharmony_cipowerpc*|ppc*) ARCH=powerpc ;; 339570af302Sopenharmony_ciriscv64*) ARCH=riscv64 ;; 340570af302Sopenharmony_ciriscv32*) ARCH=riscv32 ;; 341570af302Sopenharmony_cish[1-9bel-]*|sh|superh*) ARCH=sh ;; 342570af302Sopenharmony_cis390x*) ARCH=s390x ;; 343570af302Sopenharmony_ciunknown) fail "$0: unable to detect target arch; try $0 --target=..." ;; 344570af302Sopenharmony_ci*) fail "$0: unknown or unsupported target \"$target\"" ;; 345570af302Sopenharmony_ciesac 346570af302Sopenharmony_ci 347570af302Sopenharmony_ci# 348570af302Sopenharmony_ci# Try to get a conforming C99 freestanding environment 349570af302Sopenharmony_ci# 350570af302Sopenharmony_citryflag CFLAGS_C99FSE -std=c99 351570af302Sopenharmony_citryflag CFLAGS_C99FSE -nostdinc 352570af302Sopenharmony_citryflag CFLAGS_C99FSE -ffreestanding \ 353570af302Sopenharmony_ci|| tryflag CFLAGS_C99FSE -fno-builtin 354570af302Sopenharmony_citryflag CFLAGS_C99FSE -fexcess-precision=standard \ 355570af302Sopenharmony_ci|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; } 356570af302Sopenharmony_citryflag CFLAGS_C99FSE -frounding-math 357570af302Sopenharmony_ci 358570af302Sopenharmony_ci# 359570af302Sopenharmony_ci# Semantically we want to insist that our sources follow the 360570af302Sopenharmony_ci# C rules for type-based aliasing, but most if not all real-world 361570af302Sopenharmony_ci# compilers are known or suspected to have critical bugs in their 362570af302Sopenharmony_ci# type-based aliasing analysis. See for example GCC bug 107107. 363570af302Sopenharmony_ci# 364570af302Sopenharmony_citryflag CFLAGS_C99FSE -fno-strict-aliasing 365570af302Sopenharmony_ci 366570af302Sopenharmony_ci# 367570af302Sopenharmony_ci# We may use the may_alias attribute if __GNUC__ is defined, so 368570af302Sopenharmony_ci# if the compiler defines __GNUC__ but does not provide it, 369570af302Sopenharmony_ci# it must be defined away as part of the CFLAGS. 370570af302Sopenharmony_ci# 371570af302Sopenharmony_ciprintf "checking whether compiler needs attribute((may_alias)) suppression... " 372570af302Sopenharmony_cicat > "$tmpc" <<EOF 373570af302Sopenharmony_citypedef int 374570af302Sopenharmony_ci#ifdef __GNUC__ 375570af302Sopenharmony_ci__attribute__((__may_alias__)) 376570af302Sopenharmony_ci#endif 377570af302Sopenharmony_cix; 378570af302Sopenharmony_ciEOF 379570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \ 380570af302Sopenharmony_ci -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 381570af302Sopenharmony_ciprintf "no\n" 382570af302Sopenharmony_cielse 383570af302Sopenharmony_ciprintf "yes\n" 384570af302Sopenharmony_ciCFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__=" 385570af302Sopenharmony_cifi 386570af302Sopenharmony_ci 387570af302Sopenharmony_ci# 388570af302Sopenharmony_ci# The GNU toolchain defaults to assuming unmarked files need an 389570af302Sopenharmony_ci# executable stack, potentially exposing vulnerabilities in programs 390570af302Sopenharmony_ci# linked with such object files. Fix this. 391570af302Sopenharmony_ci# 392570af302Sopenharmony_citryflag CFLAGS_C99FSE -Wa,--noexecstack 393570af302Sopenharmony_ci 394570af302Sopenharmony_ci# 395570af302Sopenharmony_ci# Check for options to disable stack protector, which needs to be 396570af302Sopenharmony_ci# disabled for a few early-bootstrap translation units. If not found, 397570af302Sopenharmony_ci# this is not an error; we assume the toolchain does not do ssp. 398570af302Sopenharmony_ci# 399570af302Sopenharmony_citryflag CFLAGS_NOSSP -fno-stack-protector 400570af302Sopenharmony_ci 401570af302Sopenharmony_ci# 402570af302Sopenharmony_ci# Check for options that may be needed to prevent the compiler from 403570af302Sopenharmony_ci# generating self-referential versions of memcpy,, memmove, memcmp, 404570af302Sopenharmony_ci# and memset. Really, we should add a check to determine if this 405570af302Sopenharmony_ci# option is sufficient, and if not, add a macro to cripple these 406570af302Sopenharmony_ci# functions with volatile... 407570af302Sopenharmony_ci# 408570af302Sopenharmony_citryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns 409570af302Sopenharmony_ci 410570af302Sopenharmony_ci# 411570af302Sopenharmony_ci# Enable debugging if requessted. 412570af302Sopenharmony_ci# 413570af302Sopenharmony_citest "$debug" = yes && CFLAGS_AUTO=-g 414570af302Sopenharmony_ci 415570af302Sopenharmony_ci# 416570af302Sopenharmony_ci# Preprocess asm files to add extra debugging information if debug is 417570af302Sopenharmony_ci# enabled, our assembler supports the needed directives, and the 418570af302Sopenharmony_ci# preprocessing script has been written for our architecture. 419570af302Sopenharmony_ci# 420570af302Sopenharmony_ciprintf "checking whether we should preprocess assembly to add debugging information... " 421570af302Sopenharmony_ciif fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" && 422570af302Sopenharmony_ci test -f "$srcdir/tools/add-cfi.$ARCH.awk" && 423570af302Sopenharmony_ci printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null - 424570af302Sopenharmony_cithen 425570af302Sopenharmony_ci ADD_CFI=yes 426570af302Sopenharmony_cielse 427570af302Sopenharmony_ci ADD_CFI=no 428570af302Sopenharmony_cifi 429570af302Sopenharmony_ciprintf "%s\n" "$ADD_CFI" 430570af302Sopenharmony_ci 431570af302Sopenharmony_ci# 432570af302Sopenharmony_ci# Possibly add a -O option to CFLAGS and select modules to optimize with 433570af302Sopenharmony_ci# -O3 based on the status of --enable-optimize and provided CFLAGS. 434570af302Sopenharmony_ci# 435570af302Sopenharmony_ciprintf "checking for optimization settings... " 436570af302Sopenharmony_cicase "x$optimize" in 437570af302Sopenharmony_cixauto) 438570af302Sopenharmony_ciif fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then 439570af302Sopenharmony_ciprintf "using provided CFLAGS\n" ;optimize=no 440570af302Sopenharmony_cielse 441570af302Sopenharmony_ciprintf "using defaults\n" ; optimize=yes 442570af302Sopenharmony_cifi 443570af302Sopenharmony_ci;; 444570af302Sopenharmony_cixsize|xnone) printf "minimize size\n" ; optimize=size ;; 445570af302Sopenharmony_cixno|x) printf "disabled\n" ; optimize=no ;; 446570af302Sopenharmony_ci*) printf "custom\n" ;; 447570af302Sopenharmony_ciesac 448570af302Sopenharmony_ci 449570af302Sopenharmony_ciif test "$optimize" = no ; then : 450570af302Sopenharmony_cielse 451570af302Sopenharmony_citryflag CFLAGS_AUTO -O2 452570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-align-jumps 453570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-align-functions 454570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-align-loops 455570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-align-labels 456570af302Sopenharmony_citryflag CFLAGS_AUTO -fira-region=one 457570af302Sopenharmony_citryflag CFLAGS_AUTO -fira-hoist-pressure 458570af302Sopenharmony_citryflag CFLAGS_AUTO -freorder-blocks-algorithm=simple \ 459570af302Sopenharmony_ci|| tryflag CFLAGS_AUTO -fno-reorder-blocks 460570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-prefetch-loop-arrays 461570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-tree-ch 462570af302Sopenharmony_cifi 463570af302Sopenharmony_citest "$optimize" = yes && optimize="internal,malloc,string" 464570af302Sopenharmony_ci 465570af302Sopenharmony_ciif fnmatch 'no|size' "$optimize" ; then : 466570af302Sopenharmony_cielse 467570af302Sopenharmony_ciprintf "components to be optimized for speed:" 468570af302Sopenharmony_ciwhile test "$optimize" ; do 469570af302Sopenharmony_cicase "$optimize" in 470570af302Sopenharmony_ci*,*) this=${optimize%%,*} optimize=${optimize#*,} ;; 471570af302Sopenharmony_ci*) this=$optimize optimize= 472570af302Sopenharmony_ciesac 473570af302Sopenharmony_ciprintf " $this" 474570af302Sopenharmony_cicase "$this" in 475570af302Sopenharmony_ci*/*.c) ;; 476570af302Sopenharmony_ci*/*) this=$this*.c ;; 477570af302Sopenharmony_ci*) this=$this/*.c ;; 478570af302Sopenharmony_ciesac 479570af302Sopenharmony_ciOPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this" 480570af302Sopenharmony_cidone 481570af302Sopenharmony_ciOPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# } 482570af302Sopenharmony_ciprintf "\n" 483570af302Sopenharmony_cifi 484570af302Sopenharmony_ci 485570af302Sopenharmony_ci# Always try -pipe 486570af302Sopenharmony_citryflag CFLAGS_AUTO -pipe 487570af302Sopenharmony_ci 488570af302Sopenharmony_ci# 489570af302Sopenharmony_ci# If debugging is disabled, omit frame pointer. Modern GCC does this 490570af302Sopenharmony_ci# anyway on most archs even when debugging is enabled since the frame 491570af302Sopenharmony_ci# pointer is no longer needed for debugging. 492570af302Sopenharmony_ci# 493570af302Sopenharmony_ciif fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then : 494570af302Sopenharmony_cielse 495570af302Sopenharmony_citryflag CFLAGS_AUTO -fomit-frame-pointer 496570af302Sopenharmony_cifi 497570af302Sopenharmony_ci 498570af302Sopenharmony_ci# 499570af302Sopenharmony_ci# Modern GCC wants to put DWARF tables (used for debugging and 500570af302Sopenharmony_ci# unwinding) in the loaded part of the program where they are 501570af302Sopenharmony_ci# unstrippable. These options force them back to debug sections (and 502570af302Sopenharmony_ci# cause them not to get generated at all if debugging is off). 503570af302Sopenharmony_ci# 504570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-unwind-tables 505570af302Sopenharmony_citryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables 506570af302Sopenharmony_ci 507570af302Sopenharmony_ci# 508570af302Sopenharmony_ci# Attempt to put each function and each data object in its own 509570af302Sopenharmony_ci# section. This both allows additional size optimizations at link 510570af302Sopenharmony_ci# time and works around a dangerous class of compiler/assembler bugs 511570af302Sopenharmony_ci# whereby relative address expressions are constant-folded by the 512570af302Sopenharmony_ci# assembler even when one or more of the symbols involved is 513570af302Sopenharmony_ci# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc. 514570af302Sopenharmony_ci# 515570af302Sopenharmony_citryflag CFLAGS_AUTO -ffunction-sections 516570af302Sopenharmony_citryflag CFLAGS_AUTO -fdata-sections 517570af302Sopenharmony_ci 518570af302Sopenharmony_ci# 519570af302Sopenharmony_ci# On x86, make sure we don't have incompatible instruction set 520570af302Sopenharmony_ci# extensions enabled by default. This is bad for making static binaries. 521570af302Sopenharmony_ci# We cheat and use i486 rather than i386 because i386 really does not 522570af302Sopenharmony_ci# work anyway (issues with atomic ops). 523570af302Sopenharmony_ci# Some build environments pass -march and -mtune options via CC, so 524570af302Sopenharmony_ci# check both CC and CFLAGS. 525570af302Sopenharmony_ci# 526570af302Sopenharmony_ciif test "$ARCH" = "i386" ; then 527570af302Sopenharmony_cifnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486 528570af302Sopenharmony_cifnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic 529570af302Sopenharmony_cifi 530570af302Sopenharmony_ci 531570af302Sopenharmony_ci# 532570af302Sopenharmony_ci# GCC defines -w as overriding any -W options, regardless of order, but 533570af302Sopenharmony_ci# clang has a bunch of annoying warnings enabled by default and needs -w 534570af302Sopenharmony_ci# to start from a clean slate. So use -w if building with clang. Also 535570af302Sopenharmony_ci# turn off a common on-by-default cast warning regardless of compiler. 536570af302Sopenharmony_ci# 537570af302Sopenharmony_citest "$cc_family" = clang && tryflag CFLAGS_AUTO -w 538570af302Sopenharmony_ci 539570af302Sopenharmony_citryflag CFLAGS_AUTO -Wno-pointer-to-int-cast 540570af302Sopenharmony_ci 541570af302Sopenharmony_ci# 542570af302Sopenharmony_ci# Even with -std=c99, gcc accepts some constructs which are constraint 543570af302Sopenharmony_ci# violations. We want to treat these as errors regardless of whether 544570af302Sopenharmony_ci# other purely stylistic warnings are enabled -- especially implicit 545570af302Sopenharmony_ci# function declarations, which are a dangerous programming error. 546570af302Sopenharmony_ci# 547570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=implicit-function-declaration 548570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=implicit-int 549570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=pointer-sign 550570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=pointer-arith 551570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=int-conversion 552570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=incompatible-pointer-types 553570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=discarded-qualifiers 554570af302Sopenharmony_citryflag CFLAGS_AUTO -Werror=discarded-array-qualifiers 555570af302Sopenharmony_ci 556570af302Sopenharmony_ci# 557570af302Sopenharmony_ci# GCC ignores unused arguements by default, but Clang needs this extra 558570af302Sopenharmony_ci# parameter to stop printing warnings about LDFLAGS passed during 559570af302Sopenharmony_ci# compiling stage and CFLAGS passed during linking stage. 560570af302Sopenharmony_ci# 561570af302Sopenharmony_citest "$cc_family" = clang && tryflag CFLAGS_AUTO -Qunused-arguments 562570af302Sopenharmony_ci 563570af302Sopenharmony_ciif test "x$warnings" = xyes ; then 564570af302Sopenharmony_citryflag CFLAGS_AUTO -Waddress 565570af302Sopenharmony_citryflag CFLAGS_AUTO -Warray-bounds 566570af302Sopenharmony_citryflag CFLAGS_AUTO -Wchar-subscripts 567570af302Sopenharmony_citryflag CFLAGS_AUTO -Wduplicate-decl-specifier 568570af302Sopenharmony_citryflag CFLAGS_AUTO -Winit-self 569570af302Sopenharmony_citryflag CFLAGS_AUTO -Wreturn-type 570570af302Sopenharmony_citryflag CFLAGS_AUTO -Wsequence-point 571570af302Sopenharmony_citryflag CFLAGS_AUTO -Wstrict-aliasing 572570af302Sopenharmony_citryflag CFLAGS_AUTO -Wunused-function 573570af302Sopenharmony_citryflag CFLAGS_AUTO -Wunused-label 574570af302Sopenharmony_citryflag CFLAGS_AUTO -Wunused-variable 575570af302Sopenharmony_cifi 576570af302Sopenharmony_ci 577570af302Sopenharmony_ci# Determine if the compiler produces position-independent code (PIC) 578570af302Sopenharmony_ci# by default. If so, we don't need to compile separate object files 579570af302Sopenharmony_ci# for libc.a and libc.so. 580570af302Sopenharmony_ciif trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then 581570af302Sopenharmony_cipic_default=yes 582570af302Sopenharmony_cielse 583570af302Sopenharmony_cipic_default=no 584570af302Sopenharmony_cifi 585570af302Sopenharmony_ci 586570af302Sopenharmony_ci# Reduce space lost to padding for alignment purposes by sorting data 587570af302Sopenharmony_ci# objects according to their alignment reqirements. This approximates 588570af302Sopenharmony_ci# optimal packing. 589570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment 590570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--sort-common 591570af302Sopenharmony_ci 592570af302Sopenharmony_ci# When linking shared library, drop dummy weak definitions that were 593570af302Sopenharmony_ci# replaced by strong definitions from other translation units. 594570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--gc-sections 595570af302Sopenharmony_ci 596570af302Sopenharmony_ci# Some patched GCC builds have these defaults messed up... 597570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--hash-style=both 598570af302Sopenharmony_ci 599570af302Sopenharmony_ci# Prevent linking if there are undefined symbols; if any exist, 600570af302Sopenharmony_ci# libc.so will crash at runtime during relocation processing. 601570af302Sopenharmony_ci# The common way this can happen is failure to link the compiler 602570af302Sopenharmony_ci# runtime library; implementation error is also a possibility. 603570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--no-undefined 604570af302Sopenharmony_ci 605570af302Sopenharmony_ci# Avoid exporting symbols from compiler runtime libraries. They 606570af302Sopenharmony_ci# should be hidden anyway, but some toolchains including old gcc 607570af302Sopenharmony_ci# versions built without shared library support and pcc are broken. 608570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL 609570af302Sopenharmony_ci 610570af302Sopenharmony_ci# Public data symbols must be interposable to allow for copy 611570af302Sopenharmony_ci# relocations, but otherwise we want to bind symbols at libc link 612570af302Sopenharmony_ci# time to eliminate startup relocations and PLT overhead. Use 613570af302Sopenharmony_ci# --dynamic-list rather than -Bsymbolic-functions for greater 614570af302Sopenharmony_ci# control over what symbols are left unbound. 615570af302Sopenharmony_citryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list" 616570af302Sopenharmony_ci 617570af302Sopenharmony_ci# Find compiler runtime library 618570af302Sopenharmony_citest -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh 619570af302Sopenharmony_citest -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt 620570af302Sopenharmony_citest -z "$LIBCC" && try_libcc=`$CC -print-libgcc-file-name 2>/dev/null` \ 621570af302Sopenharmony_ci && tryldflag LIBCC "$try_libcc" 622570af302Sopenharmony_citest -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \ 623570af302Sopenharmony_ci && tryldflag LIBCC "$try_libcc" 624570af302Sopenharmony_ciprintf "using compiler runtime libraries: %s\n" "$LIBCC" 625570af302Sopenharmony_ci 626570af302Sopenharmony_ci# Figure out arch variants for archs with variants 627570af302Sopenharmony_ciSUBARCH= 628570af302Sopenharmony_cit="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" 629570af302Sopenharmony_ci 630570af302Sopenharmony_ciif test "$ARCH" = "i386" ; then 631570af302Sopenharmony_ciprintf "checking whether compiler can use ebx in PIC asm constraints... " 632570af302Sopenharmony_cicat > "$tmpc" <<EOF 633570af302Sopenharmony_ciint foo(int x) { __asm__ ( "" : "+b"(x) ); return x; } 634570af302Sopenharmony_ciEOF 635570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -fPIC \ 636570af302Sopenharmony_ci -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 637570af302Sopenharmony_ciprintf "yes\n" 638570af302Sopenharmony_cielse 639570af302Sopenharmony_ciprintf "no\n" 640570af302Sopenharmony_ciCFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_EBX_ASM" 641570af302Sopenharmony_cifi 642570af302Sopenharmony_cifi 643570af302Sopenharmony_ci 644570af302Sopenharmony_ciif test "$ARCH" = "x86_64" ; then 645570af302Sopenharmony_citrycppif __ILP32__ "$t" && ARCH=x32 646570af302Sopenharmony_cifi 647570af302Sopenharmony_ci 648570af302Sopenharmony_ciif test "$ARCH" = "arm" ; then 649570af302Sopenharmony_ciif trycppif __thumb2__ "$t" ; then 650570af302Sopenharmony_citryflag CFLAGS_AUTO -mimplicit-it=always 651570af302Sopenharmony_citryflag CFLAGS_AUTO -Wa,-mimplicit-it=always 652570af302Sopenharmony_citryflag CFLAGS_AUTO -Wa,-mthumb 653570af302Sopenharmony_cifi 654570af302Sopenharmony_citrycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb 655570af302Sopenharmony_citrycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf 656570af302Sopenharmony_ci# Versions of clang up until at least 3.8 have the wrong constraint codes 657570af302Sopenharmony_ci# for floating point operands to inline asm. Detect this so the affected 658570af302Sopenharmony_ci# source files can just disable the asm. 659570af302Sopenharmony_ciif test "$cc_family" = clang ; then 660570af302Sopenharmony_ciprintf "checking whether clang's vfp asm constraints work... " 661570af302Sopenharmony_ciecho 'float f(float x) { __asm__("":"+t"(x)); return x; }' > "$tmpc" 662570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 663570af302Sopenharmony_ciprintf "yes\n" 664570af302Sopenharmony_cielse 665570af302Sopenharmony_ciprintf "no\n" 666570af302Sopenharmony_ciCFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_VFP_ASM" 667570af302Sopenharmony_ciCFLAGS_AUTO="${CFLAGS_AUTO# }" 668570af302Sopenharmony_cifi 669570af302Sopenharmony_cifi 670570af302Sopenharmony_cifi 671570af302Sopenharmony_ci 672570af302Sopenharmony_ciif test "$ARCH" = "aarch64" ; then 673570af302Sopenharmony_citrycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be 674570af302Sopenharmony_cifi 675570af302Sopenharmony_ci 676570af302Sopenharmony_ciif test "$ARCH" = "loongarch64" ; then 677570af302Sopenharmony_citrycppif __loongarch_soft_float "$t" && SUBARCH=${SUBARCH}-sf 678570af302Sopenharmony_citrycppif __loongarch_single_float "$t" && SUBARCH=${SUBARCH}-sp 679570af302Sopenharmony_ciprintf "checking whether assembler support FCSRs... " 680570af302Sopenharmony_ciecho "__asm__(\"movfcsr2gr \$t0,\$fcsr0\");" > "$tmpc" 681570af302Sopenharmony_ciif $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 682570af302Sopenharmony_ciprintf "yes\n" 683570af302Sopenharmony_cielse 684570af302Sopenharmony_ciprintf "no\n" 685570af302Sopenharmony_ciCFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_LOONGARCH_FCSR_ASM" 686570af302Sopenharmony_cifi 687570af302Sopenharmony_cifi 688570af302Sopenharmony_ci 689570af302Sopenharmony_ciif test "$ARCH" = "m68k" ; then 690570af302Sopenharmony_ciif trycppif "__HAVE_68881__" ; then : ; 691570af302Sopenharmony_cielif trycppif "__mcffpu__" ; then SUBARCH="-fp64" 692570af302Sopenharmony_cielse SUBARCH="-sf" 693570af302Sopenharmony_cifi 694570af302Sopenharmony_cifi 695570af302Sopenharmony_ci 696570af302Sopenharmony_ciif test "$ARCH" = "mips" ; then 697570af302Sopenharmony_citrycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6 698570af302Sopenharmony_citrycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el 699570af302Sopenharmony_citrycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf 700570af302Sopenharmony_cifi 701570af302Sopenharmony_ci 702570af302Sopenharmony_ciif test "$ARCH" = "mips64" ; then 703570af302Sopenharmony_citrycppif "_MIPS_SIM != _ABI64" "$t" && ARCH=mipsn32 704570af302Sopenharmony_citrycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6 705570af302Sopenharmony_citrycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el 706570af302Sopenharmony_citrycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf 707570af302Sopenharmony_cifi 708570af302Sopenharmony_ci 709570af302Sopenharmony_ciif test "$ARCH" = "powerpc" ; then 710570af302Sopenharmony_citrycppif "_SOFT_FLOAT || __NO_FPRS__" "$t" && SUBARCH=${SUBARCH}-sf 711570af302Sopenharmony_ciprintf "checking whether compiler can use 'd' constraint in asm... " 712570af302Sopenharmony_ciecho 'double f(double x) { __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); return x; }' > "$tmpc" 713570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 714570af302Sopenharmony_ciprintf "yes\n" 715570af302Sopenharmony_cielse 716570af302Sopenharmony_ciprintf "no\n" 717570af302Sopenharmony_ciCFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_PPC_D_ASM" 718570af302Sopenharmony_ciCFLAGS_AUTO="${CFLAGS_AUTO# }" 719570af302Sopenharmony_cifi 720570af302Sopenharmony_cifi 721570af302Sopenharmony_ci 722570af302Sopenharmony_citest "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \ 723570af302Sopenharmony_ci&& SUBARCH=${SUBARCH}el 724570af302Sopenharmony_ci 725570af302Sopenharmony_ciif test "$ARCH" = "powerpc64" ; then 726570af302Sopenharmony_citrycppif "_CALL_ELF == 2" "$t" || fail "$0: error: unsupported powerpc64 ABI" 727570af302Sopenharmony_citrycppif __LITTLE_ENDIAN__ "$t" && SUBARCH=${SUBARCH}le 728570af302Sopenharmony_citrycppif _SOFT_FLOAT "$t" && fail "$0: error: soft-float not supported on powerpc64" 729570af302Sopenharmony_cifi 730570af302Sopenharmony_ci 731570af302Sopenharmony_ciif test "$ARCH" = "riscv64" -o "$ARCH" = "riscv32" ; then 732570af302Sopenharmony_citrycppif __riscv_float_abi_soft "$t" && SUBARCH=${SUBARCH}-sf 733570af302Sopenharmony_citrycppif __riscv_float_abi_single "$t" && SUBARCH=${SUBARCH}-sp 734570af302Sopenharmony_cifi 735570af302Sopenharmony_ci 736570af302Sopenharmony_ciif test "$ARCH" = "sh" ; then 737570af302Sopenharmony_citryflag CFLAGS_AUTO -Wa,--isa=any 738570af302Sopenharmony_citrycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb 739570af302Sopenharmony_ciif trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then 740570af302Sopenharmony_ci# Some sh configurations are broken and replace double with float 741570af302Sopenharmony_ci# rather than using softfloat when the fpu is present but only 742570af302Sopenharmony_ci# supports single precision. Reject them. 743570af302Sopenharmony_ciprintf "checking whether compiler's double type is IEEE double... " 744570af302Sopenharmony_ciecho 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc" 745570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 746570af302Sopenharmony_ciprintf "yes\n" 747570af302Sopenharmony_cielse 748570af302Sopenharmony_ciprintf "no\n" 749570af302Sopenharmony_cifail "$0: error: compiler's floating point configuration is unsupported" 750570af302Sopenharmony_cifi 751570af302Sopenharmony_cielse 752570af302Sopenharmony_ciSUBARCH=${SUBARCH}-nofpu 753570af302Sopenharmony_cifi 754570af302Sopenharmony_ciif trycppif __SH_FDPIC__ "$t" ; then 755570af302Sopenharmony_ciSUBARCH=${SUBARCH}-fdpic 756570af302Sopenharmony_cifi 757570af302Sopenharmony_cifi 758570af302Sopenharmony_ci 759570af302Sopenharmony_citest "$SUBARCH" \ 760570af302Sopenharmony_ci&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH" 761570af302Sopenharmony_ci 762570af302Sopenharmony_ci# 763570af302Sopenharmony_ci# Some archs (powerpc) have different possible long double formats 764570af302Sopenharmony_ci# that the compiler can be configured for. The logic for whether this 765570af302Sopenharmony_ci# is supported is in bits/float.h; in general, it is not. We need to 766570af302Sopenharmony_ci# check for mismatches here or code in printf, strotd, and scanf will 767570af302Sopenharmony_ci# be dangerously incorrect because it depends on (1) the macros being 768570af302Sopenharmony_ci# correct, and (2) IEEE semantics. 769570af302Sopenharmony_ci# 770570af302Sopenharmony_ciprintf "checking whether compiler's long double definition matches float.h... " 771570af302Sopenharmony_ciecho '#include <float.h>' > "$tmpc" 772570af302Sopenharmony_ciecho '#define C(m,s) (m==LDBL_MANT_DIG && s==sizeof(long double))' >> "$tmpc" 773570af302Sopenharmony_ciecho 'typedef char ldcheck[(C(53,8)||C(64,12)||C(64,16)||C(113,16))*2-1];' >> "$tmpc" 774570af302Sopenharmony_ciif $CC $CFLAGS_C99FSE \ 775570af302Sopenharmony_ci -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \ 776570af302Sopenharmony_ci $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then 777570af302Sopenharmony_ciprintf "yes\n" 778570af302Sopenharmony_cielse 779570af302Sopenharmony_ciprintf "no\n" 780570af302Sopenharmony_cifail "$0: error: unsupported long double type" 781570af302Sopenharmony_cifi 782570af302Sopenharmony_ci 783570af302Sopenharmony_ci# 784570af302Sopenharmony_ci# Some build systems globally pass in broken CFLAGS like -ffast-math 785570af302Sopenharmony_ci# for all packages. On recent GCC we can detect this and error out 786570af302Sopenharmony_ci# early rather than producing a seriously-broken math library. 787570af302Sopenharmony_ci# 788570af302Sopenharmony_ciif trycppif "__FAST_MATH__" \ 789570af302Sopenharmony_ci "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then 790570af302Sopenharmony_cifail "$0: error: compiler has broken floating point; check CFLAGS" 791570af302Sopenharmony_cifi 792570af302Sopenharmony_ci 793570af302Sopenharmony_ciprintf "creating config.mak... " 794570af302Sopenharmony_ci 795570af302Sopenharmony_cicmdline=$(quote "$0") 796570af302Sopenharmony_cifor i ; do cmdline="$cmdline $(quote "$i")" ; done 797570af302Sopenharmony_ci 798570af302Sopenharmony_ciexec 3>&1 1>config.mak 799570af302Sopenharmony_ci 800570af302Sopenharmony_ci 801570af302Sopenharmony_cicat << EOF 802570af302Sopenharmony_ci# This version of config.mak was generated by: 803570af302Sopenharmony_ci# $cmdline 804570af302Sopenharmony_ci# Any changes made here will be lost if configure is re-run 805570af302Sopenharmony_ciAR = ${AR:-\$(CROSS_COMPILE)ar} 806570af302Sopenharmony_ciRANLIB = ${RANLIB:-\$(CROSS_COMPILE)ranlib} 807570af302Sopenharmony_ciARCH = $ARCH 808570af302Sopenharmony_ciSUBARCH = $SUBARCH 809570af302Sopenharmony_ciASMSUBARCH = $ASMSUBARCH 810570af302Sopenharmony_cisrcdir = $srcdir 811570af302Sopenharmony_ciprefix = $prefix 812570af302Sopenharmony_ciexec_prefix = $exec_prefix 813570af302Sopenharmony_cibindir = $bindir 814570af302Sopenharmony_cilibdir = $libdir 815570af302Sopenharmony_ciincludedir = $includedir 816570af302Sopenharmony_cisyslibdir = $syslibdir 817570af302Sopenharmony_ciCC = $CC 818570af302Sopenharmony_ciCFLAGS = $CFLAGS 819570af302Sopenharmony_ciCFLAGS_AUTO = $CFLAGS_AUTO 820570af302Sopenharmony_ciCFLAGS_C99FSE = $CFLAGS_C99FSE 821570af302Sopenharmony_ciCFLAGS_MEMOPS = $CFLAGS_MEMOPS 822570af302Sopenharmony_ciCFLAGS_NOSSP = $CFLAGS_NOSSP 823570af302Sopenharmony_ciCPPFLAGS = $CPPFLAGS 824570af302Sopenharmony_ciLDFLAGS = $LDFLAGS 825570af302Sopenharmony_ciLDFLAGS_AUTO = $LDFLAGS_AUTO 826570af302Sopenharmony_ciCROSS_COMPILE = $CROSS_COMPILE 827570af302Sopenharmony_ciLIBCC = $LIBCC 828570af302Sopenharmony_ciOPTIMIZE_GLOBS = $OPTIMIZE_GLOBS 829570af302Sopenharmony_ciALL_TOOLS = $tools 830570af302Sopenharmony_ciTOOL_LIBS = $tool_libs 831570af302Sopenharmony_ciADD_CFI = $ADD_CFI 832570af302Sopenharmony_ciMALLOC_DIR = $malloc_dir 833570af302Sopenharmony_ciEOF 834570af302Sopenharmony_citest "x$static" = xno && echo "STATIC_LIBS =" 835570af302Sopenharmony_citest "x$shared" = xno && echo "SHARED_LIBS =" 836570af302Sopenharmony_citest "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)' 837570af302Sopenharmony_citest "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)' 838570af302Sopenharmony_citest "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)' 839570af302Sopenharmony_ciexec 1>&3 3>&- 840570af302Sopenharmony_ci 841570af302Sopenharmony_citest "$srcdir" = "." || ln -sf $srcdir/Makefile . 842570af302Sopenharmony_ci 843570af302Sopenharmony_ciprintf "done\n" 844