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-debug build with debugging information [disabled]
28 --enable-warnings build with recommended warnings flags [disabled]
29 --enable-gcc-wrapper build musl-gcc toolchain wrapper [auto]
30 --disable-shared inhibit building shared library [enabled]
31 --disable-static inhibit building static library [enabled]
33 Some influential environment variables:
34 CC C compiler command [detected]
35 CFLAGS C compiler flags [-Os -pipe ...]
36 CROSS_COMPILE prefix for cross compiler and tools [none]
37 LIBCC compiler runtime library [detected]
39 Use these variables to override the choices made by configure.
47 echo () { printf "%s\n" "$*" ; }
48 fail () { echo "$*" ; exit 1 ; }
49 fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
50 cmdexists () { type "$1" >/dev/null 2>&1 ; }
51 trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
54 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
58 printf "checking preprocessor condition %s... " "$1"
59 echo "typedef int x;" > "$tmpc"
60 echo "#if $1" >> "$tmpc"
61 echo "#error yes" >> "$tmpc"
62 echo "#endif" >> "$tmpc"
63 if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
73 printf "checking whether compiler accepts %s... " "$2"
74 echo "typedef int x;" > "$tmpc"
75 if $CC "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
77 eval "$1=\"\${$1} \$2\""
87 printf "checking whether linker accepts %s... " "$2"
88 echo "typedef int x;" > "$tmpc"
89 if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
91 eval "$1=\"\${$1} \$2\""
102 # Beginning of actual script
107 prefix=/usr/local/musl
108 exec_prefix='$(prefix)'
109 bindir='$(exec_prefix)/bin'
110 libdir='$(prefix)/lib'
111 includedir='$(prefix)/include'
122 --prefix=*) prefix=${arg#*=} ;;
123 --exec-prefix=*) exec_prefix=${arg#*=} ;;
124 --bindir=*) bindir=${arg#*=} ;;
125 --libdir=*) libdir=${arg#*=} ;;
126 --includedir=*) includedir=${arg#*=} ;;
127 --syslibdir=*) syslibdir=${arg#*=} ;;
128 --enable-shared|--enable-shared=yes) shared=yes ;;
129 --disable-shared|--enable-shared=no) shared=no ;;
130 --enable-static|--enable-static=yes) static=yes ;;
131 --disable-static|--enable-static=no) static=no ;;
132 --enable-debug|--enable-debug=yes) debug=yes ;;
133 --disable-debug|--enable-debug=no) debug=no ;;
134 --enable-warnings|--enable-warnings=yes) warnings=yes ;;
135 --disable-warnings|--enable-warnings=no) warnings=no ;;
136 --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
137 --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
138 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
139 --host=*|--target=*) target=${arg#*=} ;;
140 -* ) echo "$0: unknown option $arg" ;;
141 CC=*) CC=${arg#*=} ;;
142 CFLAGS=*) CFLAGS=${arg#*=} ;;
143 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
144 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
145 CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
146 LIBCC=*) LIBCC=${arg#*=} ;;
152 for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
157 # Get a temp filename we can use
161 while : ; do i=$(($i+1))
162 tmpc="./conf$$-$PPID-$i.c"
163 2>|/dev/null > "$tmpc" && break
164 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
167 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
170 # Find a C compiler to use
172 printf "checking for C compiler... "
173 trycc ${CROSS_COMPILE}gcc
174 trycc ${CROSS_COMPILE}c99
175 trycc ${CROSS_COMPILE}cc
177 test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
180 # Only build musl-gcc wrapper if toolchain does not already target musl
182 if test -z "$wrapper" ; then
183 printf "checking whether compiler is gcc... "
184 if fnmatch '*gcc\ version*' "$($CC -v 2>&1)" ; then
186 printf "checking whether to build musl-gcc wrapper... "
189 case "$line" in */ld-musl-*) wrapper=no ;; esac
202 # Find the target architecture
204 printf "checking target system type... "
205 test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
206 printf "%s\n" "$target"
209 # Convert to just ARCH
214 x86_64*) ARCH=x86_64 ;;
215 mips-*|mipsel-*) ARCH=mips ;;
216 microblaze-*) ARCH=microblaze ;;
217 powerpc-*) ARCH=powerpc ;;
218 unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
219 *) fail "$0: unknown or unsupported target \"$target\"" ;;
223 # Try to get a conforming C99 freestanding environment
225 tryflag CFLAGS_C99FSE -std=c99
226 tryflag CFLAGS_C99FSE -nostdinc
227 tryflag CFLAGS_C99FSE -ffreestanding \
228 || tryflag CFLAGS_C99FSE -fno-builtin
229 tryflag CFLAGS_C99FSE -fexcess-precision=standard \
230 || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
231 tryflag CFLAGS_C99FSE -frounding-math
234 # Setup basic default CFLAGS: debug, optimization, and -pipe
236 if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then :
238 tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
240 test "x$debug" = xyes && CFLAGS_AUTO="-g"
241 tryflag CFLAGS_AUTO -pipe
244 # If debugging is disabled, omit frame pointer. Modern GCC does this
245 # anyway on most archs even when debugging is enabled since the frame
246 # pointer is no longer needed for debugging.
248 if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
250 tryflag CFLAGS_AUTO -fomit-frame-pointer
254 # Modern GCC wants to put DWARF tables (used for debugging and
255 # unwinding) in the loaded part of the program where they are
256 # unstrippable. These options force them back to debug sections (and
257 # cause them not to get generated at all if debugging is off).
259 tryflag CFLAGS_AUTO -fno-unwind-tables
260 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
263 # The GNU toolchain defaults to assuming unmarked files need an
264 # executable stack, potentially exposing vulnerabilities in programs
265 # linked with such object files. Fix this.
267 tryflag CFLAGS_AUTO -Wa,--noexecstack
270 # Some optimization levels add bloated alignment that hurt performance
272 tryflag CFLAGS_AUTO -falign-functions=1
273 tryflag CFLAGS_AUTO -falign-labels=1
274 tryflag CFLAGS_AUTO -falign-loops=1
275 tryflag CFLAGS_AUTO -falign-jumps=1
278 # On x86, make sure we don't have incompatible instruction set
279 # extensions enabled by default. This is bad for making static binaries.
280 # We cheat and use i486 rather than i386 because i386 really does not
281 # work anyway (issues with atomic ops).
283 if test "$ARCH" = "i386" ; then
284 fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
285 fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
289 # Even with -std=c99, gcc accepts some constructs which are constraint
290 # violations. We want to treat these as errors regardless of whether
291 # other purely stylistic warnings are enabled -- especially implicit
292 # function declarations, which are a dangerous programming error.
294 tryflag CFLAGS_AUTO -Werror=implicit-function-declaration
295 tryflag CFLAGS_AUTO -Werror=implicit-int
296 tryflag CFLAGS_AUTO -Werror=pointer-sign
297 tryflag CFLAGS_AUTO -Werror=pointer-arith
299 if test "x$warnings" = xyes ; then
300 tryflag CFLAGS_AUTO -Wall
301 tryflag CFLAGS_AUTO -Wcast-align
302 tryflag CFLAGS_AUTO -Wno-parentheses
303 tryflag CFLAGS_AUTO -Wno-uninitialized
304 tryflag CFLAGS_AUTO -Wno-missing-braces
305 tryflag CFLAGS_AUTO -Wno-unused-value
306 tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
307 tryflag CFLAGS_AUTO -Wno-unknown-pragmas
310 # Some patched GCC builds have these defaults messed up...
311 tryflag CFLAGS_AUTO -fno-stack-protector
312 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
314 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
316 tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
317 printf "warning: disabling dynamic linking support\n"
321 # Find compiler runtime library
322 test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
323 test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
324 test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
325 && tryldflag LIBCC "$try_libcc"
326 printf "using compiler runtime libraries: %s\n" "$LIBCC"
328 # Figure out arch variants for archs with variants
330 t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS"
332 if test "$ARCH" = "arm" ; then
333 trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb
334 trycppif __SOFTFP__ "$t" || SUBARCH=${SUBARCH}hf
337 test "$ARCH" = "mips" && trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" \
338 && SUBARCH=${SUBARCH}el
340 test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \
341 && SUBARCH=${SUBARCH}el
344 && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH"
346 printf "creating config.mak... "
348 exec 3>&1 1>config.mak
352 # This version of config.mak was generated by configure
353 # Any changes made here will be lost if configure is re-run
357 exec_prefix = $exec_prefix
360 includedir = $includedir
361 syslibdir = $syslibdir
363 CFLAGS= $CFLAGS_AUTO $CFLAGS
364 CFLAGS_C99FSE = $CFLAGS_C99FSE
366 LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
367 CROSS_COMPILE = $CROSS_COMPILE
370 test "x$static" = xno && echo "STATIC_LIBS ="
371 test "x$shared" = xno && echo "SHARED_LIBS ="
372 test "x$wrapper" = xno && echo "ALL_TOOLS ="
373 test "x$wrapper" = xno && echo "TOOL_LIBS ="