2 # Based on the configure script from musl libc, MIT licensed
6 Usage: $0 [OPTION]... [VAR=VALUE]...
8 To assign environment variables (e.g., CC, CFLAGS...), specify them as
9 VAR=VALUE. See below for descriptions of some of the useful variables.
11 Defaults for the options are specified in brackets.
14 --srcdir=DIR source directory [detected]
16 Installation directories:
17 --prefix=PREFIX main installation prefix [/usr/local]
18 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
20 Fine tuning of the installation directories:
21 --bindir=DIR user executables [EPREFIX/bin]
22 --sharedir=DIR share directories [PREFIX/share]
23 --docdir=DIR misc. documentation [PREFIX/share/doc]
24 --mandir=DIR man pages [PREFIX/share/man]
26 Some influential environment variables:
27 CC C compiler command [detected]
28 CFLAGS C compiler flags [-Os -pipe ...]
31 Use these variables to override the choices made by configure.
40 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
43 printf %s
\\n
"$1" |
sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
45 echo () { printf "%s\n" "$*" ; }
46 fail
() { echo "$*" ; exit 1 ; }
47 fnmatch
() { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
48 cmdexists
() { type "$1" >/dev
/null
2>&1 ; }
49 trycc
() { test -z "$CC" && cmdexists
"$1" && CC
=$1 ; }
52 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
56 printf "checking preprocessor condition %s... " "$1"
57 echo "typedef int x;" > "$tmpc"
58 echo "#if $1" >> "$tmpc"
59 echo "#error yes" >> "$tmpc"
60 echo "#endif" >> "$tmpc"
61 if $CC $2 -c -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
71 printf "checking whether compiler accepts %s... " "$2"
72 echo "typedef int x;" > "$tmpc"
73 if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
75 eval "$1=\"\${$1} \$2\""
85 printf "checking whether linker accepts %s... " "$2"
86 echo "typedef int x;" > "$tmpc"
87 if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
89 eval "$1=\"\${$1} \$2\""
98 # Beginning of actual script
106 EXEC_PREFIX
='$(PREFIX)'
107 BINDIR
='$(EXEC_PREFIX)/bin'
108 MANDIR
='$(PREFIX)/share/man'
113 --srcdir=*) SRCDIR
=${arg#*=} ;;
114 --prefix=*) PREFIX
=${arg#*=} ;;
115 --exec-prefix=*) EXEC_PREFIX
=${arg#*=} ;;
116 --bindir=*) BINDIR
=${arg#*=} ;;
117 --sharedir=*) SHAREDIR
=${arg#*=} ;;
118 --docdir=*) DOCDIR
=${arg#*=} ;;
119 --mandir=*) MANDIR
=${arg#*=} ;;
120 --enable-*|
--disable-*|
--with-*|
--without-*|
--*dir
=*|
--build=*) ;;
121 -* ) echo "$0: unknown option $arg" ;;
122 CC
=*) CC
=${arg#*=} ;;
123 CFLAGS
=*) CFLAGS
=${arg#*=} ;;
124 CPPFLAGS
=*) CPPFLAGS
=${arg#*=} ;;
125 LDFLAGS
=*) LDFLAGS
=${arg#*=} ;;
131 for i
in SRCDIR PREFIX EXEC_PREFIX BINDIR MANDIR
; do
136 # Get the source dir for out-of-tree builds
138 if test -z "$SRCDIR" ; then
139 SRCDIR
="${0%/configure}"
142 abs_builddir
="$(pwd)" || fail
"$0: cannot determine working directory"
143 abs_srcdir
="$(cd $SRCDIR && pwd)" || fail
"$0: invalid source directory $SRCDIR"
144 test "$abs_srcdir" = "$abs_builddir" && SRCDIR
=.
145 test "$SRCDIR" != "." -a -f Makefile
-a ! -h Makefile
&& fail
"$0: Makefile already exists in the working directory"
148 # Get a temp filename we can use
152 while : ; do i
=$
(($i+1))
153 tmpc
="./conf$$-$PPID-$i.c"
154 tmpo
="./conf$$-$PPID-$i.o"
155 2>|
/dev
/null
> "$tmpc" && break
156 test "$i" -gt 50 && fail
"$0: cannot create temporary file $tmpc"
159 trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
162 # Find a C compiler to use
164 printf "checking for C compiler... "
169 test -n "$CC" ||
{ echo "$0: cannot find a C compiler" ; exit 1 ; }
171 printf "checking whether C compiler works... "
172 echo "typedef int x;" > "$tmpc"
173 if output
=$
($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
176 printf "no; compiler output follows:\n%s\n" "$output"
181 # Figure out options to force errors on unknown flags.
183 tryflag CFLAGS_TRY
-Werror=unknown-warning-option
184 tryflag CFLAGS_TRY
-Werror=unused-command-line-argument
185 tryldflag LDFLAGS_TRY
-Werror=unknown-warning-option
186 tryldflag LDFLAGS_TRY
-Werror=unused-command-line-argument
188 CFLAGS_STD
="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
189 LDFLAGS_STD
="-lc -lutil"
194 FreeBSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
195 *BSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE" ;;
196 Darwin
) CFLAGS_STD
="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
197 AIX
) CFLAGS_STD
="$CFLAGS_STD -D_ALL_SOURCE" ;;
202 # Try flags to optimize binary size
204 tryflag CFLAGS
-ffunction-sections
205 tryflag CFLAGS
-fdata-sections
206 tryldflag LDFLAGS_AUTO
-Wl,--gc-sections
208 # Try hardening flags
210 tryflag CFLAGS_AUTO
-fstack-protector-all
211 tryldflag LDFLAGS
-Wl,-z,now
212 tryldflag LDFLAGS
-Wl,-z,relro
213 tryldflag LDFLAGS_AUTO
-pie
215 printf "creating config.mk... "
217 cmdline
=$
(quote
"$0")
218 for i
; do cmdline
="$cmdline $(quote "$i")" ; done
220 exec 3>&1 1>config.mk
223 # This version of config.mk was generated by:
225 # Any changes made here will be lost if configure is re-run
228 EXEC_PREFIX = $EXEC_PREFIX
234 CFLAGS_STD = $CFLAGS_STD
235 LDFLAGS_STD = $LDFLAGS_STD
236 CFLAGS_AUTO = $CFLAGS_AUTO
237 LDFLAGS_AUTO = $LDFLAGS_AUTO
238 CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-sign-compare
244 test "$SRCDIR" = "." ||
ln -sf $SRCDIR/Makefile .