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