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