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