blob: ca5cbc0bd06d5d9c81432305f0f1e9b0621179d5 [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
Petr Hosek2f853dd2015-11-18 12:07:32 -080012Configuration:
13 --srcdir=DIR source directory [detected]
14
Rich Felker64d2f8e2012-05-04 23:24:51 -040015Installation 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]
Rich Felker278883d2012-06-03 16:22:13 -040027 --host=HOST same as --target
Rich Felker2d49c222016-04-29 19:50:33 -040028 --build=BUILD build system type; used only to infer cross-compiling
Rich Felker64d2f8e2012-05-04 23:24:51 -040029
30Optional features:
Rich Felkera80847d2013-07-22 21:22:04 -040031 --enable-optimize=... optimize listed components for speed over size [auto]
Rich Felker64d2f8e2012-05-04 23:24:51 -040032 --enable-debug build with debugging information [disabled]
Rich Felker86ac0f72020-08-27 20:43:47 -040033 --disable-warnings build with recommended warnings flags [enabled]
Shizb3cd7d12015-06-28 23:08:19 +020034 --enable-wrapper=... build given musl toolchain wrapper [auto]
Rich Felker64d2f8e2012-05-04 23:24:51 -040035 --disable-shared inhibit building shared library [enabled]
36 --disable-static inhibit building static library [enabled]
37
Rich Felkere71188f2020-06-30 15:29:58 -040038Optional packages:
Rich Felkerea6d7842020-06-30 15:30:27 -040039 --with-malloc=... choose malloc implementation [mallocng]
Rich Felkere71188f2020-06-30 15:29:58 -040040
Rich Felker64d2f8e2012-05-04 23:24:51 -040041Some influential environment variables:
42 CC C compiler command [detected]
43 CFLAGS C compiler flags [-Os -pipe ...]
Rich Felker94e920d2012-08-14 22:50:16 -040044 CROSS_COMPILE prefix for cross compiler and tools [none]
Rich Felker2c1cd232012-09-10 15:30:52 -040045 LIBCC compiler runtime library [detected]
Rich Felker64d2f8e2012-05-04 23:24:51 -040046
47Use these variables to override the choices made by configure.
48
49EOF
50exit 0
51}
52
53# Helper functions
54
Rich Felker453f4622013-08-16 18:19:47 -040055quote () {
56tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
57$1
58EOF
Rich Felkere4499742013-08-20 13:51:46 -040059printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
Rich Felker453f4622013-08-16 18:19:47 -040060}
Rich Felker64d2f8e2012-05-04 23:24:51 -040061echo () { 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
Rich Felker3d9e3a32012-11-08 17:20:50 -050067stripdir () {
68while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
Rich Felker64d2f8e2012-05-04 23:24:51 -040069}
70
Rich Felker3e7f1862013-07-18 20:30:58 -040071trycppif () {
72printf "checking preprocessor condition %s... " "$1"
Rich Felkerdf065782013-07-18 20:37:19 -040073echo "typedef int x;" > "$tmpc"
74echo "#if $1" >> "$tmpc"
Rich Felker3e7f1862013-07-18 20:30:58 -040075echo "#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
Rich Felker64d2f8e2012-05-04 23:24:51 -040086tryflag () {
87printf "checking whether compiler accepts %s... " "$2"
88echo "typedef int x;" > "$tmpc"
Shizfc431d32015-05-28 05:52:22 +020089if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker64d2f8e2012-05-04 23:24:51 -040090printf "yes\n"
91eval "$1=\"\${$1} \$2\""
92eval "$1=\${$1# }"
93return 0
94else
95printf "no\n"
96return 1
97fi
98}
99
Rich Felker08f70a32012-06-06 20:45:52 -0400100tryldflag () {
101printf "checking whether linker accepts %s... " "$2"
Rich Felker67a03832012-06-07 00:23:58 -0400102echo "typedef int x;" > "$tmpc"
Shizfc431d32015-05-28 05:52:22 +0200103if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker08f70a32012-06-06 20:45:52 -0400104printf "yes\n"
105eval "$1=\"\${$1} \$2\""
106eval "$1=\${$1# }"
107return 0
108else
109printf "no\n"
110return 1
111fi
112}
113
Rich Felker64d2f8e2012-05-04 23:24:51 -0400114
115
116# Beginning of actual script
117
Rich Felker08f70a32012-06-06 20:45:52 -0400118CFLAGS_C99FSE=
119CFLAGS_AUTO=
Rich Felker4a1f55e2013-08-01 17:12:23 -0400120CFLAGS_MEMOPS=
Rich Felker1ef849c2015-04-13 20:13:10 -0400121CFLAGS_NOSSP=
Shizfc431d32015-05-28 05:52:22 +0200122CFLAGS_TRY=
Rich Felker08f70a32012-06-06 20:45:52 -0400123LDFLAGS_AUTO=
Shizfc431d32015-05-28 05:52:22 +0200124LDFLAGS_TRY=
Rich Felkera80847d2013-07-22 21:22:04 -0400125OPTIMIZE_GLOBS=
Petr Hosek2f853dd2015-11-18 12:07:32 -0800126srcdir=
Rich Felker3d9e3a32012-11-08 17:20:50 -0500127prefix=/usr/local/musl
128exec_prefix='$(prefix)'
129bindir='$(exec_prefix)/bin'
130libdir='$(prefix)/lib'
131includedir='$(prefix)/include'
132syslibdir='/lib'
Shizb3cd7d12015-06-28 23:08:19 +0200133tools=
134tool_libs=
Rich Felker2d49c222016-04-29 19:50:33 -0400135build=
Rich Felker278883d2012-06-03 16:22:13 -0400136target=
Rich Felkera80847d2013-07-22 21:22:04 -0400137optimize=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400138debug=no
Rich Felker86ac0f72020-08-27 20:43:47 -0400139warnings=yes
Rich Felkerd79b2772014-06-10 12:11:12 -0400140shared=auto
Rich Felker64d2f8e2012-05-04 23:24:51 -0400141static=yes
Rich Felker9ca4dae2014-05-19 10:33:28 -0400142wrapper=auto
Shizb3cd7d12015-06-28 23:08:19 +0200143gcc_wrapper=no
Shizfb585452015-06-28 23:08:21 +0200144clang_wrapper=no
Rich Felkerea6d7842020-06-30 15:30:27 -0400145malloc_dir=mallocng
Rich Felker64d2f8e2012-05-04 23:24:51 -0400146
147for arg ; do
148case "$arg" in
Rich Felker47314f12016-02-02 21:14:09 -0500149--help|-h) usage ;;
Petr Hosek2f853dd2015-11-18 12:07:32 -0800150--srcdir=*) srcdir=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400151--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 ;;
Rich Felkera80847d2013-07-22 21:22:04 -0400161--enable-optimize) optimize=yes ;;
162--enable-optimize=*) optimize=${arg#*=} ;;
163--disable-optimize) optimize=no ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400164--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 ;;
Shizb3cd7d12015-06-28 23:08:19 +0200168--enable-wrapper|--enable-wrapper=yes) wrapper=detect ;;
Shizfb585452015-06-28 23:08:21 +0200169--enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ; clang_wrapper=yes ;;
Shizb3cd7d12015-06-28 23:08:19 +0200170--enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;;
Shizfb585452015-06-28 23:08:21 +0200171--enable-wrapper=clang) wrapper=yes ; clang_wrapper=yes ;;
Shizb3cd7d12015-06-28 23:08:19 +0200172--disable-wrapper|--enable-wrapper=no) wrapper=no ;;
173--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400174--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
Rich Felkere71188f2020-06-30 15:29:58 -0400175--with-malloc=*) malloc_dir=${arg#*=} ;;
LeMay, Michael6bc7d9c2016-05-04 03:29:42 +0000176--enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
Rich Felker278883d2012-06-03 16:22:13 -0400177--host=*|--target=*) target=${arg#*=} ;;
Rich Felker2d49c222016-04-29 19:50:33 -0400178--build=*) build=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400179-* ) echo "$0: unknown option $arg" ;;
Fangrui Song4b5ba072019-06-27 08:10:04 +0000180AR=*) AR=${arg#*=} ;;
181RANLIB=*) RANLIB=${arg#*=} ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400182CC=*) CC=${arg#*=} ;;
183CFLAGS=*) CFLAGS=${arg#*=} ;;
184CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
185LDFLAGS=*) LDFLAGS=${arg#*=} ;;
Rich Felker94e920d2012-08-14 22:50:16 -0400186CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
Rich Felker2c1cd232012-09-10 15:30:52 -0400187LIBCC=*) LIBCC=${arg#*=} ;;
Rich Felker278883d2012-06-03 16:22:13 -0400188*=*) ;;
Rich Felker2d49c222016-04-29 19:50:33 -0400189*) build=$arg ; target=$arg ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400190esac
191done
192
Petr Hosek2f853dd2015-11-18 12:07:32 -0800193for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do
Rich Felker3d9e3a32012-11-08 17:20:50 -0500194stripdir $i
195done
Rich Felker64d2f8e2012-05-04 23:24:51 -0400196
197#
Petr Hosek2f853dd2015-11-18 12:07:32 -0800198# 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=.
Issam E. Maghnid046ec92020-11-02 17:16:41 -0500207test "$srcdir" != "." && test -f Makefile && test ! -h Makefile && fail "$0: Makefile already exists in the working directory"
Petr Hosek2f853dd2015-11-18 12:07:32 -0800208
209#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400210# Get a temp filename we can use
211#
212i=0
213set -C
214while : ; do i=$(($i+1))
215tmpc="./conf$$-$PPID-$i.c"
Rich Felker6c0cba82012-11-18 23:15:47 -05002162>|/dev/null > "$tmpc" && break
Rich Felker64d2f8e2012-05-04 23:24:51 -0400217test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
218done
219set +C
220trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
221
222#
Rich Felkere71188f2020-06-30 15:29:58 -0400223# 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
228#
Rich Felker2d49c222016-04-29 19:50:33 -0400229# 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#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400238# Find a C compiler to use
239#
240printf "checking for C compiler... "
Rich Felker94e920d2012-08-14 22:50:16 -0400241trycc ${CROSS_COMPILE}gcc
242trycc ${CROSS_COMPILE}c99
243trycc ${CROSS_COMPILE}cc
Rich Felker64d2f8e2012-05-04 23:24:51 -0400244printf "%s\n" "$CC"
245test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
246
Rich Felker89456672014-05-12 14:22:57 -0400247printf "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
Rich Felker64d2f8e2012-05-04 23:24:51 -0400256#
Shizfc431d32015-05-28 05:52:22 +0200257# 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
Dmitry Golovin9d12a6a2017-06-09 17:10:47 +0300261tryflag CFLAGS_TRY -Werror=ignored-optimization-argument
Shizfc431d32015-05-28 05:52:22 +0200262tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
263tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
264
265#
Shizb3cd7d12015-06-28 23:08:19 +0200266# Need to know if the compiler is gcc or clang to decide which toolchain
267# wrappers to build.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400268#
Shizb3cd7d12015-06-28 23:08:19 +0200269printf "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
Shizfb585452015-06-28 23:08:21 +0200274elif fnmatch '*clang\ version*' "$cc_ver" ; then
275cc_family=clang
Rich Felker9ca4dae2014-05-19 10:33:28 -0400276fi
Shizb3cd7d12015-06-28 23:08:19 +0200277echo "$cc_family"
Rich Felker9ca4dae2014-05-19 10:33:28 -0400278
279#
Shizb3cd7d12015-06-28 23:08:19 +0200280# Figure out toolchain wrapper to build
Rich Felker9ca4dae2014-05-19 10:33:28 -0400281#
Issam E. Maghnid046ec92020-11-02 17:16:41 -0500282if test "$wrapper" = auto || test "$wrapper" = detect ; then
Shizf8db6f72015-06-28 23:08:20 +0200283echo "#include <stdlib.h>" > "$tmpc"
284echo "#if ! __GLIBC__" >> "$tmpc"
285echo "#error no" >> "$tmpc"
286echo "#endif" >> "$tmpc"
Shizb3cd7d12015-06-28 23:08:19 +0200287printf "checking for toolchain wrapper to build... "
Shizf8db6f72015-06-28 23:08:20 +0200288if test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
289echo "none"
290elif test "$cc_family" = gcc ; then
Shizb3cd7d12015-06-28 23:08:19 +0200291gcc_wrapper=yes
Shizf8db6f72015-06-28 23:08:20 +0200292echo "gcc"
Shizfb585452015-06-28 23:08:21 +0200293elif test "$cc_family" = clang ; then
294clang_wrapper=yes
295echo "clang"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400296else
Shizb3cd7d12015-06-28 23:08:19 +0200297echo "none"
298if test "$wrapper" = detect ; then
299fail "$0: could not find an appropriate toolchain wrapper"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400300fi
Shizb3cd7d12015-06-28 23:08:19 +0200301fi
Rich Felker64d2f8e2012-05-04 23:24:51 -0400302fi
303
Shizb3cd7d12015-06-28 23:08:19 +0200304if test "$gcc_wrapper" = yes ; then
Petr Hosek2f853dd2015-11-18 12:07:32 -0800305tools="$tools obj/musl-gcc"
Shizb3cd7d12015-06-28 23:08:19 +0200306tool_libs="$tool_libs lib/musl-gcc.specs"
307fi
Shizfb585452015-06-28 23:08:21 +0200308if test "$clang_wrapper" = yes ; then
Petr Hosek2f853dd2015-11-18 12:07:32 -0800309tools="$tools obj/musl-clang obj/ld.musl-clang"
Shizfb585452015-06-28 23:08:21 +0200310fi
Rich Felker64d2f8e2012-05-04 23:24:51 -0400311
312#
Rich Felker278883d2012-06-03 16:22:13 -0400313# Find the target architecture
Rich Felker64d2f8e2012-05-04 23:24:51 -0400314#
Rich Felker278883d2012-06-03 16:22:13 -0400315printf "checking target system type... "
Rich Felker01e5a1b2012-10-18 23:02:53 -0400316test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
Rich Felker278883d2012-06-03 16:22:13 -0400317printf "%s\n" "$target"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400318
319#
320# Convert to just ARCH
321#
Rich Felker278883d2012-06-03 16:22:13 -0400322case "$target" in
Rich Felker0b8f0c52014-02-28 13:12:40 -0500323# Catch these early to simplify matching for 32-bit archs
Rich Felker64d2f8e2012-05-04 23:24:51 -0400324arm*) ARCH=arm ;;
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000325aarch64*) ARCH=aarch64 ;;
Rich Felker4c101e12016-02-19 00:10:23 -0500326i?86-nt32*) ARCH=nt32 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400327i?86*) ARCH=i386 ;;
Rich Felkerf162c062014-03-17 17:38:22 -0400328x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
Rich Felker4c101e12016-02-19 00:10:23 -0500329x86_64-nt64*) ARCH=nt64 ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400330x86_64*) ARCH=x86_64 ;;
Rich Felkerf81e44a2018-06-14 14:26:30 -0400331m68k*) ARCH=m68k ;;
Szabolcs Nagyfff88012016-08-24 12:40:10 +0200332mips64*|mipsisa64*) ARCH=mips64 ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500333mips*) ARCH=mips ;;
334microblaze*) ARCH=microblaze ;;
Stefan Kristiansson200d1542014-07-17 22:09:10 +0300335or1k*) ARCH=or1k ;;
Rich Felkeraba17aa2019-01-19 18:39:54 -0500336powerpc64*|ppc64*) ARCH=powerpc64 ;;
337powerpc*|ppc*) ARCH=powerpc ;;
Rich Felker0a488602019-05-24 10:46:08 -0400338riscv64*) ARCH=riscv64 ;;
Rich Felker0b8f0c52014-02-28 13:12:40 -0500339sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
Bobby Bingham15094942016-11-11 21:52:05 -0600340s390x*) ARCH=s390x ;;
Rich Felker278883d2012-06-03 16:22:13 -0400341unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
342*) fail "$0: unknown or unsupported target \"$target\"" ;;
Rich Felker64d2f8e2012-05-04 23:24:51 -0400343esac
344
345#
346# Try to get a conforming C99 freestanding environment
347#
348tryflag CFLAGS_C99FSE -std=c99
349tryflag CFLAGS_C99FSE -nostdinc
350tryflag CFLAGS_C99FSE -ffreestanding \
351|| tryflag CFLAGS_C99FSE -fno-builtin
352tryflag CFLAGS_C99FSE -fexcess-precision=standard \
Rich Felker2121b8a2012-07-03 23:53:05 -0400353|| { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
Rich Felkerb4ccc3c2012-05-05 17:18:31 -0400354tryflag CFLAGS_C99FSE -frounding-math
Rich Felker64d2f8e2012-05-04 23:24:51 -0400355
Rich Felker4a1f55e2013-08-01 17:12:23 -0400356#
Rich Felker06ceee82013-08-27 17:33:47 -0400357# We may use the may_alias attribute if __GNUC__ is defined, so
358# if the compiler defines __GNUC__ but does not provide it,
359# it must be defined away as part of the CFLAGS.
360#
361printf "checking whether compiler needs attribute((may_alias)) suppression... "
362cat > "$tmpc" <<EOF
363typedef int
364#ifdef __GNUC__
365__attribute__((__may_alias__))
366#endif
367x;
368EOF
Rich Felkere1d99892016-01-27 19:01:21 -0500369if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
Rich Felker06ceee82013-08-27 17:33:47 -0400370 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
371printf "no\n"
372else
373printf "yes\n"
374CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
375fi
376
377#
Rich Felkerbc0c4842015-10-23 00:01:01 -0400378# The GNU toolchain defaults to assuming unmarked files need an
379# executable stack, potentially exposing vulnerabilities in programs
380# linked with such object files. Fix this.
381#
382tryflag CFLAGS_C99FSE -Wa,--noexecstack
383
384#
Rich Felker1ef849c2015-04-13 20:13:10 -0400385# Check for options to disable stack protector, which needs to be
386# disabled for a few early-bootstrap translation units. If not found,
387# this is not an error; we assume the toolchain does not do ssp.
388#
389tryflag CFLAGS_NOSSP -fno-stack-protector
390
391#
Rich Felker4a1f55e2013-08-01 17:12:23 -0400392# Check for options that may be needed to prevent the compiler from
393# generating self-referential versions of memcpy,, memmove, memcmp,
394# and memset. Really, we should add a check to determine if this
395# option is sufficient, and if not, add a macro to cripple these
396# functions with volatile...
397#
398tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
Rich Felkera80847d2013-07-22 21:22:04 -0400399
Rich Felker64d2f8e2012-05-04 23:24:51 -0400400#
Rich Felker4ad35882014-06-20 16:10:48 -0400401# Enable debugging if requessted.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400402#
Rich Felker4ad35882014-06-20 16:10:48 -0400403test "$debug" = yes && CFLAGS_AUTO=-g
Rich Felkera80847d2013-07-22 21:22:04 -0400404
405#
Alex Dowad35b33122015-07-10 15:03:24 +0200406# Preprocess asm files to add extra debugging information if debug is
407# enabled, our assembler supports the needed directives, and the
408# preprocessing script has been written for our architecture.
409#
410printf "checking whether we should preprocess assembly to add debugging information... "
411if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" &&
Wesley Wiserc4d40282021-10-21 16:09:30 +0000412 test -f "$srcdir/tools/add-cfi.$ARCH.awk" &&
Alex Dowad35b33122015-07-10 15:03:24 +0200413 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 -
414then
415 ADD_CFI=yes
416else
417 ADD_CFI=no
418fi
419printf "%s\n" "$ADD_CFI"
420
421#
Rich Felkera80847d2013-07-22 21:22:04 -0400422# Possibly add a -O option to CFLAGS and select modules to optimize with
423# -O3 based on the status of --enable-optimize and provided CFLAGS.
424#
425printf "checking for optimization settings... "
426case "x$optimize" in
427xauto)
428if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
429printf "using provided CFLAGS\n" ;optimize=no
430else
431printf "using defaults\n" ; optimize=yes
432fi
433;;
434xsize|xnone) printf "minimize size\n" ; optimize=size ;;
435xno|x) printf "disabled\n" ; optimize=no ;;
436*) printf "custom\n" ;;
437esac
438
439test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
Rich Felker43d25312013-07-24 23:21:45 -0400440test "$optimize" = yes && optimize="internal,malloc,string"
Rich Felkera80847d2013-07-22 21:22:04 -0400441
442if fnmatch 'no|size' "$optimize" ; then :
443else
444printf "components to be optimized for speed:"
445while test "$optimize" ; do
446case "$optimize" in
447*,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
448*) this=$optimize optimize=
449esac
450printf " $this"
451case "$this" in
452*/*.c) ;;
453*/*) this=$this*.c ;;
454*) this=$this/*.c ;;
455esac
456OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
457done
458OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
459printf "\n"
460fi
461
462# Always try -pipe
Rich Felker64d2f8e2012-05-04 23:24:51 -0400463tryflag CFLAGS_AUTO -pipe
464
465#
Rich Felkerb439c052012-08-29 09:36:02 -0400466# If debugging is disabled, omit frame pointer. Modern GCC does this
467# anyway on most archs even when debugging is enabled since the frame
468# pointer is no longer needed for debugging.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400469#
470if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
Issam E. Maghnid046ec92020-11-02 17:16:41 -0500471else
Rich Felker64d2f8e2012-05-04 23:24:51 -0400472tryflag CFLAGS_AUTO -fomit-frame-pointer
473fi
474
475#
Rich Felkerb439c052012-08-29 09:36:02 -0400476# Modern GCC wants to put DWARF tables (used for debugging and
477# unwinding) in the loaded part of the program where they are
478# unstrippable. These options force them back to debug sections (and
479# cause them not to get generated at all if debugging is off).
480#
481tryflag CFLAGS_AUTO -fno-unwind-tables
482tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
483
484#
Rich Felker27c1ecc2015-11-04 13:24:11 -0500485# Attempt to put each function and each data object in its own
486# section. This both allows additional size optimizations at link
487# time and works around a dangerous class of compiler/assembler bugs
488# whereby relative address expressions are constant-folded by the
489# assembler even when one or more of the symbols involved is
490# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc.
491#
492tryflag CFLAGS_AUTO -ffunction-sections
493tryflag CFLAGS_AUTO -fdata-sections
494
495#
Rich Felker64d2f8e2012-05-04 23:24:51 -0400496# On x86, make sure we don't have incompatible instruction set
497# extensions enabled by default. This is bad for making static binaries.
498# We cheat and use i486 rather than i386 because i386 really does not
499# work anyway (issues with atomic ops).
Andre McCurdya6274a12015-04-21 10:34:05 -0700500# Some build environments pass -march and -mtune options via CC, so
501# check both CC and CFLAGS.
Rich Felker64d2f8e2012-05-04 23:24:51 -0400502#
503if test "$ARCH" = "i386" ; then
Andre McCurdya6274a12015-04-21 10:34:05 -0700504fnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
505fnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
Rich Felker64d2f8e2012-05-04 23:24:51 -0400506fi
507
Rich Felker2384f272012-12-11 23:28:31 -0500508#
Rich Felkerc40157d2020-06-01 20:53:42 -0400509# GCC defines -w as overriding any -W options, regardless of order, but
510# clang has a bunch of annoying warnings enabled by default and needs -w
Rich Felker0a312d32020-08-27 20:39:41 -0400511# to start from a clean slate. So use -w if building with clang. Also
512# turn off a common on-by-default cast warning regardless of compiler.
Rich Felkerc40157d2020-06-01 20:53:42 -0400513#
514test "$cc_family" = clang && tryflag CFLAGS_AUTO -w
515
Rich Felker0a312d32020-08-27 20:39:41 -0400516tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
517
Rich Felkerc40157d2020-06-01 20:53:42 -0400518#
Rich Felker2384f272012-12-11 23:28:31 -0500519# Even with -std=c99, gcc accepts some constructs which are constraint
520# violations. We want to treat these as errors regardless of whether
521# other purely stylistic warnings are enabled -- especially implicit
522# function declarations, which are a dangerous programming error.
523#
524tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
525tryflag CFLAGS_AUTO -Werror=implicit-int
526tryflag CFLAGS_AUTO -Werror=pointer-sign
527tryflag CFLAGS_AUTO -Werror=pointer-arith
Rich Felkere7f808e2020-08-27 18:50:02 -0400528tryflag CFLAGS_AUTO -Werror=int-conversion
529tryflag CFLAGS_AUTO -Werror=incompatible-pointer-types
530tryflag CFLAGS_AUTO -Werror=discarded-qualifiers
531tryflag CFLAGS_AUTO -Werror=discarded-array-qualifiers
Rich Felker2384f272012-12-11 23:28:31 -0500532
Dmitry Golovin9d12a6a2017-06-09 17:10:47 +0300533#
534# GCC ignores unused arguements by default, but Clang needs this extra
535# parameter to stop printing warnings about LDFLAGS passed during
536# compiling stage and CFLAGS passed during linking stage.
537#
Rich Felker76341012018-09-12 22:43:38 -0400538test "$cc_family" = clang && tryflag CFLAGS_AUTO -Qunused-arguments
Dmitry Golovin9d12a6a2017-06-09 17:10:47 +0300539
Rich Felker64d2f8e2012-05-04 23:24:51 -0400540if test "x$warnings" = xyes ; then
Rich Felker0a312d32020-08-27 20:39:41 -0400541tryflag CFLAGS_AUTO -Waddress
542tryflag CFLAGS_AUTO -Warray-bounds
543tryflag CFLAGS_AUTO -Wchar-subscripts
544tryflag CFLAGS_AUTO -Wduplicate-decl-specifier
545tryflag CFLAGS_AUTO -Winit-self
546tryflag CFLAGS_AUTO -Wreturn-type
547tryflag CFLAGS_AUTO -Wsequence-point
548tryflag CFLAGS_AUTO -Wstrict-aliasing
549tryflag CFLAGS_AUTO -Wunused-function
550tryflag CFLAGS_AUTO -Wunused-label
551tryflag CFLAGS_AUTO -Wunused-variable
Rich Felker64d2f8e2012-05-04 23:24:51 -0400552fi
553
Rich Felker16191272016-01-25 19:57:38 -0500554# Determine if the compiler produces position-independent code (PIC)
555# by default. If so, we don't need to compile separate object files
556# for libc.a and libc.so.
557if trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
558pic_default=yes
559else
560pic_default=no
561fi
562
Rich Felker2efd38e2015-11-04 21:39:13 -0500563# Reduce space lost to padding for alignment purposes by sorting data
564# objects according to their alignment reqirements. This approximates
565# optimal packing.
566tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment
567tryldflag LDFLAGS_AUTO -Wl,--sort-common
568
Rich Felker6a851e32015-11-04 21:40:36 -0500569# When linking shared library, drop dummy weak definitions that were
570# replaced by strong definitions from other translation units.
571tryldflag LDFLAGS_AUTO -Wl,--gc-sections
572
Rich Felker0c5efde2012-06-06 22:00:08 -0400573# Some patched GCC builds have these defaults messed up...
Rich Felker2bd05a42012-08-25 17:13:28 -0400574tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
Rich Felker08f70a32012-06-06 20:45:52 -0400575
Rich Felker24623702015-09-22 15:45:40 +0000576# Prevent linking if there are undefined symbols; if any exist,
577# libc.so will crash at runtime during relocation processing.
578# The common way this can happen is failure to link the compiler
579# runtime library; implementation error is also a possibility.
580tryldflag LDFLAGS_AUTO -Wl,--no-undefined
581
Rich Felkerea1e2c52015-11-07 20:23:49 -0500582# Avoid exporting symbols from compiler runtime libraries. They
583# should be hidden anyway, but some toolchains including old gcc
584# versions built without shared library support and pcc are broken.
585tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL
586
Rich Felkerb9410062018-04-16 20:12:12 -0400587# Public data symbols must be interposable to allow for copy
588# relocations, but otherwise we want to bind symbols at libc link
589# time to eliminate startup relocations and PLT overhead. Use
590# --dynamic-list rather than -Bsymbolic-functions for greater
591# control over what symbols are left unbound.
592tryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list"
Rich Felker498a1002012-06-07 00:32:22 -0400593
Rich Felker2c1cd232012-09-10 15:30:52 -0400594# Find compiler runtime library
595test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
596test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
Matúš Olekšákfcf24b92018-02-21 12:03:04 -0500597test -z "$LIBCC" && try_libcc=`$CC -print-libgcc-file-name 2>/dev/null` \
598 && tryldflag LIBCC "$try_libcc"
Rich Felkercd31a1f2012-10-26 18:15:51 -0400599test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
600 && tryldflag LIBCC "$try_libcc"
Rich Felker2c1cd232012-09-10 15:30:52 -0400601printf "using compiler runtime libraries: %s\n" "$LIBCC"
Rich Felkera1546e82012-07-12 14:24:10 -0400602
Rich Felker3e7f1862013-07-18 20:30:58 -0400603# Figure out arch variants for archs with variants
604SUBARCH=
Rich Felker428462a2015-04-22 01:41:00 -0400605t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS"
Rich Felker3e7f1862013-07-18 20:30:58 -0400606
Rich Felkerbdb08172019-05-11 19:44:21 -0400607if test "$ARCH" = "i386" ; then
608printf "checking whether compiler can use ebx in PIC asm constraints... "
609cat > "$tmpc" <<EOF
610int foo(int x) { __asm__ ( "" : "+b"(x) ); return x; }
611EOF
612if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -fPIC \
613 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
614printf "yes\n"
615else
616printf "no\n"
617CFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_EBX_ASM"
618fi
619fi
620
rofl0r8c820232014-03-19 22:31:00 +0100621if test "$ARCH" = "x86_64" ; then
622trycppif __ILP32__ "$t" && ARCH=x32
623fi
624
Rich Felker3e7f1862013-07-18 20:30:58 -0400625if test "$ARCH" = "arm" ; then
Rich Felker088c9672016-12-19 21:53:33 -0500626if trycppif __thumb2__ "$t" ; then
Rich Felkerdffc2052018-09-19 01:31:26 -0400627tryflag CFLAGS_AUTO -mimplicit-it=always
Rich Felker088c9672016-12-19 21:53:33 -0500628tryflag CFLAGS_AUTO -Wa,-mimplicit-it=always
629tryflag CFLAGS_AUTO -Wa,-mthumb
630fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400631trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
Rich Felker4918c2b2013-08-16 17:09:07 -0400632trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
Rich Felker71c334f2016-02-19 01:20:07 +0000633# Versions of clang up until at least 3.8 have the wrong constraint codes
634# for floating point operands to inline asm. Detect this so the affected
635# source files can just disable the asm.
636if test "$cc_family" = clang ; then
637printf "checking whether clang's vfp asm constraints work... "
638echo 'float f(float x) { __asm__("":"+t"(x)); return x; }' > "$tmpc"
639if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
640printf "yes\n"
641else
642printf "no\n"
643CFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_VFP_ASM"
644CFLAGS_AUTO="${CFLAGS_AUTO# }"
645fi
646fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400647fi
648
Szabolcs Nagy01ef3dd2015-03-10 21:18:41 +0000649if test "$ARCH" = "aarch64" ; then
650trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
651fi
652
Rich Felkerf81e44a2018-06-14 14:26:30 -0400653if test "$ARCH" = "m68k" ; then
654if trycppif "__HAVE_68881__" ; then : ;
655elif trycppif "__mcffpu__" ; then SUBARCH="-fp64"
656else SUBARCH="-sf"
657fi
658fi
659
Szabolcs Nagye5bb1652014-02-24 23:16:29 +0100660if test "$ARCH" = "mips" ; then
Rich Felker6d99ad92016-04-03 10:42:37 +0000661trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6
Szabolcs Nagye5bb1652014-02-24 23:16:29 +0100662trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
663trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
664fi
Rich Felker3e7f1862013-07-18 20:30:58 -0400665
Rich Felker83933572016-03-06 17:41:56 +0000666if test "$ARCH" = "mips64" ; then
Rich Felker5972c4a2016-04-18 05:19:13 +0000667trycppif "_MIPS_SIM != _ABI64" "$t" && ARCH=mipsn32
Rich Felker6d99ad92016-04-03 10:42:37 +0000668trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6
Rich Felker83933572016-03-06 17:41:56 +0000669trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
670trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
671fi
672
Felix Fietkau5a92dd92016-01-25 13:20:52 +0100673if test "$ARCH" = "powerpc" ; then
Rich Felker7be59732021-09-23 19:11:46 -0400674trycppif "_SOFT_FLOAT || __NO_FPRS__" "$t" && SUBARCH=${SUBARCH}-sf
rofl0r66d1e312019-11-05 21:01:42 +0000675printf "checking whether compiler can use 'd' constraint in asm... "
676echo 'double f(double x) { __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); return x; }' > "$tmpc"
677if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
678printf "yes\n"
679else
680printf "no\n"
681CFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_PPC_D_ASM"
682CFLAGS_AUTO="${CFLAGS_AUTO# }"
683fi
Felix Fietkau5a92dd92016-01-25 13:20:52 +0100684fi
685
Rich Felker3e7f1862013-07-18 20:30:58 -0400686test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
687&& SUBARCH=${SUBARCH}el
688
Bobby Binghamc0ede9e2016-04-30 19:18:17 -0500689if test "$ARCH" = "powerpc64" ; then
690trycppif "_CALL_ELF == 2" "$t" || fail "$0: error: unsupported powerpc64 ABI"
691trycppif __LITTLE_ENDIAN__ "$t" && SUBARCH=${SUBARCH}le
692trycppif _SOFT_FLOAT "$t" && fail "$0: error: soft-float not supported on powerpc64"
693fi
694
Rich Felker0a488602019-05-24 10:46:08 -0400695if test "$ARCH" = "riscv64" ; then
696trycppif __riscv_float_abi_soft "$t" && SUBARCH=${SUBARCH}-sf
697trycppif __riscv_float_abi_single "$t" && SUBARCH=${SUBARCH}-sp
698fi
699
Rich Felkerb1683a12014-02-27 23:18:42 -0500700if test "$ARCH" = "sh" ; then
Rich Felker79789982015-10-15 17:21:07 -0400701tryflag CFLAGS_AUTO -Wa,--isa=any
Rich Felkerb1683a12014-02-27 23:18:42 -0500702trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
Bobby Bingham23d64182014-04-27 21:13:59 -0500703if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
Rich Felkerb1683a12014-02-27 23:18:42 -0500704# Some sh configurations are broken and replace double with float
705# rather than using softfloat when the fpu is present but only
706# supports single precision. Reject them.
707printf "checking whether compiler's double type is IEEE double... "
Rich Felker946b9fa2014-02-27 23:55:04 -0500708echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
Rich Felkerb1683a12014-02-27 23:18:42 -0500709if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
710printf "yes\n"
711else
712printf "no\n"
713fail "$0: error: compiler's floating point configuration is unsupported"
714fi
715else
716SUBARCH=${SUBARCH}-nofpu
717fi
Rich Felkerd4c82d02015-09-12 03:22:19 +0000718if trycppif __SH_FDPIC__ "$t" ; then
719SUBARCH=${SUBARCH}-fdpic
Rich Felkerd4c82d02015-09-12 03:22:19 +0000720fi
Rich Felkerb1683a12014-02-27 23:18:42 -0500721fi
Bobby Bingham3a3c8132013-10-05 05:13:18 -0500722
Rich Felker3e7f1862013-07-18 20:30:58 -0400723test "$SUBARCH" \
724&& printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
Rich Felker64d2f8e2012-05-04 23:24:51 -0400725
Rich Felker90d77722013-08-11 03:27:35 -0400726case "$ARCH$SUBARCH" in
727arm) ASMSUBARCH=el ;;
728*) ASMSUBARCH=$SUBARCH ;;
729esac
730
Rich Felker86cc54b2013-08-02 19:34:22 -0400731#
732# Some archs (powerpc) have different possible long double formats
733# that the compiler can be configured for. The logic for whether this
734# is supported is in bits/float.h; in general, it is not. We need to
735# check for mismatches here or code in printf, strotd, and scanf will
736# be dangerously incorrect because it depends on (1) the macros being
737# correct, and (2) IEEE semantics.
738#
739printf "checking whether compiler's long double definition matches float.h... "
740echo '#include <float.h>' > "$tmpc"
Szabolcs Nagy249b6212017-09-17 15:35:55 +0000741echo '#define C(m,s) (m==LDBL_MANT_DIG && s==sizeof(long double))' >> "$tmpc"
742echo 'typedef char ldcheck[(C(53,8)||C(64,12)||C(64,16)||C(113,16))*2-1];' >> "$tmpc"
Rich Felkerefdf04c2016-01-27 19:31:15 -0500743if $CC $CFLAGS_C99FSE \
744 -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \
745 $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
Rich Felker86cc54b2013-08-02 19:34:22 -0400746printf "yes\n"
747else
748printf "no\n"
749fail "$0: error: unsupported long double type"
750fi
751
Rich Felker80fbaac2016-02-17 13:53:54 -0500752#
753# Some build systems globally pass in broken CFLAGS like -ffast-math
754# for all packages. On recent GCC we can detect this and error out
755# early rather than producing a seriously-broken math library.
756#
Rich Felker5030e4a2016-02-18 04:09:33 +0000757if trycppif "__FAST_MATH__" \
Rich Felker80fbaac2016-02-17 13:53:54 -0500758 "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
759fail "$0: error: compiler has broken floating point; check CFLAGS"
760fi
761
Rich Felker64d2f8e2012-05-04 23:24:51 -0400762printf "creating config.mak... "
763
Rich Felker453f4622013-08-16 18:19:47 -0400764cmdline=$(quote "$0")
765for i ; do cmdline="$cmdline $(quote "$i")" ; done
766
Rich Felker64d2f8e2012-05-04 23:24:51 -0400767exec 3>&1 1>config.mak
768
769
770cat << EOF
Rich Felker453f4622013-08-16 18:19:47 -0400771# This version of config.mak was generated by:
772# $cmdline
Rich Felker64d2f8e2012-05-04 23:24:51 -0400773# Any changes made here will be lost if configure is re-run
Fangrui Song4b5ba072019-06-27 08:10:04 +0000774AR = ${AR:-\$(CROSS_COMPILE)ar}
775RANLIB = ${RANLIB:-\$(CROSS_COMPILE)ranlib}
Rich Felker64d2f8e2012-05-04 23:24:51 -0400776ARCH = $ARCH
Rich Felker3e7f1862013-07-18 20:30:58 -0400777SUBARCH = $SUBARCH
Rich Felker90d77722013-08-11 03:27:35 -0400778ASMSUBARCH = $ASMSUBARCH
Petr Hosek2f853dd2015-11-18 12:07:32 -0800779srcdir = $srcdir
Rich Felker64d2f8e2012-05-04 23:24:51 -0400780prefix = $prefix
781exec_prefix = $exec_prefix
782bindir = $bindir
783libdir = $libdir
784includedir = $includedir
785syslibdir = $syslibdir
786CC = $CC
Rich Felker4cd8b472015-11-02 16:58:14 -0500787CFLAGS = $CFLAGS
788CFLAGS_AUTO = $CFLAGS_AUTO
Rich Felker64d2f8e2012-05-04 23:24:51 -0400789CFLAGS_C99FSE = $CFLAGS_C99FSE
Rich Felker4a1f55e2013-08-01 17:12:23 -0400790CFLAGS_MEMOPS = $CFLAGS_MEMOPS
Rich Felker1ef849c2015-04-13 20:13:10 -0400791CFLAGS_NOSSP = $CFLAGS_NOSSP
Rich Felker64d2f8e2012-05-04 23:24:51 -0400792CPPFLAGS = $CPPFLAGS
Rich Felker4cd8b472015-11-02 16:58:14 -0500793LDFLAGS = $LDFLAGS
794LDFLAGS_AUTO = $LDFLAGS_AUTO
Rich Felker94e920d2012-08-14 22:50:16 -0400795CROSS_COMPILE = $CROSS_COMPILE
Rich Felker2c1cd232012-09-10 15:30:52 -0400796LIBCC = $LIBCC
Rich Felkera80847d2013-07-22 21:22:04 -0400797OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
Shizb3cd7d12015-06-28 23:08:19 +0200798ALL_TOOLS = $tools
799TOOL_LIBS = $tool_libs
Alex Dowad35b33122015-07-10 15:03:24 +0200800ADD_CFI = $ADD_CFI
Rich Felkere71188f2020-06-30 15:29:58 -0400801MALLOC_DIR = $malloc_dir
Rich Felker64d2f8e2012-05-04 23:24:51 -0400802EOF
803test "x$static" = xno && echo "STATIC_LIBS ="
804test "x$shared" = xno && echo "SHARED_LIBS ="
Shizb3cd7d12015-06-28 23:08:19 +0200805test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
Shizfb585452015-06-28 23:08:21 +0200806test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)'
Rich Felker16191272016-01-25 19:57:38 -0500807test "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)'
Rich Felker64d2f8e2012-05-04 23:24:51 -0400808exec 1>&3 3>&-
809
Petr Hosek2f853dd2015-11-18 12:07:32 -0800810test "$srcdir" = "." || ln -sf $srcdir/Makefile .
811
Rich Felker64d2f8e2012-05-04 23:24:51 -0400812printf "done\n"