blob: 7304b132ae72e86273542477c5e7e44d2ab3a1b9 [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]
30 --enable-gcc-wrapper build musl-gcc toolchain wrapper [auto]
31 --disable-shared inhibit building shared library [enabled]
32 --disable-static inhibit building static library [enabled]
33
34Some influential environment variables:
35 CC C compiler command [detected]
36 CFLAGS C compiler flags [-Os -pipe ...]
Rich Felker94e920d2012-08-14 22:50:16 -040037 CROSS_COMPILE prefix for cross compiler and tools [none]
Rich Felker2c1cd232012-09-10 15:30:52 -040038 LIBCC compiler runtime library [detected]
Rich Felker64d2f8e2012-05-04 23:24:51 -040039
40Use these variables to override the choices made by configure.
41
42EOF
43exit 0
44}
45
46# Helper functions
47
Rich Felker453f4622013-08-16 18:19:47 -040048quote () {
49tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
50$1
51EOF
Rich Felkere4499742013-08-20 13:51:46 -040052printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
Rich Felker453f4622013-08-16 18:19:47 -040053}
Rich Felker64d2f8e2012-05-04 23:24:51 -040054echo () { printf "%s\n" "$*" ; }
55fail () { echo "$*" ; exit 1 ; }
56fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
57cmdexists () { type "$1" >/dev/null 2>&1 ; }
58trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
59
Rich Felker3d9e3a32012-11-08 17:20:50 -050060stripdir () {
61while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
Rich Felker64d2f8e2012-05-04 23:24:51 -040062}
63
Rich Felker3e7f1862013-07-18 20:30:58 -040064trycppif () {
65printf "checking preprocessor condition %s... " "$1"
Rich Felkerdf065782013-07-18 20:37:19 -040066echo "typedef int x;" > "$tmpc"
67echo "#if $1" >> "$tmpc"
Rich Felker3e7f1862013-07-18 20:30:58 -040068echo "#error yes" >> "$tmpc"
69echo "#endif" >> "$tmpc"
70if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
71printf "false\n"
72return 1
73else
74printf "true\n"
75return 0
76fi
77}
78
Rich Felker64d2f8e2012-05-04 23:24:51 -040079tryflag () {
80printf "checking whether compiler accepts %s... " "$2"
81echo "typedef int x;" > "$tmpc"
Rich Felkercd31a1f2012-10-26 18:15:51 -040082if $CC "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -040083printf "yes\n"
84eval "$1=\"\${$1} \$2\""
85eval "$1=\${$1# }"
86return 0
87else
88printf "no\n"
89return 1
90fi
91}
92
Rich Felker08f70a32012-06-06 20:45:52 -040093tryldflag () {
94printf "checking whether linker accepts %s... " "$2"
Rich Felker67a03832012-06-07 00:23:58 -040095echo "typedef int x;" > "$tmpc"
Rich Felkercd31a1f2012-10-26 18:15:51 -040096if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker08f70a32012-06-06 20:45:52 -040097printf "yes\n"
98eval "$1=\"\${$1} \$2\""
99eval "$1=\${$1# }"
100return 0
101else
102printf "no\n"
103return 1
104fi
105}
106
Rich Felker64d2f8e2012-05-04 23:24:51 -0400107
108
109# Beginning of actual script
110
Rich Felker08f70a32012-06-06 20:45:52 -0400111CFLAGS_C99FSE=
112CFLAGS_AUTO=
Rich Felker4a1f55e2013-08-01 17:12:23 -0400113CFLAGS_MEMOPS=
Rich Felker08f70a32012-06-06 20:45:52 -0400114LDFLAGS_AUTO=
Rich Felkera80847d2013-07-22 21:22:04 -0400115OPTIMIZE_GLOBS=
Rich Felker3d9e3a32012-11-08 17:20:50 -0500116prefix=/usr/local/musl
117exec_prefix='$(prefix)'
118bindir='$(exec_prefix)/bin'
119libdir='$(prefix)/lib'
120includedir='$(prefix)/include'
121syslibdir='/lib'
Rich Felker278883d2012-06-03 16:22:13 -0400122target=
Rich Felkera80847d2013-07-22 21:22:04 -0400123optimize=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400124debug=no
Rich Felker3d9e3a32012-11-08 17:20:50 -0500125warnings=no
Rich Felkerd79b2772014-06-10 12:11:12 -0400126shared=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400127static=yes
Rich Felker9ca4dae2014-05-19 10:33:28 -0400128wrapper=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400129
130for arg ; do
131case "$arg" in
132--help) usage ;;
133--prefix=*) prefix=${arg#*=} ;;
134--exec-prefix=*) exec_prefix=${arg#*=} ;;
135--bindir=*) bindir=${arg#*=} ;;
136--libdir=*) libdir=${arg#*=} ;;
137--includedir=*) includedir=${arg#*=} ;;
138--syslibdir=*) syslibdir=${arg#*=} ;;
139--enable-shared|--enable-shared=yes) shared=yes ;;
140--disable-shared|--enable-shared=no) shared=no ;;
141--enable-static|--enable-static=yes) static=yes ;;
142--disable-static|--enable-static=no) static=no ;;
Rich Felkera80847d2013-07-22 21:22:04 -0400143--enable-optimize) optimize=yes ;;
144--enable-optimize=*) optimize=${arg#*=} ;;
145--disable-optimize) optimize=no ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400146--enable-debug|--enable-debug=yes) debug=yes ;;
147--disable-debug|--enable-debug=no) debug=no ;;
148--enable-warnings|--enable-warnings=yes) warnings=yes ;;
149--disable-warnings|--enable-warnings=no) warnings=no ;;
150--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
151--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
Rich Felker278883d2012-06-03 16:22:13 -0400152--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
153--host=*|--target=*) target=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400154-* ) echo "$0: unknown option $arg" ;;
155CC=*) CC=${arg#*=} ;;
156CFLAGS=*) CFLAGS=${arg#*=} ;;
157CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
158LDFLAGS=*) LDFLAGS=${arg#*=} ;;
Rich Felker94e920d2012-08-14 22:50:16 -0400159CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
Rich Felker2c1cd232012-09-10 15:30:52 -0400160LIBCC=*) LIBCC=${arg#*=} ;;
Rich Felker278883d2012-06-03 16:22:13 -0400161*=*) ;;
162*) target=$arg ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400163esac
164done
165
Rich Felker3d9e3a32012-11-08 17:20:50 -0500166for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
167stripdir $i
168done
Rich Felker64d2f8e2012-05-04 23:24:51 -0400169
170#
171# Get a temp filename we can use
172#
173i=0
174set -C
175while : ; do i=$(($i+1))
176tmpc="./conf$$-$PPID-$i.c"
Rich Felker6c0cba82012-11-18 23:15:47 -05001772>|/dev/null > "$tmpc" && break
Rich Felker64d2f8e2012-05-04 23:24:51 -0400178test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
179done
180set +C
181trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
182
183#
184# Find a C compiler to use
185#
186printf "checking for C compiler... "
Rich Felker94e920d2012-08-14 22:50:16 -0400187trycc ${CROSS_COMPILE}gcc
188trycc ${CROSS_COMPILE}c99
189trycc ${CROSS_COMPILE}cc
Rich Felker64d2f8e2012-05-04 23:24:51 -0400190printf "%s\n" "$CC"
191test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
192
Rich Felker89456672014-05-12 14:22:57 -0400193printf "checking whether C compiler works... "
194echo "typedef int x;" > "$tmpc"
195if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then
196printf "yes\n"
197else
198printf "no; compiler output follows:\n%s\n" "$output"
199exit 1
200fi
201
Rich Felker64d2f8e2012-05-04 23:24:51 -0400202#
Rich Felker9ca4dae2014-05-19 10:33:28 -0400203# Need to know if the compiler is gcc to decide whether to build the
204# musl-gcc wrapper, and for critical bug detection in some gcc versions.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400205#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400206printf "checking whether compiler is gcc... "
Rich Felkerb553dc42015-01-30 21:54:58 -0500207if fnmatch '*gcc\ version*' "$(LC_ALL=C $CC -v 2>&1)" ; then
Rich Felker9ca4dae2014-05-19 10:33:28 -0400208cc_is_gcc=yes
209else
210cc_is_gcc=no
211fi
212echo "$cc_is_gcc"
213
214#
215# Only build musl-gcc wrapper if toolchain does not already target musl
216#
217if test "$wrapper" = auto ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -0400218printf "checking whether to build musl-gcc wrapper... "
Rich Felker9ca4dae2014-05-19 10:33:28 -0400219if test "$cc_is_gcc" = yes ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -0400220wrapper=yes
221while read line ; do
222case "$line" in */ld-musl-*) wrapper=no ;; esac
223done <<EOF
224$($CC -dumpspecs)
225EOF
Rich Felker64d2f8e2012-05-04 23:24:51 -0400226else
Rich Felker9ca4dae2014-05-19 10:33:28 -0400227wrapper=no
Rich Felker64d2f8e2012-05-04 23:24:51 -0400228fi
Rich Felker9ca4dae2014-05-19 10:33:28 -0400229echo "$wrapper"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400230fi
231
232
233
234#
Rich Felker278883d2012-06-03 16:22:13 -0400235# Find the target architecture
Rich Felker64d2f8e2012-05-04 23:24:51 -0400236#
Rich Felker278883d2012-06-03 16:22:13 -0400237printf "checking target system type... "
Rich Felker01e5a1b2012-10-18 23:02:53 -0400238test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
Rich Felker278883d2012-06-03 16:22:13 -0400239printf "%s\n" "$target"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400240
241#
242# Convert to just ARCH
243#
Rich Felker278883d2012-06-03 16:22:13 -0400244case "$target" in
Rich Felker0b8f0c52014-02-28 13:12:40 -0500245# Catch these early to simplify matching for 32-bit archs
246mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400247arm*) ARCH=arm ;;
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000248aarch64*) ARCH=aarch64 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400249i?86*) ARCH=i386 ;;
Rich Felkerf162c062014-03-17 17:38:22 -0400250x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400251x86_64*) ARCH=x86_64 ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500252mips*) ARCH=mips ;;
253microblaze*) ARCH=microblaze ;;
Stefan Kristiansson200d1542014-07-17 22:09:10 +0300254or1k*) ARCH=or1k ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500255powerpc*) ARCH=powerpc ;;
256sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
Rich Felker278883d2012-06-03 16:22:13 -0400257unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
258*) fail "$0: unknown or unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400259esac
260
261#
262# Try to get a conforming C99 freestanding environment
263#
264tryflag CFLAGS_C99FSE -std=c99
265tryflag CFLAGS_C99FSE -nostdinc
266tryflag CFLAGS_C99FSE -ffreestanding \
267|| tryflag CFLAGS_C99FSE -fno-builtin
268tryflag CFLAGS_C99FSE -fexcess-precision=standard \
Rich Felker2121b8a2012-07-03 23:53:05 -0400269|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
Rich Felkerb4ccc3c2012-05-05 17:18:31 -0400270tryflag CFLAGS_C99FSE -frounding-math
Rich Felker64d2f8e2012-05-04 23:24:51 -0400271
Rich Felker4a1f55e2013-08-01 17:12:23 -0400272#
Rich Felker06ceee82013-08-27 17:33:47 -0400273# We may use the may_alias attribute if __GNUC__ is defined, so
274# if the compiler defines __GNUC__ but does not provide it,
275# it must be defined away as part of the CFLAGS.
276#
277printf "checking whether compiler needs attribute((may_alias)) suppression... "
278cat > "$tmpc" <<EOF
279typedef int
280#ifdef __GNUC__
281__attribute__((__may_alias__))
282#endif
283x;
284EOF
285if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
286 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
287printf "no\n"
288else
289printf "yes\n"
290CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
291fi
292
293#
Rich Felker4a1f55e2013-08-01 17:12:23 -0400294# Check for options that may be needed to prevent the compiler from
295# generating self-referential versions of memcpy,, memmove, memcmp,
296# and memset. Really, we should add a check to determine if this
297# option is sufficient, and if not, add a macro to cripple these
298# functions with volatile...
299#
300tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
Rich Felkera80847d2013-07-22 21:22:04 -0400301
Rich Felker64d2f8e2012-05-04 23:24:51 -0400302#
Rich Felker4ad35882014-06-20 16:10:48 -0400303# Enable debugging if requessted.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400304#
Rich Felker4ad35882014-06-20 16:10:48 -0400305test "$debug" = yes && CFLAGS_AUTO=-g
Rich Felkera80847d2013-07-22 21:22:04 -0400306
307#
308# Possibly add a -O option to CFLAGS and select modules to optimize with
309# -O3 based on the status of --enable-optimize and provided CFLAGS.
310#
311printf "checking for optimization settings... "
312case "x$optimize" in
313xauto)
314if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
315printf "using provided CFLAGS\n" ;optimize=no
316else
317printf "using defaults\n" ; optimize=yes
318fi
319;;
320xsize|xnone) printf "minimize size\n" ; optimize=size ;;
321xno|x) printf "disabled\n" ; optimize=no ;;
322*) printf "custom\n" ;;
323esac
324
325test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
Rich Felker43d25312013-07-24 23:21:45 -0400326test "$optimize" = yes && optimize="internal,malloc,string"
Rich Felkera80847d2013-07-22 21:22:04 -0400327
328if fnmatch 'no|size' "$optimize" ; then :
329else
330printf "components to be optimized for speed:"
331while test "$optimize" ; do
332case "$optimize" in
333*,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
334*) this=$optimize optimize=
335esac
336printf " $this"
337case "$this" in
338*/*.c) ;;
339*/*) this=$this*.c ;;
340*) this=$this/*.c ;;
341esac
342OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
343done
344OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
345printf "\n"
346fi
347
348# Always try -pipe
Rich Felker64d2f8e2012-05-04 23:24:51 -0400349tryflag CFLAGS_AUTO -pipe
350
351#
Rich Felkerb439c052012-08-29 09:36:02 -0400352# If debugging is disabled, omit frame pointer. Modern GCC does this
353# anyway on most archs even when debugging is enabled since the frame
354# pointer is no longer needed for debugging.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400355#
356if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
357else
Rich Felker64d2f8e2012-05-04 23:24:51 -0400358tryflag CFLAGS_AUTO -fomit-frame-pointer
359fi
360
361#
Rich Felkerb439c052012-08-29 09:36:02 -0400362# Modern GCC wants to put DWARF tables (used for debugging and
363# unwinding) in the loaded part of the program where they are
364# unstrippable. These options force them back to debug sections (and
365# cause them not to get generated at all if debugging is off).
366#
367tryflag CFLAGS_AUTO -fno-unwind-tables
368tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
369
370#
Rich Felkeradefe832012-10-03 11:49:58 -0400371# The GNU toolchain defaults to assuming unmarked files need an
372# executable stack, potentially exposing vulnerabilities in programs
373# linked with such object files. Fix this.
374#
375tryflag CFLAGS_AUTO -Wa,--noexecstack
376
377#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400378# On x86, make sure we don't have incompatible instruction set
379# extensions enabled by default. This is bad for making static binaries.
380# We cheat and use i486 rather than i386 because i386 really does not
381# work anyway (issues with atomic ops).
382#
383if test "$ARCH" = "i386" ; then
Rich Felker80a45452012-10-25 14:52:12 -0400384fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
385fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
Rich Felker64d2f8e2012-05-04 23:24:51 -0400386fi
387
Rich Felker2384f272012-12-11 23:28:31 -0500388#
389# Even with -std=c99, gcc accepts some constructs which are constraint
390# violations. We want to treat these as errors regardless of whether
391# other purely stylistic warnings are enabled -- especially implicit
392# function declarations, which are a dangerous programming error.
393#
394tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
395tryflag CFLAGS_AUTO -Werror=implicit-int
396tryflag CFLAGS_AUTO -Werror=pointer-sign
397tryflag CFLAGS_AUTO -Werror=pointer-arith
398
Rich Felker64d2f8e2012-05-04 23:24:51 -0400399if test "x$warnings" = xyes ; then
400tryflag CFLAGS_AUTO -Wall
Rich Felker64d2f8e2012-05-04 23:24:51 -0400401tryflag CFLAGS_AUTO -Wno-parentheses
402tryflag CFLAGS_AUTO -Wno-uninitialized
403tryflag CFLAGS_AUTO -Wno-missing-braces
404tryflag CFLAGS_AUTO -Wno-unused-value
405tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
406tryflag CFLAGS_AUTO -Wno-unknown-pragmas
rofl0radbeefb2014-01-08 03:11:46 +0100407tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
Rich Felker64d2f8e2012-05-04 23:24:51 -0400408fi
409
Rich Felker0c5efde2012-06-06 22:00:08 -0400410# Some patched GCC builds have these defaults messed up...
411tryflag CFLAGS_AUTO -fno-stack-protector
Rich Felker2bd05a42012-08-25 17:13:28 -0400412tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
Rich Felker08f70a32012-06-06 20:45:52 -0400413
Rich Felkerd79b2772014-06-10 12:11:12 -0400414test "$shared" = "no" || {
Rich Felker498a1002012-06-07 00:32:22 -0400415# Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
416LDFLAGS_DUMMY=
417tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
Rich Felkerd79b2772014-06-10 12:11:12 -0400418test "$shared" = "yes" && fail "$0: error: linker cannot build shared library"
Rich Felker498a1002012-06-07 00:32:22 -0400419printf "warning: disabling dynamic linking support\n"
420shared=no
421}
Rich Felkerd79b2772014-06-10 12:11:12 -0400422}
Rich Felker498a1002012-06-07 00:32:22 -0400423
Rich Felker2c1cd232012-09-10 15:30:52 -0400424# Find compiler runtime library
425test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
426test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
Rich Felkercd31a1f2012-10-26 18:15:51 -0400427test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
428 && tryldflag LIBCC "$try_libcc"
Rich Felker2c1cd232012-09-10 15:30:52 -0400429printf "using compiler runtime libraries: %s\n" "$LIBCC"
Rich Felkera1546e82012-07-12 14:24:10 -0400430
Rich Felker3e7f1862013-07-18 20:30:58 -0400431# Figure out arch variants for archs with variants
432SUBARCH=
433t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS"
434
rofl0r8c820232014-03-19 22:31:00 +0100435if test "$ARCH" = "x86_64" ; then
436trycppif __ILP32__ "$t" && ARCH=x32
437fi
438
Rich Felker3e7f1862013-07-18 20:30:58 -0400439if test "$ARCH" = "arm" ; then
440trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
Rich Felker4918c2b2013-08-16 17:09:07 -0400441trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
Rich Felker3e7f1862013-07-18 20:30:58 -0400442fi
443
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000444if test "$ARCH" = "aarch64" ; then
445trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
446fi
447
Szabolcs Nagye5bb1652014-02-24 23:16:29 +0100448if test "$ARCH" = "mips" ; then
449trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
450trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
451fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400452
453test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
454&& SUBARCH=${SUBARCH}el
455
Rich Felkerb1683a12014-02-27 23:18:42 -0500456if test "$ARCH" = "sh" ; then
457trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
Bobby Bingham23d64182014-04-27 21:13:59 -0500458if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
Rich Felkerb1683a12014-02-27 23:18:42 -0500459# Some sh configurations are broken and replace double with float
460# rather than using softfloat when the fpu is present but only
461# supports single precision. Reject them.
462printf "checking whether compiler's double type is IEEE double... "
Rich Felker946b9fa2014-02-27 23:55:04 -0500463echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
Rich Felkerb1683a12014-02-27 23:18:42 -0500464if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
465printf "yes\n"
466else
467printf "no\n"
468fail "$0: error: compiler's floating point configuration is unsupported"
469fi
470else
471SUBARCH=${SUBARCH}-nofpu
472fi
473fi
Bobby Bingham3a3c8132013-10-05 05:13:18 -0500474
Rich Felker3e7f1862013-07-18 20:30:58 -0400475test "$SUBARCH" \
476&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400477
Rich Felker90d77722013-08-11 03:27:35 -0400478case "$ARCH$SUBARCH" in
479arm) ASMSUBARCH=el ;;
480*) ASMSUBARCH=$SUBARCH ;;
481esac
482
Rich Felker86cc54b2013-08-02 19:34:22 -0400483#
484# Some archs (powerpc) have different possible long double formats
485# that the compiler can be configured for. The logic for whether this
486# is supported is in bits/float.h; in general, it is not. We need to
487# check for mismatches here or code in printf, strotd, and scanf will
488# be dangerously incorrect because it depends on (1) the macros being
489# correct, and (2) IEEE semantics.
490#
491printf "checking whether compiler's long double definition matches float.h... "
492echo '#include <float.h>' > "$tmpc"
493echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
494echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
495echo '#endif' >> "$tmpc"
496if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
497 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
498printf "yes\n"
499else
500printf "no\n"
501fail "$0: error: unsupported long double type"
502fi
503
Rich Felker64d2f8e2012-05-04 23:24:51 -0400504printf "creating config.mak... "
505
Rich Felker453f4622013-08-16 18:19:47 -0400506cmdline=$(quote "$0")
507for i ; do cmdline="$cmdline $(quote "$i")" ; done
508
Rich Felker64d2f8e2012-05-04 23:24:51 -0400509exec 3>&1 1>config.mak
510
511
512cat << EOF
Rich Felker453f4622013-08-16 18:19:47 -0400513# This version of config.mak was generated by:
514# $cmdline
Rich Felker64d2f8e2012-05-04 23:24:51 -0400515# Any changes made here will be lost if configure is re-run
516ARCH = $ARCH
Rich Felker3e7f1862013-07-18 20:30:58 -0400517SUBARCH = $SUBARCH
Rich Felker90d77722013-08-11 03:27:35 -0400518ASMSUBARCH = $ASMSUBARCH
Rich Felker64d2f8e2012-05-04 23:24:51 -0400519prefix = $prefix
520exec_prefix = $exec_prefix
521bindir = $bindir
522libdir = $libdir
523includedir = $includedir
524syslibdir = $syslibdir
525CC = $CC
Rich Felker7c6db372014-05-20 15:49:21 -0400526CFLAGS = $CFLAGS_AUTO $CFLAGS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400527CFLAGS_C99FSE = $CFLAGS_C99FSE
Rich Felker4a1f55e2013-08-01 17:12:23 -0400528CFLAGS_MEMOPS = $CFLAGS_MEMOPS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400529CPPFLAGS = $CPPFLAGS
Rich Felker08f70a32012-06-06 20:45:52 -0400530LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
Rich Felker94e920d2012-08-14 22:50:16 -0400531CROSS_COMPILE = $CROSS_COMPILE
Rich Felker2c1cd232012-09-10 15:30:52 -0400532LIBCC = $LIBCC
Rich Felkera80847d2013-07-22 21:22:04 -0400533OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400534EOF
535test "x$static" = xno && echo "STATIC_LIBS ="
536test "x$shared" = xno && echo "SHARED_LIBS ="
537test "x$wrapper" = xno && echo "ALL_TOOLS ="
538test "x$wrapper" = xno && echo "TOOL_LIBS ="
539exec 1>&3 3>&-
540
541printf "done\n"