]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/configure
Format changes to musl code to fit musl's style.
[wasi-libc.git] / libc-top-half / musl / configure
CommitLineData
320054e8
DG
1#!/bin/sh
2
3usage () {
4cat <<EOF
5Usage: $0 [OPTION]... [VAR=VALUE]... [TARGET]
6
7To assign environment variables (e.g., CC, CFLAGS...), specify them as
8VAR=VALUE. See below for descriptions of some of the useful variables.
9
10Defaults for the options are specified in brackets.
11
12Configuration:
13 --srcdir=DIR source directory [detected]
14
15Installation directories:
16 --prefix=PREFIX main installation prefix [/usr/local/musl]
17 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
18
19Fine tuning of the installation directories:
20 --bindir=DIR user executables [EPREFIX/bin]
21 --libdir=DIR library files for the linker [PREFIX/lib]
22 --includedir=DIR include files for the C compiler [PREFIX/include]
23 --syslibdir=DIR location for the dynamic linker [/lib]
24
25System types:
26 --target=TARGET configure to run on target TARGET [detected]
27 --host=HOST same as --target
28 --build=BUILD build system type; used only to infer cross-compiling
29
30Optional features:
31 --enable-optimize=... optimize listed components for speed over size [auto]
32 --enable-debug build with debugging information [disabled]
33 --enable-warnings build with recommended warnings flags [disabled]
34 --enable-wrapper=... build given musl toolchain wrapper [auto]
35 --disable-shared inhibit building shared library [enabled]
36 --disable-static inhibit building static library [enabled]
37
38Some influential environment variables:
39 CC C compiler command [detected]
40 CFLAGS C compiler flags [-Os -pipe ...]
41 CROSS_COMPILE prefix for cross compiler and tools [none]
42 LIBCC compiler runtime library [detected]
43
44Use these variables to override the choices made by configure.
45
46EOF
47exit 0
48}
49
50# Helper functions
51
52quote () {
53tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
54$1
55EOF
56printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
57}
58echo () { printf "%s\n" "$*" ; }
59fail () { echo "$*" ; exit 1 ; }
60fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
61cmdexists () { type "$1" >/dev/null 2>&1 ; }
62trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
63
64stripdir () {
65while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
66}
67
68trycppif () {
69printf "checking preprocessor condition %s... " "$1"
70echo "typedef int x;" > "$tmpc"
71echo "#if $1" >> "$tmpc"
72echo "#error yes" >> "$tmpc"
73echo "#endif" >> "$tmpc"
74if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
75printf "false\n"
76return 1
77else
78printf "true\n"
79return 0
80fi
81}
82
83tryflag () {
84printf "checking whether compiler accepts %s... " "$2"
85echo "typedef int x;" > "$tmpc"
86if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
87printf "yes\n"
88eval "$1=\"\${$1} \$2\""
89eval "$1=\${$1# }"
90return 0
91else
92printf "no\n"
93return 1
94fi
95}
96
97tryldflag () {
98printf "checking whether linker accepts %s... " "$2"
99echo "typedef int x;" > "$tmpc"
100if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
101printf "yes\n"
102eval "$1=\"\${$1} \$2\""
103eval "$1=\${$1# }"
104return 0
105else
106printf "no\n"
107return 1
108fi
109}
110
111
112
113# Beginning of actual script
114
115CFLAGS_C99FSE=
116CFLAGS_AUTO=
117CFLAGS_MEMOPS=
118CFLAGS_NOSSP=
119CFLAGS_TRY=
120LDFLAGS_AUTO=
121LDFLAGS_TRY=
122OPTIMIZE_GLOBS=
123srcdir=
124prefix=/usr/local/musl
125exec_prefix='$(prefix)'
126bindir='$(exec_prefix)/bin'
127libdir='$(prefix)/lib'
128includedir='$(prefix)/include'
129syslibdir='/lib'
130tools=
131tool_libs=
132build=
133target=
134optimize=auto
135debug=no
136warnings=no
137shared=auto
138static=yes
139wrapper=auto
140gcc_wrapper=no
141clang_wrapper=no
142
143for arg ; do
144case "$arg" in
145--help|-h) usage ;;
146--srcdir=*) srcdir=${arg#*=} ;;
147--prefix=*) prefix=${arg#*=} ;;
148--exec-prefix=*) exec_prefix=${arg#*=} ;;
149--bindir=*) bindir=${arg#*=} ;;
150--libdir=*) libdir=${arg#*=} ;;
151--includedir=*) includedir=${arg#*=} ;;
152--syslibdir=*) syslibdir=${arg#*=} ;;
153--enable-shared|--enable-shared=yes) shared=yes ;;
154--disable-shared|--enable-shared=no) shared=no ;;
155--enable-static|--enable-static=yes) static=yes ;;
156--disable-static|--enable-static=no) static=no ;;
157--enable-optimize) optimize=yes ;;
158--enable-optimize=*) optimize=${arg#*=} ;;
159--disable-optimize) optimize=no ;;
160--enable-debug|--enable-debug=yes) debug=yes ;;
161--disable-debug|--enable-debug=no) debug=no ;;
162--enable-warnings|--enable-warnings=yes) warnings=yes ;;
163--disable-warnings|--enable-warnings=no) warnings=no ;;
164--enable-wrapper|--enable-wrapper=yes) wrapper=detect ;;
165--enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ; clang_wrapper=yes ;;
166--enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;;
167--enable-wrapper=clang) wrapper=yes ; clang_wrapper=yes ;;
168--disable-wrapper|--enable-wrapper=no) wrapper=no ;;
169--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;;
170--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
171--enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
172--host=*|--target=*) target=${arg#*=} ;;
173--build=*) build=${arg#*=} ;;
174-* ) echo "$0: unknown option $arg" ;;
175CC=*) CC=${arg#*=} ;;
176CFLAGS=*) CFLAGS=${arg#*=} ;;
177CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
178LDFLAGS=*) LDFLAGS=${arg#*=} ;;
179CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
180LIBCC=*) LIBCC=${arg#*=} ;;
181*=*) ;;
182*) build=$arg ; target=$arg ;;
183esac
184done
185
186for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do
187stripdir $i
188done
189
190#
191# Get the source dir for out-of-tree builds
192#
193if test -z "$srcdir" ; then
194srcdir="${0%/configure}"
195stripdir srcdir
196fi
197abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
198abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
199test "$abs_srcdir" = "$abs_builddir" && srcdir=.
200test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
201
202#
203# Get a temp filename we can use
204#
205i=0
206set -C
207while : ; do i=$(($i+1))
208tmpc="./conf$$-$PPID-$i.c"
2092>|/dev/null > "$tmpc" && break
210test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
211done
212set +C
213trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
214
215#
216# Check whether we are cross-compiling, and set a default
217# CROSS_COMPILE prefix if none was provided.
218#
219test "$target" && \
220test "$target" != "$build" && \
221test -z "$CROSS_COMPILE" && \
222CROSS_COMPILE="$target-"
223
224#
225# Find a C compiler to use
226#
227printf "checking for C compiler... "
228trycc ${CROSS_COMPILE}gcc
229trycc ${CROSS_COMPILE}c99
230trycc ${CROSS_COMPILE}cc
231printf "%s\n" "$CC"
232test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
233
234printf "checking whether C compiler works... "
235echo "typedef int x;" > "$tmpc"
236if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then
237printf "yes\n"
238else
239printf "no; compiler output follows:\n%s\n" "$output"
240exit 1
241fi
242
243#
244# Figure out options to force errors on unknown flags.
245#
246tryflag CFLAGS_TRY -Werror=unknown-warning-option
247tryflag CFLAGS_TRY -Werror=unused-command-line-argument
248tryflag CFLAGS_TRY -Werror=ignored-optimization-argument
249tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
250tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
251
252#
253# Need to know if the compiler is gcc or clang to decide which toolchain
254# wrappers to build.
255#
256printf "checking for C compiler family... "
257cc_ver="$(LC_ALL=C $CC -v 2>&1)"
258cc_family=unknown
259if fnmatch '*gcc\ version*' "$cc_ver" ; then
260cc_family=gcc
261elif fnmatch '*clang\ version*' "$cc_ver" ; then
262cc_family=clang
263fi
264echo "$cc_family"
265
266#
267# Figure out toolchain wrapper to build
268#
269if test "$wrapper" = auto -o "$wrapper" = detect ; then
270echo "#include <stdlib.h>" > "$tmpc"
271echo "#if ! __GLIBC__" >> "$tmpc"
272echo "#error no" >> "$tmpc"
273echo "#endif" >> "$tmpc"
274printf "checking for toolchain wrapper to build... "
275if test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
276echo "none"
277elif test "$cc_family" = gcc ; then
278gcc_wrapper=yes
279echo "gcc"
280elif test "$cc_family" = clang ; then
281clang_wrapper=yes
282echo "clang"
283else
284echo "none"
285if test "$wrapper" = detect ; then
286fail "$0: could not find an appropriate toolchain wrapper"
287fi
288fi
289fi
290
291if test "$gcc_wrapper" = yes ; then
292tools="$tools obj/musl-gcc"
293tool_libs="$tool_libs lib/musl-gcc.specs"
294fi
295if test "$clang_wrapper" = yes ; then
296tools="$tools obj/musl-clang obj/ld.musl-clang"
297fi
298
299#
300# Find the target architecture
301#
302printf "checking target system type... "
303test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
304printf "%s\n" "$target"
305
306#
307# Convert to just ARCH
308#
309case "$target" in
310# Catch these early to simplify matching for 32-bit archs
311arm*) ARCH=arm ;;
312aarch64*) ARCH=aarch64 ;;
313i?86-nt32*) ARCH=nt32 ;;
314i?86*) ARCH=i386 ;;
315x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
316x86_64-nt64*) ARCH=nt64 ;;
317x86_64*) ARCH=x86_64 ;;
318m68k*) ARCH=m68k ;;
319mips64*|mipsisa64*) ARCH=mips64 ;;
320mips*) ARCH=mips ;;
321microblaze*) ARCH=microblaze ;;
322or1k*) ARCH=or1k ;;
323powerpc64*|ppc64*) ARCH=powerpc64 ;;
324powerpc*|ppc*) ARCH=powerpc ;;
325sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
326s390x*) ARCH=s390x ;;
327wasm32) ARCH=wasm32 ;;
328wasm64) ARCH=wasm64 ;;
329unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
330*) fail "$0: unknown or unsupported target \"$target\"" ;;
331esac
332
333#
334# Try to get a conforming C99 freestanding environment
335#
336tryflag CFLAGS_C99FSE -std=c99
337tryflag CFLAGS_C99FSE -nostdinc
338tryflag CFLAGS_C99FSE -ffreestanding \
339|| tryflag CFLAGS_C99FSE -fno-builtin
340tryflag CFLAGS_C99FSE -fexcess-precision=standard \
341|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
342tryflag CFLAGS_C99FSE -frounding-math
343
344#
345# We may use the may_alias attribute if __GNUC__ is defined, so
346# if the compiler defines __GNUC__ but does not provide it,
347# it must be defined away as part of the CFLAGS.
348#
349printf "checking whether compiler needs attribute((may_alias)) suppression... "
350cat > "$tmpc" <<EOF
351typedef int
352#ifdef __GNUC__
353__attribute__((__may_alias__))
354#endif
355x;
356EOF
357if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
358 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
359printf "no\n"
360else
361printf "yes\n"
362CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
363fi
364
365#
366# The GNU toolchain defaults to assuming unmarked files need an
367# executable stack, potentially exposing vulnerabilities in programs
368# linked with such object files. Fix this.
369#
370tryflag CFLAGS_C99FSE -Wa,--noexecstack
371
372#
373# Check for options to disable stack protector, which needs to be
374# disabled for a few early-bootstrap translation units. If not found,
375# this is not an error; we assume the toolchain does not do ssp.
376#
377tryflag CFLAGS_NOSSP -fno-stack-protector
378
379#
380# Check for options that may be needed to prevent the compiler from
381# generating self-referential versions of memcpy,, memmove, memcmp,
382# and memset. Really, we should add a check to determine if this
383# option is sufficient, and if not, add a macro to cripple these
384# functions with volatile...
385#
386tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
387
388#
389# Enable debugging if requessted.
390#
391test "$debug" = yes && CFLAGS_AUTO=-g
392
393#
394# Preprocess asm files to add extra debugging information if debug is
395# enabled, our assembler supports the needed directives, and the
396# preprocessing script has been written for our architecture.
397#
398printf "checking whether we should preprocess assembly to add debugging information... "
399if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" &&
400 test -f "tools/add-cfi.$ARCH.awk" &&
401 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 -
402then
403 ADD_CFI=yes
404else
405 ADD_CFI=no
406fi
407printf "%s\n" "$ADD_CFI"
408
409#
410# Possibly add a -O option to CFLAGS and select modules to optimize with
411# -O3 based on the status of --enable-optimize and provided CFLAGS.
412#
413printf "checking for optimization settings... "
414case "x$optimize" in
415xauto)
416if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
417printf "using provided CFLAGS\n" ;optimize=no
418else
419printf "using defaults\n" ; optimize=yes
420fi
421;;
422xsize|xnone) printf "minimize size\n" ; optimize=size ;;
423xno|x) printf "disabled\n" ; optimize=no ;;
424*) printf "custom\n" ;;
425esac
426
427test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
428test "$optimize" = yes && optimize="internal,malloc,string"
429
430if fnmatch 'no|size' "$optimize" ; then :
431else
432printf "components to be optimized for speed:"
433while test "$optimize" ; do
434case "$optimize" in
435*,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
436*) this=$optimize optimize=
437esac
438printf " $this"
439case "$this" in
440*/*.c) ;;
441*/*) this=$this*.c ;;
442*) this=$this/*.c ;;
443esac
444OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
445done
446OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
447printf "\n"
448fi
449
450# Always try -pipe
451tryflag CFLAGS_AUTO -pipe
452
453#
454# If debugging is disabled, omit frame pointer. Modern GCC does this
455# anyway on most archs even when debugging is enabled since the frame
456# pointer is no longer needed for debugging.
457#
458if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
459else
460tryflag CFLAGS_AUTO -fomit-frame-pointer
461fi
462
463#
464# Modern GCC wants to put DWARF tables (used for debugging and
465# unwinding) in the loaded part of the program where they are
466# unstrippable. These options force them back to debug sections (and
467# cause them not to get generated at all if debugging is off).
468#
469tryflag CFLAGS_AUTO -fno-unwind-tables
470tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
471
472#
473# Attempt to put each function and each data object in its own
474# section. This both allows additional size optimizations at link
475# time and works around a dangerous class of compiler/assembler bugs
476# whereby relative address expressions are constant-folded by the
477# assembler even when one or more of the symbols involved is
478# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc.
479#
480tryflag CFLAGS_AUTO -ffunction-sections
481tryflag CFLAGS_AUTO -fdata-sections
482
483#
484# On x86, make sure we don't have incompatible instruction set
485# extensions enabled by default. This is bad for making static binaries.
486# We cheat and use i486 rather than i386 because i386 really does not
487# work anyway (issues with atomic ops).
488# Some build environments pass -march and -mtune options via CC, so
489# check both CC and CFLAGS.
490#
491if test "$ARCH" = "i386" ; then
492fnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
493fnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
494fi
495
496#
497# Even with -std=c99, gcc accepts some constructs which are constraint
498# violations. We want to treat these as errors regardless of whether
499# other purely stylistic warnings are enabled -- especially implicit
500# function declarations, which are a dangerous programming error.
501#
502tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
503tryflag CFLAGS_AUTO -Werror=implicit-int
504tryflag CFLAGS_AUTO -Werror=pointer-sign
505tryflag CFLAGS_AUTO -Werror=pointer-arith
506
507#
508# GCC ignores unused arguements by default, but Clang needs this extra
509# parameter to stop printing warnings about LDFLAGS passed during
510# compiling stage and CFLAGS passed during linking stage.
511#
512test "$cc_family" = clang && tryflag CFLAGS_AUTO -Qunused-arguments
513
514if test "x$warnings" = xyes ; then
515tryflag CFLAGS_AUTO -Wall
516tryflag CFLAGS_AUTO -Wno-parentheses
517tryflag CFLAGS_AUTO -Wno-uninitialized
518tryflag CFLAGS_AUTO -Wno-missing-braces
519tryflag CFLAGS_AUTO -Wno-unused-value
520tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
521tryflag CFLAGS_AUTO -Wno-unknown-pragmas
522tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
523fi
524
525# Determine if the compiler produces position-independent code (PIC)
526# by default. If so, we don't need to compile separate object files
527# for libc.a and libc.so.
528if trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
529pic_default=yes
530else
531pic_default=no
532fi
533
534# Reduce space lost to padding for alignment purposes by sorting data
535# objects according to their alignment reqirements. This approximates
536# optimal packing.
537tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment
538tryldflag LDFLAGS_AUTO -Wl,--sort-common
539
540# When linking shared library, drop dummy weak definitions that were
541# replaced by strong definitions from other translation units.
542tryldflag LDFLAGS_AUTO -Wl,--gc-sections
543
544# Some patched GCC builds have these defaults messed up...
545tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
546
547# Prevent linking if there are undefined symbols; if any exist,
548# libc.so will crash at runtime during relocation processing.
549# The common way this can happen is failure to link the compiler
550# runtime library; implementation error is also a possibility.
551tryldflag LDFLAGS_AUTO -Wl,--no-undefined
552
553# Avoid exporting symbols from compiler runtime libraries. They
554# should be hidden anyway, but some toolchains including old gcc
555# versions built without shared library support and pcc are broken.
556tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL
557
558# Public data symbols must be interposable to allow for copy
559# relocations, but otherwise we want to bind symbols at libc link
560# time to eliminate startup relocations and PLT overhead. Use
561# --dynamic-list rather than -Bsymbolic-functions for greater
562# control over what symbols are left unbound.
563tryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list"
564
565# Find compiler runtime library
566test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
567test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
568test -z "$LIBCC" && try_libcc=`$CC -print-libgcc-file-name 2>/dev/null` \
569 && tryldflag LIBCC "$try_libcc"
570test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
571 && tryldflag LIBCC "$try_libcc"
572printf "using compiler runtime libraries: %s\n" "$LIBCC"
573
574# Figure out arch variants for archs with variants
575SUBARCH=
576t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS"
577
578if test "$ARCH" = "x86_64" ; then
579trycppif __ILP32__ "$t" && ARCH=x32
580fi
581
582if test "$ARCH" = "arm" ; then
583if trycppif __thumb2__ "$t" ; then
584tryflag CFLAGS_AUTO -mimplicit-it=always
585tryflag CFLAGS_AUTO -Wa,-mimplicit-it=always
586tryflag CFLAGS_AUTO -Wa,-mthumb
587fi
588trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
589trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
590# Versions of clang up until at least 3.8 have the wrong constraint codes
591# for floating point operands to inline asm. Detect this so the affected
592# source files can just disable the asm.
593if test "$cc_family" = clang ; then
594printf "checking whether clang's vfp asm constraints work... "
595echo 'float f(float x) { __asm__("":"+t"(x)); return x; }' > "$tmpc"
596if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
597printf "yes\n"
598else
599printf "no\n"
600CFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_VFP_ASM"
601CFLAGS_AUTO="${CFLAGS_AUTO# }"
602fi
603fi
604fi
605
606if test "$ARCH" = "aarch64" ; then
607trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
608fi
609
610if test "$ARCH" = "m68k" ; then
611if trycppif "__HAVE_68881__" ; then : ;
612elif trycppif "__mcffpu__" ; then SUBARCH="-fp64"
613else SUBARCH="-sf"
614fi
615fi
616
617if test "$ARCH" = "mips" ; then
618trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6
619trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
620trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
621fi
622
623if test "$ARCH" = "mips64" ; then
624trycppif "_MIPS_SIM != _ABI64" "$t" && ARCH=mipsn32
625trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6
626trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
627trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
628fi
629
630if test "$ARCH" = "powerpc" ; then
631trycppif "__NO_FPRS__ && !_SOFT_FLOAT" "$t" && fail \
632 "$0: error: compiler's floating point configuration is unsupported"
633trycppif _SOFT_FLOAT "$t" && SUBARCH=${SUBARCH}-sf
634fi
635
636test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
637&& SUBARCH=${SUBARCH}el
638
639if test "$ARCH" = "powerpc64" ; then
640trycppif "_CALL_ELF == 2" "$t" || fail "$0: error: unsupported powerpc64 ABI"
641trycppif __LITTLE_ENDIAN__ "$t" && SUBARCH=${SUBARCH}le
642trycppif _SOFT_FLOAT "$t" && fail "$0: error: soft-float not supported on powerpc64"
643fi
644
645if test "$ARCH" = "sh" ; then
646tryflag CFLAGS_AUTO -Wa,--isa=any
647trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
648if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
649# Some sh configurations are broken and replace double with float
650# rather than using softfloat when the fpu is present but only
651# supports single precision. Reject them.
652printf "checking whether compiler's double type is IEEE double... "
653echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
654if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
655printf "yes\n"
656else
657printf "no\n"
658fail "$0: error: compiler's floating point configuration is unsupported"
659fi
660else
661SUBARCH=${SUBARCH}-nofpu
662fi
663if trycppif __SH_FDPIC__ "$t" ; then
664SUBARCH=${SUBARCH}-fdpic
665fi
666fi
667
668test "$SUBARCH" \
669&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
670
671case "$ARCH$SUBARCH" in
672arm) ASMSUBARCH=el ;;
673*) ASMSUBARCH=$SUBARCH ;;
674esac
675
676#
677# Some archs (powerpc) have different possible long double formats
678# that the compiler can be configured for. The logic for whether this
679# is supported is in bits/float.h; in general, it is not. We need to
680# check for mismatches here or code in printf, strotd, and scanf will
681# be dangerously incorrect because it depends on (1) the macros being
682# correct, and (2) IEEE semantics.
683#
684printf "checking whether compiler's long double definition matches float.h... "
685echo '#include <float.h>' > "$tmpc"
686echo '#define C(m,s) (m==LDBL_MANT_DIG && s==sizeof(long double))' >> "$tmpc"
687echo 'typedef char ldcheck[(C(53,8)||C(64,12)||C(64,16)||C(113,16))*2-1];' >> "$tmpc"
688if $CC $CFLAGS_C99FSE \
689 -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \
690 $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
691printf "yes\n"
692else
693printf "no\n"
694fail "$0: error: unsupported long double type"
695fi
696
697#
698# Some build systems globally pass in broken CFLAGS like -ffast-math
699# for all packages. On recent GCC we can detect this and error out
700# early rather than producing a seriously-broken math library.
701#
702if trycppif "__FAST_MATH__" \
703 "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
704fail "$0: error: compiler has broken floating point; check CFLAGS"
705fi
706
707printf "creating config.mak... "
708
709cmdline=$(quote "$0")
710for i ; do cmdline="$cmdline $(quote "$i")" ; done
711
712exec 3>&1 1>config.mak
713
714
715cat << EOF
716# This version of config.mak was generated by:
717# $cmdline
718# Any changes made here will be lost if configure is re-run
719ARCH = $ARCH
720SUBARCH = $SUBARCH
721ASMSUBARCH = $ASMSUBARCH
722srcdir = $srcdir
723prefix = $prefix
724exec_prefix = $exec_prefix
725bindir = $bindir
726libdir = $libdir
727includedir = $includedir
728syslibdir = $syslibdir
729CC = $CC
730CFLAGS = $CFLAGS
731CFLAGS_AUTO = $CFLAGS_AUTO
732CFLAGS_C99FSE = $CFLAGS_C99FSE
733CFLAGS_MEMOPS = $CFLAGS_MEMOPS
734CFLAGS_NOSSP = $CFLAGS_NOSSP
735CPPFLAGS = $CPPFLAGS
736LDFLAGS = $LDFLAGS
737LDFLAGS_AUTO = $LDFLAGS_AUTO
738CROSS_COMPILE = $CROSS_COMPILE
739LIBCC = $LIBCC
740OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
741ALL_TOOLS = $tools
742TOOL_LIBS = $tool_libs
743ADD_CFI = $ADD_CFI
744EOF
745test "x$static" = xno && echo "STATIC_LIBS ="
746test "x$shared" = xno && echo "SHARED_LIBS ="
747test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
748test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)'
749test "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)'
750exec 1>&3 3>&-
751
752test "$srcdir" = "." || ln -sf $srcdir/Makefile .
753
754printf "done\n"