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