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 if eval "test -z \"\${$1}\"" ; then eval "$1=\$2"
55 else eval "fnmatch '*/' \"\${$1}\"" && eval "$1=\${$1%/}" ; fi
59 printf "checking whether compiler accepts %s... " "$2"
60 echo "typedef int x;" > "$tmpc"
61 if $CC "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
63 eval "$1=\"\${$1} \$2\""
73 printf "checking whether linker accepts %s... " "$2"
74 echo "typedef int x;" > "$tmpc"
75 if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
77 eval "$1=\"\${$1} \$2\""
88 # Beginning of actual script
108 --prefix=*) prefix=${arg#*=} ;;
109 --exec-prefix=*) exec_prefix=${arg#*=} ;;
110 --bindir=*) bindir=${arg#*=} ;;
111 --libdir=*) libdir=${arg#*=} ;;
112 --includedir=*) includedir=${arg#*=} ;;
113 --syslibdir=*) syslibdir=${arg#*=} ;;
114 --enable-shared|--enable-shared=yes) shared=yes ;;
115 --disable-shared|--enable-shared=no) shared=no ;;
116 --enable-static|--enable-static=yes) static=yes ;;
117 --disable-static|--enable-static=no) static=no ;;
118 --enable-debug|--enable-debug=yes) debug=yes ;;
119 --disable-debug|--enable-debug=no) debug=no ;;
120 --enable-warnings|--enable-warnings=yes) warnings=yes ;;
121 --disable-warnings|--enable-warnings=no) warnings=no ;;
122 --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
123 --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
124 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
125 --host=*|--target=*) target=${arg#*=} ;;
126 -* ) echo "$0: unknown option $arg" ;;
127 CC=*) CC=${arg#*=} ;;
128 CFLAGS=*) CFLAGS=${arg#*=} ;;
129 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
130 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
131 CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
132 LIBCC=*) LIBCC=${arg#*=} ;;
138 setdir prefix /usr/local/musl
139 setdir exec_prefix '$(prefix)'
140 setdir bindir '$(exec_prefix)/bin'
141 setdir libdir '$(prefix)/lib'
142 setdir includedir '$(prefix)/include'
143 setdir syslibdir '/lib'
146 # Get a temp filename we can use
150 while : ; do i=$(($i+1))
151 tmpc="./conf$$-$PPID-$i.c"
152 2>/dev/null > "$tmpc" && break
153 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
156 trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
159 # Find a C compiler to use
161 printf "checking for C compiler... "
162 trycc ${CROSS_COMPILE}gcc
163 trycc ${CROSS_COMPILE}c99
164 trycc ${CROSS_COMPILE}cc
166 test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
169 # Only build musl-gcc wrapper if toolchain does not already target musl
171 if test -z "$wrapper" ; then
172 printf "checking whether compiler is gcc... "
173 if fnmatch '*gcc\ version*' "$($CC -v 2>&1)" ; then
175 printf "checking whether to build musl-gcc wrapper... "
178 case "$line" in */ld-musl-*) wrapper=no ;; esac
191 # Find the target architecture
193 printf "checking target system type... "
194 test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown
195 printf "%s\n" "$target"
198 # Convert to just ARCH
203 x86_64*) ARCH=x86_64 ;;
204 mips-*|mipsel-*) ARCH=mips ;;
205 microblaze-*) ARCH=microblaze ;;
206 powerpc-*) ARCH=powerpc ;;
207 unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
208 *) fail "$0: unknown or unsupported target \"$target\"" ;;
212 # Try to get a conforming C99 freestanding environment
214 tryflag CFLAGS_C99FSE -std=c99
215 tryflag CFLAGS_C99FSE -nostdinc
216 tryflag CFLAGS_C99FSE -ffreestanding \
217 || tryflag CFLAGS_C99FSE -fno-builtin
218 tryflag CFLAGS_C99FSE -fexcess-precision=standard \
219 || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; }
220 tryflag CFLAGS_C99FSE -frounding-math
223 # Setup basic default CFLAGS: debug, optimization, and -pipe
225 if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then :
227 tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
229 test "x$debug" = xyes && CFLAGS_AUTO="-g"
230 tryflag CFLAGS_AUTO -pipe
233 # If debugging is disabled, omit frame pointer. Modern GCC does this
234 # anyway on most archs even when debugging is enabled since the frame
235 # pointer is no longer needed for debugging.
237 if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
239 tryflag CFLAGS_AUTO -fomit-frame-pointer
243 # Modern GCC wants to put DWARF tables (used for debugging and
244 # unwinding) in the loaded part of the program where they are
245 # unstrippable. These options force them back to debug sections (and
246 # cause them not to get generated at all if debugging is off).
248 tryflag CFLAGS_AUTO -fno-unwind-tables
249 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
252 # The GNU toolchain defaults to assuming unmarked files need an
253 # executable stack, potentially exposing vulnerabilities in programs
254 # linked with such object files. Fix this.
256 tryflag CFLAGS_AUTO -Wa,--noexecstack
259 # Some optimization levels add bloated alignment that hurt performance
261 tryflag CFLAGS_AUTO -falign-functions=1
262 tryflag CFLAGS_AUTO -falign-labels=1
263 tryflag CFLAGS_AUTO -falign-loops=1
264 tryflag CFLAGS_AUTO -falign-jumps=1
267 # On x86, make sure we don't have incompatible instruction set
268 # extensions enabled by default. This is bad for making static binaries.
269 # We cheat and use i486 rather than i386 because i386 really does not
270 # work anyway (issues with atomic ops).
272 if test "$ARCH" = "i386" ; then
273 fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486
274 fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic
277 if test "x$warnings" = xyes ; then
278 tryflag CFLAGS_AUTO -Wall
279 tryflag CFLAGS_AUTO -Wpointer-arith
280 tryflag CFLAGS_AUTO -Wcast-align
281 tryflag CFLAGS_AUTO -Wno-parentheses
282 tryflag CFLAGS_AUTO -Wno-uninitialized
283 tryflag CFLAGS_AUTO -Wno-missing-braces
284 tryflag CFLAGS_AUTO -Wno-unused-value
285 tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
286 tryflag CFLAGS_AUTO -Wno-unknown-pragmas
289 # Some patched GCC builds have these defaults messed up...
290 tryflag CFLAGS_AUTO -fno-stack-protector
291 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
293 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
295 tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
296 printf "warning: disabling dynamic linking support\n"
300 # Find compiler runtime library
301 test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
302 test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
303 test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \
304 && tryldflag LIBCC "$try_libcc"
305 printf "using compiler runtime libraries: %s\n" "$LIBCC"
308 printf "creating config.mak... "
310 exec 3>&1 1>config.mak
314 # This version of config.mak was generated by configure
315 # Any changes made here will be lost if configure is re-run
318 exec_prefix = $exec_prefix
321 includedir = $includedir
322 syslibdir = $syslibdir
324 CFLAGS= $CFLAGS_AUTO $CFLAGS
325 CFLAGS_C99FSE = $CFLAGS_C99FSE
327 LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
328 CROSS_COMPILE = $CROSS_COMPILE
331 test "x$static" = xno && echo "STATIC_LIBS ="
332 test "x$shared" = xno && echo "SHARED_LIBS ="
333 test "x$wrapper" = xno && echo "ALL_TOOLS ="
334 test "x$wrapper" = xno && echo "TOOL_LIBS ="