5 Usage: $0 [OPTION]... [VAR=VALUE]... [TARGET]
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.
10 Defaults for the options are specified in brackets.
12 Installation directories:
13 --prefix=PREFIX main installation prefix [/usr/local/musl]
14 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
16 Fine 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]
23 --target=TARGET configure to run on target TARGET [detected]
24 --host=HOST same as --target
27 --enable-optimize=... optimize listed components for speed over size [auto]
28 --enable-debug build with debugging information [disabled]
29 --enable-warnings build with recommended warnings flags [disabled]
30 --enable-visibility use global visibility options to optimize PIC [auto]
31 --enable-wrapper=... build given musl toolchain wrapper [auto]
32 --disable-shared inhibit building shared library [enabled]
33 --disable-static inhibit building static library [enabled]
35 Some influential environment variables:
36 CC C compiler command [detected]
37 CFLAGS C compiler flags [-Os -pipe ...]
38 CROSS_COMPILE prefix for cross compiler and tools [none]
39 LIBCC compiler runtime library [detected]
41 Use these variables to override the choices made by configure.
50 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
53 printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
55 echo () { printf "%s\n" "$*" ; }
56 fail () { echo "$*" ; exit 1 ; }
57 fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
58 cmdexists () { type "$1" >/dev/null 2>&1 ; }
59 trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
62 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
66 printf "checking preprocessor condition %s... " "$1"
67 echo "typedef int x;" > "$tmpc"
68 echo "#if $1" >> "$tmpc"
69 echo "#error yes" >> "$tmpc"
70 echo "#endif" >> "$tmpc"
71 if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
81 printf "checking whether compiler accepts %s... " "$2"
82 echo "typedef int x;" > "$tmpc"
83 if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
85 eval "$1=\"\${$1} \$2\""
95 printf "checking whether linker accepts %s... " "$2"
96 echo "typedef int x;" > "$tmpc"
97 if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
99 eval "$1=\"\${$1} \$2\""
110 # Beginning of actual script
120 prefix=/usr/local/musl
121 exec_prefix='$(prefix)'
122 bindir='$(exec_prefix)/bin'
123 libdir='$(prefix)/lib'
124 includedir='$(prefix)/include'
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 ;;
151 --enable-optimize) optimize=yes ;;
152 --enable-optimize=*) optimize=${arg#*=} ;;
153 --disable-optimize) optimize=no ;;
154 --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 ;;
158 --enable-visibility|--enable-visibility=yes) visibility=yes ;;
159 --disable-visibility|--enable-visibility=no) visibility=no ;;
160 --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 ;;
165 --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
166 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
167 --host=*|--target=*) target=${arg#*=} ;;
168 -* ) echo "$0: unknown option $arg" ;;
169 CC=*) CC=${arg#*=} ;;
170 CFLAGS=*) CFLAGS=${arg#*=} ;;
171 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
172 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
173 CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
174 LIBCC=*) LIBCC=${arg#*=} ;;
180 for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
185 # Get a temp filename we can use
189 while : ; do i=$(($i+1))
190 tmpc="./conf$$-$PPID-$i.c"
191 2>|/dev/null > "$tmpc" && break
192 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
195 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
198 # Find a C compiler to use
200 printf "checking for C compiler... "
201 trycc ${CROSS_COMPILE}gcc
202 trycc ${CROSS_COMPILE}c99
203 trycc ${CROSS_COMPILE}cc
205 test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
207 printf "checking whether C compiler works... "
208 echo "typedef int x;" > "$tmpc"
209 if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then
212 printf "no; compiler output follows:\n%s\n" "$output"
217 # Figure out options to force errors on unknown flags.
219 tryflag CFLAGS_TRY -Werror=unknown-warning-option
220 tryflag CFLAGS_TRY -Werror=unused-command-line-argument
221 tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
222 tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
225 # Need to know if the compiler is gcc or clang to decide which toolchain
228 printf "checking for C compiler family... "
229 cc_ver="$(LC_ALL=C $CC -v 2>&1)"
231 if fnmatch '*gcc\ version*' "$cc_ver" ; then
237 # Figure out toolchain wrapper to build
239 if test "$wrapper" = auto -o "$wrapper" = detect ; then
240 printf "checking for toolchain wrapper to build... "
241 if test "$cc_family" = gcc ; then
243 if test "$wrapper" = auto ; then
245 case "$line" in */ld-musl-*) gcc_wrapper=no ;; esac
250 test "$gcc_wrapper" = yes && echo "gcc"
253 if test "$wrapper" = detect ; then
254 fail "$0: could not find an appropriate toolchain wrapper"
259 if test "$gcc_wrapper" = yes ; then
260 tools="$tools tools/musl-gcc"
261 tool_libs="$tool_libs lib/musl-gcc.specs"
265 # Find the target architecture
267 printf "checking target system type... "
268 test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
269 printf "%s\n" "$target"
272 # Convert to just ARCH
275 # Catch these early to simplify matching for 32-bit archs
276 mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
278 aarch64*) ARCH=aarch64 ;;
280 x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
281 x86_64*) ARCH=x86_64 ;;
283 microblaze*) ARCH=microblaze ;;
285 powerpc*) ARCH=powerpc ;;
286 sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
287 unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
288 *) fail "$0: unknown or unsupported target \"$target\"" ;;
292 # Try to get a conforming C99 freestanding environment
294 tryflag CFLAGS_C99FSE -std=c99
295 tryflag CFLAGS_C99FSE -nostdinc
296 tryflag CFLAGS_C99FSE -ffreestanding \
297 || tryflag CFLAGS_C99FSE -fno-builtin
298 tryflag CFLAGS_C99FSE -fexcess-precision=standard \
299 || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
300 tryflag CFLAGS_C99FSE -frounding-math
303 # We may use the may_alias attribute if __GNUC__ is defined, so
304 # if the compiler defines __GNUC__ but does not provide it,
305 # it must be defined away as part of the CFLAGS.
307 printf "checking whether compiler needs attribute((may_alias)) suppression... "
311 __attribute__((__may_alias__))
315 if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
316 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
320 CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
324 # Check for options to disable stack protector, which needs to be
325 # disabled for a few early-bootstrap translation units. If not found,
326 # this is not an error; we assume the toolchain does not do ssp.
328 tryflag CFLAGS_NOSSP -fno-stack-protector
331 # Check for options that may be needed to prevent the compiler from
332 # generating self-referential versions of memcpy,, memmove, memcmp,
333 # and memset. Really, we should add a check to determine if this
334 # option is sufficient, and if not, add a macro to cripple these
335 # functions with volatile...
337 tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
340 # Enable debugging if requessted.
342 test "$debug" = yes && CFLAGS_AUTO=-g
345 # Possibly add a -O option to CFLAGS and select modules to optimize with
346 # -O3 based on the status of --enable-optimize and provided CFLAGS.
348 printf "checking for optimization settings... "
351 if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
352 printf "using provided CFLAGS\n" ;optimize=no
354 printf "using defaults\n" ; optimize=yes
357 xsize|xnone) printf "minimize size\n" ; optimize=size ;;
358 xno|x) printf "disabled\n" ; optimize=no ;;
359 *) printf "custom\n" ;;
362 test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
363 test "$optimize" = yes && optimize="internal,malloc,string"
365 if fnmatch 'no|size' "$optimize" ; then :
367 printf "components to be optimized for speed:"
368 while test "$optimize" ; do
370 *,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
371 *) this=$optimize optimize=
376 */*) this=$this*.c ;;
379 OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
381 OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
386 tryflag CFLAGS_AUTO -pipe
389 # If debugging is disabled, omit frame pointer. Modern GCC does this
390 # anyway on most archs even when debugging is enabled since the frame
391 # pointer is no longer needed for debugging.
393 if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
395 tryflag CFLAGS_AUTO -fomit-frame-pointer
399 # Modern GCC wants to put DWARF tables (used for debugging and
400 # unwinding) in the loaded part of the program where they are
401 # unstrippable. These options force them back to debug sections (and
402 # cause them not to get generated at all if debugging is off).
404 tryflag CFLAGS_AUTO -fno-unwind-tables
405 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
408 # The GNU toolchain defaults to assuming unmarked files need an
409 # executable stack, potentially exposing vulnerabilities in programs
410 # linked with such object files. Fix this.
412 tryflag CFLAGS_AUTO -Wa,--noexecstack
415 # On x86, make sure we don't have incompatible instruction set
416 # extensions enabled by default. This is bad for making static binaries.
417 # We cheat and use i486 rather than i386 because i386 really does not
418 # work anyway (issues with atomic ops).
419 # Some build environments pass -march and -mtune options via CC, so
420 # check both CC and CFLAGS.
422 if test "$ARCH" = "i386" ; then
423 fnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
424 fnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
428 # Even with -std=c99, gcc accepts some constructs which are constraint
429 # violations. We want to treat these as errors regardless of whether
430 # other purely stylistic warnings are enabled -- especially implicit
431 # function declarations, which are a dangerous programming error.
433 tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
434 tryflag CFLAGS_AUTO -Werror=implicit-int
435 tryflag CFLAGS_AUTO -Werror=pointer-sign
436 tryflag CFLAGS_AUTO -Werror=pointer-arith
438 if test "x$warnings" = xyes ; then
439 tryflag CFLAGS_AUTO -Wall
440 tryflag CFLAGS_AUTO -Wno-parentheses
441 tryflag CFLAGS_AUTO -Wno-uninitialized
442 tryflag CFLAGS_AUTO -Wno-missing-braces
443 tryflag CFLAGS_AUTO -Wno-unused-value
444 tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
445 tryflag CFLAGS_AUTO -Wno-unknown-pragmas
446 tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
449 if test "x$visibility" = xauto ; then
450 # This test checks toolchain support for several things:
451 # - the -include option
452 # - the attributes/pragmas used in vis.h
453 # - linking code that takes the address of protected symbols
454 printf "checking whether global visibility preinclude works... "
455 echo 'int (*fp)(void);' > "$tmpc"
456 echo 'int foo(void) { }' >> "$tmpc"
457 echo 'int bar(void) { fp = foo; return foo(); }' >> "$tmpc"
458 if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
459 -DSHARED -fPIC -I./src/internal -include vis.h \
460 -nostdlib -shared -Wl,-Bsymbolic-functions \
461 -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
466 printf "%s\n" "$visibility"
469 if test "x$visibility" = xyes ; then
470 CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h"
471 CFLAGS_AUTO="${CFLAGS_AUTO# }"
474 # Some patched GCC builds have these defaults messed up...
475 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
477 test "$shared" = "no" || {
478 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
480 tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
481 test "$shared" = "yes" && fail "$0: error: linker cannot build shared library"
482 printf "warning: disabling dynamic linking support\n"
487 # Find compiler runtime library
488 test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
489 test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
490 test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
491 && tryldflag LIBCC "$try_libcc"
492 printf "using compiler runtime libraries: %s\n" "$LIBCC"
494 # Figure out arch variants for archs with variants
496 t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS"
498 if test "$ARCH" = "x86_64" ; then
499 trycppif __ILP32__ "$t" && ARCH=x32
502 if test "$ARCH" = "arm" ; then
503 trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
504 trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
507 if test "$ARCH" = "aarch64" ; then
508 trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be
511 if test "$ARCH" = "mips" ; then
512 trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
513 trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
516 test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
517 && SUBARCH=${SUBARCH}el
519 if test "$ARCH" = "sh" ; then
520 trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
521 if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then
522 # Some sh configurations are broken and replace double with float
523 # rather than using softfloat when the fpu is present but only
524 # supports single precision. Reject them.
525 printf "checking whether compiler's double type is IEEE double... "
526 echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
527 if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
531 fail "$0: error: compiler's floating point configuration is unsupported"
534 SUBARCH=${SUBARCH}-nofpu
539 && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
541 case "$ARCH$SUBARCH" in
542 arm) ASMSUBARCH=el ;;
543 *) ASMSUBARCH=$SUBARCH ;;
547 # Some archs (powerpc) have different possible long double formats
548 # that the compiler can be configured for. The logic for whether this
549 # is supported is in bits/float.h; in general, it is not. We need to
550 # check for mismatches here or code in printf, strotd, and scanf will
551 # be dangerously incorrect because it depends on (1) the macros being
552 # correct, and (2) IEEE semantics.
554 printf "checking whether compiler's long double definition matches float.h... "
555 echo '#include <float.h>' > "$tmpc"
556 echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
557 echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
558 echo '#endif' >> "$tmpc"
559 if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
560 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
564 fail "$0: error: unsupported long double type"
567 printf "creating config.mak... "
569 cmdline=$(quote "$0")
570 for i ; do cmdline="$cmdline $(quote "$i")" ; done
572 exec 3>&1 1>config.mak
576 # This version of config.mak was generated by:
578 # Any changes made here will be lost if configure is re-run
581 ASMSUBARCH = $ASMSUBARCH
583 exec_prefix = $exec_prefix
586 includedir = $includedir
587 syslibdir = $syslibdir
589 CFLAGS = $CFLAGS_AUTO $CFLAGS
590 CFLAGS_C99FSE = $CFLAGS_C99FSE
591 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
592 CFLAGS_NOSSP = $CFLAGS_NOSSP
594 LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
595 CROSS_COMPILE = $CROSS_COMPILE
597 OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
599 TOOL_LIBS = $tool_libs
601 test "x$static" = xno && echo "STATIC_LIBS ="
602 test "x$shared" = xno && echo "SHARED_LIBS ="
603 test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'