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