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]
27 --enable-curses build with Curses terminal output [yes]
28 --enable-lua build with Lua support [auto]
29 --enable-lpeg-static build with support for statically linked LPeg [auto]
30 --enable-tre build with TRE regex support [auto]
31 --enable-selinux build with SELinux support [auto]
32 --enable-acl build with POSIX ACL support [auto]
33 --enable-help build with built-in help texts [yes]
35 Some influential environment variables:
36 CC C compiler command [detected]
37 CFLAGS C compiler flags [-Os -pipe ...]
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 "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
80 printf "checking whether compiler accepts %s... " "$2"
81 echo "typedef int x;" > "$tmpc"
82 if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$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 $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
98 eval "$1=\"\${$1} \$2\""
107 # Beginning of actual script
115 EXEC_PREFIX
='$(PREFIX)'
116 BINDIR
='$(EXEC_PREFIX)/bin'
117 SHAREDIR
='$(PREFIX)/share'
118 DOCDIR
='$(PREFIX)/share/doc'
119 MANDIR
='$(PREFIX)/share/man'
132 --srcdir=*) SRCDIR
=${arg#*=} ;;
133 --prefix=*) PREFIX
=${arg#*=} ;;
134 --exec-prefix=*) EXEC_PREFIX
=${arg#*=} ;;
135 --bindir=*) BINDIR
=${arg#*=} ;;
136 --sharedir=*) SHAREDIR
=${arg#*=} ;;
137 --docdir=*) DOCDIR
=${arg#*=} ;;
138 --mandir=*) MANDIR
=${arg#*=} ;;
139 --environment-only) environmentonly
=yes ;;
140 --static) static
=yes ;;
141 --enable-help|
--enable-help=yes) help=yes ;;
142 --disable-help|
--enable-help=no
) help=no
;;
143 --enable-curses|
--enable-curses=yes) curses
=yes ;;
144 --disable-curses|
--enable-curses=no
) curses
=no
;;
145 --enable-lua|
--enable-lua=yes) lua
=yes ;;
146 --disable-lua|
--enable-lua=no
) lua
=no
;;
147 --enable-lpeg-static|
--enable-lpeg-static=yes) lpeg
=yes ;;
148 --disable-lpeg-static|
--enable-lpeg-static=no
) lpeg
=no
;;
149 --enable-tre|
--enable-tre=yes) tre
=yes ;;
150 --disable-tre|
--enable-tre=no
) tre
=no
;;
151 --enable-selinux|
--enable-selinux=yes) selinux
=yes ;;
152 --disable-selinux|
--enable-selinux=no
) selinux
=no
;;
153 --enable-acl|
--enable-acl=yes) acl
=yes ;;
154 --disable-acl|
--enable-acl=no
) acl
=no
;;
155 --enable-*|
--disable-*|
--with-*|
--without-*|
--*dir
=*|
--build=*) ;;
156 -* ) echo "$0: unknown option $arg" ;;
157 CC
=*) CC
=${arg#*=} ;;
158 CFLAGS
=*) CFLAGS
=${arg#*=} ;;
159 CPPFLAGS
=*) CPPFLAGS
=${arg#*=} ;;
160 LDFLAGS
=*) LDFLAGS
=${arg#*=} ;;
166 for i
in SRCDIR PREFIX EXEC_PREFIX BINDIR SHAREDIR DOCDIR MANDIR
; do
171 # Get the source dir for out-of-tree builds
173 if test -z "$SRCDIR" ; then
174 SRCDIR
="${0%/configure}"
177 abs_builddir
="$(pwd)" || fail
"$0: cannot determine working directory"
178 abs_srcdir
="$(cd $SRCDIR && pwd)" || fail
"$0: invalid source directory $SRCDIR"
179 test "$abs_srcdir" = "$abs_builddir" && SRCDIR
=.
180 test "$SRCDIR" != "." -a -f Makefile
-a ! -h Makefile
&& fail
"$0: Makefile already exists in the working directory"
183 # Get a temp filename we can use
187 while : ; do i
=$
(($i+1))
188 tmpc
="./conf$$-$PPID-$i.c"
189 tmpo
="./conf$$-$PPID-$i.o"
190 2>|
/dev
/null
> "$tmpc" && break
191 test "$i" -gt 50 && fail
"$0: cannot create temporary file $tmpc"
194 trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
197 # Find a C compiler to use
199 printf "checking for C compiler... "
204 test -n "$CC" ||
{ echo "$0: cannot find a C compiler" ; exit 1 ; }
206 printf "checking whether C compiler works... "
207 echo "typedef int x;" > "$tmpc"
208 if output
=$
($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
211 printf "no; compiler output follows:\n%s\n" "$output"
216 # Figure out options to force errors on unknown flags.
218 tryflag CFLAGS_TRY
-Werror=unknown-warning-option
219 tryflag CFLAGS_TRY
-Werror=unused-command-line-argument
220 tryldflag LDFLAGS_TRY
-Werror=unknown-warning-option
221 tryldflag LDFLAGS_TRY
-Werror=unused-command-line-argument
223 CFLAGS_STD
="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
229 FreeBSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
230 *BSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE" ;;
231 Darwin
) CFLAGS_STD
="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
232 AIX
) CFLAGS_STD
="$CFLAGS_STD -D_ALL_SOURCE" ;;
237 # Try flags to optimize binary size
239 tryflag CFLAGS
-ffunction-sections
240 tryflag CFLAGS
-fdata-sections
241 tryldflag LDFLAGS_AUTO
-Wl,--gc-sections
243 # Try hardening flags
245 tryflag CFLAGS_AUTO
-fstack-protector-all
246 tryldflag LDFLAGS
-Wl,-z,now
247 tryldflag LDFLAGS
-Wl,-z,relro
248 # in theory it should be perfectly fine to produce a staticically linked PIE
249 # however in practice it is not yet properly supported by gcc:
251 # cc -fPIE -pie --static
253 # will always add a PT_INTERP referencing the dynamic loader/linker
254 if test "$static" != "yes" || tryldflag LDFLAGS_AUTO
-Wl,--no-dynamic-linker ; then
255 tryldflag LDFLAGS_AUTO
-pie
258 printf "creating config.mk... "
260 cmdline
=$
(quote
"$0")
261 for i
; do cmdline
="$cmdline $(quote "$i")" ; done
263 exec 3>&1 1>config.mk
266 # This version of config.mk was generated by:
268 # Any changes made here will be lost if configure is re-run
271 EXEC_PREFIX = $EXEC_PREFIX
275 SHAREPREFIX = $SHAREDIR
279 CFLAGS_STD = $CFLAGS_STD
280 LDFLAGS_STD = $LDFLAGS_STD
281 CFLAGS_AUTO = $CFLAGS_AUTO
282 LDFLAGS_AUTO = $LDFLAGS_AUTO
283 CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-missing-field-initializers -Wno-unused-parameter
289 if test "$environmentonly" = "yes"; then
294 printf "checking for pkg-config... "
295 cmdexists pkg-config
&& have_pkgconfig
=yes
296 printf "%s\n" "$have_pkgconfig"
298 if test "$help" = "yes" ; then
306 if test "$curses" != "no" ; then
308 printf "checking for libcurses...\n"
313 int main(int argc, char *argv[]) {
320 for libcurses
in ncursesw ncurses libcurses
; do
321 printf " checking for %s... " "$libcurses"
323 if test "$have_pkgconfig" = "yes" ; then
324 CFLAGS_CURSES
=$
(pkg-config
--cflags $libcurses 2>/dev
/null
)
325 LDFLAGS_CURSES
=$
(pkg-config
--libs $libcurses 2>/dev
/null
)
326 if test $?
-eq 0 && $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
327 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev
/null
2>&1 ; then
335 LDFLAGS_CURSES
="-l$libcurses"
337 if $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
338 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev
/null
2>&1 ; then
349 test "$curses" = "yes" -a $CONFIG_CURSES -ne 1 && fail
"$0: cannot find libcurses"
352 # libtermkey is a mandatory dependency
354 printf "checking for libtermkey... "
358 int main(int argc, char *argv[]) {
359 TERMKEY_CHECK_VERSION;
364 if test "$have_pkgconfig" = "yes" ; then
365 CFLAGS_TERMKEY
=$
(pkg-config
--cflags termkey
2>/dev
/null
)
366 LDFLAGS_TERMKEY
=$
(pkg-config
--libs termkey
2>/dev
/null
)
369 if test -z "$LDFLAGS_TERMKEY"; then
371 LDFLAGS_TERMKEY
="-ltermkey -lncursesw"
374 if $CC $CFLAGS $CFLAGS_TERMKEY "$tmpc" $LDFLAGS $LDFLAGS_TERMKEY $LDFLAGS_CURSES \
375 -o "$tmpo" >/dev
/null
2>&1; then
379 fail
"$0: cannot find libtermkey"
383 REGEX_SRC
=text-regex.c
385 if test "$tre" != "no" ; then
387 printf "checking for libtre... "
394 tre_str_source *source = NULL;
395 regmatch_t pmatch[1];
396 tre_regcomp(&preg, "\0", REG_EXTENDED);
397 tre_reguexec(&preg, source, 1, pmatch, 0);
403 if test "$have_pkgconfig" = "yes" ; then
404 CFLAGS_TRE
=$
(pkg-config
--cflags tre
2>/dev
/null
)
405 LDFLAGS_TRE
=$
(pkg-config
--libs tre
2>/dev
/null
)
408 if test -z "$LDFLAGS_TRE"; then
413 if $CC $CFLAGS $CFLAGS_TRE "$tmpc" \
414 $LDFLAGS $LDFLAGS_TRE -o "$tmpo" >/dev
/null
2>&1; then
416 REGEX_SRC
=text-regex-tre.c
422 test "$tre" = "yes" && fail
"$0: cannot find libtre"
428 # enabling builtin lpeg requires lua support
429 test "$lpeg" = "yes" -a "$lua" = "no" && fail
"$0: need lua support for built-in lpeg"
430 test "$lpeg" = "yes" && lua
=yes
432 if test "$lua" != "no" ; then
434 printf "checking for liblua >= 5.2 ...\n"
440 #if LUA_VERSION_NUM < 502
441 #error "Need at least Lua 5.2"
444 int main(int argc, char *argv[]) {
445 lua_State *L = luaL_newstate();
452 for liblua
in lua lua5.3 lua5.2 lua-5.3 lua-5.2 lua53 lua52
; do
453 printf " checking for %s... " "$liblua"
455 if test "$have_pkgconfig" = "yes" ; then
456 CFLAGS_LUA
=$
(pkg-config
--cflags $liblua 2>/dev
/null
)
457 LDFLAGS_LUA
=$
(pkg-config
--libs $liblua 2>/dev
/null
)
458 if test $?
-eq 0 && $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
459 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev
/null
2>&1 ; then
467 LDFLAGS_LUA
="-l$liblua -lm -ldl"
469 if $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
470 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev
/null
2>&1 ; then
481 test "$lua" = "yes" -a $CONFIG_LUA -ne 1 && fail
"$0: cannot find liblua"
483 if test $CONFIG_LUA -eq 1; then
484 CFLAGS_LUA
="$CFLAGS_LUA -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL"
490 if test $CONFIG_LUA -eq 1 -a "$lpeg" != "no" ; then
492 printf "checking for statically linked liblpeg ... "
498 int main(int argc, char *argv[]) {
499 lua_State *L = luaL_newstate();
501 extern int luaopen_lpeg(lua_State *L);
502 lua_getglobal(L, "package");
503 lua_getfield(L, -1, "preload");
504 lua_pushcfunction(L, luaopen_lpeg);
505 lua_setfield(L, -2, "lpeg");
513 LDFLAGS_LPEG
="-llpeg"
515 if $CC $CFLAGS $CFLAGS_LUA $CFLAGS_LPEG "$tmpc" \
516 $LDFLAGS $LDFLAGS_LUA $LDFLAGS_LPEG -o "$tmpo" >/dev
/null
2>&1 ; then
526 test "$lpeg" = "yes" -a $CONFIG_LPEG -ne 1 && fail
"$0: cannot find liblpeg"
531 if test "$OS" = "Linux" -a "$acl" != "no"; then
532 printf "checking for libacl... "
535 #include <sys/types.h>
538 int main(int argc, char *argv[]) {
539 acl_t acl = acl_get_fd(0);
544 if test "$have_pkgconfig" = "yes" ; then
545 CFLAGS_ACL
=$
(pkg-config
--cflags acl
2>/dev
/null
)
546 LDFLAGS_ACL
=$
(pkg-config
--libs acl
2>/dev
/null
)
549 if test -z "$LDFLAGS_ACL"; then
554 if $CC $CFLAGS $CFLAGS_ACL "$tmpc" \
555 $LDFLAGS $LDFLAGS_ACL -o "$tmpo" >/dev
/null
2>&1; then
562 test "$acl" = "yes" && fail
"$0: cannot find libacl"
568 if test "$OS" = "Linux" -a "$selinux" != "no"; then
569 printf "checking for libselinux... "
572 #include <selinux/selinux.h>
574 int main(int argc, char *argv[]) {
575 return is_selinux_enabled();
579 if test "$have_pkgconfig" = "yes" ; then
580 CFLAGS_SELINUX
=$
(pkg-config
--cflags selinux
2>/dev
/null
)
581 LDFLAGS_SELINUX
=$
(pkg-config
--libs selinux
2>/dev
/null
)
584 if test -z "$LDFLAGS_SELINUX"; then
586 LDFLAGS_SELINUX
="-lselinux"
589 if $CC $CFLAGS $CFLAGS_SELINUX "$tmpc" \
590 $LDFLAGS $LDFLAGS_SELINUX -o "$tmpo" >/dev
/null
2>&1; then
597 test "$selinux" = "yes" && fail
"$0: cannot find libselinux"
601 printf "checking for memrchr... "
607 int main(int argc, char *argv[]) {
608 return !memrchr("\n", '\n', 1);
612 if $CC $CFLAGS "$tmpc" $LDFLAGS -o "$tmpo" >/dev
/null
2>&1; then
620 printf "completing config.mk... "
622 exec 3>&1 1>>config.mk
625 CONFIG_HELP = $CONFIG_HELP
626 CFLAGS_TERMKEY = $CFLAGS_TERMKEY
627 LDFLAGS_TERMKEY = $LDFLAGS_TERMKEY
628 CONFIG_CURSES = $CONFIG_CURSES
629 CFLAGS_CURSES = $CFLAGS_CURSES
630 LDFLAGS_CURSES = $LDFLAGS_CURSES
631 REGEX_SRC = $REGEX_SRC
632 CONFIG_TRE = $CONFIG_TRE
633 CFLAGS_TRE = $CFLAGS_TRE
634 LDFLAGS_TRE = $LDFLAGS_TRE
635 CONFIG_LUA = $CONFIG_LUA
636 CFLAGS_LUA = $CFLAGS_LUA
637 LDFLAGS_LUA = $LDFLAGS_LUA
638 CONFIG_LPEG = $CONFIG_LPEG
639 CFLAGS_LPEG = $CFLAGS_LPEG
640 LDFLAGS_LPEG = $LDFLAGS_LPEG
641 CONFIG_ACL = $CONFIG_ACL
642 CFLAGS_ACL = $CFLAGS_ACL
643 LDFLAGS_ACL = $LDFLAGS_ACL
644 CONFIG_SELINUX = $CONFIG_SELINUX
645 CFLAGS_SELINUX = $CFLAGS_SELINUX
646 LDFLAGS_SELINUX = $LDFLAGS_SELINUX
647 CFLAGS_LIBC = -DHAVE_MEMRCHR=$HAVE_MEMRCHR
651 test "$SRCDIR" = "." ||
ln -sf $SRCDIR/Makefile .