blob: 99cb04d1ddd6d3747d1abe02e7886cd930acf143 [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]
Shizb3cd7d12015-06-28 23:08:19 +020031 --enable-wrapper=... build given musl toolchain wrapper [auto]
Rich Felker64d2f8e2012-05-04 23:24:51 -040032 --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"
Shizfc431d32015-05-28 05:52:22 +020083if $CC $CFLAGS_TRY $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"
Shizfc431d32015-05-28 05:52:22 +020097if $CC $LDFLAGS_TRY -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=
Shizfc431d32015-05-28 05:52:22 +0200116CFLAGS_TRY=
Rich Felker08f70a32012-06-06 20:45:52 -0400117LDFLAGS_AUTO=
Shizfc431d32015-05-28 05:52:22 +0200118LDFLAGS_TRY=
Rich Felkera80847d2013-07-22 21:22:04 -0400119OPTIMIZE_GLOBS=
Rich Felker3d9e3a32012-11-08 17:20:50 -0500120prefix=/usr/local/musl
121exec_prefix='$(prefix)'
122bindir='$(exec_prefix)/bin'
123libdir='$(prefix)/lib'
124includedir='$(prefix)/include'
125syslibdir='/lib'
Shizb3cd7d12015-06-28 23:08:19 +0200126tools=
127tool_libs=
Rich Felker278883d2012-06-03 16:22:13 -0400128target=
Rich Felkera80847d2013-07-22 21:22:04 -0400129optimize=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400130debug=no
Rich Felker3d9e3a32012-11-08 17:20:50 -0500131warnings=no
Rich Felkerde2b67f2015-04-19 22:05:29 -0400132visibility=auto
Rich Felkerd79b2772014-06-10 12:11:12 -0400133shared=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400134static=yes
Rich Felker9ca4dae2014-05-19 10:33:28 -0400135wrapper=auto
Shizb3cd7d12015-06-28 23:08:19 +0200136gcc_wrapper=no
Rich Felker64d2f8e2012-05-04 23:24:51 -0400137
138for arg ; do
139case "$arg" in
140--help) usage ;;
141--prefix=*) prefix=${arg#*=} ;;
142--exec-prefix=*) exec_prefix=${arg#*=} ;;
143--bindir=*) bindir=${arg#*=} ;;
144--libdir=*) libdir=${arg#*=} ;;
145--includedir=*) includedir=${arg#*=} ;;
146--syslibdir=*) syslibdir=${arg#*=} ;;
147--enable-shared|--enable-shared=yes) shared=yes ;;
148--disable-shared|--enable-shared=no) shared=no ;;
149--enable-static|--enable-static=yes) static=yes ;;
150--disable-static|--enable-static=no) static=no ;;
Rich Felkera80847d2013-07-22 21:22:04 -0400151--enable-optimize) optimize=yes ;;
152--enable-optimize=*) optimize=${arg#*=} ;;
153--disable-optimize) optimize=no ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400154--enable-debug|--enable-debug=yes) debug=yes ;;
155--disable-debug|--enable-debug=no) debug=no ;;
156--enable-warnings|--enable-warnings=yes) warnings=yes ;;
157--disable-warnings|--enable-warnings=no) warnings=no ;;
Rich Felkerde2b67f2015-04-19 22:05:29 -0400158--enable-visibility|--enable-visibility=yes) visibility=yes ;;
159--disable-visibility|--enable-visibility=no) visibility=no ;;
Shizb3cd7d12015-06-28 23:08:19 +0200160--enable-wrapper|--enable-wrapper=yes) wrapper=detect ;;
161--enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ;;
162--enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;;
163--disable-wrapper|--enable-wrapper=no) wrapper=no ;;
164--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400165--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
Rich Felker278883d2012-06-03 16:22:13 -0400166--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
167--host=*|--target=*) target=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400168-* ) echo "$0: unknown option $arg" ;;
169CC=*) CC=${arg#*=} ;;
170CFLAGS=*) CFLAGS=${arg#*=} ;;
171CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
172LDFLAGS=*) LDFLAGS=${arg#*=} ;;
Rich Felker94e920d2012-08-14 22:50:16 -0400173CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
Rich Felker2c1cd232012-09-10 15:30:52 -0400174LIBCC=*) LIBCC=${arg#*=} ;;
Rich Felker278883d2012-06-03 16:22:13 -0400175*=*) ;;
176*) target=$arg ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400177esac
178done
179
Rich Felker3d9e3a32012-11-08 17:20:50 -0500180for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
181stripdir $i
182done
Rich Felker64d2f8e2012-05-04 23:24:51 -0400183
184#
185# Get a temp filename we can use
186#
187i=0
188set -C
189while : ; do i=$(($i+1))
190tmpc="./conf$$-$PPID-$i.c"
Rich Felker6c0cba82012-11-18 23:15:47 -05001912>|/dev/null > "$tmpc" && break
Rich Felker64d2f8e2012-05-04 23:24:51 -0400192test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
193done
194set +C
195trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
196
197#
198# Find a C compiler to use
199#
200printf "checking for C compiler... "
Rich Felker94e920d2012-08-14 22:50:16 -0400201trycc ${CROSS_COMPILE}gcc
202trycc ${CROSS_COMPILE}c99
203trycc ${CROSS_COMPILE}cc
Rich Felker64d2f8e2012-05-04 23:24:51 -0400204printf "%s\n" "$CC"
205test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
206
Rich Felker89456672014-05-12 14:22:57 -0400207printf "checking whether C compiler works... "
208echo "typedef int x;" > "$tmpc"
209if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then
210printf "yes\n"
211else
212printf "no; compiler output follows:\n%s\n" "$output"
213exit 1
214fi
215
Rich Felker64d2f8e2012-05-04 23:24:51 -0400216#
Shizfc431d32015-05-28 05:52:22 +0200217# Figure out options to force errors on unknown flags.
218#
219tryflag CFLAGS_TRY -Werror=unknown-warning-option
220tryflag CFLAGS_TRY -Werror=unused-command-line-argument
221tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
222tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
223
224#
Shizb3cd7d12015-06-28 23:08:19 +0200225# Need to know if the compiler is gcc or clang to decide which toolchain
226# wrappers to build.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400227#
Shizb3cd7d12015-06-28 23:08:19 +0200228printf "checking for C compiler family... "
229cc_ver="$(LC_ALL=C $CC -v 2>&1)"
230cc_family=unknown
231if fnmatch '*gcc\ version*' "$cc_ver" ; then
232cc_family=gcc
Rich Felker9ca4dae2014-05-19 10:33:28 -0400233fi
Shizb3cd7d12015-06-28 23:08:19 +0200234echo "$cc_family"
Rich Felker9ca4dae2014-05-19 10:33:28 -0400235
236#
Shizb3cd7d12015-06-28 23:08:19 +0200237# Figure out toolchain wrapper to build
Rich Felker9ca4dae2014-05-19 10:33:28 -0400238#
Shizb3cd7d12015-06-28 23:08:19 +0200239if test "$wrapper" = auto -o "$wrapper" = detect ; then
Shizf8db6f72015-06-28 23:08:20 +0200240echo "#include <stdlib.h>" > "$tmpc"
241echo "#if ! __GLIBC__" >> "$tmpc"
242echo "#error no" >> "$tmpc"
243echo "#endif" >> "$tmpc"
Shizb3cd7d12015-06-28 23:08:19 +0200244printf "checking for toolchain wrapper to build... "
Shizf8db6f72015-06-28 23:08:20 +0200245if test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
246echo "none"
247elif test "$cc_family" = gcc ; then
Shizb3cd7d12015-06-28 23:08:19 +0200248gcc_wrapper=yes
Shizf8db6f72015-06-28 23:08:20 +0200249echo "gcc"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400250else
Shizb3cd7d12015-06-28 23:08:19 +0200251echo "none"
252if test "$wrapper" = detect ; then
253fail "$0: could not find an appropriate toolchain wrapper"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400254fi
Shizb3cd7d12015-06-28 23:08:19 +0200255fi
Rich Felker64d2f8e2012-05-04 23:24:51 -0400256fi
257
Shizb3cd7d12015-06-28 23:08:19 +0200258if test "$gcc_wrapper" = yes ; then
259tools="$tools tools/musl-gcc"
260tool_libs="$tool_libs lib/musl-gcc.specs"
261fi
Rich Felker64d2f8e2012-05-04 23:24:51 -0400262
263#
Rich Felker278883d2012-06-03 16:22:13 -0400264# Find the target architecture
Rich Felker64d2f8e2012-05-04 23:24:51 -0400265#
Rich Felker278883d2012-06-03 16:22:13 -0400266printf "checking target system type... "
Rich Felker01e5a1b2012-10-18 23:02:53 -0400267test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
Rich Felker278883d2012-06-03 16:22:13 -0400268printf "%s\n" "$target"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400269
270#
271# Convert to just ARCH
272#
Rich Felker278883d2012-06-03 16:22:13 -0400273case "$target" in
Rich Felker0b8f0c52014-02-28 13:12:40 -0500274# Catch these early to simplify matching for 32-bit archs
275mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400276arm*) ARCH=arm ;;
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000277aarch64*) ARCH=aarch64 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400278i?86*) ARCH=i386 ;;
Rich Felkerf162c062014-03-17 17:38:22 -0400279x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400280x86_64*) ARCH=x86_64 ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500281mips*) ARCH=mips ;;
282microblaze*) ARCH=microblaze ;;
Stefan Kristiansson200d1542014-07-17 22:09:10 +0300283or1k*) ARCH=or1k ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500284powerpc*) ARCH=powerpc ;;
285sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
Rich Felker278883d2012-06-03 16:22:13 -0400286unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
287*) fail "$0: unknown or unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400288esac
289
290#
291# Try to get a conforming C99 freestanding environment
292#
293tryflag CFLAGS_C99FSE -std=c99
294tryflag CFLAGS_C99FSE -nostdinc
295tryflag CFLAGS_C99FSE -ffreestanding \
296|| tryflag CFLAGS_C99FSE -fno-builtin
297tryflag CFLAGS_C99FSE -fexcess-precision=standard \
Rich Felker2121b8a2012-07-03 23:53:05 -0400298|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
Rich Felkerb4ccc3c2012-05-05 17:18:31 -0400299tryflag CFLAGS_C99FSE -frounding-math
Rich Felker64d2f8e2012-05-04 23:24:51 -0400300
Rich Felker4a1f55e2013-08-01 17:12:23 -0400301#
Rich Felker06ceee82013-08-27 17:33:47 -0400302# We may use the may_alias attribute if __GNUC__ is defined, so
303# if the compiler defines __GNUC__ but does not provide it,
304# it must be defined away as part of the CFLAGS.
305#
306printf "checking whether compiler needs attribute((may_alias)) suppression... "
307cat > "$tmpc" <<EOF
308typedef int
309#ifdef __GNUC__
310__attribute__((__may_alias__))
311#endif
312x;
313EOF
314if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
315 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
316printf "no\n"
317else
318printf "yes\n"
319CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
320fi
321
322#
Rich Felker1ef849c2015-04-13 20:13:10 -0400323# Check for options to disable stack protector, which needs to be
324# disabled for a few early-bootstrap translation units. If not found,
325# this is not an error; we assume the toolchain does not do ssp.
326#
327tryflag CFLAGS_NOSSP -fno-stack-protector
328
329#
Rich Felker4a1f55e2013-08-01 17:12:23 -0400330# Check for options that may be needed to prevent the compiler from
331# generating self-referential versions of memcpy,, memmove, memcmp,
332# and memset. Really, we should add a check to determine if this
333# option is sufficient, and if not, add a macro to cripple these
334# functions with volatile...
335#
336tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
Rich Felkera80847d2013-07-22 21:22:04 -0400337
Rich Felker64d2f8e2012-05-04 23:24:51 -0400338#
Rich Felker4ad35882014-06-20 16:10:48 -0400339# Enable debugging if requessted.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400340#
Rich Felker4ad35882014-06-20 16:10:48 -0400341test "$debug" = yes && CFLAGS_AUTO=-g
Rich Felkera80847d2013-07-22 21:22:04 -0400342
343#
344# Possibly add a -O option to CFLAGS and select modules to optimize with
345# -O3 based on the status of --enable-optimize and provided CFLAGS.
346#
347printf "checking for optimization settings... "
348case "x$optimize" in
349xauto)
350if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
351printf "using provided CFLAGS\n" ;optimize=no
352else
353printf "using defaults\n" ; optimize=yes
354fi
355;;
356xsize|xnone) printf "minimize size\n" ; optimize=size ;;
357xno|x) printf "disabled\n" ; optimize=no ;;
358*) printf "custom\n" ;;
359esac
360
361test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
Rich Felker43d25312013-07-24 23:21:45 -0400362test "$optimize" = yes && optimize="internal,malloc,string"
Rich Felkera80847d2013-07-22 21:22:04 -0400363
364if fnmatch 'no|size' "$optimize" ; then :
365else
366printf "components to be optimized for speed:"
367while test "$optimize" ; do
368case "$optimize" in
369*,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
370*) this=$optimize optimize=
371esac
372printf " $this"
373case "$this" in
374*/*.c) ;;
375*/*) this=$this*.c ;;
376*) this=$this/*.c ;;
377esac
378OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
379done
380OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
381printf "\n"
382fi
383
384# Always try -pipe
Rich Felker64d2f8e2012-05-04 23:24:51 -0400385tryflag CFLAGS_AUTO -pipe
386
387#
Rich Felkerb439c052012-08-29 09:36:02 -0400388# If debugging is disabled, omit frame pointer. Modern GCC does this
389# anyway on most archs even when debugging is enabled since the frame
390# pointer is no longer needed for debugging.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400391#
392if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
393else
Rich Felker64d2f8e2012-05-04 23:24:51 -0400394tryflag CFLAGS_AUTO -fomit-frame-pointer
395fi
396
397#
Rich Felkerb439c052012-08-29 09:36:02 -0400398# Modern GCC wants to put DWARF tables (used for debugging and
399# unwinding) in the loaded part of the program where they are
400# unstrippable. These options force them back to debug sections (and
401# cause them not to get generated at all if debugging is off).
402#
403tryflag CFLAGS_AUTO -fno-unwind-tables
404tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
405
406#
Rich Felkeradefe832012-10-03 11:49:58 -0400407# The GNU toolchain defaults to assuming unmarked files need an
408# executable stack, potentially exposing vulnerabilities in programs
409# linked with such object files. Fix this.
410#
411tryflag CFLAGS_AUTO -Wa,--noexecstack
412
413#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400414# On x86, make sure we don't have incompatible instruction set
415# extensions enabled by default. This is bad for making static binaries.
416# We cheat and use i486 rather than i386 because i386 really does not
417# work anyway (issues with atomic ops).
Andre McCurdya6274a12015-04-21 10:34:05 -0700418# Some build environments pass -march and -mtune options via CC, so
419# check both CC and CFLAGS.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400420#
421if test "$ARCH" = "i386" ; then
Andre McCurdya6274a12015-04-21 10:34:05 -0700422fnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
423fnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
Rich Felker64d2f8e2012-05-04 23:24:51 -0400424fi
425
Rich Felker2384f272012-12-11 23:28:31 -0500426#
427# Even with -std=c99, gcc accepts some constructs which are constraint
428# violations. We want to treat these as errors regardless of whether
429# other purely stylistic warnings are enabled -- especially implicit
430# function declarations, which are a dangerous programming error.
431#
432tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
433tryflag CFLAGS_AUTO -Werror=implicit-int
434tryflag CFLAGS_AUTO -Werror=pointer-sign
435tryflag CFLAGS_AUTO -Werror=pointer-arith
436
Rich Felker64d2f8e2012-05-04 23:24:51 -0400437if test "x$warnings" = xyes ; then
438tryflag CFLAGS_AUTO -Wall
Rich Felker64d2f8e2012-05-04 23:24:51 -0400439tryflag CFLAGS_AUTO -Wno-parentheses
440tryflag CFLAGS_AUTO -Wno-uninitialized
441tryflag CFLAGS_AUTO -Wno-missing-braces
442tryflag CFLAGS_AUTO -Wno-unused-value
443tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
444tryflag CFLAGS_AUTO -Wno-unknown-pragmas
rofl0radbeefb2014-01-08 03:11:46 +0100445tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
Rich Felker64d2f8e2012-05-04 23:24:51 -0400446fi
447
Rich Felker3aacb542015-04-22 22:11:48 -0400448if test "x$visibility" = xauto ; then
Rich Felkerde2b67f2015-04-19 22:05:29 -0400449# This test checks toolchain support for several things:
450# - the -include option
451# - the attributes/pragmas used in vis.h
452# - linking code that takes the address of protected symbols
453printf "checking whether global visibility preinclude works... "
454echo 'int (*fp)(void);' > "$tmpc"
455echo 'int foo(void) { }' >> "$tmpc"
456echo 'int bar(void) { fp = foo; return foo(); }' >> "$tmpc"
Rich Felker60ed9882015-04-20 18:14:19 -0400457if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
Rich Felker428462a2015-04-22 01:41:00 -0400458 -DSHARED -fPIC -I./src/internal -include vis.h \
Rich Felkerde2b67f2015-04-19 22:05:29 -0400459 -nostdlib -shared -Wl,-Bsymbolic-functions \
460 -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
461visibility=yes
462else
463visibility=no
464fi
465printf "%s\n" "$visibility"
466fi
467
Rich Felker3aacb542015-04-22 22:11:48 -0400468if test "x$visibility" = xyes ; then
Rich Felker428462a2015-04-22 01:41:00 -0400469CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h"
Rich Felkerde2b67f2015-04-19 22:05:29 -0400470CFLAGS_AUTO="${CFLAGS_AUTO# }"
471fi
472
Rich Felker0c5efde2012-06-06 22:00:08 -0400473# Some patched GCC builds have these defaults messed up...
Rich Felker2bd05a42012-08-25 17:13:28 -0400474tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
Rich Felker08f70a32012-06-06 20:45:52 -0400475
Rich Felkerd79b2772014-06-10 12:11:12 -0400476test "$shared" = "no" || {
Rich Felker498a1002012-06-07 00:32:22 -0400477# Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
478LDFLAGS_DUMMY=
479tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
Rich Felkerd79b2772014-06-10 12:11:12 -0400480test "$shared" = "yes" && fail "$0: error: linker cannot build shared library"
Rich Felker498a1002012-06-07 00:32:22 -0400481printf "warning: disabling dynamic linking support\n"
482shared=no
483}
Rich Felkerd79b2772014-06-10 12:11:12 -0400484}
Rich Felker498a1002012-06-07 00:32:22 -0400485
Rich Felker2c1cd232012-09-10 15:30:52 -0400486# Find compiler runtime library
487test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
488test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
Rich Felkercd31a1f2012-10-26 18:15:51 -0400489test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
490 && tryldflag LIBCC "$try_libcc"
Rich Felker2c1cd232012-09-10 15:30:52 -0400491printf "using compiler runtime libraries: %s\n" "$LIBCC"
Rich Felkera1546e82012-07-12 14:24:10 -0400492
Rich Felker3e7f1862013-07-18 20:30:58 -0400493# Figure out arch variants for archs with variants
494SUBARCH=
Rich Felker428462a2015-04-22 01:41:00 -0400495t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS"
Rich Felker3e7f1862013-07-18 20:30:58 -0400496
rofl0r8c820232014-03-19 22:31:00 +0100497if test "$ARCH" = "x86_64" ; then
498trycppif __ILP32__ "$t" && ARCH=x32
499fi
500
Rich Felker3e7f1862013-07-18 20:30:58 -0400501if test "$ARCH" = "arm" ; then
502trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
Rich Felker4918c2b2013-08-16 17:09:07 -0400503trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
Rich Felker3e7f1862013-07-18 20:30:58 -0400504fi
505
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000506if test "$ARCH" = "aarch64" ; then
507trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
508fi
509
Szabolcs Nagye5bb1652014-02-24 23:16:29 +0100510if test "$ARCH" = "mips" ; then
511trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
512trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
513fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400514
515test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
516&& SUBARCH=${SUBARCH}el
517
Rich Felkerb1683a12014-02-27 23:18:42 -0500518if test "$ARCH" = "sh" ; then
519trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
Bobby Bingham23d64182014-04-27 21:13:59 -0500520if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
Rich Felkerb1683a12014-02-27 23:18:42 -0500521# Some sh configurations are broken and replace double with float
522# rather than using softfloat when the fpu is present but only
523# supports single precision. Reject them.
524printf "checking whether compiler's double type is IEEE double... "
Rich Felker946b9fa2014-02-27 23:55:04 -0500525echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
Rich Felkerb1683a12014-02-27 23:18:42 -0500526if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
527printf "yes\n"
528else
529printf "no\n"
530fail "$0: error: compiler's floating point configuration is unsupported"
531fi
532else
533SUBARCH=${SUBARCH}-nofpu
534fi
535fi
Bobby Bingham3a3c8132013-10-05 05:13:18 -0500536
Rich Felker3e7f1862013-07-18 20:30:58 -0400537test "$SUBARCH" \
538&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400539
Rich Felker90d77722013-08-11 03:27:35 -0400540case "$ARCH$SUBARCH" in
541arm) ASMSUBARCH=el ;;
542*) ASMSUBARCH=$SUBARCH ;;
543esac
544
Rich Felker86cc54b2013-08-02 19:34:22 -0400545#
546# Some archs (powerpc) have different possible long double formats
547# that the compiler can be configured for. The logic for whether this
548# is supported is in bits/float.h; in general, it is not. We need to
549# check for mismatches here or code in printf, strotd, and scanf will
550# be dangerously incorrect because it depends on (1) the macros being
551# correct, and (2) IEEE semantics.
552#
553printf "checking whether compiler's long double definition matches float.h... "
554echo '#include <float.h>' > "$tmpc"
555echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
556echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
557echo '#endif' >> "$tmpc"
558if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
559 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
560printf "yes\n"
561else
562printf "no\n"
563fail "$0: error: unsupported long double type"
564fi
565
Rich Felker64d2f8e2012-05-04 23:24:51 -0400566printf "creating config.mak... "
567
Rich Felker453f4622013-08-16 18:19:47 -0400568cmdline=$(quote "$0")
569for i ; do cmdline="$cmdline $(quote "$i")" ; done
570
Rich Felker64d2f8e2012-05-04 23:24:51 -0400571exec 3>&1 1>config.mak
572
573
574cat << EOF
Rich Felker453f4622013-08-16 18:19:47 -0400575# This version of config.mak was generated by:
576# $cmdline
Rich Felker64d2f8e2012-05-04 23:24:51 -0400577# Any changes made here will be lost if configure is re-run
578ARCH = $ARCH
Rich Felker3e7f1862013-07-18 20:30:58 -0400579SUBARCH = $SUBARCH
Rich Felker90d77722013-08-11 03:27:35 -0400580ASMSUBARCH = $ASMSUBARCH
Rich Felker64d2f8e2012-05-04 23:24:51 -0400581prefix = $prefix
582exec_prefix = $exec_prefix
583bindir = $bindir
584libdir = $libdir
585includedir = $includedir
586syslibdir = $syslibdir
587CC = $CC
Rich Felker7c6db372014-05-20 15:49:21 -0400588CFLAGS = $CFLAGS_AUTO $CFLAGS
Rich Felker64d2f8e2012-05-04 23:24:51 -0400589CFLAGS_C99FSE = $CFLAGS_C99FSE
Rich Felker4a1f55e2013-08-01 17:12:23 -0400590CFLAGS_MEMOPS = $CFLAGS_MEMOPS
Rich Felker1ef849c2015-04-13 20:13:10 -0400591CFLAGS_NOSSP = $CFLAGS_NOSSP
Rich Felker64d2f8e2012-05-04 23:24:51 -0400592CPPFLAGS = $CPPFLAGS
Rich Felker08f70a32012-06-06 20:45:52 -0400593LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
Rich Felker94e920d2012-08-14 22:50:16 -0400594CROSS_COMPILE = $CROSS_COMPILE
Rich Felker2c1cd232012-09-10 15:30:52 -0400595LIBCC = $LIBCC
Rich Felkera80847d2013-07-22 21:22:04 -0400596OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
Shizb3cd7d12015-06-28 23:08:19 +0200597ALL_TOOLS = $tools
598TOOL_LIBS = $tool_libs
Rich Felker64d2f8e2012-05-04 23:24:51 -0400599EOF
600test "x$static" = xno && echo "STATIC_LIBS ="
601test "x$shared" = xno && echo "SHARED_LIBS ="
Shizb3cd7d12015-06-28 23:08:19 +0200602test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
Rich Felker64d2f8e2012-05-04 23:24:51 -0400603exec 1>&3 3>&-
604
605printf "done\n"