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-gcc-wrapper build musl-gcc toolchain wrapper [auto]
31 --disable-shared inhibit building shared library [enabled]
32 --disable-static inhibit building static library [enabled]
34 Some influential environment variables:
35 CC C compiler command [detected]
36 CFLAGS C compiler flags [-Os -pipe ...]
37 CROSS_COMPILE prefix for cross compiler and tools [none]
38 LIBCC compiler runtime library [detected]
40 Use these variables to override the choices made by configure.
49 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
52 printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
54 echo () { printf "%s\n" "$*" ; }
55 fail () { echo "$*" ; exit 1 ; }
56 fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
57 cmdexists () { type "$1" >/dev/null 2>&1 ; }
58 trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
61 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
65 printf "checking preprocessor condition %s... " "$1"
66 echo "typedef int x;" > "$tmpc"
67 echo "#if $1" >> "$tmpc"
68 echo "#error yes" >> "$tmpc"
69 echo "#endif" >> "$tmpc"
70 if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
80 printf "checking whether compiler accepts %s... " "$2"
81 echo "typedef int x;" > "$tmpc"
82 if $CC "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
84 eval "$1=\"\${$1} \$2\""
94 printf "checking whether linker accepts %s... " "$2"
95 echo "typedef int x;" > "$tmpc"
96 if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
98 eval "$1=\"\${$1} \$2\""
109 # Beginning of actual script
116 prefix=/usr/local/musl
117 exec_prefix='$(prefix)'
118 bindir='$(exec_prefix)/bin'
119 libdir='$(prefix)/lib'
120 includedir='$(prefix)/include'
132 --prefix=*) prefix=${arg#*=} ;;
133 --exec-prefix=*) exec_prefix=${arg#*=} ;;
134 --bindir=*) bindir=${arg#*=} ;;
135 --libdir=*) libdir=${arg#*=} ;;
136 --includedir=*) includedir=${arg#*=} ;;
137 --syslibdir=*) syslibdir=${arg#*=} ;;
138 --enable-shared|--enable-shared=yes) shared=yes ;;
139 --disable-shared|--enable-shared=no) shared=no ;;
140 --enable-static|--enable-static=yes) static=yes ;;
141 --disable-static|--enable-static=no) static=no ;;
142 --enable-optimize) optimize=yes ;;
143 --enable-optimize=*) optimize=${arg#*=} ;;
144 --disable-optimize) optimize=no ;;
145 --enable-debug|--enable-debug=yes) debug=yes ;;
146 --disable-debug|--enable-debug=no) debug=no ;;
147 --enable-warnings|--enable-warnings=yes) warnings=yes ;;
148 --disable-warnings|--enable-warnings=no) warnings=no ;;
149 --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
150 --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
151 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
152 --host=*|--target=*) target=${arg#*=} ;;
153 -* ) echo "$0: unknown option $arg" ;;
154 CC=*) CC=${arg#*=} ;;
155 CFLAGS=*) CFLAGS=${arg#*=} ;;
156 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
157 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
158 CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
159 LIBCC=*) LIBCC=${arg#*=} ;;
165 for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
170 # Get a temp filename we can use
174 while : ; do i=$(($i+1))
175 tmpc="./conf$$-$PPID-$i.c"
176 2>|/dev/null > "$tmpc" && break
177 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
180 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
183 # Find a C compiler to use
185 printf "checking for C compiler... "
186 trycc ${CROSS_COMPILE}gcc
187 trycc ${CROSS_COMPILE}c99
188 trycc ${CROSS_COMPILE}cc
190 test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
193 # Only build musl-gcc wrapper if toolchain does not already target musl
195 if test -z "$wrapper" ; then
196 printf "checking whether compiler is gcc... "
197 if fnmatch '*gcc\ version*' "$($CC -v 2>&1)" ; then
199 printf "checking whether to build musl-gcc wrapper... "
202 case "$line" in */ld-musl-*) wrapper=no ;; esac
215 # Find the target architecture
217 printf "checking target system type... "
218 test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
219 printf "%s\n" "$target"
222 # Convert to just ARCH
225 # Catch these early to simplify matching for 32-bit archs
226 mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
229 x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;;
230 x86_64*) ARCH=x86_64 ;;
232 microblaze*) ARCH=microblaze ;;
233 powerpc*) ARCH=powerpc ;;
234 sh[1-9bel-]*|sh|superh*) ARCH=sh ;;
235 unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
236 *) fail "$0: unknown or unsupported target \"$target\"" ;;
240 # Try to get a conforming C99 freestanding environment
242 tryflag CFLAGS_C99FSE -std=c99
243 tryflag CFLAGS_C99FSE -nostdinc
244 tryflag CFLAGS_C99FSE -ffreestanding \
245 || tryflag CFLAGS_C99FSE -fno-builtin
246 tryflag CFLAGS_C99FSE -fexcess-precision=standard \
247 || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
248 tryflag CFLAGS_C99FSE -frounding-math
251 # We may use the may_alias attribute if __GNUC__ is defined, so
252 # if the compiler defines __GNUC__ but does not provide it,
253 # it must be defined away as part of the CFLAGS.
255 printf "checking whether compiler needs attribute((may_alias)) suppression... "
259 __attribute__((__may_alias__))
263 if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
264 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
268 CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__="
272 # Check for options that may be needed to prevent the compiler from
273 # generating self-referential versions of memcpy,, memmove, memcmp,
274 # and memset. Really, we should add a check to determine if this
275 # option is sufficient, and if not, add a macro to cripple these
276 # functions with volatile...
278 tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns
281 # If debugging is explicitly enabled, don't auto-enable optimizations
283 if test "$debug" = yes ; then
285 test "$optimize" = auto && optimize=no
289 # Possibly add a -O option to CFLAGS and select modules to optimize with
290 # -O3 based on the status of --enable-optimize and provided CFLAGS.
292 printf "checking for optimization settings... "
295 if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
296 printf "using provided CFLAGS\n" ;optimize=no
298 printf "using defaults\n" ; optimize=yes
301 xsize|xnone) printf "minimize size\n" ; optimize=size ;;
302 xno|x) printf "disabled\n" ; optimize=no ;;
303 *) printf "custom\n" ;;
306 test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
307 test "$optimize" = yes && optimize="internal,malloc,string"
309 if fnmatch 'no|size' "$optimize" ; then :
311 printf "components to be optimized for speed:"
312 while test "$optimize" ; do
314 *,*) this=${optimize%%,*} optimize=${optimize#*,} ;;
315 *) this=$optimize optimize=
320 */*) this=$this*.c ;;
323 OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this"
325 OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# }
330 tryflag CFLAGS_AUTO -pipe
333 # If debugging is disabled, omit frame pointer. Modern GCC does this
334 # anyway on most archs even when debugging is enabled since the frame
335 # pointer is no longer needed for debugging.
337 if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
339 tryflag CFLAGS_AUTO -fomit-frame-pointer
343 # Modern GCC wants to put DWARF tables (used for debugging and
344 # unwinding) in the loaded part of the program where they are
345 # unstrippable. These options force them back to debug sections (and
346 # cause them not to get generated at all if debugging is off).
348 tryflag CFLAGS_AUTO -fno-unwind-tables
349 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
352 # The GNU toolchain defaults to assuming unmarked files need an
353 # executable stack, potentially exposing vulnerabilities in programs
354 # linked with such object files. Fix this.
356 tryflag CFLAGS_AUTO -Wa,--noexecstack
359 # On x86, make sure we don't have incompatible instruction set
360 # extensions enabled by default. This is bad for making static binaries.
361 # We cheat and use i486 rather than i386 because i386 really does not
362 # work anyway (issues with atomic ops).
364 if test "$ARCH" = "i386" ; then
365 fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
366 fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
370 # Even with -std=c99, gcc accepts some constructs which are constraint
371 # violations. We want to treat these as errors regardless of whether
372 # other purely stylistic warnings are enabled -- especially implicit
373 # function declarations, which are a dangerous programming error.
375 tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
376 tryflag CFLAGS_AUTO -Werror=implicit-int
377 tryflag CFLAGS_AUTO -Werror=pointer-sign
378 tryflag CFLAGS_AUTO -Werror=pointer-arith
380 if test "x$warnings" = xyes ; then
381 tryflag CFLAGS_AUTO -Wall
382 tryflag CFLAGS_AUTO -Wno-parentheses
383 tryflag CFLAGS_AUTO -Wno-uninitialized
384 tryflag CFLAGS_AUTO -Wno-missing-braces
385 tryflag CFLAGS_AUTO -Wno-unused-value
386 tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
387 tryflag CFLAGS_AUTO -Wno-unknown-pragmas
388 tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast
391 # Some patched GCC builds have these defaults messed up...
392 tryflag CFLAGS_AUTO -fno-stack-protector
393 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
395 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
397 tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
398 printf "warning: disabling dynamic linking support\n"
402 # Find compiler runtime library
403 test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
404 test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
405 test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
406 && tryldflag LIBCC "$try_libcc"
407 printf "using compiler runtime libraries: %s\n" "$LIBCC"
409 # Figure out arch variants for archs with variants
411 t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS"
413 if test "$ARCH" = "x86_64" ; then
414 trycppif __ILP32__ "$t" && ARCH=x32
417 if test "$ARCH" = "arm" ; then
418 trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
419 trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf
422 if test "$ARCH" = "mips" ; then
423 trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el
424 trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
427 test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
428 && SUBARCH=${SUBARCH}el
430 if test "$ARCH" = "sh" ; then
431 trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb
432 if trycppif __SH_FPU_ANY__ "$t" ; then
433 # Some sh configurations are broken and replace double with float
434 # rather than using softfloat when the fpu is present but only
435 # supports single precision. Reject them.
436 printf "checking whether compiler's double type is IEEE double... "
437 echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc"
438 if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
442 fail "$0: error: compiler's floating point configuration is unsupported"
445 SUBARCH=${SUBARCH}-nofpu
450 && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
452 case "$ARCH$SUBARCH" in
453 arm) ASMSUBARCH=el ;;
454 *) ASMSUBARCH=$SUBARCH ;;
458 # Some archs (powerpc) have different possible long double formats
459 # that the compiler can be configured for. The logic for whether this
460 # is supported is in bits/float.h; in general, it is not. We need to
461 # check for mismatches here or code in printf, strotd, and scanf will
462 # be dangerously incorrect because it depends on (1) the macros being
463 # correct, and (2) IEEE semantics.
465 printf "checking whether compiler's long double definition matches float.h... "
466 echo '#include <float.h>' > "$tmpc"
467 echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
468 echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
469 echo '#endif' >> "$tmpc"
470 if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
471 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
475 fail "$0: error: unsupported long double type"
478 printf "creating config.mak... "
480 cmdline=$(quote "$0")
481 for i ; do cmdline="$cmdline $(quote "$i")" ; done
483 exec 3>&1 1>config.mak
487 # This version of config.mak was generated by:
489 # Any changes made here will be lost if configure is re-run
492 ASMSUBARCH = $ASMSUBARCH
494 exec_prefix = $exec_prefix
497 includedir = $includedir
498 syslibdir = $syslibdir
500 CFLAGS= $CFLAGS_AUTO $CFLAGS
501 CFLAGS_C99FSE = $CFLAGS_C99FSE
502 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
504 LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
505 CROSS_COMPILE = $CROSS_COMPILE
507 OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
509 test "x$static" = xno && echo "STATIC_LIBS ="
510 test "x$shared" = xno && echo "SHARED_LIBS ="
511 test "x$wrapper" = xno && echo "ALL_TOOLS ="
512 test "x$wrapper" = xno && echo "TOOL_LIBS ="