blob: e35c9b6384347a9669e60a86252709de0174e7d3 [file] [log] [blame]
Rich Felker64d2f8e2012-05-04 23:24:51 -04001#!/bin/sh
2
3usage () {
4cat <<EOF
Rich Felker278883d2012-06-03 16:22:13 -04005Usage: $0 [OPTION]... [VAR=VALUE]... [TARGET]
Rich Felker64d2f8e2012-05-04 23:24:51 -04006
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
12Installation directories:
13 --prefix=PREFIX main installation prefix [/usr/local/musl]
14 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
15
16Fine tuning of the installation directories:
17 --bindir=DIR user executables [EPREFIX/bin]
18 --libdir=DIR library files for the linker [PREFIX/lib]
19 --includedir=DIR include files for the C compiler [PREFIX/include]
20 --syslibdir=DIR location for the dynamic linker [/lib]
21
22System types:
23 --target=TARGET configure to run on target TARGET [detected]
Rich Felker278883d2012-06-03 16:22:13 -040024 --host=HOST same as --target
Rich Felker64d2f8e2012-05-04 23:24:51 -040025
26Optional features:
Rich Felkera80847d2013-07-22 21:22:04 -040027 --enable-optimize=... optimize listed components for speed over size [auto]
Rich Felker64d2f8e2012-05-04 23:24:51 -040028 --enable-debug build with debugging information [disabled]
29 --enable-warnings build with recommended warnings flags [disabled]
Rich Felkerde2b67f2015-04-19 22:05:29 -040030 --enable-visibility use global visibility options to optimize PIC [auto]
Rich Felker64d2f8e2012-05-04 23:24:51 -040031 --enable-gcc-wrapper build musl-gcc toolchain wrapper [auto]
32 --disable-shared inhibit building shared library [enabled]
33 --disable-static inhibit building static library [enabled]
34
35Some influential environment variables:
36 CC C compiler command [detected]
37 CFLAGS C compiler flags [-Os -pipe ...]
Rich Felker94e920d2012-08-14 22:50:16 -040038 CROSS_COMPILE prefix for cross compiler and tools [none]
Rich Felker2c1cd232012-09-10 15:30:52 -040039 LIBCC compiler runtime library [detected]
Rich Felker64d2f8e2012-05-04 23:24:51 -040040
41Use these variables to override the choices made by configure.
42
43EOF
44exit 0
45}
46
47# Helper functions
48
Rich Felker453f4622013-08-16 18:19:47 -040049quote () {
50tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
51$1
52EOF
Rich Felkere4499742013-08-20 13:51:46 -040053printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
Rich Felker453f4622013-08-16 18:19:47 -040054}
Rich Felker64d2f8e2012-05-04 23:24:51 -040055echo () { printf "%s\n" "$*" ; }
56fail () { echo "$*" ; exit 1 ; }
57fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
58cmdexists () { type "$1" >/dev/null 2>&1 ; }
59trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
60
Rich Felker3d9e3a32012-11-08 17:20:50 -050061stripdir () {
62while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
Rich Felker64d2f8e2012-05-04 23:24:51 -040063}
64
Rich Felker3e7f1862013-07-18 20:30:58 -040065trycppif () {
66printf "checking preprocessor condition %s... " "$1"
Rich Felkerdf065782013-07-18 20:37:19 -040067echo "typedef int x;" > "$tmpc"
68echo "#if $1" >> "$tmpc"
Rich Felker3e7f1862013-07-18 20:30:58 -040069echo "#error yes" >> "$tmpc"
70echo "#endif" >> "$tmpc"
71if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
72printf "false\n"
73return 1
74else
75printf "true\n"
76return 0
77fi
78}
79
Rich Felker64d2f8e2012-05-04 23:24:51 -040080tryflag () {
81printf "checking whether compiler accepts %s... " "$2"
82echo "typedef int x;" > "$tmpc"
Rich Felkerde2b67f2015-04-19 22:05:29 -040083if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -040084printf "yes\n"
85eval "$1=\"\${$1} \$2\""
86eval "$1=\${$1# }"
87return 0
88else
89printf "no\n"
90return 1
91fi
92}
93
Rich Felker08f70a32012-06-06 20:45:52 -040094tryldflag () {
95printf "checking whether linker accepts %s... " "$2"
Rich Felker67a03832012-06-07 00:23:58 -040096echo "typedef int x;" > "$tmpc"
Rich Felkercd31a1f2012-10-26 18:15:51 -040097if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker08f70a32012-06-06 20:45:52 -040098printf "yes\n"
99eval "$1=\"\${$1} \$2\""
100eval "$1=\${$1# }"
101return 0
102else
103printf "no\n"
104return 1
105fi
106}
107
Rich Felker64d2f8e2012-05-04 23:24:51 -0400108
109
110# Beginning of actual script
111
Rich Felker08f70a32012-06-06 20:45:52 -0400112CFLAGS_C99FSE=
113CFLAGS_AUTO=
Rich Felker4a1f55e2013-08-01 17:12:23 -0400114CFLAGS_MEMOPS=
Rich Felker1ef849c2015-04-13 20:13:10 -0400115CFLAGS_NOSSP=
Rich Felker08f70a32012-06-06 20:45:52 -0400116LDFLAGS_AUTO=
Rich Felkera80847d2013-07-22 21:22:04 -0400117OPTIMIZE_GLOBS=
Rich Felker3d9e3a32012-11-08 17:20:50 -0500118prefix=/usr/local/musl
119exec_prefix='$(prefix)'
120bindir='$(exec_prefix)/bin'
121libdir='$(prefix)/lib'
122includedir='$(prefix)/include'
123syslibdir='/lib'
Rich Felker278883d2012-06-03 16:22:13 -0400124target=
Rich Felkera80847d2013-07-22 21:22:04 -0400125optimize=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400126debug=no
Rich Felker3d9e3a32012-11-08 17:20:50 -0500127warnings=no
Rich Felkerde2b67f2015-04-19 22:05:29 -0400128visibility=auto
Rich Felkerd79b2772014-06-10 12:11:12 -0400129shared=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400130static=yes
Rich Felker9ca4dae2014-05-19 10:33:28 -0400131wrapper=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400132
133for arg ; do
134case "$arg" in
135--help) usage ;;
136--prefix=*) prefix=${arg#*=} ;;
137--exec-prefix=*) exec_prefix=${arg#*=} ;;
138--bindir=*) bindir=${arg#*=} ;;
139--libdir=*) libdir=${arg#*=} ;;
140--includedir=*) includedir=${arg#*=} ;;
141--syslibdir=*) syslibdir=${arg#*=} ;;
142--enable-shared|--enable-shared=yes) shared=yes ;;
143--disable-shared|--enable-shared=no) shared=no ;;
144--enable-static|--enable-static=yes) static=yes ;;
145--disable-static|--enable-static=no) static=no ;;
Rich Felkera80847d2013-07-22 21:22:04 -0400146--enable-optimize) optimize=yes ;;
147--enable-optimize=*) optimize=${arg#*=} ;;
148--disable-optimize) optimize=no ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400149--enable-debug|--enable-debug=yes) debug=yes ;;
150--disable-debug|--enable-debug=no) debug=no ;;
151--enable-warnings|--enable-warnings=yes) warnings=yes ;;
152--disable-warnings|--enable-warnings=no) warnings=no ;;
Rich Felkerde2b67f2015-04-19 22:05:29 -0400153--enable-visibility|--enable-visibility=yes) visibility=yes ;;
154--disable-visibility|--enable-visibility=no) visibility=no ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400155--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
156--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
Rich Felker278883d2012-06-03 16:22:13 -0400157--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
158--host=*|--target=*) target=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400159-* ) echo "$0: unknown option $arg" ;;
160CC=*) CC=${arg#*=} ;;
161CFLAGS=*) CFLAGS=${arg#*=} ;;
162CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
163LDFLAGS=*) LDFLAGS=${arg#*=} ;;
Rich Felker94e920d2012-08-14 22:50:16 -0400164CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
Rich Felker2c1cd232012-09-10 15:30:52 -0400165LIBCC=*) LIBCC=${arg#*=} ;;
Rich Felker278883d2012-06-03 16:22:13 -0400166*=*) ;;
167*) target=$arg ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400168esac
169done
170
Rich Felker3d9e3a32012-11-08 17:20:50 -0500171for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
172stripdir $i
173done
Rich Felker64d2f8e2012-05-04 23:24:51 -0400174
175#
176# Get a temp filename we can use
177#
178i=0
179set -C
180while : ; do i=$(($i+1))
181tmpc="./conf$$-$PPID-$i.c"
Rich Felker6c0cba82012-11-18 23:15:47 -05001822>|/dev/null > "$tmpc" && break
Rich Felker64d2f8e2012-05-04 23:24:51 -0400183test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
184done
185set +C
186trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
187
188#
189# Find a C compiler to use
190#
191printf "checking for C compiler... "
Rich Felker94e920d2012-08-14 22:50:16 -0400192trycc ${CROSS_COMPILE}gcc
193trycc ${CROSS_COMPILE}c99
194trycc ${CROSS_COMPILE}cc
Rich Felker64d2f8e2012-05-04 23:24:51 -0400195printf "%s\n" "$CC"
196test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
197
Rich Felker89456672014-05-12 14:22:57 -0400198printf "checking whether C compiler works... "
199echo "typedef int x;" > "$tmpc"
200if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then
201printf "yes\n"
202else
203printf "no; compiler output follows:\n%s\n" "$output"
204exit 1
205fi
206
Rich Felker64d2f8e2012-05-04 23:24:51 -0400207#
Rich Felker9ca4dae2014-05-19 10:33:28 -0400208# Need to know if the compiler is gcc to decide whether to build the
209# musl-gcc wrapper, and for critical bug detection in some gcc versions.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400210#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400211printf "checking whether compiler is gcc... "
Rich Felkerb553dc42015-01-30 21:54:58 -0500212if fnmatch '*gcc\ version*' "$(LC_ALL=C $CC -v 2>&1)" ; then
Rich Felker9ca4dae2014-05-19 10:33:28 -0400213cc_is_gcc=yes
214else
215cc_is_gcc=no
216fi
217echo "$cc_is_gcc"
218
219#
220# Only build musl-gcc wrapper if toolchain does not already target musl
221#
222if test "$wrapper" = auto ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -0400223printf "checking whether to build musl-gcc wrapper... "
Rich Felker9ca4dae2014-05-19 10:33:28 -0400224if test "$cc_is_gcc" = yes ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -0400225wrapper=yes
226while read line ; do
227case "$line" in */ld-musl-*) wrapper=no ;; esac
228done <<EOF
229$($CC -dumpspecs)
230EOF
Rich Felker64d2f8e2012-05-04 23:24:51 -0400231else
Rich Felker9ca4dae2014-05-19 10:33:28 -0400232wrapper=no
Rich Felker64d2f8e2012-05-04 23:24:51 -0400233fi
Rich Felker9ca4dae2014-05-19 10:33:28 -0400234echo "$wrapper"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400235fi
236
237
238
239#
Rich Felker278883d2012-06-03 16:22:13 -0400240# Find the target architecture
Rich Felker64d2f8e2012-05-04 23:24:51 -0400241#
Rich Felker278883d2012-06-03 16:22:13 -0400242printf "checking target system type... "
Rich Felker01e5a1b2012-10-18 23:02:53 -0400243test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
Rich Felker278883d2012-06-03 16:22:13 -0400244printf "%s\n" "$target"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400245
246#
247# Convert to just ARCH
248#
Rich Felker278883d2012-06-03 16:22:13 -0400249case "$target" in
Rich Felker0b8f0c52014-02-28 13:12:40 -0500250# Catch these early to simplify matching for 32-bit archs
251mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400252arm*) ARCH=arm ;;
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000253aarch64*) ARCH=aarch64 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400254i?86*) ARCH=i386 ;;
Rich Felkerf162c062014-03-17 17:38:22 -0400255x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400256x86_64*) ARCH=x86_64 ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500257mips*) ARCH=mips ;;
258microblaze*) ARCH=microblaze ;;
Stefan Kristiansson200d1542014-07-17 22:09:10 +0300259or1k*) ARCH=or1k ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500260powerpc*) ARCH=powerpc ;;
261sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
Rich Felker278883d2012-06-03 16:22:13 -0400262unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
263*) fail "$0: unknown or unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400264esac
265
266#
267# Try to get a conforming C99 freestanding environment
268#
269tryflag CFLAGS_C99FSE -std=c99
270tryflag CFLAGS_C99FSE -nostdinc
271tryflag CFLAGS_C99FSE -ffreestanding \
272|| tryflag CFLAGS_C99FSE -fno-builtin
273tryflag CFLAGS_C99FSE -fexcess-precision=standard \
Rich Felker2121b8a2012-07-03 23:53:05 -0400274|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
Rich Felkerb4ccc3c2012-05-05 17:18:31 -0400275tryflag CFLAGS_C99FSE -frounding-math
Rich Felker64d2f8e2012-05-04 23:24:51 -0400276
Rich Felker4a1f55e2013-08-01 17:12:23 -0400277#
Rich Felker06ceee82013-08-27 17:33:47 -0400278# We may use the may_alias attribute if __GNUC__ is defined, so
279# if the compiler defines __GNUC__ but does not provide it,
280# it must be defined away as part of the CFLAGS.
281#
282printf "checking whether compiler needs attribute((may_alias)) suppression... "
283cat > "$tmpc" <<EOF
284typedef int
285#ifdef __GNUC__
286__attribute__((__may_alias__))
287#endif
288x;
289EOF
290if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
291 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
292printf "no\n"
293else
294printf "yes\n"
295CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
296fi
297
298#
Rich Felker1ef849c2015-04-13 20:13:10 -0400299# Check for options to disable stack protector, which needs to be
300# disabled for a few early-bootstrap translation units. If not found,
301# this is not an error; we assume the toolchain does not do ssp.
302#
303tryflag CFLAGS_NOSSP -fno-stack-protector
304
305#
Rich Felker4a1f55e2013-08-01 17:12:23 -0400306# Check for options that may be needed to prevent the compiler from
307# generating self-referential versions of memcpy,, memmove, memcmp,
308# and memset. Really, we should add a check to determine if this
309# option is sufficient, and if not, add a macro to cripple these
310# functions with volatile...
311#
312tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
Rich Felkera80847d2013-07-22 21:22:04 -0400313
Rich Felker64d2f8e2012-05-04 23:24:51 -0400314#
Rich Felker4ad35882014-06-20 16:10:48 -0400315# Enable debugging if requessted.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400316#
Rich Felker4ad35882014-06-20 16:10:48 -0400317test "$debug" = yes && CFLAGS_AUTO=-g
Rich Felkera80847d2013-07-22 21:22:04 -0400318
319#
320# Possibly add a -O option to CFLAGS and select modules to optimize with
321# -O3 based on the status of --enable-optimize and provided CFLAGS.
322#
323printf "checking for optimization settings... "
324case "x$optimize" in
325xauto)
326if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
327printf "using provided CFLAGS\n" ;optimize=no
328else
329printf "using defaults\n" ; optimize=yes
330fi
331;;
332xsize|xnone) printf "minimize size\n" ; optimize=size ;;
333xno|x) printf "disabled\n" ; optimize=no ;;
334*) printf "custom\n" ;;
335esac
336
337test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
Rich Felker43d25312013-07-24 23:21:45 -0400338test "$optimize" = yes && optimize="internal,malloc,string"
Rich Felkera80847d2013-07-22 21:22:04 -0400339
340if fnmatch 'no|size' "$optimize" ; then :
341else
342printf "components to be optimized for speed:"
343while test "$optimize" ; do
344case "$optimize" in
345*,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
346*) this=$optimize optimize=
347esac
348printf " $this"
349case "$this" in
350*/*.c) ;;
351*/*) this=$this*.c ;;
352*) this=$this/*.c ;;
353esac
354OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
355done
356OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
357printf "\n"
358fi
359
360# Always try -pipe
Rich Felker64d2f8e2012-05-04 23:24:51 -0400361tryflag CFLAGS_AUTO -pipe
362
363#
Rich Felkerb439c052012-08-29 09:36:02 -0400364# If debugging is disabled, omit frame pointer. Modern GCC does this
365# anyway on most archs even when debugging is enabled since the frame
366# pointer is no longer needed for debugging.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400367#
368if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
369else
Rich Felker64d2f8e2012-05-04 23:24:51 -0400370tryflag CFLAGS_AUTO -fomit-frame-pointer
371fi
372
373#
Rich Felkerb439c052012-08-29 09:36:02 -0400374# Modern GCC wants to put DWARF tables (used for debugging and
375# unwinding) in the loaded part of the program where they are
376# unstrippable. These options force them back to debug sections (and
377# cause them not to get generated at all if debugging is off).
378#
379tryflag CFLAGS_AUTO -fno-unwind-tables
380tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
381
382#
Rich Felkeradefe832012-10-03 11:49:58 -0400383# The GNU toolchain defaults to assuming unmarked files need an
384# executable stack, potentially exposing vulnerabilities in programs
385# linked with such object files. Fix this.
386#
387tryflag CFLAGS_AUTO -Wa,--noexecstack
388
389#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400390# On x86, make sure we don't have incompatible instruction set
391# extensions enabled by default. This is bad for making static binaries.
392# We cheat and use i486 rather than i386 because i386 really does not
393# work anyway (issues with atomic ops).
394#
395if test "$ARCH" = "i386" ; then
Rich Felker80a45452012-10-25 14:52:12 -0400396fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
397fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
Rich Felker64d2f8e2012-05-04 23:24:51 -0400398fi
399
Rich Felker2384f272012-12-11 23:28:31 -0500400#
401# Even with -std=c99, gcc accepts some constructs which are constraint
402# violations. We want to treat these as errors regardless of whether
403# other purely stylistic warnings are enabled -- especially implicit
404# function declarations, which are a dangerous programming error.
405#
406tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
407tryflag CFLAGS_AUTO -Werror=implicit-int
408tryflag CFLAGS_AUTO -Werror=pointer-sign
409tryflag CFLAGS_AUTO -Werror=pointer-arith
410
Rich Felker64d2f8e2012-05-04 23:24:51 -0400411if test "x$warnings" = xyes ; then
412tryflag CFLAGS_AUTO -Wall
Rich Felker64d2f8e2012-05-04 23:24:51 -0400413tryflag CFLAGS_AUTO -Wno-parentheses
414tryflag CFLAGS_AUTO -Wno-uninitialized
415tryflag CFLAGS_AUTO -Wno-missing-braces
416tryflag CFLAGS_AUTO -Wno-unused-value
417tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
418tryflag CFLAGS_AUTO -Wno-unknown-pragmas
rofl0radbeefb2014-01-08 03:11:46 +0100419tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
Rich Felker64d2f8e2012-05-04 23:24:51 -0400420fi
421
Rich Felkerde2b67f2015-04-19 22:05:29 -0400422if test "x$visibility" == xauto ; then
423# This test checks toolchain support for several things:
424# - the -include option
425# - the attributes/pragmas used in vis.h
426# - linking code that takes the address of protected symbols
427printf "checking whether global visibility preinclude works... "
428echo 'int (*fp)(void);' > "$tmpc"
429echo 'int foo(void) { }' >> "$tmpc"
430echo 'int bar(void) { fp = foo; return foo(); }' >> "$tmpc"
Rich Felker60ed9882015-04-20 18:14:19 -0400431if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
432 -DSHARED -fPIC -include src/internal/vis.h \
Rich Felkerde2b67f2015-04-19 22:05:29 -0400433 -nostdlib -shared -Wl,-Bsymbolic-functions \
434 -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
435visibility=yes
436else
437visibility=no
438fi
439printf "%s\n" "$visibility"
440fi
441
442if test "x$visibility" == xyes ; then
Rich Felker60ed9882015-04-20 18:14:19 -0400443CFLAGS_AUTO="$CFLAGS_AUTO -include src/internal/vis.h"
Rich Felkerde2b67f2015-04-19 22:05:29 -0400444CFLAGS_AUTO="${CFLAGS_AUTO# }"
445fi
446
Rich Felker0c5efde2012-06-06 22:00:08 -0400447# Some patched GCC builds have these defaults messed up...
Rich Felker2bd05a42012-08-25 17:13:28 -0400448tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
Rich Felker08f70a32012-06-06 20:45:52 -0400449
Rich Felkerd79b2772014-06-10 12:11:12 -0400450test "$shared" = "no" || {
Rich Felker498a1002012-06-07 00:32:22 -0400451# Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
452LDFLAGS_DUMMY=
453tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
Rich Felkerd79b2772014-06-10 12:11:12 -0400454test "$shared" = "yes" && fail "$0: error: linker cannot build shared library"
Rich Felker498a1002012-06-07 00:32:22 -0400455printf "warning: disabling dynamic linking support\n"
456shared=no
457}
Rich Felkerd79b2772014-06-10 12:11:12 -0400458}
Rich Felker498a1002012-06-07 00:32:22 -0400459
Rich Felker2c1cd232012-09-10 15:30:52 -0400460# Find compiler runtime library
461test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
462test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
Rich Felkercd31a1f2012-10-26 18:15:51 -0400463test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
464 && tryldflag LIBCC "$try_libcc"
Rich Felker2c1cd232012-09-10 15:30:52 -0400465printf "using compiler runtime libraries: %s\n" "$LIBCC"
Rich Felkera1546e82012-07-12 14:24:10 -0400466
Rich Felker3e7f1862013-07-18 20:30:58 -0400467# Figure out arch variants for archs with variants
468SUBARCH=
469t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS"
470
rofl0r8c820232014-03-19 22:31:00 +0100471if test "$ARCH" = "x86_64" ; then
472trycppif __ILP32__ "$t" && ARCH=x32
473fi
474
Rich Felker3e7f1862013-07-18 20:30:58 -0400475if test "$ARCH" = "arm" ; then
476trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
Rich Felker4918c2b2013-08-16 17:09:07 -0400477trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
Rich Felker3e7f1862013-07-18 20:30:58 -0400478fi
479
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000480if test "$ARCH" = "aarch64" ; then
481trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
482fi
483
Szabolcs Nagye5bb1652014-02-24 23:16:29 +0100484if test "$ARCH" = "mips" ; then
485trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
486trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
487fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400488
489test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
490&& SUBARCH=${SUBARCH}el
491
Rich Felkerb1683a12014-02-27 23:18:42 -0500492if test "$ARCH" = "sh" ; then
493trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
Bobby Bingham23d64182014-04-27 21:13:59 -0500494if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
Rich Felkerb1683a12014-02-27 23:18:42 -0500495# Some sh configurations are broken and replace double with float
496# rather than using softfloat when the fpu is present but only
497# supports single precision. Reject them.
498printf "checking whether compiler's double type is IEEE double... "
Rich Felker946b9fa2014-02-27 23:55:04 -0500499echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
Rich Felkerb1683a12014-02-27 23:18:42 -0500500if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
501printf "yes\n"
502else
503printf "no\n"
504fail "$0: error: compiler's floating point configuration is unsupported"
505fi
506else
507SUBARCH=${SUBARCH}-nofpu
508fi
509fi
Bobby Bingham3a3c8132013-10-05 05:13:18 -0500510
Rich Felker3e7f1862013-07-18 20:30:58 -0400511test "$SUBARCH" \
512&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400513
Rich Felker90d77722013-08-11 03:27:35 -0400514case "$ARCH$SUBARCH" in
515arm) ASMSUBARCH=el ;;
516*) ASMSUBARCH=$SUBARCH ;;
517esac
518
Rich Felker86cc54b2013-08-02 19:34:22 -0400519#
520# Some archs (powerpc) have different possible long double formats
521# that the compiler can be configured for. The logic for whether this
522# is supported is in bits/float.h; in general, it is not. We need to
523# check for mismatches here or code in printf, strotd, and scanf will
524# be dangerously incorrect because it depends on (1) the macros being
525# correct, and (2) IEEE semantics.
526#
527printf "checking whether compiler's long double definition matches float.h... "
528echo '#include <float.h>' > "$tmpc"
529echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
530echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
531echo '#endif' >> "$tmpc"
532if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
533 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
534printf "yes\n"
535else
536printf "no\n"
537fail "$0: error: unsupported long double type"
538fi
539
Rich Felker64d2f8e2012-05-04 23:24:51 -0400540printf "creating config.mak... "
541
Rich Felker453f4622013-08-16 18:19:47 -0400542cmdline=$(quote "$0")
543for i ; do cmdline="$cmdline $(quote "$i")" ; done
544
Rich Felker64d2f8e2012-05-04 23:24:51 -0400545exec 3>&1 1>config.mak
546
547
548cat << EOF
Rich Felker453f4622013-08-16 18:19:47 -0400549# This version of config.mak was generated by:
550# $cmdline
Rich Felker64d2f8e2012-05-04 23:24:51 -0400551# Any changes made here will be lost if configure is re-run
552ARCH = $ARCH
Rich Felker3e7f1862013-07-18 20:30:58 -0400553SUBARCH = $SUBARCH
Rich Felker90d77722013-08-11 03:27:35 -0400554ASMSUBARCH = $ASMSUBARCH
Rich Felker64d2f8e2012-05-04 23:24:51 -0400555prefix = $prefix
556exec_prefix = $exec_prefix
557bindir = $bindir
558libdir = $libdir
559includedir = $includedir
560syslibdir = $syslibdir
561CC = $CC
Rich Felker7c6db372014-05-20 15:49:21 -0400562CFLAGS = $CFLAGS_AUTO $CFLAGS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400563CFLAGS_C99FSE = $CFLAGS_C99FSE
Rich Felker4a1f55e2013-08-01 17:12:23 -0400564CFLAGS_MEMOPS = $CFLAGS_MEMOPS
Rich Felker1ef849c2015-04-13 20:13:10 -0400565CFLAGS_NOSSP = $CFLAGS_NOSSP
Rich Felker64d2f8e2012-05-04 23:24:51 -0400566CPPFLAGS = $CPPFLAGS
Rich Felker08f70a32012-06-06 20:45:52 -0400567LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
Rich Felker94e920d2012-08-14 22:50:16 -0400568CROSS_COMPILE = $CROSS_COMPILE
Rich Felker2c1cd232012-09-10 15:30:52 -0400569LIBCC = $LIBCC
Rich Felkera80847d2013-07-22 21:22:04 -0400570OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400571EOF
572test "x$static" = xno && echo "STATIC_LIBS ="
573test "x$shared" = xno && echo "SHARED_LIBS ="
574test "x$wrapper" = xno && echo "ALL_TOOLS ="
575test "x$wrapper" = xno && echo "TOOL_LIBS ="
576exec 1>&3 3>&-
577
578printf "done\n"