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.
48 echo () { printf "%s\n" "$*" ; }
49 fail
() { echo "$*" ; exit 1 ; }
50 fnmatch
() { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
51 cmdexists
() { type "$1" >/dev
/null
2>&1 ; }
52 trycc
() { test -z "$CC" && cmdexists
"$1" && CC
=$1 ; }
55 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
59 printf "checking preprocessor condition %s... " "$1"
60 echo "typedef int x;" > "$tmpc"
61 echo "#if $1" >> "$tmpc"
62 echo "#error yes" >> "$tmpc"
63 echo "#endif" >> "$tmpc"
64 if $CC $2 -c -o /dev
/null
"$tmpc" >/dev
/null
2>&1 ; then
74 printf "checking whether compiler accepts %s... " "$2"
75 echo "typedef int x;" > "$tmpc"
76 if $CC "$2" -c -o /dev
/null
"$tmpc" >/dev
/null
2>&1 ; then
78 eval "$1=\"\${$1} \$2\""
88 printf "checking whether linker accepts %s... " "$2"
89 echo "typedef int x;" > "$tmpc"
90 if $CC -nostdlib -shared "$2" -o /dev
/null
"$tmpc" >/dev
/null
2>&1 ; then
92 eval "$1=\"\${$1} \$2\""
103 # Beginning of actual script
110 prefix
=/usr
/local
/musl
111 exec_prefix
='$(prefix)'
112 bindir
='$(exec_prefix)/bin'
113 libdir
='$(prefix)/lib'
114 includedir
='$(prefix)/include'
126 --prefix=*) prefix
=${arg#*=} ;;
127 --exec-prefix=*) exec_prefix
=${arg#*=} ;;
128 --bindir=*) bindir
=${arg#*=} ;;
129 --libdir=*) libdir
=${arg#*=} ;;
130 --includedir=*) includedir
=${arg#*=} ;;
131 --syslibdir=*) syslibdir
=${arg#*=} ;;
132 --enable-shared|
--enable-shared=yes) shared
=yes ;;
133 --disable-shared|
--enable-shared=no
) shared
=no
;;
134 --enable-static|
--enable-static=yes) static
=yes ;;
135 --disable-static|
--enable-static=no
) static
=no
;;
136 --enable-optimize) optimize
=yes ;;
137 --enable-optimize=*) optimize
=${arg#*=} ;;
138 --disable-optimize) optimize
=no
;;
139 --enable-debug|
--enable-debug=yes) debug
=yes ;;
140 --disable-debug|
--enable-debug=no
) debug
=no
;;
141 --enable-warnings|
--enable-warnings=yes) warnings
=yes ;;
142 --disable-warnings|
--enable-warnings=no
) warnings
=no
;;
143 --enable-gcc-wrapper|
--enable-gcc-wrapper=yes) wrapper
=yes ;;
144 --disable-gcc-wrapper|
--enable-gcc-wrapper=no
) wrapper
=no
;;
145 --enable-*|
--disable-*|
--with-*|
--without-*|
--*dir
=*|
--build=*) ;;
146 --host=*|
--target=*) target
=${arg#*=} ;;
147 -* ) echo "$0: unknown option $arg" ;;
148 CC
=*) CC
=${arg#*=} ;;
149 CFLAGS
=*) CFLAGS
=${arg#*=} ;;
150 CPPFLAGS
=*) CPPFLAGS
=${arg#*=} ;;
151 LDFLAGS
=*) LDFLAGS
=${arg#*=} ;;
152 CROSS_COMPILE
=*) CROSS_COMPILE
=${arg#*=} ;;
153 LIBCC
=*) LIBCC
=${arg#*=} ;;
159 for i
in prefix exec_prefix bindir libdir includedir syslibdir
; do
164 # Get a temp filename we can use
168 while : ; do i
=$
(($i+1))
169 tmpc
="./conf$$-$PPID-$i.c"
170 2>|
/dev
/null
> "$tmpc" && break
171 test "$i" -gt 50 && fail
"$0: cannot create temporary file $tmpc"
174 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
177 # Find a C compiler to use
179 printf "checking for C compiler... "
180 trycc
${CROSS_COMPILE}gcc
181 trycc
${CROSS_COMPILE}c99
182 trycc
${CROSS_COMPILE}cc
184 test -n "$CC" ||
{ echo "$0: cannot find a C compiler" ; exit 1 ; }
187 # Only build musl-gcc wrapper if toolchain does not already target musl
189 if test -z "$wrapper" ; then
190 printf "checking whether compiler is gcc... "
191 if fnmatch
'*gcc\ version*' "$($CC -v 2>&1)" ; then
193 printf "checking whether to build musl-gcc wrapper... "
196 case "$line" in */ld-musl-
*) wrapper
=no
;; esac
209 # Find the target architecture
211 printf "checking target system type... "
212 test -n "$target" || target
=$
($CC -dumpmachine 2>/dev
/null
) || target
=unknown
213 printf "%s\n" "$target"
216 # Convert to just ARCH
221 x86_64
*) ARCH
=x86_64
;;
222 mips-
*|mipsel-
*) ARCH
=mips
;;
223 microblaze-
*) ARCH
=microblaze
;;
224 powerpc-
*) ARCH
=powerpc
;;
225 unknown
) fail
"$0: unable to detect target arch; try $0 --target=..." ;;
226 *) fail
"$0: unknown or unsupported target \"$target\"" ;;
230 # Try to get a conforming C99 freestanding environment
232 tryflag CFLAGS_C99FSE
-std=c99
233 tryflag CFLAGS_C99FSE
-nostdinc
234 tryflag CFLAGS_C99FSE
-ffreestanding \
235 || tryflag CFLAGS_C99FSE
-fno-builtin
236 tryflag CFLAGS_C99FSE
-fexcess-precision=standard \
237 ||
{ test "$ARCH" = i386
&& tryflag CFLAGS_C99FSE
-ffloat-store ; }
238 tryflag CFLAGS_C99FSE
-frounding-math
241 # Check for options that may be needed to prevent the compiler from
242 # generating self-referential versions of memcpy,, memmove, memcmp,
243 # and memset. Really, we should add a check to determine if this
244 # option is sufficient, and if not, add a macro to cripple these
245 # functions with volatile...
247 tryflag CFLAGS_MEMOPS
-fno-tree-loop-distribute-patterns
250 # If debugging is explicitly enabled, don't auto-enable optimizations
252 if test "$debug" = yes ; then
254 test "$optimize" = auto
&& optimize
=no
258 # Possibly add a -O option to CFLAGS and select modules to optimize with
259 # -O3 based on the status of --enable-optimize and provided CFLAGS.
261 printf "checking for optimization settings... "
264 if fnmatch
'-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then
265 printf "using provided CFLAGS\n" ;optimize
=no
267 printf "using defaults\n" ; optimize
=yes
270 xsize|xnone
) printf "minimize size\n" ; optimize
=size
;;
271 xno|x
) printf "disabled\n" ; optimize
=no
;;
272 *) printf "custom\n" ;;
275 test "$optimize" = no || tryflag CFLAGS_AUTO
-Os || tryflag CFLAGS_AUTO
-O2
276 test "$optimize" = yes && optimize
="internal,malloc,string"
278 if fnmatch
'no|size' "$optimize" ; then :
280 printf "components to be optimized for speed:"
281 while test "$optimize" ; do
283 *,*) this
=${optimize%%,*} optimize
=${optimize#*,} ;;
284 *) this
=$optimize optimize
=
289 */*) this
=$this*.c
;;
292 OPTIMIZE_GLOBS
="$OPTIMIZE_GLOBS $this"
294 OPTIMIZE_GLOBS
=${OPTIMIZE_GLOBS# }
299 tryflag CFLAGS_AUTO
-pipe
302 # If debugging is disabled, omit frame pointer. Modern GCC does this
303 # anyway on most archs even when debugging is enabled since the frame
304 # pointer is no longer needed for debugging.
306 if fnmatch
'-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
308 tryflag CFLAGS_AUTO
-fomit-frame-pointer
312 # Modern GCC wants to put DWARF tables (used for debugging and
313 # unwinding) in the loaded part of the program where they are
314 # unstrippable. These options force them back to debug sections (and
315 # cause them not to get generated at all if debugging is off).
317 tryflag CFLAGS_AUTO
-fno-unwind-tables
318 tryflag CFLAGS_AUTO
-fno-asynchronous-unwind-tables
321 # The GNU toolchain defaults to assuming unmarked files need an
322 # executable stack, potentially exposing vulnerabilities in programs
323 # linked with such object files. Fix this.
325 tryflag CFLAGS_AUTO
-Wa,--noexecstack
328 # On x86, make sure we don't have incompatible instruction set
329 # extensions enabled by default. This is bad for making static binaries.
330 # We cheat and use i486 rather than i386 because i386 really does not
331 # work anyway (issues with atomic ops).
333 if test "$ARCH" = "i386" ; then
334 fnmatch
'-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO
-march=i486
335 fnmatch
'-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO
-mtune=generic
339 # Even with -std=c99, gcc accepts some constructs which are constraint
340 # violations. We want to treat these as errors regardless of whether
341 # other purely stylistic warnings are enabled -- especially implicit
342 # function declarations, which are a dangerous programming error.
344 tryflag CFLAGS_AUTO
-Werror=implicit-function-declaration
345 tryflag CFLAGS_AUTO
-Werror=implicit-int
346 tryflag CFLAGS_AUTO
-Werror=pointer-sign
347 tryflag CFLAGS_AUTO
-Werror=pointer-arith
349 if test "x$warnings" = xyes
; then
350 tryflag CFLAGS_AUTO
-Wall
351 tryflag CFLAGS_AUTO
-Wcast-align
352 tryflag CFLAGS_AUTO
-Wno-parentheses
353 tryflag CFLAGS_AUTO
-Wno-uninitialized
354 tryflag CFLAGS_AUTO
-Wno-missing-braces
355 tryflag CFLAGS_AUTO
-Wno-unused-value
356 tryflag CFLAGS_AUTO
-Wno-unused-but-set-variable
357 tryflag CFLAGS_AUTO
-Wno-unknown-pragmas
360 # Some patched GCC builds have these defaults messed up...
361 tryflag CFLAGS_AUTO
-fno-stack-protector
362 tryldflag LDFLAGS_AUTO
-Wl,--hash-style=both
364 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
366 tryldflag LDFLAGS_DUMMY
-Wl,-Bsymbolic-functions ||
{
367 printf "warning: disabling dynamic linking support\n"
371 # Find compiler runtime library
372 test -z "$LIBCC" && tryldflag LIBCC
-lgcc && tryldflag LIBCC
-lgcc_eh
373 test -z "$LIBCC" && tryldflag LIBCC
-lcompiler_rt
374 test -z "$LIBCC" && try_libcc
=`$CC -print-file-name=libpcc.a 2>/dev/null` \
375 && tryldflag LIBCC
"$try_libcc"
376 printf "using compiler runtime libraries: %s\n" "$LIBCC"
378 # Figure out arch variants for archs with variants
380 t
="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS"
382 if test "$ARCH" = "arm" ; then
383 trycppif __ARMEB__
"$t" && SUBARCH
=${SUBARCH}eb
384 trycppif __SOFTFP__
"$t" || SUBARCH
=${SUBARCH}hf
387 test "$ARCH" = "mips" && trycppif
"_MIPSEL || __MIPSEL || __MIPSEL__" "$t" \
388 && SUBARCH
=${SUBARCH}el
390 test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__
"$t" \
391 && SUBARCH
=${SUBARCH}el
394 && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
397 # Some archs (powerpc) have different possible long double formats
398 # that the compiler can be configured for. The logic for whether this
399 # is supported is in bits/float.h; in general, it is not. We need to
400 # check for mismatches here or code in printf, strotd, and scanf will
401 # be dangerously incorrect because it depends on (1) the macros being
402 # correct, and (2) IEEE semantics.
404 printf "checking whether compiler's long double definition matches float.h... "
405 echo '#include <float.h>' > "$tmpc"
406 echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
407 echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
408 echo '#endif' >> "$tmpc"
409 if $CC $CFLAGS_C99FSE -I.
/arch
/$ARCH -I.
/include
$CPPFLAGS $CFLAGS \
410 -c -o /dev
/null
"$tmpc" >/dev
/null
2>&1 ; then
414 fail
"$0: error: unsupported long double type"
417 printf "creating config.mak... "
419 exec 3>&1 1>config.mak
423 # This version of config.mak was generated by configure
424 # Any changes made here will be lost if configure is re-run
428 exec_prefix = $exec_prefix
431 includedir = $includedir
432 syslibdir = $syslibdir
434 CFLAGS= $CFLAGS_AUTO $CFLAGS
435 CFLAGS_C99FSE = $CFLAGS_C99FSE
436 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
438 LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
439 CROSS_COMPILE = $CROSS_COMPILE
441 OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
443 test "x$static" = xno
&& echo "STATIC_LIBS ="
444 test "x$shared" = xno
&& echo "SHARED_LIBS ="
445 test "x$wrapper" = xno
&& echo "ALL_TOOLS ="
446 test "x$wrapper" = xno
&& echo "TOOL_LIBS ="